1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-18 13:38:12 +00:00
trezor-firmware/src/trezor/workflows/request_pin.py

60 lines
1.6 KiB
Python
Raw Normal View History

2016-06-09 14:28:34 +00:00
from trezor import ui
from trezor import wire
2016-06-09 14:28:34 +00:00
from trezor import config
from trezor.utils import unimport_gen
2016-06-09 14:28:34 +00:00
MGMT_APP = const(1)
2016-06-09 14:28:34 +00:00
PASSPHRASE_PROTECT = (1) # 0 | 1
PIN_PROTECT = const(2) # 0 | 1
PIN = const(4) # str
def prompt_pin(*args, **kwargs):
from trezor.ui.pin import PinMatrix
from trezor.ui.confirm import ConfirmDialog, CONFIRMED
2016-06-09 14:28:34 +00:00
ui.clear()
matrix = PinMatrix(*args, **kwargs)
dialog = ConfirmDialog(matrix)
result = yield from dialog.wait()
return matrix.pin if result == CONFIRMED else None
def request_pin(*args, **kwargs):
from trezor.messages.ButtonRequest import ButtonRequest
from trezor.messages.ButtonRequestType import ProtectCall
from trezor.messages.ButtonAck import ButtonAck
ack = yield from wire.call(ButtonRequest(code=ProtectCall), ButtonAck)
2016-06-09 14:28:34 +00:00
pin = yield from prompt_pin(*args, **kwargs)
return pin
def change_pin():
pass
@unimport_gen
def protect_with_pin():
from trezor.messages.Failure import Failure
from trezor.messages.FailureType import PinInvalid
from trezor.messages.FailureType import ActionCancelled
pin_protect = config.get(MGMT_APP, PIN_PROTECT)
if not pin_protect:
return
entered_pin = yield from request_pin()
if entered_pin is None:
yield from wire.write(Failure(code=ActionCancelled, message='Cancelled'))
raise Exception('Cancelled')
2016-06-09 14:28:34 +00:00
stored_pin = config.get(MGMT_APP, PIN)
if stored_pin != entered_pin:
yield from wire.write(Failure(code=PinInvalid, message='PIN invalid'))
raise Exception('PIN invalid')