From 8811814867dc33065980ed6c0a348e29e6bd986d Mon Sep 17 00:00:00 2001 From: Jan Pochyla Date: Thu, 15 Dec 2016 12:36:07 +0100 Subject: [PATCH] apps.management: add change_pin workflow --- src/apps/management/__init__.py | 9 +++++- src/apps/management/change_pin.py | 53 +++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 src/apps/management/change_pin.py diff --git a/src/apps/management/__init__.py b/src/apps/management/__init__.py index 3bc27cd0f..3f6e54f77 100644 --- a/src/apps/management/__init__.py +++ b/src/apps/management/__init__.py @@ -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) diff --git a/src/apps/management/change_pin.py b/src/apps/management/change_pin.py new file mode 100644 index 000000000..e29cc3fc5 --- /dev/null +++ b/src/apps/management/change_pin.py @@ -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')