mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-05 13:01:12 +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
|
_LABEL = const(0x04) # str
|
||||||
_USE_PASSPHRASE = const(0x05) # 0x01 or empty
|
_USE_PASSPHRASE = const(0x05) # 0x01 or empty
|
||||||
_HOMESCREEN = const(0x06) # bytes
|
_HOMESCREEN = const(0x06) # bytes
|
||||||
|
_NEEDS_BACKUP = const(0x07) # 0x01 or empty
|
||||||
|
|
||||||
|
|
||||||
def get_device_id() -> str:
|
def get_device_id() -> str:
|
||||||
@ -42,9 +43,13 @@ def get_homescreen() -> bytes:
|
|||||||
return config.get(_APP, _HOMESCREEN, True) # public
|
return config.get(_APP, _HOMESCREEN, True) # public
|
||||||
|
|
||||||
|
|
||||||
def load_mnemonic(mnemonic: str):
|
def load_mnemonic(mnemonic: str, needs_backup: bool):
|
||||||
config.set(_APP, _VERSION, _STORAGE_VERSION)
|
|
||||||
config.set(_APP, _MNEMONIC, mnemonic.encode())
|
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):
|
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,
|
FailureType.UnexpectedMessage,
|
||||||
'Already initialized')
|
'Already initialized')
|
||||||
|
|
||||||
# request new PIN
|
|
||||||
if msg.pin_protection:
|
if msg.pin_protection:
|
||||||
|
# request new PIN
|
||||||
newpin = await request_pin_confirm(ctx)
|
newpin = await request_pin_confirm(ctx)
|
||||||
else:
|
else:
|
||||||
|
# new PIN is empty
|
||||||
newpin = ''
|
newpin = ''
|
||||||
|
|
||||||
# generate and display internal entropy
|
# generate and display internal entropy
|
||||||
@ -49,20 +50,22 @@ async def reset_device(ctx, msg):
|
|||||||
await show_entropy(ctx, internal_entropy)
|
await show_entropy(ctx, internal_entropy)
|
||||||
|
|
||||||
# request external entropy and compute mnemonic
|
# 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(
|
mnemonic = generate_mnemonic(
|
||||||
msg.strength,
|
msg.strength, internal_entropy, ack.entropy)
|
||||||
internal_entropy,
|
|
||||||
ext_ack.entropy)
|
|
||||||
|
|
||||||
# warn user about mnemonic safety
|
if msg.skip_backup:
|
||||||
await show_warning(ctx)
|
# let user backup the mnemonic later
|
||||||
while True:
|
pass
|
||||||
# show mnemonic and make user to confirm a random word
|
else:
|
||||||
await show_mnemonic(ctx, mnemonic)
|
# warn user about mnemonic safety
|
||||||
if await check_mnemonic(ctx, mnemonic):
|
await show_warning(ctx)
|
||||||
break
|
while True:
|
||||||
await show_wrong_entry(ctx)
|
# 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
|
# write PIN into storage
|
||||||
if not config.change_pin('', newpin):
|
if not config.change_pin('', newpin):
|
||||||
@ -72,7 +75,8 @@ async def reset_device(ctx, msg):
|
|||||||
# write settings and mnemonic into storage
|
# write settings and mnemonic into storage
|
||||||
storage.load_settings(
|
storage.load_settings(
|
||||||
label=msg.label, use_passphrase=msg.passphrase_protection)
|
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
|
# show success message
|
||||||
await show_success(ctx)
|
await show_success(ctx)
|
||||||
|
Loading…
Reference in New Issue
Block a user