mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-17 05:03:07 +00:00
apps.management: add change_pin workflow
This commit is contained in:
parent
64dad27abe
commit
8811814867
@ -1,7 +1,7 @@
|
|||||||
from trezor.wire import register, protobuf_workflow
|
from trezor.wire import register, protobuf_workflow
|
||||||
from trezor.utils import unimport
|
from trezor.utils import unimport
|
||||||
from trezor.messages.wire_types import \
|
from trezor.messages.wire_types import \
|
||||||
LoadDevice, ResetDevice, WipeDevice, RecoveryDevice, ApplySettings
|
LoadDevice, ResetDevice, WipeDevice, RecoveryDevice, ApplySettings, ChangePin
|
||||||
|
|
||||||
|
|
||||||
@unimport
|
@unimport
|
||||||
@ -34,9 +34,16 @@ def dispatch_ApplySettings(*args, **kwargs):
|
|||||||
return layout_apply_settings(*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():
|
def boot():
|
||||||
register(LoadDevice, protobuf_workflow, dispatch_LoadDevice)
|
register(LoadDevice, protobuf_workflow, dispatch_LoadDevice)
|
||||||
register(ResetDevice, protobuf_workflow, dispatch_ResetDevice)
|
register(ResetDevice, protobuf_workflow, dispatch_ResetDevice)
|
||||||
register(WipeDevice, protobuf_workflow, dispatch_WipeDevice)
|
register(WipeDevice, protobuf_workflow, dispatch_WipeDevice)
|
||||||
register(RecoveryDevice, protobuf_workflow, dispatch_RecoveryDevice)
|
register(RecoveryDevice, protobuf_workflow, dispatch_RecoveryDevice)
|
||||||
register(ApplySettings, protobuf_workflow, dispatch_ApplySettings)
|
register(ApplySettings, protobuf_workflow, dispatch_ApplySettings)
|
||||||
|
register(ChangePin, protobuf_workflow, dispatch_ChangePin)
|
||||||
|
53
src/apps/management/change_pin.py
Normal file
53
src/apps/management/change_pin.py
Normal 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')
|
Loading…
Reference in New Issue
Block a user