mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-16 19:38:09 +00:00
Display the number of PIN entry attempts remaining.
This commit is contained in:
parent
9f75d342a4
commit
3517018f30
@ -11,7 +11,7 @@ class PinCancelled(Exception):
|
|||||||
|
|
||||||
|
|
||||||
@ui.layout
|
@ui.layout
|
||||||
async def request_pin(label=None, cancellable: bool = True) -> str:
|
async def request_pin(label=None, attempts_remaining=None, cancellable: bool = True) -> str:
|
||||||
def onchange():
|
def onchange():
|
||||||
c = dialog.cancel
|
c = dialog.cancel
|
||||||
if matrix.pin:
|
if matrix.pin:
|
||||||
@ -36,7 +36,13 @@ async def request_pin(label=None, cancellable: bool = True) -> str:
|
|||||||
|
|
||||||
if label is None:
|
if label is None:
|
||||||
label = "Enter your PIN"
|
label = "Enter your PIN"
|
||||||
matrix = PinMatrix(label)
|
sublabel = None
|
||||||
|
if attempts_remaining:
|
||||||
|
if attempts_remaining == 1:
|
||||||
|
sublabel = "This is your last attempt"
|
||||||
|
else:
|
||||||
|
sublabel = "{} attempts remaining".format(attempts_remaining)
|
||||||
|
matrix = PinMatrix(label, sublabel)
|
||||||
matrix.onchange = onchange
|
matrix.onchange = onchange
|
||||||
dialog = ConfirmDialog(matrix)
|
dialog = ConfirmDialog(matrix)
|
||||||
dialog.cancel.area = ui.grid(12)
|
dialog.cancel.area = ui.grid(12)
|
||||||
|
@ -34,11 +34,11 @@ def _new_device_id() -> str:
|
|||||||
|
|
||||||
|
|
||||||
def get_device_id() -> str:
|
def get_device_id() -> str:
|
||||||
dev_id = config.get(_APP, _DEVICE_ID, True).decode() # public
|
dev_id = config.get(_APP, _DEVICE_ID, True) # public
|
||||||
if not dev_id:
|
if not dev_id:
|
||||||
dev_id = _new_device_id()
|
dev_id = _new_device_id().encode()
|
||||||
config.set(_APP, _DEVICE_ID, dev_id.encode(), True) # public
|
config.set(_APP, _DEVICE_ID, dev_id, True) # public
|
||||||
return dev_id
|
return dev_id.decode()
|
||||||
|
|
||||||
|
|
||||||
def is_initialized() -> bool:
|
def is_initialized() -> bool:
|
||||||
|
@ -16,7 +16,7 @@ async def change_pin(ctx, msg):
|
|||||||
|
|
||||||
# get current pin, return failure if invalid
|
# get current pin, return failure if invalid
|
||||||
if config.has_pin():
|
if config.has_pin():
|
||||||
curpin = await request_pin_ack(ctx)
|
curpin = await request_pin_ack(ctx, "Enter old PIN", config.get_pin_rem())
|
||||||
if not config.check_pin(pin_to_int(curpin)):
|
if not config.check_pin(pin_to_int(curpin)):
|
||||||
raise wire.PinInvalid("PIN invalid")
|
raise wire.PinInvalid("PIN invalid")
|
||||||
else:
|
else:
|
||||||
|
@ -13,7 +13,7 @@ async def bootscreen():
|
|||||||
await lockscreen()
|
await lockscreen()
|
||||||
label = None
|
label = None
|
||||||
while True:
|
while True:
|
||||||
pin = await request_pin(label)
|
pin = await request_pin(label, config.get_pin_rem())
|
||||||
if config.unlock(pin_to_int(pin)):
|
if config.unlock(pin_to_int(pin)):
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
|
@ -19,8 +19,9 @@ def generate_digits():
|
|||||||
|
|
||||||
|
|
||||||
class PinMatrix(ui.Widget):
|
class PinMatrix(ui.Widget):
|
||||||
def __init__(self, label, pin="", maxlength=9):
|
def __init__(self, label, sublabel, pin="", maxlength=9):
|
||||||
self.label = label
|
self.label = label
|
||||||
|
self.sublabel = sublabel
|
||||||
self.pin = pin
|
self.pin = pin
|
||||||
self.maxlength = maxlength
|
self.maxlength = maxlength
|
||||||
self.digits = generate_digits()
|
self.digits = generate_digits()
|
||||||
@ -48,7 +49,7 @@ class PinMatrix(ui.Widget):
|
|||||||
return
|
return
|
||||||
|
|
||||||
# clear canvas under input line
|
# clear canvas under input line
|
||||||
display.bar(0, 0, ui.WIDTH, 45, ui.BG)
|
display.bar(0, 0, ui.WIDTH, 52, ui.BG)
|
||||||
|
|
||||||
if self.pin:
|
if self.pin:
|
||||||
# input line with pin
|
# input line with pin
|
||||||
@ -60,6 +61,10 @@ class PinMatrix(ui.Widget):
|
|||||||
x = (box_w - l * padding) // 2
|
x = (box_w - l * padding) // 2
|
||||||
for i in range(0, l):
|
for i in range(0, l):
|
||||||
ui.display.bar_radius(x + i * padding, y, size, size, ui.GREY, ui.BG, 4)
|
ui.display.bar_radius(x + i * padding, y, size, size, ui.GREY, ui.BG, 4)
|
||||||
|
elif self.sublabel:
|
||||||
|
# input line with header label and sublabel
|
||||||
|
display.text_center(ui.WIDTH // 2, 20, self.label, ui.BOLD, ui.GREY, ui.BG)
|
||||||
|
display.text_center(ui.WIDTH // 2, 46, self.sublabel, ui.NORMAL, ui.GREY, ui.BG)
|
||||||
else:
|
else:
|
||||||
# input line with header label
|
# input line with header label
|
||||||
display.text_center(ui.WIDTH // 2, 36, self.label, ui.BOLD, ui.GREY, ui.BG)
|
display.text_center(ui.WIDTH // 2, 36, self.label, ui.BOLD, ui.GREY, ui.BG)
|
||||||
|
Loading…
Reference in New Issue
Block a user