From d00ae56eeff88beef23edb8f1943d124efe07622 Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Wed, 17 Apr 2019 21:45:57 -0400 Subject: [PATCH] Don't send Initialize when first connecting to a Trezor Instead of sending Initialize, don't. This lets it stay in the same "session" as previous commands so some state such as passphrases are still cached by the device. If GetFeatures fails, then try sending Initialize so that any inconsistent state on the device is cleared. --- hwilib/devices/trezorlib/client.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hwilib/devices/trezorlib/client.py b/hwilib/devices/trezorlib/client.py index 1c57f74..d7b2bc0 100644 --- a/hwilib/devices/trezorlib/client.py +++ b/hwilib/devices/trezorlib/client.py @@ -178,7 +178,10 @@ class TrezorClient: @tools.session def init_device(self): - resp = self.call_raw(messages.Initialize(state=self.state)) + resp = self.call_raw(messages.GetFeatures()) + # If GetFeatures fails, try initializing and clearing inconsistent state on the device + if isinstance(resp, messages.Failure): + resp = self.call_raw(messages.Initialize()) if not isinstance(resp, messages.Features): raise exceptions.TrezorException("Unexpected initial response") else: