Skip to content

Commit

Permalink
Merge #481: Handle PassphraseRequest after sending pin
Browse files Browse the repository at this point in the history
663d7eb Move some Trezor tests to end of test suite (Andrew Chow)
c50834b Handle PassphraseRequest after sending pin (Andrew Chow)

Pull request description:

  After sending the PIN to a Trezor 1, it is possible that a `PassphraseRequest` is returned. When the device does this, it enters a state where it expects only a limited set of messages. To resolve this, we need to send the passphrase to the device so that it proceeds to its normal state. Otherwise any attempts to communicate with the device will fail. This can be observed after doing `sendpin` and then `enumerate`. In the `enumerate` result, there will be an error for the device.

  Also added a test for this. The `sendpin` test is updated to set a passphrase on the Trezor.

  Fixes #476

ACKs for top commit:
  instagibbs:
    utACK 663d7eb

Tree-SHA512: 08d7c9f397b686a4ce458f751433a5de23c089434de5ed5a383480da8a13411fc3eb4c27f7594d704388211d637554e94655a4998c2f561862f37b32620593c8
  • Loading branch information
achow101 committed Mar 8, 2021
2 parents d3a15b9 + 663d7eb commit 3190d1f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 4 additions & 0 deletions hwilib/devices/trezor.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,10 @@ def send_pin(self, pin: str) -> bool:
if self.client.features.unlocked:
raise DeviceAlreadyUnlockedError('The PIN has already been sent to this device')
return False
elif isinstance(resp, messages.PassphraseRequest):
pass_resp = self.client.call_raw(messages.PassphraseAck(passphrase=self.client.ui.get_passphrase(available_on_device=False), on_device=False))
if isinstance(pass_resp, messages.Deprecated_PassphraseStateRequest):
self.client.call_raw(messages.Deprecated_PassphraseStateAck())
return True

@trezor_exception
Expand Down
6 changes: 3 additions & 3 deletions test/test_trezor.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def test_pins(self):

# Set a PIN
device.wipe(self.client)
load_device_by_mnemonic(client=self.client, mnemonic='alcohol woman abuse must during monitor noble actual mixed trade anger aisle', pin='1234', passphrase_protection=False, label='test')
load_device_by_mnemonic(client=self.client, mnemonic='alcohol woman abuse must during monitor noble actual mixed trade anger aisle', pin='1234', passphrase_protection=True, label='test')
self.client.lock(_refresh_features=False)
self.client.end_session()
result = self.do_command(self.dev_args + ['enumerate'])
Expand Down Expand Up @@ -339,10 +339,10 @@ def trezor_test_suite(emulator, rpc, userpass, interface, model):
suite.addTest(DeviceTestCase.parameterize(TestSignTx, rpc, userpass, type, full_type, path, fingerprint, master_xpub, emulator=dev_emulator, interface=interface))
suite.addTest(DeviceTestCase.parameterize(TestDisplayAddress, rpc, userpass, type, full_type, path, fingerprint, master_xpub, emulator=dev_emulator, interface=interface))
suite.addTest(DeviceTestCase.parameterize(TestSignMessage, rpc, userpass, type, full_type, path, fingerprint, master_xpub, emulator=dev_emulator, interface=interface))
suite.addTest(TrezorTestCase.parameterize(TestTrezorGetxpub, emulator=dev_emulator, interface=interface))
suite.addTest(DeviceTestCase.parameterize(TestDeviceConnect, rpc, userpass, 'trezor_{}_simulator'.format(model), full_type, path, fingerprint, master_xpub, emulator=dev_emulator, interface=interface))
if model != 't':
suite.addTest(TrezorTestCase.parameterize(TestTrezorManCommands, emulator=dev_emulator, interface=interface))
suite.addTest(DeviceTestCase.parameterize(TestDeviceConnect, rpc, userpass, 'trezor_{}_simulator'.format(model), full_type, path, fingerprint, master_xpub, emulator=dev_emulator, interface=interface))
suite.addTest(TrezorTestCase.parameterize(TestTrezorGetxpub, emulator=dev_emulator, interface=interface))

result = unittest.TextTestRunner(stream=sys.stdout, verbosity=2).run(suite)
sys.stderr = sys.__stderr__
Expand Down

0 comments on commit 3190d1f

Please sign in to comment.