mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-07-06 06:42:33 +00:00
trezorctl: Validate PIN digits and length.
This commit is contained in:
parent
77bb6deb66
commit
ac78d1e2f3
@ -169,9 +169,9 @@ class TrezorClient:
|
|||||||
self.call_raw(messages.Cancel())
|
self.call_raw(messages.Cancel())
|
||||||
raise
|
raise
|
||||||
|
|
||||||
if not pin.isdigit():
|
if any(d not in "123456789" for d in pin) or not (1 <= len(pin) <= 9):
|
||||||
self.call_raw(messages.Cancel())
|
self.call_raw(messages.Cancel())
|
||||||
raise ValueError("Non-numeric PIN provided")
|
raise ValueError("Invalid PIN provided")
|
||||||
|
|
||||||
resp = self.call_raw(messages.PinMatrixAck(pin=pin))
|
resp = self.call_raw(messages.PinMatrixAck(pin=pin))
|
||||||
if isinstance(resp, messages.Failure) and resp.code in (
|
if isinstance(resp, messages.Failure) and resp.code in (
|
||||||
|
@ -95,8 +95,10 @@ class ClickUI:
|
|||||||
pin = prompt("Please enter {}".format(desc), hide_input=True)
|
pin = prompt("Please enter {}".format(desc), hide_input=True)
|
||||||
except click.Abort:
|
except click.Abort:
|
||||||
raise Cancelled from None
|
raise Cancelled from None
|
||||||
if not pin.isdigit():
|
if any(d not in "123456789" for d in pin):
|
||||||
echo("Non-numerical value provided, please try again")
|
echo("The value may only consist of digits 1 to 9.")
|
||||||
|
elif len(pin) > 9:
|
||||||
|
echo("The value must be at most 9 digits in length.")
|
||||||
else:
|
else:
|
||||||
return pin
|
return pin
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user