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

Merge pull request #536 from trezor/534

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:
Andrew Kozlik 2019-04-10 15:24:53 +02:00 committed by GitHub
commit d4cfc82fce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 21 deletions

View File

@ -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.

View File

@ -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:
title = "Device recovery"
text = Text(title, ui.ICON_RECOVERY)
text.normal("Do you really want to", "recover the device?", "") 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:
if config.has_pin():
curpin = await request_pin_ack(ctx, "Enter PIN", config.get_pin_rem()) 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))