fixup! feat(core): implement repeated backup

Ioan Bizău 4 weeks ago
parent 1898605cc7
commit e2dba7388e

@ -22,7 +22,9 @@ async def backup_device(msg: BackupDevice) -> Success:
# do this early before we show any UI
# the homescreen will clear the flag right after its own UI is gone
repeated_backup_unlocked = storage_cache.get_bool(storage_cache.APP_RECOVERY_REPEATED_BACKUP_UNLOCKED)
repeated_backup_unlocked = storage_cache.get_bool(
storage_cache.APP_RECOVERY_REPEATED_BACKUP_UNLOCKED
)
if not storage_device.is_initialized():
raise wire.NotInitialized("Device is not initialized")

@ -44,14 +44,15 @@ async def recovery_device(msg: RecoveryDevice) -> Success:
elif recovery_kind in (RecoveryKind.DryRun, RecoveryKind.UnlockRepeatedBackup):
if not storage_device.is_initialized():
raise wire.NotInitialized("Device is not initialized")
if recovery_kind == RecoveryKind.UnlockRepeatedBackup and mnemonic.get_type() == BackupType.Bip39:
if (
recovery_kind == RecoveryKind.UnlockRepeatedBackup
and mnemonic.get_type() == BackupType.Bip39
):
raise wire.ProcessError("Repeated Backup not available for BIP39 backups")
# check that only allowed fields are set
for key, value in msg.__dict__.items():
if key not in DRY_RUN_ALLOWED_FIELDS and value is not None:
raise wire.ProcessError(
f"Forbidden field set in dry-run: {key}"
)
raise wire.ProcessError(f"Forbidden field set in dry-run: {key}")
else:
raise ValueError("Unknown RecoveryKind")

@ -209,7 +209,9 @@ async def _finish_recovery_unlock_repeated_backup(
result = _check_secret_against_stored_secret(secret, is_slip39)
if result:
storage_cache.set_bool(storage_cache.APP_RECOVERY_REPEATED_BACKUP_UNLOCKED, True)
storage_cache.set_bool(
storage_cache.APP_RECOVERY_REPEATED_BACKUP_UNLOCKED, True
)
return Success(message="Backup unlocked")
else:
raise wire.ProcessError("The seed does not match the one in the device")

@ -491,10 +491,10 @@ void fsm_msgApplyFlags(const ApplyFlags *msg) {
void fsm_msgRecoveryDevice(const RecoveryDevice *msg) {
CHECK_PIN_UNCACHED
CHECK_PARAM(!msg->has_kind || msg->kind == 0 || msg->kind == 1,
_("UnlockRepeatedBackup not supported"))
CHECK_PARAM(!msg->has_dry_run || msg->dry_run == 0 || msg->dry_run == 1,
_("dry_run should be a boolean, if present"))
const bool dry_run = msg->has_kind ? msg->kind == 1 /* RecoveryKind.DryRun */ : false;
const bool dry_run = msg->has_dry_run ? msg->dry_run == 1 : false;
if (!dry_run) {
CHECK_NOT_INITIALIZED
} else {

@ -184,6 +184,9 @@ def recover(
else:
recovery_kind = messages.RecoveryKind.NormalRecovery
if recovery_kind is None:
recovery_kind = messages.RecoveryKind.NormalRecovery
if client.features.model == "1" and input_callback is None:
raise RuntimeError("Input callback required for Trezor One")

@ -127,7 +127,10 @@ def test_repeated_backup(
assert features.initialized is True
assert features.needs_backup is False
assert features.no_backup is False
assert features.recovery_status == messages.RecoveryStatus.InUnlockRepeatedBackupRecovery
assert (
features.recovery_status
== messages.RecoveryStatus.InUnlockRepeatedBackupRecovery
)
# at this point, the backup is unlocked...
@ -194,7 +197,10 @@ def test_repeated_backup(
assert features.initialized is True
assert features.needs_backup is False
assert features.no_backup is False
assert features.recovery_status == messages.RecoveryStatus.InUnlockRepeatedBackupRecovery
assert (
features.recovery_status
== messages.RecoveryStatus.InUnlockRepeatedBackupRecovery
)
# but if we cancel the backup at this point...
reset.cancel_backup(debug)

@ -202,10 +202,10 @@ def test_already_initialized(client: Client):
with pytest.raises(RuntimeError):
device.recover(
client,
12,
False,
False,
"label",
word_count=12,
pin_protection=False,
passphrase_protection=False,
label="label",
input_callback=client.mnemonic_callback,
)

@ -49,7 +49,9 @@ def test_repeated_backup(client: Client):
with client:
IF = InputFlowSlip39BasicRecoveryDryRun(client, mnemonics[:3])
client.set_input_flow(IF.get())
ret = device.recover(client, recovery_kind=messages.RecoveryKind.UnlockRepeatedBackup)
ret = device.recover(
client, recovery_kind=messages.RecoveryKind.UnlockRepeatedBackup
)
assert ret == messages.Success(message="Backup unlocked")
# we can now perform another backup

Loading…
Cancel
Save