- request/response manner of usual protobuf workflows is enforced, workflows are expected to either return a valid protobuf response, or raise an exception - added wire.FailureError exception that allows workflow to provide Failure code & message - pin workflows simplified TODO: all this workflow work does not really belong in trezor.wirepull/25/head
parent
70110187cc
commit
34ed2fb86a
@ -1,58 +1,37 @@
|
||||
from trezor import ui
|
||||
from trezor import wire
|
||||
from trezor import config
|
||||
from trezor.utils import unimport
|
||||
|
||||
MANAGEMENT_APP = const(1)
|
||||
|
||||
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
|
||||
@unimport
|
||||
async def request_pin(session_id, *args, **kwargs):
|
||||
from trezor.messages.ButtonRequest import ButtonRequest
|
||||
from trezor.messages.ButtonRequestType import ProtectCall
|
||||
from trezor.messages.FailureType import PinCancelled
|
||||
from trezor.messages.wire_types import ButtonAck
|
||||
from trezor.ui.confirm import ConfirmDialog, CONFIRMED
|
||||
from trezor.ui.pin import PinMatrix
|
||||
|
||||
ui.clear()
|
||||
await wire.reply_message(session_id,
|
||||
ButtonRequest(code=ProtectCall),
|
||||
ButtonAck)
|
||||
|
||||
ui.clear()
|
||||
matrix = PinMatrix(*args, **kwargs)
|
||||
dialog = ConfirmDialog(matrix)
|
||||
result = yield from dialog.wait()
|
||||
if await dialog != CONFIRMED:
|
||||
raise wire.FailureError(PinCancelled, 'PIN cancelled')
|
||||
|
||||
return matrix.pin if result == CONFIRMED else None
|
||||
return matrix.pin
|
||||
|
||||
|
||||
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)
|
||||
pin = yield from prompt_pin(*args, **kwargs)
|
||||
|
||||
return pin
|
||||
|
||||
|
||||
def change_pin():
|
||||
pass
|
||||
|
||||
|
||||
def protect_with_pin():
|
||||
from trezor.messages.Failure import Failure
|
||||
@unimport
|
||||
async def request_new_pin(session_id):
|
||||
from trezor.messages.FailureType import PinInvalid
|
||||
from trezor.messages.FailureType import ActionCancelled
|
||||
|
||||
pin_protect = config.get(MANAGEMENT_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')
|
||||
pin_first = await request_pin(session_id)
|
||||
pin_again = await request_pin(session_id, 'Enter PIN again')
|
||||
if pin_first != pin_again:
|
||||
raise wire.FailureError(PinInvalid, 'PIN invalid')
|
||||
|
||||
stored_pin = config.get(MANAGEMENT_APP, PIN)
|
||||
if stored_pin != entered_pin:
|
||||
yield from wire.write(Failure(code=PinInvalid, message='PIN invalid'))
|
||||
raise Exception('PIN invalid')
|
||||
return pin_first
|
||||
|
Loading…
Reference in new issue