From f7608f55ffea2c40bf32c01ce35bc7aa7ecb6705 Mon Sep 17 00:00:00 2001 From: matejcik Date: Mon, 10 Feb 2020 13:01:47 +0100 Subject: [PATCH] python: implement backwards compatibility for pre-2.3.0 firmwares --- python/src/trezorlib/__init__.py | 4 ++-- python/src/trezorlib/client.py | 21 +++++++++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/python/src/trezorlib/__init__.py b/python/src/trezorlib/__init__.py index ee24df129..ceb5048e8 100644 --- a/python/src/trezorlib/__init__.py +++ b/python/src/trezorlib/__init__.py @@ -2,7 +2,7 @@ __version__ = "0.12.0" # fmt: off MINIMUM_FIRMWARE_VERSION = { - "1": (1, 9, 0), - "T": (2, 3, 0), + "1": (1, 8, 0), + "T": (2, 1, 0), } # fmt: on diff --git a/python/src/trezorlib/client.py b/python/src/trezorlib/client.py index dcaa06050..6c2e2176d 100644 --- a/python/src/trezorlib/client.py +++ b/python/src/trezorlib/client.py @@ -184,6 +184,21 @@ class TrezorClient: def _callback_passphrase(self, msg: messages.PassphraseRequest): available_on_device = Capability.PassphraseEntry in self.features.capabilities + + def send_passphrase(passphrase=None, on_device=None): + msg = messages.PassphraseAck( + _state=self.session_id, passphrase=passphrase, on_device=on_device + ) + resp = self.call_raw(msg) + if isinstance(resp, messages.Deprecated_PassphraseStateRequest): + self.session_id = resp.state + resp = self.call_raw(messages.Deprecated_PassphraseStateAck()) + return resp + + # short-circuit old style entry + if msg._on_device is True: + return send_passphrase(None, None) + try: passphrase = self.ui.get_passphrase(available_on_device=available_on_device) except exceptions.Cancelled: @@ -195,7 +210,7 @@ class TrezorClient: self.call_raw(messages.Cancel()) raise RuntimeError("Device is not capable of entering passphrase") else: - return self.call_raw(messages.PassphraseAck(on_device=True)) + return send_passphrase(on_device=True) # else process host-entered passphrase passphrase = Mnemonic.normalize_string(passphrase) @@ -203,9 +218,7 @@ class TrezorClient: self.call_raw(messages.Cancel()) raise ValueError("Passphrase too long") - return self.call_raw( - messages.PassphraseAck(passphrase=passphrase, on_device=False) - ) + return send_passphrase(passphrase, on_device=False) def _callback_button(self, msg): __tracebackhide__ = True # for pytest # pylint: disable=W0612