gpg: cache the passphrase for better UX

master
Roman Zeyde 6 years ago
parent 34ea224290
commit 73d60dbec0
No known key found for this signature in database
GPG Key ID: 87CAE5FA46917CBB

@ -75,22 +75,26 @@ class Trezor(interface.Device):
conn.callback_PinMatrixRequest = new_handler conn.callback_PinMatrixRequest = new_handler
cached_passphrase_ack = 0
def _override_passphrase_handler(self, conn): def _override_passphrase_handler(self, conn):
cli_handler = conn.callback_PassphraseRequest cli_handler = conn.callback_PassphraseRequest
def new_handler(msg): def new_handler(msg):
if _is_open_tty(sys.stdin): if self.__class__.cached_passphrase_ack:
return cli_handler(msg) # CLI-based PIN handler log.debug('re-using cached %s passphrase', self)
return self.__class__.cached_passphrase_ack
# Reusing environment variable from trezorlib/client.py if _is_open_tty(sys.stdin):
passphrase = os.getenv("PASSPHRASE") # use CLI-based PIN handler
if passphrase is not None: ack = cli_handler(msg)
log.info("Using PASSPHRASE environment variable.") else:
return self._defs.PassphraseAck( passphrase = _message_box('Please enter passphrase:')
passphrase=mnemonic.Mnemonic.normalize_string(passphrase)) passphrase = mnemonic.Mnemonic.normalize_string(passphrase)
ack = self._defs.PassphraseAck(passphrase=passphrase)
passphrase = _message_box('Please enter passphrase:') self.__class__.cached_passphrase_ack = ack
return self._defs.PassphraseAck(passphrase=passphrase) return ack
conn.callback_PassphraseRequest = new_handler conn.callback_PassphraseRequest = new_handler

Loading…
Cancel
Save