From: Emanuele Giuseppe Esposito Date: Tue, 26 Sep 2023 16:04:01 +0000 (-0400) Subject: ukify: automatically infer --signtool from the parameters given X-Git-Tag: v255-rc1~118^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5c52078162f0c83cdbb5e0bdade9a4677982f394;p=thirdparty%2Fsystemd.git ukify: automatically infer --signtool from the parameters given --signtool is actually useless: it can be inferred depending on if --secureboot-certificate-name (pesign) is given, or --secureboot-private-key and --secureboot-certificate (sbsign) is given. Leave the option just for backwards compatibility. --- diff --git a/src/ukify/ukify.py b/src/ukify/ukify.py index 432dc87988d..40550e8c541 100755 --- a/src/ukify/ukify.py +++ b/src/ukify/ukify.py @@ -1277,8 +1277,9 @@ CONFIG_ITEMS = [ '--signtool', choices = ('sbsign', 'pesign'), dest = 'signtool', - default = 'sbsign', - help = 'whether to use sbsign or pesign. Default is sbsign.', + help = 'whether to use sbsign or pesign. It will also be inferred by the other \ + parameters given: when using --secureboot-{private-key/certificate}, sbsign \ + will be used, otherwise pesign will be used', config_key = 'UKI/SecureBootSigningTool', ), ConfigItem( @@ -1571,12 +1572,19 @@ def finalize_options(opts): if opts.sb_cert: opts.sb_cert = pathlib.Path(opts.sb_cert) - if opts.signtool == 'sbsign': - if bool(opts.sb_key) ^ bool(opts.sb_cert): - raise ValueError('--secureboot-private-key= and --secureboot-certificate= must be specified together when using --signtool=sbsign') - else: - if not bool(opts.sb_cert_name): - raise ValueError('--secureboot-certificate-name must be specified when using --signtool=pesign') + if bool(opts.sb_key) ^ bool(opts.sb_cert): + # one param only given, sbsign need boths + raise ValueError('--secureboot-private-key= and --secureboot-certificate= must be specified together') + elif bool(opts.sb_key) and bool(opts.sb_cert): + # both param given, infer sbsign and in case it was given, ensure signtool=sbsign + if opts.signtool and opts.signtool != 'sbsign': + raise ValueError(f'Cannot provide --signtool={opts.signtool} with --secureboot-private-key= and --secureboot-certificate=') + opts.signtool = 'sbsign' + elif bool(opts.sb_cert_name): + # sb_cert_name given, infer pesign and in case it was given, ensure signtool=pesign + if opts.signtool and opts.signtool != 'pesign': + raise ValueError(f'Cannot provide --signtool={opts.signtool} with --secureboot-certificate-name=') + opts.signtool = 'pesign' if opts.sign_kernel and not opts.sb_key and not opts.sb_cert_name: raise ValueError('--sign-kernel requires either --secureboot-private-key= and --secureboot-certificate= (for sbsign) or --secureboot-certificate-name= (for pesign) to be specified')