1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-25 15:58:08 +00:00

core/tools: pass fw instance properly in keyctl-proxy

This commit is contained in:
matejcik 2020-01-06 16:05:14 +01:00 committed by Pavol Rusnak
parent 388843f772
commit e9c68d7397
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

View File

@ -93,10 +93,10 @@ class KeyctlProxy:
@click.option( @click.option(
"-l", "--listen", "ipaddr", default="0.0.0.0", help="Bind to particular ip address" "-l", "--listen", "ipaddr", default="0.0.0.0", help="Bind to particular ip address"
) )
@click.option("-t", "--header-type", type=click.Choice(indexmap.keys())) @click.option("-t", "--header-type", "fw_or_type", type=click.Choice(indexmap.keys()))
@click.option("-d", "--digest") @click.option("-d", "--digest")
@click.argument("fw_file", type=click.File("rb"), required=False) @click.argument("fw_file", type=click.File("rb"), required=False)
def cli(ipaddr, fw_file, header_type, digest): def cli(ipaddr, fw_file, fw_or_type, digest):
"""Participate in signing of firmware. """Participate in signing of firmware.
Specify either fw_file to auto-detect type and digest, or use -t and -d to specify Specify either fw_file to auto-detect type and digest, or use -t and -d to specify
@ -104,20 +104,20 @@ def cli(ipaddr, fw_file, header_type, digest):
""" """
public_keys = None public_keys = None
if fw_file: if fw_file:
if header_type or digest: if fw_or_type or digest:
raise click.ClickException("Do not specify fw_file together with -t/-d") raise click.ClickException("Do not specify fw_file together with -t/-d")
fw = parse_image(fw_file.read()) fw_or_type = parse_image(fw_file.read())
digest = fw.digest() digest = fw_or_type.digest()
public_keys = fw.public_keys public_keys = fw_or_type.public_keys
click.echo(fw.format()) click.echo(fw_or_type.format())
if not fw_file and (not header_type or not digest): if not fw_file and (not fw_or_type or not digest):
raise click.ClickException("Please specify either fw_file or -t and -h") raise click.ClickException("Please specify either fw_file or -t and -h")
while True: while True:
pubkey, R = make_commit(header_type.BIP32_INDEX, digest) pubkey, R = make_commit(fw_or_type.NAME, fw_or_type.BIP32_INDEX, digest)
if public_keys is not None and pubkey not in public_keys: if public_keys is not None and pubkey not in public_keys:
click.echo(f"\n\nPublic key {pubkey.hex()} is unknown.") click.echo(f"\n\nPublic key {pubkey.hex()} is unknown.")
if click.confirm("Retry with a different passphrase?"): if click.confirm("Retry with a different passphrase?"):
@ -125,7 +125,7 @@ def cli(ipaddr, fw_file, header_type, digest):
break break
daemon = Pyro4.Daemon(host=ipaddr, port=PORT) daemon = Pyro4.Daemon(host=ipaddr, port=PORT)
proxy = KeyctlProxy(header_type, digest, (pubkey, R)) proxy = KeyctlProxy(fw_or_type, digest, (pubkey, R))
uri = daemon.register(proxy, "keyctl") uri = daemon.register(proxy, "keyctl")
click.echo(f"keyctl-proxy running at URI: {uri}") click.echo(f"keyctl-proxy running at URI: {uri}")
click.echo("Press Ctrl+C to abort.") click.echo("Press Ctrl+C to abort.")