diff --git a/core/emu.py b/core/emu.py index ac568e62b0..fb09b75174 100755 --- a/core/emu.py +++ b/core/emu.py @@ -283,7 +283,6 @@ def cli( assert emulator.client is not None trezorlib.device.wipe(emulator.client.get_management_session()) - emulator.client = emulator.client.get_new_client() trezorlib.debuglink.load_device( emulator.client.get_management_session(), diff --git a/python/src/trezorlib/_internal/emulator.py b/python/src/trezorlib/_internal/emulator.py index d171f58200..2eb0e332bb 100644 --- a/python/src/trezorlib/_internal/emulator.py +++ b/python/src/trezorlib/_internal/emulator.py @@ -93,17 +93,10 @@ class Emulator: """ if self._client is None: raise RuntimeError + if self._client.is_invalidated: + self._client = self._client.get_new_client() return self._client - @client.setter - def client(self, new_client: TrezorClientDebugLink) -> None: - """Setter for the client property to update _client.""" - if not isinstance(new_client, TrezorClientDebugLink): - raise TypeError( - f"Expected a TrezorClientDebugLink, got {type(new_client).__name__}." - ) - self._client = new_client - def make_args(self) -> List[str]: return [] diff --git a/python/src/trezorlib/client.py b/python/src/trezorlib/client.py index d82554dd93..1cca8339b1 100644 --- a/python/src/trezorlib/client.py +++ b/python/src/trezorlib/client.py @@ -72,6 +72,7 @@ class TrezorClient: protobuf_mapping: ProtobufMapping | None = None, protocol: ProtocolAndChannel | None = None, ) -> None: + self._is_invalidated: bool = False self.transport = transport if protobuf_mapping is None: @@ -181,6 +182,9 @@ class TrezorClient: assert self._management_session is not None return self._management_session + def invalidate(self) -> None: + self._is_invalidated = True + @property def features(self) -> messages.Features: if self._features is None: @@ -214,6 +218,10 @@ class TrezorClient: ) return ver + @property + def is_invalidated(self) -> bool: + return self._is_invalidated + def refresh_features(self) -> None: self.protocol.update_features() self._features = self.protocol.get_features() diff --git a/python/src/trezorlib/device.py b/python/src/trezorlib/device.py index 2542f00dde..530362180b 100644 --- a/python/src/trezorlib/device.py +++ b/python/src/trezorlib/device.py @@ -139,6 +139,7 @@ def sd_protect( def wipe(session: "Session") -> "MessageType": ret = session.call(messages.WipeDevice()) + session.invalidate() # if not session.features.bootloader_mode: # session.refresh_features() return ret diff --git a/python/src/trezorlib/transport/session.py b/python/src/trezorlib/transport/session.py index 6b6f4cce2c..4015f48a8f 100644 --- a/python/src/trezorlib/transport/session.py +++ b/python/src/trezorlib/transport/session.py @@ -77,6 +77,9 @@ class Session: ) return resp.message or "" + def invalidate(self) -> None: + self.client.invalidate() + @property def features(self) -> messages.Features: return self.client.features diff --git a/tests/persistence_tests/test_safety_checks.py b/tests/persistence_tests/test_safety_checks.py index c2552f04b3..81a6705b05 100644 --- a/tests/persistence_tests/test_safety_checks.py +++ b/tests/persistence_tests/test_safety_checks.py @@ -21,7 +21,6 @@ def test_safety_checks_level_after_reboot( core_emulator: Emulator, set_level: SafetyCheckLevel, after_level: SafetyCheckLevel ): device.wipe(core_emulator.client.get_management_session()) - core_emulator.client = core_emulator.client.get_new_client() debuglink.load_device( core_emulator.client.get_management_session(), mnemonic=MNEMONIC12, diff --git a/tests/upgrade_tests/test_passphrase_consistency.py b/tests/upgrade_tests/test_passphrase_consistency.py index bdeb74cabf..06c33fd612 100644 --- a/tests/upgrade_tests/test_passphrase_consistency.py +++ b/tests/upgrade_tests/test_passphrase_consistency.py @@ -53,7 +53,7 @@ def emulator(gen: str, tag: str) -> Iterator[Emulator]: pin_protection=False, skip_backup=True, ) - emu.client = emu.client.get_new_client() + emu.client.invalidate() resp = emu.client.get_management_session().call( ApplySettingsCompat(use_passphrase=True, passphrase_source=SOURCE_HOST) )