1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-14 03:30:02 +00:00

apps/management: fix change_pin

This commit is contained in:
Jan Pochyla 2017-12-08 17:26:51 +01:00
parent 314e6a99c1
commit 757978e1c8
3 changed files with 50 additions and 41 deletions

View File

@ -51,10 +51,6 @@ def load_settings(label: str = None, use_passphrase: bool = None):
config.set(_APP, _USE_PASSPHRASE, b'')
def change_pin(pin: str, newpin: str):
return config.change_pin(pin, newpin)
def wipe():
from . import cache
config.wipe()

View File

@ -1,57 +1,70 @@
from trezor import ui
from trezor import config
from trezor.utils import unimport
def confirm_set_pin(ctx):
async def request_pin(ctx):
from trezor.messages.ButtonRequest import ButtonRequest
from trezor.messages.wire_types import ButtonAck
from apps.common.request_pin import request_pin
await ctx.call(ButtonRequest(), ButtonAck)
return await request_pin()
async def request_pin_confirm(ctx):
while True:
pin1 = await request_pin(ctx)
pin2 = await request_pin(ctx)
if pin1 == pin2:
return pin1
# TODO: display a message and wait
def confirm_change_pin(ctx, msg):
from apps.common.confirm import require_confirm
from trezor.ui.text import Text
return require_confirm(ctx, Text(
'Change PIN', ui.ICON_RESET,
'Do you really want to', ui.BOLD,
'set new PIN?'))
has_pin = config.has_pin()
def confirm_change_pin(ctx):
from apps.common.confirm import require_confirm
from trezor.ui.text import Text
return require_confirm(ctx, Text(
'Change PIN', ui.ICON_RESET,
'Do you really want to', ui.BOLD,
'change current PIN?'))
if msg.remove and has_pin: # removing pin
return require_confirm(ctx, Text(
'Remove PIN', ui.ICON_RESET,
'Do you really want to', ui.BOLD,
'remove current PIN?'))
if not msg.remove and has_pin: # changing pin
return require_confirm(ctx, Text(
'Change PIN', ui.ICON_RESET,
'Do you really want to', ui.BOLD,
'change current PIN?'))
def confirm_remove_pin(ctx):
from apps.common.confirm import require_confirm
from trezor.ui.text import Text
return require_confirm(ctx, Text(
'Remove PIN', ui.ICON_RESET,
'Do you really want to', ui.BOLD,
'remove current PIN?'))
if not msg.remove and not has_pin: # setting new pin
return require_confirm(ctx, Text(
'Change PIN', ui.ICON_RESET,
'Do you really want to', ui.BOLD,
'set new PIN?'))
@unimport
async def layout_change_pin(ctx, msg):
from trezor.messages.Success import Success
from apps.common.request_pin import protect_by_pin, request_pin_twice
from apps.common import storage
if msg.remove:
if storage.is_protected_by_pin():
await confirm_remove_pin(ctx)
await protect_by_pin(ctx, at_least_once=True)
pin = ''
await confirm_change_pin(ctx, msg)
if config.has_pin():
curr_pin = await request_pin(ctx)
else:
if storage.is_protected_by_pin():
await confirm_change_pin(ctx)
await protect_by_pin(ctx, at_least_once=True)
else:
await confirm_set_pin(ctx)
pin = await request_pin_twice(ctx)
curr_pin = ''
if msg.remove:
new_pin = ''
else:
new_pin = await request_pin_confirm(ctx)
storage.load_settings(pin=pin)
if pin:
storage.lock()
config.change_pin(curr_pin, new_pin)
if new_pin:
return Success(message='PIN changed')
else:
return Success(message='PIN removed')

View File

@ -1,4 +1,4 @@
from trezor import wire, ui
from trezor import wire, ui, config
from trezor.utils import unimport
@ -29,6 +29,6 @@ async def layout_load_device(ctx, msg):
storage.load_settings(use_passphrase=msg.passphrase_protection,
label=msg.label)
if msg.pin:
storage.change_pin('', msg.pin)
config.change_pin('', msg.pin)
return Success(message='Device loaded')