mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-03 12:00:59 +00:00
management: restore u2f_counter on device recovery
This commit is contained in:
parent
2b24fe14bb
commit
2d70d5d447
@ -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():
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user