1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-27 00:28:10 +00:00

apps.management: add change_pin workflow

This commit is contained in:
Jan Pochyla 2016-12-15 12:36:07 +01:00
parent 64dad27abe
commit 8811814867
2 changed files with 61 additions and 1 deletions

View File

@ -1,7 +1,7 @@
from trezor.wire import register, protobuf_workflow
from trezor.utils import unimport
from trezor.messages.wire_types import \
LoadDevice, ResetDevice, WipeDevice, RecoveryDevice, ApplySettings
LoadDevice, ResetDevice, WipeDevice, RecoveryDevice, ApplySettings, ChangePin
@unimport
@ -34,9 +34,16 @@ def dispatch_ApplySettings(*args, **kwargs):
return layout_apply_settings(*args, **kwargs)
@unimport
def dispatch_ChangePin(*args, **kwargs):
from .change_pin import layout_change_pin
return layout_change_pin(*args, **kwargs)
def boot():
register(LoadDevice, protobuf_workflow, dispatch_LoadDevice)
register(ResetDevice, protobuf_workflow, dispatch_ResetDevice)
register(WipeDevice, protobuf_workflow, dispatch_WipeDevice)
register(RecoveryDevice, protobuf_workflow, dispatch_RecoveryDevice)
register(ApplySettings, protobuf_workflow, dispatch_ApplySettings)
register(ChangePin, protobuf_workflow, dispatch_ChangePin)

View File

@ -0,0 +1,53 @@
from trezor import ui
from trezor.utils import unimport
def confirm_set_pin(session_id):
from apps.common.confirm import require_confirm
from trezor.ui.text import Text
return require_confirm(session_id, Text(
'Change PIN', ui.ICON_RESET,
'Do you really want to', ui.BOLD,
'set new PIN?'))
def confirm_change_pin(session_id):
from apps.common.confirm import require_confirm
from trezor.ui.text import Text
return require_confirm(session_id, Text(
'Change PIN', ui.ICON_RESET,
'Do you really want to', ui.BOLD,
'change current PIN?'))
def confirm_remove_pin(session_id):
from apps.common.confirm import require_confirm
from trezor.ui.text import Text
return require_confirm(session_id, Text(
'Remove PIN', ui.ICON_RESET,
'Do you really want to', ui.BOLD,
'remove current PIN?'))
@unimport
async def layout_change_pin(session_id, msg):
from trezor.messages.Success import Success
from ..common.request_pin import protect_by_pin, request_pin_twice
from ..common import storage
if msg.remove:
if storage.is_protected_by_pin():
await confirm_remove_pin(session_id)
await protect_by_pin(session_id)
storage.load_settings(pin='')
return Success(message='PIN removed')
else:
if storage.is_protected_by_pin():
await confirm_change_pin(session_id)
await protect_by_pin(session_id)
else:
await confirm_set_pin(session_id)
pin = await request_pin_twice(session_id)
storage.load_settings(pin=pin)
return Success(message='PIN changed')