@@ -99,14 +99,16 @@ def save_signature(sigfile, sig):
99
99
f .write (signature )
100
100
101
101
102
- def load_key (keyfile ):
102
+ def load_key (keyfile , passwd = None ):
103
103
# TODO: better handling of invalid pass-phrase
104
104
key = keys .load (keyfile )
105
105
if key is not None :
106
106
return key
107
- passwd = getpass .getpass ("Enter key passphrase: " ).encode ('utf-8' )
108
- return keys .load (keyfile , passwd )
109
107
108
+ if passwd is None :
109
+ passwd = getpass .getpass ("Enter key passphrase: " )
110
+
111
+ return keys .load (keyfile , passwd .encode ('utf-8' ))
110
112
111
113
def get_password ():
112
114
while True :
@@ -423,6 +425,7 @@ def convert(self, value, param, ctx):
423
425
default = 'hash' , help = 'In what format to add the public key to '
424
426
'the image manifest: full key or hash of the key.' )
425
427
@click .option ('-k' , '--key' , metavar = 'filename' )
428
+ @click .option ('--key-pswd' , required = False , help = 'Password for the key file' )
426
429
@click .option ('--fix-sig' , metavar = 'filename' ,
427
430
help = 'fixed signature for the image. It will be used instead of '
428
431
'the signature calculated using the public key' )
@@ -447,7 +450,7 @@ def convert(self, value, param, ctx):
447
450
@click .command (help = '''Create a signed or unsigned image\n
448
451
INFILE and OUTFILE are parsed as Intel HEX if the params have
449
452
.hex extension, otherwise binary format is used''' )
450
- def sign (key , public_key_format , align , version , pad_sig , header_size ,
453
+ def sign (key , key_pswd , public_key_format , align , version , pad_sig , header_size ,
451
454
pad_header , slot_size , pad , confirm , max_sectors , overwrite_only ,
452
455
endian , encrypt_keylen , encrypt , compression , infile , outfile ,
453
456
dependencies , load_addr , hex_addr , erased_val , save_enctlv ,
@@ -469,7 +472,7 @@ def sign(key, public_key_format, align, version, pad_sig, header_size,
469
472
non_bootable = non_bootable )
470
473
compression_tlvs = {}
471
474
img .load (infile )
472
- key = load_key (key ) if key else None
475
+ key = load_key (key , passwd = key_pswd ) if key else None
473
476
enckey = load_key (encrypt ) if encrypt else None
474
477
if enckey and key :
475
478
if ((isinstance (key , keys .ECDSA256P1 ) and
0 commit comments