1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-01-29 08:40:57 +00:00

feat(trezorctl): Add firmware get-hash command.

This commit is contained in:
Andrew Kozlik 2022-04-23 00:19:07 +02:00 committed by Martin Milata
parent 106ab65e21
commit e43c14f448
3 changed files with 16 additions and 1 deletions

View File

@ -0,0 +1 @@
Add firmware get-hash command.

View File

@ -590,3 +590,12 @@ def update(
click.echo("Dry run. Not uploading firmware to device.")
else:
upload_firmware_into_device(client=client, firmware_data=firmware_data)
@cli.command()
@click.argument("hex_challenge", required=False)
@with_client
def get_hash(client: "TrezorClient", hex_challenge: Optional[str]) -> str:
"""Get a hash of the installed firmware combined with the optional challenge."""
challenge = bytes.fromhex(hex_challenge) if hex_challenge else None
return firmware.get_hash(client, challenge).hex()

View File

@ -23,7 +23,7 @@ import construct as c
import ecdsa
from . import cosi, messages
from .tools import session
from .tools import expect, session
if TYPE_CHECKING:
from .client import TrezorClient
@ -518,3 +518,8 @@ def update(
return
else:
raise RuntimeError(f"Unexpected message {resp}")
@expect(messages.FirmwareHash, field="hash", ret_type=bytes)
def get_hash(client: "TrezorClient", challenge: Optional[bytes]):
return client.call(messages.GetFirmwareHash(challenge=challenge))