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

device: add reasonable defaults for reset/recovery

This commit is contained in:
matejcik 2018-11-23 14:43:13 +01:00
parent 40eaa1fa36
commit eb50d54ec2
2 changed files with 45 additions and 36 deletions

View File

@ -441,22 +441,20 @@ def recovery_device(
return device.recover(
connect(),
int(words),
passphrase_protection,
pin_protection,
label,
"english",
input_callback,
rec_type,
dry_run,
word_count=int(words),
passphrase_protection=passphrase_protection,
pin_protection=pin_protection,
label=label,
language="english",
input_callback=input_callback,
type=rec_type,
dry_run=dry_run,
)
@cli.command(help="Perform device setup and generate new seed.")
@click.option("-e", "--entropy", is_flag=True)
@click.option(
"-t", "--strength", type=click.Choice(["128", "192", "256"]), default="256"
)
@click.option("-e", "--show-entropy", is_flag=True)
@click.option("-t", "--strength", type=click.Choice(["128", "192", "256"]))
@click.option("-r", "--passphrase-protection", is_flag=True)
@click.option("-p", "--pin-protection", is_flag=True)
@click.option("-l", "--label")
@ -466,7 +464,7 @@ def recovery_device(
@click.pass_obj
def reset_device(
connect,
entropy,
show_entropy,
strength,
passphrase_protection,
pin_protection,
@ -475,17 +473,19 @@ def reset_device(
skip_backup,
no_backup,
):
if strength:
strength = int(strength)
return device.reset(
connect(),
entropy,
int(strength),
passphrase_protection,
pin_protection,
label,
"english",
u2f_counter,
skip_backup,
no_backup,
display_random=show_entropy,
strength=strength,
passphrase_protection=passphrase_protection,
pin_protection=pin_protection,
label=label,
language="english",
u2f_counter=u2f_counter,
skip_backup=skip_backup,
no_backup=no_backup,
)

View File

@ -102,15 +102,18 @@ def wipe(client):
@expect(proto.Success, field="message")
def recover(
client,
word_count,
passphrase_protection,
pin_protection,
label,
language,
input_callback,
word_count=24,
passphrase_protection=False,
pin_protection=True,
label=None,
language="english",
input_callback=None,
type=proto.RecoveryDeviceType.ScrambledWords,
dry_run=False,
):
if client.features.model == "1" and input_callback is None:
raise RuntimeError("Input callback required for Trezor One")
if word_count not in (12, 18, 24):
raise ValueError("Invalid word count. Use 12/18/24")
@ -121,7 +124,7 @@ def recover(
res = client.call(
proto.RecoveryDevice(
word_count=int(word_count),
word_count=word_count,
passphrase_protection=bool(passphrase_protection),
pin_protection=bool(pin_protection),
label=label,
@ -147,12 +150,12 @@ def recover(
@session
def reset(
client,
display_random,
strength,
passphrase_protection,
pin_protection,
label,
language,
display_random=False,
strength=None,
passphrase_protection=False,
pin_protection=True,
label=None,
language="english",
u2f_counter=0,
skip_backup=False,
no_backup=False,
@ -162,9 +165,15 @@ def reset(
"Device is initialized already. Call wipe_device() and try again."
)
if strength is None:
if client.features.model == "1":
strength = 256
else:
strength = 128
# Begin with device reset workflow
msg = proto.ResetDevice(
display_random=display_random,
display_random=bool(display_random),
strength=strength,
passphrase_protection=bool(passphrase_protection),
pin_protection=bool(pin_protection),