1#! /usr/bin/env python3 

2 

3"""Manage external signature requests 

4 

5@contact: Debian FTPMaster <ftpmaster@debian.org> 

6@copyright: 2018, Ansgar Burchardt <ansgar@debian.org> 

7 

8""" 

9 

10# This program is free software; you can redistribute it and/or modify 

11# it under the terms of the GNU General Public License as published by 

12# the Free Software Foundation; either version 2 of the License, or 

13# (at your option) any later version. 

14 

15# This program is distributed in the hope that it will be useful, 

16# but WITHOUT ANY WARRANTY; without even the implied warranty of 

17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

18# GNU General Public License for more details. 

19 

20# You should have received a copy of the GNU General Public License 

21# along with this program; if not, write to the Free Software 

22# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 

23 

24################################################################################ 

25 

26import sys 

27 

28import apt_pkg 

29 

30from daklib import daklog 

31from daklib.config import Config 

32from daklib.dbconn import DBConn 

33from daklib.externalsignature import ( 

34 export_external_signature_requests, 

35 sign_external_signature_requests, 

36) 

37 

38################################################################################ 

39 

40Options = None 

41Logger = None 

42 

43################################################################################ 

44 

45 

46def usage(exit_code=0): 

47 print( 

48 """Usage: dak manage-external-signature-requests [OPTIONS] 

49Manage external signature requests such as requests to sign EFI binaries or 

50kernel modules. 

51 

52 -h, --help show this help and exit""" 

53 ) 

54 

55 sys.exit(exit_code) 

56 

57 

58################################################################################ 

59 

60 

61def main(): 

62 global Options, Logger 

63 

64 cnf = Config() 

65 

66 for i in ["Help"]: 

67 key = "Manage-External-Signature-Requests::Options::{}".format(i) 

68 if key not in cnf: 68 ↛ 66line 68 didn't jump to line 66, because the condition on line 68 was never false

69 cnf[key] = "" 

70 

71 Arguments = [("h", "help", "Manage-External-Signature-Requests::Options::Help")] 

72 

73 apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv) 

74 Options = cnf.subtree("Manage-External-Signature-Requests::Options") 

75 

76 if Options["Help"]: 

77 usage() 

78 

79 Logger = daklog.Logger("manage-external-signature-requests") 

80 

81 if "External-Signature-Requests" not in cnf: 81 ↛ 82line 81 didn't jump to line 82, because the condition on line 81 was never true

82 print("DAK not configured to handle external signature requests") 

83 return 

84 

85 config = cnf.subtree("External-Signature-Requests") 

86 

87 session = DBConn().session() 

88 

89 export_external_signature_requests(session, config["Export"]) 

90 

91 if "ExportSigningKeys" in config: 91 ↛ 92line 91 didn't jump to line 92

92 args = { 

93 "pubring": cnf.get("Dinstall::SigningPubKeyring") or None, 

94 "secring": cnf.get("Dinstall::SigningKeyring") or None, 

95 "homedir": cnf.get("Dinstall::SigningHomedir") or None, 

96 "passphrase_file": cnf.get("Dinstall::SigningPassphraseFile") or None, 

97 } 

98 sign_external_signature_requests( 

99 session, config["Export"], config.value_list("ExportSigningKeys"), args 

100 ) 

101 

102 session.close() 

103 

104 Logger.close() 

105 

106 

107####################################################################################### 

108 

109 

110if __name__ == "__main__": 

111 main()