Skip to content

Commit

Permalink
Merge #542: keepkey, trezor: Handle if ButtonRequest is sent during s…
Browse files Browse the repository at this point in the history
…endpin

6fbb2a2 tests: Test sendpin with passphrase (Andrew Chow)
2fa0c94 keepkey, trezor: Handle if ButtonRequest is sent during sendpin (Andrew Chow)

Pull request description:

  Keepkey and Trezor may ask the user for confirmation of their passphrase after the PIN is sent. This could cause some issues as `ButtonRequests` were not being handled by `sendpin`. Additionally, `TrezorClient.call` would not work because it needs access to `TrezorClient.features`, which is not set for the `sendpin` command. In order to resolve this, `TrezorClient.call` is modified to optionally skip the firmware check that requires `TrezorClient.features`, and `sendpin` uses `TrezorClient.call` instead of `TrezorClient.call_raw`.

  Fixes #526
  Fixes $539

Top commit has no ACKs.

Tree-SHA512: 87b0cc2d21f8e4647e17540aa16291aade5cc514efcc2b592484f227a96c2e5be029bd1953e3df00ad1036aa8084fdd5869e9bde990cd5f81968e1e5755f964e
  • Loading branch information
achow101 committed Nov 10, 2021
2 parents 8c1b50a + 6fbb2a2 commit 4edf4f6
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion hwilib/devices/trezor.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ def send_pin(self, pin: str) -> bool:
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))
pass_resp = self.client.call(messages.PassphraseAck(passphrase=self.client.ui.get_passphrase(available_on_device=False), on_device=False), check_fw=False)
if isinstance(pass_resp, messages.Deprecated_PassphraseStateRequest):
self.client.call_raw(messages.Deprecated_PassphraseStateAck())
return True
Expand Down
5 changes: 3 additions & 2 deletions hwilib/devices/trezorlib/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,9 @@ def _callback_button(self, msg):
return self._raw_read()

@tools.session
def call(self, msg):
self.check_firmware_version()
def call(self, msg, check_fw = True):
if check_fw:
self.check_firmware_version()
resp = self.call_raw(msg)
while True:
if isinstance(resp, messages.PinMatrixRequest):
Expand Down
4 changes: 2 additions & 2 deletions test/test_keepkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,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.call(messages.LockDevice())
result = self.do_command(self.dev_args + ['enumerate'])
for dev in result:
Expand Down Expand Up @@ -272,7 +272,7 @@ def test_pins(self):
# Send the PIN
self.client.open()
pin = self.client.debug.encode_pin('1234')
result = self.do_command(self.dev_args + ['sendpin', pin])
result = self.do_command(self.dev_args + ["-p", "test", 'sendpin', pin])
self.assertTrue(result['success'])

result = self.do_command(self.dev_args + ['enumerate'])
Expand Down
2 changes: 1 addition & 1 deletion test/test_trezor.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def test_pins(self):
# Send the PIN
self.client.open()
pin = self.client.debug.encode_pin('1234')
result = self.do_command(self.dev_args + ['sendpin', pin])
result = self.do_command(self.dev_args + ["-p", "asdf", 'sendpin', pin])
self.assertTrue(result['success'])

result = self.do_command(self.dev_args + ['enumerate'])
Expand Down

0 comments on commit 4edf4f6

Please sign in to comment.