1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-26 09:28:13 +00:00

trezorctl: firmware tweaks, add dry_run mode

This commit is contained in:
matejcik 2019-02-26 14:07:45 +01:00
parent 302f2589a0
commit fa5734a2a8

View File

@ -545,7 +545,7 @@ def validate_firmware(version, fw, expected_fingerprint=None):
_print_version(fw.firmware_header.version) _print_version(fw.firmware_header.version)
try: try:
firmware.validate(version, fw) firmware.validate(version, fw, allow_unsigned=False)
click.echo("Signatures are valid.") click.echo("Signatures are valid.")
except firmware.Unsigned: except firmware.Unsigned:
if not click.confirm("No signatures found. Continue?", default=False): if not click.confirm("No signatures found. Continue?", default=False):
@ -633,13 +633,22 @@ def find_best_firmware_version(bootloader_version, requested_version=None):
@click.option("-u", "--url") @click.option("-u", "--url")
@click.option("-v", "--version") @click.option("-v", "--version")
@click.option("-s", "--skip-check", is_flag=True, help="Do not validate firmware integrity") @click.option("-s", "--skip-check", is_flag=True, help="Do not validate firmware integrity")
@click.option("-n", "--dry-run", is_flag=True, help="Perform all steps but do not actually upload the firmware")
@click.option("--raw", is_flag=True, help="Push raw data to Trezor") @click.option("--raw", is_flag=True, help="Push raw data to Trezor")
@click.option("--fingerprint", help="Expected firmware fingerprint in hex") @click.option("--fingerprint", help="Expected firmware fingerprint in hex")
@click.option("--skip-vendor-header", help="Skip vendor header validation on Trezor T") @click.option("--skip-vendor-header", help="Skip vendor header validation on Trezor T")
# fmt: on # fmt: on
@click.pass_obj @click.pass_obj
def firmware_update( def firmware_update(
connect, filename, url, version, skip_check, fingerprint, skip_vendor_header, raw connect,
filename,
url,
version,
skip_check,
fingerprint,
skip_vendor_header,
raw,
dry_run,
): ):
"""Upload new firmware to device. """Upload new firmware to device.
@ -662,7 +671,7 @@ def firmware_update(
sys.exit(1) sys.exit(1)
client = connect() client = connect()
if not client.features.bootloader_mode: if not dry_run and not client.features.bootloader_mode:
click.echo("Please switch your device to bootloader mode.") click.echo("Please switch your device to bootloader mode.")
sys.exit(1) sys.exit(1)
@ -714,8 +723,12 @@ def firmware_update(
# for bootloader < 1.8, keep the embedding # for bootloader < 1.8, keep the embedding
# for bootloader 1.8.0 and up, strip the old OneV1 header # for bootloader 1.8.0 and up, strip the old OneV1 header
if bootloader_onev2 and data[:4] == b"TRZR" and data[256 : 256 + 4] == b"TRZF": if bootloader_onev2 and data[:4] == b"TRZR" and data[256 : 256 + 4] == b"TRZF":
click.echo("Extracting embedded firmware image (fingerprint may change).")
data = data[256:] data = data[256:]
if dry_run:
click.echo("Dry run. Not uploading firmware to device.")
else:
try: try:
if f.major_version == 1 and f.firmware_present: if f.major_version == 1 and f.firmware_present:
# Trezor One does not send ButtonRequest # Trezor One does not send ButtonRequest