diff --git a/src/apps/common/storage.py b/src/apps/common/storage.py index af43a6321e..d1be98c2ab 100644 --- a/src/apps/common/storage.py +++ b/src/apps/common/storage.py @@ -165,7 +165,7 @@ def set_autolock_delay_ms(delay_ms: int) -> None: def next_u2f_counter() -> int: b = config.get(_APP, _U2F_COUNTER) - if b is None: + if not b: b = 0 else: b = int.from_bytes(b, "big") + 1 @@ -174,7 +174,10 @@ def next_u2f_counter() -> int: def set_u2f_counter(cntr: int): - config.set(_APP, _U2F_COUNTER, cntr.to_bytes(4, "big")) + if cntr: + config.set(_APP, _U2F_COUNTER, cntr.to_bytes(4, "big")) + else: + config.set(_APP, _U2F_COUNTER, b"") def wipe(): diff --git a/src/apps/management/recovery_device.py b/src/apps/management/recovery_device.py index c95d29f214..4d3ca7ac5b 100644 --- a/src/apps/management/recovery_device.py +++ b/src/apps/management/recovery_device.py @@ -52,14 +52,8 @@ async def recovery_device(ctx, msg): if msg.pin_protection: newpin = await request_pin_confirm(ctx, cancellable=False) - # save into storage - if not msg.dry_run: - if msg.pin_protection: - config.change_pin(pin_to_int(""), pin_to_int(newpin)) - storage.load_settings(label=msg.label, use_passphrase=msg.passphrase_protection) - storage.load_mnemonic(mnemonic=mnemonic, needs_backup=False, no_backup=False) - return Success(message="Device recovered") - else: + # dry run + if msg.dry_run: if storage.get_mnemonic() == mnemonic: return Success( message="The seed is valid and matches the one in the device" @@ -69,6 +63,15 @@ async def recovery_device(ctx, msg): "The seed is valid but does not match the one in the device" ) + # save into storage + if msg.pin_protection: + config.change_pin(pin_to_int(""), pin_to_int(newpin)) + storage.set_u2f_counter(msg.u2f_counter) + storage.load_settings(label=msg.label, use_passphrase=msg.passphrase_protection) + storage.load_mnemonic(mnemonic=mnemonic, needs_backup=False, no_backup=False) + + return Success(message="Device recovered") + @ui.layout async def request_wordcount(ctx):