From b4c5ef88d954519180b493a3091c7f729b03d0de Mon Sep 17 00:00:00 2001 From: matejcik Date: Mon, 15 May 2023 12:13:55 +0200 Subject: [PATCH] wip: move wipe_device to load_device --- core/src/apps/debug/load_device.py | 12 +++++++----- legacy/firmware/fsm_msg_common.h | 2 +- python/src/trezorlib/debuglink.py | 6 ++---- tests/conftest.py | 7 ++++--- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/core/src/apps/debug/load_device.py b/core/src/apps/debug/load_device.py index 79471a027..526c5f4c3 100644 --- a/core/src/apps/debug/load_device.py +++ b/core/src/apps/debug/load_device.py @@ -6,20 +6,18 @@ if TYPE_CHECKING: async def load_device(ctx: Context, msg: LoadDevice) -> Success: + import storage import storage.device as storage_device from trezor import config from trezor.crypto import bip39, slip39 from trezor.enums import BackupType from trezor.messages import Success + from apps.base import reload_settings_from_storage from apps.management import backup_types from trezor.wire import UnexpectedMessage, ProcessError from trezor.ui.layouts import confirm_action mnemonics = msg.mnemonics # local_cache_attribute - - # _validate - if storage_device.is_initialized(): - raise UnexpectedMessage("Already initialized") if not mnemonics: raise ProcessError("No mnemonic provided") @@ -41,11 +39,15 @@ async def load_device(ctx: Context, msg: LoadDevice) -> Success: ctx, "warn_loading_seed", "Loading seed", - "Loading private seed is not recommended.", + "Wipe the device and set up seed from host?", "Continue only if you know what you are doing!", + hold_danger=True, ) # END _warn + storage.wipe() + reload_settings_from_storage() + if not is_slip39: # BIP-39 secret = msg.mnemonics[0].encode() backup_type = BackupType.Bip39 diff --git a/legacy/firmware/fsm_msg_common.h b/legacy/firmware/fsm_msg_common.h index 5debd36ea..add71c078 100644 --- a/legacy/firmware/fsm_msg_common.h +++ b/legacy/firmware/fsm_msg_common.h @@ -281,7 +281,7 @@ void fsm_msgGetEntropy(const GetEntropy *msg) { void fsm_msgLoadDevice(const LoadDevice *msg) { CHECK_PIN - CHECK_NOT_INITIALIZED + config_wipe(); layoutDialogSwipe(&bmp_icon_question, _("Cancel"), _("I take the risk"), NULL, _("Loading private seed"), _("is not recommended."), diff --git a/python/src/trezorlib/debuglink.py b/python/src/trezorlib/debuglink.py index f09ebd180..ba44f6a9e 100644 --- a/python/src/trezorlib/debuglink.py +++ b/python/src/trezorlib/debuglink.py @@ -44,7 +44,7 @@ from typing import ( from mnemonic import Mnemonic from typing_extensions import Literal -from . import mapping, messages, protobuf +from . import device, mapping, messages, protobuf from .client import TrezorClient from .exceptions import TrezorFailure from .log import DUMP_BYTES @@ -1199,9 +1199,7 @@ def load_device( mnemonics = [Mnemonic.normalize_string(m) for m in mnemonic] if client.features.initialized: - raise RuntimeError( - "Device is initialized already. Call device.wipe() and try again." - ) + device.wipe(client) resp = client.call( messages.LoadDevice( diff --git a/tests/conftest.py b/tests/conftest.py index 639333ef1..223384d6a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -222,8 +222,6 @@ def client( should_format = sd_marker.kwargs.get("formatted", True) _raw_client.debug.erase_sd_card(format=should_format) - wipe_device(_raw_client) - setup_params = dict( uninitialized=False, mnemonic=" ".join(["all"] * 12), @@ -241,7 +239,10 @@ def client( setup_params["passphrase"], str ) - if not setup_params["uninitialized"]: + if setup_params["uninitialized"]: + wipe_device(_raw_client) + + else: debuglink.load_device( _raw_client, mnemonic=setup_params["mnemonic"], # type: ignore