mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-16 03:18:09 +00:00
apps/management/reset_device: allow to skip backup
This commit is contained in:
parent
f20ce1fcc9
commit
5a5842111b
@ -12,6 +12,7 @@ _LANGUAGE = const(0x03) # str
|
||||
_LABEL = const(0x04) # str
|
||||
_USE_PASSPHRASE = const(0x05) # 0x01 or empty
|
||||
_HOMESCREEN = const(0x06) # bytes
|
||||
_NEEDS_BACKUP = const(0x07) # 0x01 or empty
|
||||
|
||||
|
||||
def get_device_id() -> str:
|
||||
@ -42,9 +43,13 @@ def get_homescreen() -> bytes:
|
||||
return config.get(_APP, _HOMESCREEN, True) # public
|
||||
|
||||
|
||||
def load_mnemonic(mnemonic: str):
|
||||
config.set(_APP, _VERSION, _STORAGE_VERSION)
|
||||
def load_mnemonic(mnemonic: str, needs_backup: bool):
|
||||
config.set(_APP, _MNEMONIC, mnemonic.encode())
|
||||
config.set(_APP, _VERSION, _STORAGE_VERSION)
|
||||
if needs_backup:
|
||||
config.set(_APP, _NEEDS_BACKUP, b'\x01')
|
||||
else:
|
||||
config.set(_APP, _NEEDS_BACKUP, b'')
|
||||
|
||||
|
||||
def load_settings(label: str=None, use_passphrase: bool=None, homescreen: bytes=None):
|
||||
|
@ -37,10 +37,11 @@ async def reset_device(ctx, msg):
|
||||
FailureType.UnexpectedMessage,
|
||||
'Already initialized')
|
||||
|
||||
# request new PIN
|
||||
if msg.pin_protection:
|
||||
# request new PIN
|
||||
newpin = await request_pin_confirm(ctx)
|
||||
else:
|
||||
# new PIN is empty
|
||||
newpin = ''
|
||||
|
||||
# generate and display internal entropy
|
||||
@ -49,20 +50,22 @@ async def reset_device(ctx, msg):
|
||||
await show_entropy(ctx, internal_entropy)
|
||||
|
||||
# request external entropy and compute mnemonic
|
||||
ext_ack = await ctx.call(EntropyRequest(), wire_types.EntropyAck)
|
||||
ack = await ctx.call(EntropyRequest(), wire_types.EntropyAck)
|
||||
mnemonic = generate_mnemonic(
|
||||
msg.strength,
|
||||
internal_entropy,
|
||||
ext_ack.entropy)
|
||||
msg.strength, internal_entropy, ack.entropy)
|
||||
|
||||
# warn user about mnemonic safety
|
||||
await show_warning(ctx)
|
||||
while True:
|
||||
# show mnemonic and make user to confirm a random word
|
||||
await show_mnemonic(ctx, mnemonic)
|
||||
if await check_mnemonic(ctx, mnemonic):
|
||||
break
|
||||
await show_wrong_entry(ctx)
|
||||
if msg.skip_backup:
|
||||
# let user backup the mnemonic later
|
||||
pass
|
||||
else:
|
||||
# warn user about mnemonic safety
|
||||
await show_warning(ctx)
|
||||
while True:
|
||||
# show mnemonic and require confirmation of a random word
|
||||
await show_mnemonic(ctx, mnemonic)
|
||||
if await check_mnemonic(ctx, mnemonic):
|
||||
break
|
||||
await show_wrong_entry(ctx)
|
||||
|
||||
# write PIN into storage
|
||||
if not config.change_pin('', newpin):
|
||||
@ -72,7 +75,8 @@ async def reset_device(ctx, msg):
|
||||
# write settings and mnemonic into storage
|
||||
storage.load_settings(
|
||||
label=msg.label, use_passphrase=msg.passphrase_protection)
|
||||
storage.load_mnemonic(mnemonic)
|
||||
storage.load_mnemonic(
|
||||
mnemonic=mnemonic, needs_backup=msg.skip_backup)
|
||||
|
||||
# show success message
|
||||
await show_success(ctx)
|
||||
|
Loading…
Reference in New Issue
Block a user