Skip to content

Commit

Permalink
trezor: use UI-based passphrase entry
Browse files Browse the repository at this point in the history
Now TREZOR_PASSPHRASE environment variable is ignored.
  • Loading branch information
romanz committed Nov 16, 2017
1 parent 2482dba commit 0d34a70
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions libagent/device/trezor.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def _defs(self):
return trezor_defs

required_version = '>=1.4.0'
passphrase = os.environ.get('TREZOR_PASSPHRASE', '')

def _override_pin_handler(self, conn):
cli_handler = conn.callback_PinMatrixRequest
Expand All @@ -65,19 +64,26 @@ def new_handler(msg):

conn.callback_PinMatrixRequest = new_handler

def _override_passphrase_handler(self, conn):
cli_handler = conn.callback_PassphraseRequest

def new_handler(msg):
if _is_open_tty(sys.stdin):
return cli_handler(msg) # CLI-based PIN handler

passphrase = _message_box('Please enter passphrase:')
return self._defs.PassphraseAck(passphrase=passphrase)

conn.callback_PassphraseRequest = new_handler

def connect(self):
"""Enumerate and connect to the first USB HID interface."""
def passphrase_handler(_):
log.debug('using %s passphrase for %s',
'non-empty' if self.passphrase else 'empty', self)
return self._defs.PassphraseAck(passphrase=self.passphrase)

for d in self._defs.Transport.enumerate():
log.debug('endpoint: %s', d)
transport = self._defs.Transport(d)
connection = self._defs.Client(transport)
connection.callback_PassphraseRequest = passphrase_handler
self._override_pin_handler(connection)
self._override_passphrase_handler(connection)
f = connection.features
log.debug('connected to %s %s', self, f.device_id)
log.debug('label : %s', f.label)
Expand Down

0 comments on commit 0d34a70

Please sign in to comment.