mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-23 06:48:16 +00:00
apps.common: fix request_pin
This commit is contained in:
parent
26f204d04d
commit
984f088519
@ -52,7 +52,7 @@ async def request_pin_on_client(session_id: int, code: int=None) -> str:
|
|||||||
matrix.render()
|
matrix.render()
|
||||||
|
|
||||||
ack = await wire.call(session_id,
|
ack = await wire.call(session_id,
|
||||||
PinMatrixRequest(code=code),
|
PinMatrixRequest(type=code),
|
||||||
PinMatrixAck, Cancel)
|
PinMatrixAck, Cancel)
|
||||||
digits = matrix.digits
|
digits = matrix.digits
|
||||||
matrix = None
|
matrix = None
|
||||||
@ -78,7 +78,7 @@ async def request_pin_twice(session_id: int) -> str:
|
|||||||
return pin_first
|
return pin_first
|
||||||
|
|
||||||
|
|
||||||
async def protect_by_pin(session_id: int, at_least_once: bool=False):
|
async def protect_by_pin_repeatedly(session_id: int, at_least_once: bool=False):
|
||||||
from . import storage
|
from . import storage
|
||||||
|
|
||||||
locked = storage.is_locked() or at_least_once
|
locked = storage.is_locked() or at_least_once
|
||||||
@ -87,9 +87,23 @@ async def protect_by_pin(session_id: int, at_least_once: bool=False):
|
|||||||
locked = not storage.unlock(pin, _render_pin_failure)
|
locked = not storage.unlock(pin, _render_pin_failure)
|
||||||
|
|
||||||
|
|
||||||
|
async def protect_by_pin_or_fail(session_id: int, at_least_once: bool=False):
|
||||||
|
from trezor.messages.FailureType import PinInvalid
|
||||||
|
from . import storage
|
||||||
|
|
||||||
|
locked = storage.is_locked() or at_least_once
|
||||||
|
if locked:
|
||||||
|
pin = await request_pin(session_id)
|
||||||
|
if not storage.unlock(pin, _render_pin_failure):
|
||||||
|
raise wire.FailureError(PinInvalid, 'PIN invalid')
|
||||||
|
|
||||||
|
|
||||||
|
protect_by_pin = protect_by_pin_or_fail
|
||||||
|
|
||||||
|
|
||||||
def _render_pin_failure(sleep_ms: int):
|
def _render_pin_failure(sleep_ms: int):
|
||||||
ui.display.clear()
|
ui.display.clear()
|
||||||
ui.display.text_center(240, 240, 'Sleeping for %d seconds' % sleep_ms / 1000,
|
ui.display.text_center(240, 240, 'Sleeping for %d seconds' % (sleep_ms / 1000),
|
||||||
ui.BOLD, ui.RED, ui.BLACK)
|
ui.BOLD, ui.RED, ui.BLACK)
|
||||||
|
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ def lock():
|
|||||||
|
|
||||||
|
|
||||||
def const_equal(a: bytes, b: bytes) -> bool:
|
def const_equal(a: bytes, b: bytes) -> bool:
|
||||||
return a == b
|
return a == b # TODO: proper const equal
|
||||||
|
|
||||||
|
|
||||||
# settings
|
# settings
|
||||||
@ -176,4 +176,4 @@ def int_to_bytes(i: int) -> bytes:
|
|||||||
|
|
||||||
|
|
||||||
def bytes_to_int(b: bytes) -> int:
|
def bytes_to_int(b: bytes) -> int:
|
||||||
return ustruct.unpack('>L', b) if b else 0
|
return ustruct.unpack('>L', b)[0] if b else 0
|
||||||
|
Loading…
Reference in New Issue
Block a user