1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-23 23:08:14 +00:00

client: allow canceling pin/passphrase entry

This commit is contained in:
matejcik 2018-11-16 13:36:04 +01:00
parent 11e56a7e1b
commit f04458d6ea
2 changed files with 25 additions and 10 deletions

View File

@ -102,7 +102,12 @@ class TrezorClient:
return self.transport.read() return self.transport.read()
def _callback_pin(self, msg): def _callback_pin(self, msg):
pin = self.ui.get_pin(msg.type) try:
pin = self.ui.get_pin(msg.type)
except exceptions.Cancelled:
self.call_raw(messages.Cancel())
raise
if not pin.isdigit(): if not pin.isdigit():
raise ValueError("Non-numeric PIN provided") raise ValueError("Non-numeric PIN provided")
@ -120,7 +125,11 @@ class TrezorClient:
if msg.on_device: if msg.on_device:
passphrase = None passphrase = None
else: else:
passphrase = self.ui.get_passphrase() try:
passphrase = self.ui.get_passphrase()
except exceptions.Cancelled:
self.call_raw(messages.Cancel())
raise
resp = self.call_raw(messages.PassphraseAck(passphrase=passphrase)) resp = self.call_raw(messages.PassphraseAck(passphrase=passphrase))
if isinstance(resp, messages.PassphraseStateRequest): if isinstance(resp, messages.PassphraseStateRequest):

View File

@ -73,7 +73,10 @@ class ClickUI:
echo(PIN_MATRIX_DESCRIPTION) echo(PIN_MATRIX_DESCRIPTION)
while True: while True:
pin = prompt("Please enter {}".format(desc), hide_input=True) try:
pin = prompt("Please enter {}".format(desc), hide_input=True)
except click.Abort:
raise Cancelled from None
if not pin.isdigit(): if not pin.isdigit():
echo("Non-numerical PIN provided, please try again") echo("Non-numerical PIN provided, please try again")
else: else:
@ -86,12 +89,15 @@ class ClickUI:
return os.getenv("PASSPHRASE") return os.getenv("PASSPHRASE")
while True: while True:
passphrase = prompt("Passphrase required", hide_input=True) try:
second = prompt("Confirm your passphrase", hide_input=True) passphrase = prompt("Passphrase required", hide_input=True)
if passphrase == second: second = prompt("Confirm your passphrase", hide_input=True)
return passphrase if passphrase == second:
else: return passphrase
echo("Passphrase did not match. Please try again.") else:
echo("Passphrase did not match. Please try again.")
except click.Abort:
raise Cancelled from None
def mnemonic_words(expand=False, language="english"): def mnemonic_words(expand=False, language="english"):
@ -119,7 +125,7 @@ def mnemonic_words(expand=False, language="english"):
return expand_word(word) return expand_word(word)
except KeyError: except KeyError:
pass pass
except (KeyboardInterrupt, click.Abort): except click.Abort:
raise Cancelled from None raise Cancelled from None
return get_word return get_word