mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-22 15:38:11 +00:00
recovery: Verify the return value of config.has_pin() in dry run recovery. Improve UI messages. Remove code duplication in modtrezorconfig.c.
This commit is contained in:
parent
396f5f1937
commit
388fc2ae77
@ -65,20 +65,6 @@ STATIC mp_obj_t mod_trezorconfig_init(size_t n_args, const mp_obj_t *args) {
|
|||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorconfig_init_obj, 0, 1,
|
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorconfig_init_obj, 0, 1,
|
||||||
mod_trezorconfig_init);
|
mod_trezorconfig_init);
|
||||||
|
|
||||||
/// def check_pin(pin: int) -> bool:
|
|
||||||
/// '''
|
|
||||||
/// Check the given PIN. Returns True on success, False on failure.
|
|
||||||
/// '''
|
|
||||||
STATIC mp_obj_t mod_trezorconfig_check_pin(mp_obj_t pin) {
|
|
||||||
uint32_t pin_i = trezor_obj_get_uint(pin);
|
|
||||||
if (sectrue != storage_unlock(pin_i)) {
|
|
||||||
return mp_const_false;
|
|
||||||
}
|
|
||||||
return mp_const_true;
|
|
||||||
}
|
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorconfig_check_pin_obj,
|
|
||||||
mod_trezorconfig_check_pin);
|
|
||||||
|
|
||||||
/// def unlock(pin: int) -> bool:
|
/// def unlock(pin: int) -> bool:
|
||||||
/// '''
|
/// '''
|
||||||
/// Attempts to unlock the storage with given PIN. Returns True on
|
/// Attempts to unlock the storage with given PIN. Returns True on
|
||||||
@ -94,6 +80,16 @@ STATIC mp_obj_t mod_trezorconfig_unlock(mp_obj_t pin) {
|
|||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorconfig_unlock_obj,
|
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorconfig_unlock_obj,
|
||||||
mod_trezorconfig_unlock);
|
mod_trezorconfig_unlock);
|
||||||
|
|
||||||
|
/// def check_pin(pin: int) -> bool:
|
||||||
|
/// '''
|
||||||
|
/// Check the given PIN. Returns True on success, False on failure.
|
||||||
|
/// '''
|
||||||
|
STATIC mp_obj_t mod_trezorconfig_check_pin(mp_obj_t pin) {
|
||||||
|
return mod_trezorconfig_unlock(pin);
|
||||||
|
}
|
||||||
|
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorconfig_check_pin_obj,
|
||||||
|
mod_trezorconfig_check_pin);
|
||||||
|
|
||||||
/// def lock() -> None:
|
/// def lock() -> None:
|
||||||
/// '''
|
/// '''
|
||||||
/// Locks the storage.
|
/// Locks the storage.
|
||||||
|
@ -33,18 +33,27 @@ async def recovery_device(ctx, msg):
|
|||||||
if not msg.dry_run and storage.is_initialized():
|
if not msg.dry_run and storage.is_initialized():
|
||||||
raise wire.UnexpectedMessage("Already initialized")
|
raise wire.UnexpectedMessage("Already initialized")
|
||||||
|
|
||||||
text = Text("Device recovery", ui.ICON_RECOVERY)
|
if not msg.dry_run:
|
||||||
text.normal("Do you really want to", "recover the device?", "")
|
title = "Device recovery"
|
||||||
|
text = Text(title, ui.ICON_RECOVERY)
|
||||||
|
text.normal("Do you really want to", "recover the device?", "")
|
||||||
|
else:
|
||||||
|
title = "Simulated recovery"
|
||||||
|
text = Text(title, ui.ICON_RECOVERY)
|
||||||
|
text.normal("Do you really want to", "check the recovery", "seed?")
|
||||||
|
|
||||||
await require_confirm(ctx, text, code=ProtectCall)
|
await require_confirm(ctx, text, code=ProtectCall)
|
||||||
|
|
||||||
if msg.dry_run and config.has_pin():
|
if msg.dry_run:
|
||||||
curpin = await request_pin_ack(ctx, "Enter PIN", config.get_pin_rem())
|
if config.has_pin():
|
||||||
|
curpin = await request_pin_ack(ctx, "Enter PIN", config.get_pin_rem())
|
||||||
|
else:
|
||||||
|
curpin = ""
|
||||||
if not config.check_pin(pin_to_int(curpin)):
|
if not config.check_pin(pin_to_int(curpin)):
|
||||||
raise wire.PinInvalid("PIN invalid")
|
raise wire.PinInvalid("PIN invalid")
|
||||||
|
|
||||||
# ask for the number of words
|
# ask for the number of words
|
||||||
wordcount = await request_wordcount(ctx)
|
wordcount = await request_wordcount(ctx, title)
|
||||||
|
|
||||||
# ask for mnemonic words one by one
|
# ask for mnemonic words one by one
|
||||||
words = await request_mnemonic(ctx, wordcount)
|
words = await request_mnemonic(ctx, wordcount)
|
||||||
@ -92,10 +101,10 @@ async def recovery_device(ctx, msg):
|
|||||||
|
|
||||||
|
|
||||||
@ui.layout
|
@ui.layout
|
||||||
async def request_wordcount(ctx):
|
async def request_wordcount(ctx, title: str) -> int:
|
||||||
await ctx.call(ButtonRequest(code=MnemonicWordCount), ButtonAck)
|
await ctx.call(ButtonRequest(code=MnemonicWordCount), ButtonAck)
|
||||||
|
|
||||||
text = Text("Device recovery", ui.ICON_RECOVERY)
|
text = Text(title, ui.ICON_RECOVERY)
|
||||||
text.normal("Number of words?")
|
text.normal("Number of words?")
|
||||||
count = await ctx.wait(WordSelector(text))
|
count = await ctx.wait(WordSelector(text))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user