1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-05-21 16:28:46 +00:00

rework signer to consume secexp format as well

This commit is contained in:
Pavol Rusnak 2015-03-02 19:16:45 +01:00
parent 6dd6deb2ad
commit 6eb2933bfe

View File

@ -56,10 +56,11 @@ def compose_message(json, proto):
return cfg.SerializeToString() return cfg.SerializeToString()
def sign_message(data, key_pem): def sign_message(data, key):
# curve = ecdsa.curves.SECP256k1 if key.startswith('-----BEGIN'):
# x = ecdsa.keys.SigningKey.generate(curve=curve) key = ecdsa.keys.SigningKey.from_pem(key)
key = ecdsa.keys.SigningKey.from_pem(key_pem) else:
key = ecdsa.keys.SigningKey.from_secret_exponent(secexp = int(key, 16), curve=ecdsa.curves.SECP256k1, hashfunc=hashlib.sha256)
verify = key.get_verifying_key() verify = key.get_verifying_key()
print "Verifying key:" print "Verifying key:"
@ -79,22 +80,22 @@ def pack_datafile(filename, signature, data):
print "Signature and data stored to", filename print "Signature and data stored to", filename
if __name__ == '__main__': if __name__ == '__main__':
key_pem = '' key = ''
print "Paste ECDSA private key (in PEM format) and press Enter:" print "Paste ECDSA private key (in PEM format or SECEXP format) and press Enter:"
while True: while True:
inp = raw_input() inp = raw_input()
if inp == '': if inp == '':
break break
key_pem += inp + "\n" key += inp + "\n"
# key_pem = open('sample.key', 'r').read() # key = open('sample.key', 'r').read()
compile_config() compile_config()
json = parse_json() json = parse_json()
proto = get_compiled_proto() proto = get_compiled_proto()
data = compose_message(json, proto) data = compose_message(json, proto)
signature = sign_message(data, key_pem) signature = sign_message(data, key)
pack_datafile('config_signed.bin', signature, data) pack_datafile('config_signed.bin', signature, data)