1#! /usr/bin/env python3
3"""Manage external signature requests
5@contact: Debian FTPMaster <ftpmaster@debian.org>
6@copyright: 2018, Ansgar Burchardt <ansgar@debian.org>
8"""
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.
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.
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
24################################################################################
26import sys
28import apt_pkg
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)
38################################################################################
40Options = None
41Logger = None
43################################################################################
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.
52 -h, --help show this help and exit"""
53 )
55 sys.exit(exit_code)
58################################################################################
61def main():
62 global Options, Logger
64 cnf = Config()
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] = ""
71 Arguments = [("h", "help", "Manage-External-Signature-Requests::Options::Help")]
73 apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)
74 Options = cnf.subtree("Manage-External-Signature-Requests::Options")
76 if Options["Help"]:
77 usage()
79 Logger = daklog.Logger("manage-external-signature-requests")
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
85 config = cnf.subtree("External-Signature-Requests")
87 session = DBConn().session()
89 export_external_signature_requests(session, config["Export"])
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 )
102 session.close()
104 Logger.close()
107#######################################################################################
110if __name__ == "__main__":
111 main()