mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-16 17:42:02 +00:00
wipe_device workflow, pin API work
This commit is contained in:
parent
dd713fe6e2
commit
01ac17440d
@ -1,24 +1,20 @@
|
|||||||
from trezor import wire
|
|
||||||
from trezor import ui
|
from trezor import ui
|
||||||
from trezor.utils import unimport
|
from trezor.utils import unimport
|
||||||
from trezor.workflows.confirm import confirm
|
|
||||||
|
|
||||||
|
|
||||||
@unimport
|
@unimport
|
||||||
def layout_load_device(message):
|
async def layout_load_device(session_id, message):
|
||||||
|
from trezor.workflows.confirm import protect_with_confirm
|
||||||
|
from trezor.messages.Success import Success
|
||||||
|
|
||||||
ui.clear()
|
ui.clear()
|
||||||
ui.display.text_center(120, 40, 'Really load device?',
|
ui.display.text_center(
|
||||||
ui.BOLD, ui.WHITE, ui.BLACK)
|
120, 40, 'Really load device?', ui.BOLD, ui.WHITE, ui.BLACK)
|
||||||
ui.display.text_center(
|
ui.display.text_center(
|
||||||
120, 100, 'Never do this, please.', ui.NORMAL, ui.WHITE, ui.BLACK)
|
120, 100, 'Never do this, please.', ui.NORMAL, ui.WHITE, ui.BLACK)
|
||||||
|
|
||||||
confirmed = yield from confirm()
|
await protect_with_confirm(session_id)
|
||||||
|
|
||||||
if confirmed:
|
# TODO
|
||||||
from trezor.messages.Success import Success
|
|
||||||
yield from wire.write(Success(message='Loaded'))
|
return Success(message='Loaded')
|
||||||
else:
|
|
||||||
from trezor.messages.Failure import Failure
|
|
||||||
from trezor.messages.FailureType import ActionCancelled
|
|
||||||
yield from wire.write(Failure(message='Cancelled', code=ActionCancelled))
|
|
||||||
|
@ -11,7 +11,7 @@ def nth(n):
|
|||||||
|
|
||||||
|
|
||||||
@unimport
|
@unimport
|
||||||
def layout_recovery_device(message):
|
async def layout_recovery_device(session_id, message):
|
||||||
|
|
||||||
msg = 'Please enter ' + nth(message.word_count) + ' word'
|
msg = 'Please enter ' + nth(message.word_count) + ' word'
|
||||||
|
|
||||||
@ -20,4 +20,5 @@ def layout_recovery_device(message):
|
|||||||
ui.BOLD, ui.LIGHT_GREEN, ui.BLACK)
|
ui.BOLD, ui.LIGHT_GREEN, ui.BLACK)
|
||||||
ui.display.text(10, 74, msg, ui.BOLD, ui.WHITE, ui.BLACK)
|
ui.display.text(10, 74, msg, ui.BOLD, ui.WHITE, ui.BLACK)
|
||||||
ui.display.text(10, 104, 'of your mnemonic.', ui.BOLD, ui.WHITE, ui.BLACK)
|
ui.display.text(10, 104, 'of your mnemonic.', ui.BOLD, ui.WHITE, ui.BLACK)
|
||||||
yield from wire.read(None)
|
|
||||||
|
# TODO
|
||||||
|
@ -1,20 +1,23 @@
|
|||||||
from trezor import wire, ui, config
|
from trezor import wire, ui
|
||||||
from trezor.workflows.request_pin import request_new_pin
|
from trezor.workflows.request_pin import request_pin_repeatedly
|
||||||
from trezor.messages.wire_types import EntropyAck
|
from trezor.messages.wire_types import EntropyAck
|
||||||
from trezor.ui.button import Button, CONFIRM_BUTTON, CONFIRM_BUTTON_ACTIVE
|
from trezor.ui.button import Button, CONFIRM_BUTTON, CONFIRM_BUTTON_ACTIVE
|
||||||
from trezor.ui.scroll import paginate, render_scrollbar, animate_swipe
|
from trezor.ui.scroll import paginate, render_scrollbar, animate_swipe
|
||||||
from trezor.crypto import hashlib, random, bip39
|
from trezor.crypto import hashlib, random, bip39
|
||||||
from trezor.utils import unimport, chunks
|
from trezor.utils import unimport, chunks
|
||||||
|
|
||||||
|
from .storage import get_storage, set_storage
|
||||||
APP_MANAGEMENT = const(1)
|
|
||||||
CFG_STORAGE = const(1)
|
|
||||||
|
|
||||||
|
|
||||||
@unimport
|
@unimport
|
||||||
async def layout_reset_device(message, session_id):
|
async def layout_reset_device(message, session_id):
|
||||||
from trezor.messages.Success import Success
|
from trezor.messages.Success import Success
|
||||||
from trezor.messages.Storage import Storage
|
from trezor.messages.Storage import Storage
|
||||||
|
from trezor.messages.FailureType import UnexpectedMessage
|
||||||
|
|
||||||
|
if get_storage(session_id):
|
||||||
|
raise wire.FailureError(
|
||||||
|
UnexpectedMessage, 'Device is already initialized')
|
||||||
|
|
||||||
mnemonic = await generate_mnemonic(
|
mnemonic = await generate_mnemonic(
|
||||||
message.strength, message.display_random, session_id)
|
message.strength, message.display_random, session_id)
|
||||||
@ -22,7 +25,7 @@ async def layout_reset_device(message, session_id):
|
|||||||
await show_mnemonic(mnemonic)
|
await show_mnemonic(mnemonic)
|
||||||
|
|
||||||
if message.pin_protection:
|
if message.pin_protection:
|
||||||
pin = await request_new_pin(session_id)
|
pin = await request_pin_repeatedly(session_id)
|
||||||
else:
|
else:
|
||||||
pin = ''
|
pin = ''
|
||||||
|
|
||||||
@ -30,10 +33,9 @@ async def layout_reset_device(message, session_id):
|
|||||||
version=1, pin=pin, mnemonic=mnemonic,
|
version=1, pin=pin, mnemonic=mnemonic,
|
||||||
passphrase_protection=message.passphrase_protection,
|
passphrase_protection=message.passphrase_protection,
|
||||||
language=message.language, label=message.label)
|
language=message.language, label=message.label)
|
||||||
|
set_storage(session_id, await storage.dumps())
|
||||||
|
|
||||||
config.set(session_id, APP_MANAGEMENT, CFG_STORAGE, await storage.dumps())
|
return Success(message='Initialized')
|
||||||
|
|
||||||
return Success()
|
|
||||||
|
|
||||||
|
|
||||||
@unimport
|
@unimport
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
from trezor import wire
|
from trezor import wire
|
||||||
from trezor import ui
|
from trezor import ui
|
||||||
from trezor.utils import unimport
|
from trezor.utils import unimport
|
||||||
from trezor.workflows.confirm import confirm
|
from trezor.workflows.confirm import protect_with_confirm
|
||||||
|
|
||||||
|
from .storage import clear_storage
|
||||||
|
|
||||||
|
|
||||||
@unimport
|
@unimport
|
||||||
def layout_wipe_device(message):
|
async def layout_wipe_device(message, session_id):
|
||||||
|
from trezor.messages.Success import Success
|
||||||
|
|
||||||
ui.clear()
|
ui.clear()
|
||||||
ui.display.text(10, 30, 'Wiping device', ui.BOLD, ui.LIGHT_GREEN, ui.BLACK)
|
ui.display.text(10, 30, 'Wiping device', ui.BOLD, ui.LIGHT_GREEN, ui.BLACK)
|
||||||
@ -15,12 +18,8 @@ def layout_wipe_device(message):
|
|||||||
ui.display.text(10, 164, 'All data will be lost.',
|
ui.display.text(10, 164, 'All data will be lost.',
|
||||||
ui.NORMAL, ui.WHITE, ui.BLACK)
|
ui.NORMAL, ui.WHITE, ui.BLACK)
|
||||||
|
|
||||||
confirmed = yield from confirm()
|
await protect_with_confirm(session_id)
|
||||||
|
|
||||||
if confirmed:
|
clear_storage(session_id)
|
||||||
from trezor.messages.Success import Success
|
|
||||||
yield from wire.write(Success(message='Wiped'))
|
return Success(message='Wiped')
|
||||||
else:
|
|
||||||
from trezor.messages.Failure import Failure
|
|
||||||
from trezor.messages.FailureType import ActionCancelled
|
|
||||||
yield from wire.write(Failure(message='Cancelled', code=ActionCancelled))
|
|
||||||
|
17
src/apps/management/storage.py
Normal file
17
src/apps/management/storage.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
from trezor import config
|
||||||
|
|
||||||
|
|
||||||
|
APP_MANAGEMENT = const(1)
|
||||||
|
CFG_STORAGE = const(1)
|
||||||
|
|
||||||
|
|
||||||
|
def get_storage(session_id):
|
||||||
|
return config.get(session_id, APP_MANAGEMENT, CFG_STORAGE)
|
||||||
|
|
||||||
|
|
||||||
|
def set_storage(session_id, buf):
|
||||||
|
config.set(session_id, APP_MANAGEMENT, CFG_STORAGE, buf)
|
||||||
|
|
||||||
|
|
||||||
|
def clear_storage(session_id):
|
||||||
|
set_storage(session_id, '')
|
@ -1,27 +1,22 @@
|
|||||||
from trezor import wire, ui
|
from trezor import wire, ui
|
||||||
from trezor.utils import unimport
|
from trezor.utils import unimport
|
||||||
from trezor.workflows.request_pin import request_pin
|
|
||||||
|
|
||||||
|
|
||||||
@unimport
|
@unimport
|
||||||
def layout_get_public_key(message):
|
async def layout_get_public_key(session_id, message):
|
||||||
|
from trezor.messages.PublicKey import PublicKey
|
||||||
|
from trezor.messages.HDNodeType import HDNodeType
|
||||||
|
|
||||||
ui.clear()
|
# TODO: protect with pin
|
||||||
pin = yield from request_pin()
|
# TODO: fail if not initialized
|
||||||
|
# TODO: derive correct node
|
||||||
|
|
||||||
if pin is not None:
|
pubkey = PublicKey()
|
||||||
from trezor.messages.PublicKey import PublicKey
|
pubkey.node = HDNodeType()
|
||||||
from trezor.messages.HDNodeType import HDNodeType
|
pubkey.node.depth = 0
|
||||||
pubkey = PublicKey()
|
pubkey.node.child_num = 0
|
||||||
pubkey.node = HDNodeType()
|
pubkey.node.fingerprint = 0
|
||||||
pubkey.node.depth = 0
|
pubkey.node.chain_code = 'deadbeef'
|
||||||
pubkey.node.child_num = 0
|
pubkey.node.public_key = 'deadbeef'
|
||||||
pubkey.node.fingerprint = 0
|
|
||||||
pubkey.node.chain_code = 'deadbeef'
|
|
||||||
pubkey.node.public_key = 'deadbeef'
|
|
||||||
yield from wire.write(pubkey)
|
|
||||||
|
|
||||||
else:
|
return pubkey
|
||||||
from trezor.messages.Failure import Failure
|
|
||||||
from trezor.messages.FailureType import ActionCancelled
|
|
||||||
yield from wire.write(Failure(message='Cancelled', code=ActionCancelled))
|
|
||||||
|
@ -3,18 +3,26 @@ from trezor.utils import unimport
|
|||||||
|
|
||||||
|
|
||||||
@unimport
|
@unimport
|
||||||
async def confirm(content=None, code=None, **kwargs):
|
async def confirm(session_id, content=None, code=None, **kwargs):
|
||||||
from trezor.ui.confirm import ConfirmDialog, CONFIRMED
|
from trezor.ui.confirm import ConfirmDialog, CONFIRMED
|
||||||
from trezor.messages.ButtonRequest import ButtonRequest
|
from trezor.messages.ButtonRequest import ButtonRequest
|
||||||
from trezor.messages.ButtonRequestType import Other
|
from trezor.messages.ButtonRequestType import Other
|
||||||
from trezor.messages.ButtonAck import ButtonAck
|
from trezor.messages.wire_types import ButtonAck
|
||||||
|
|
||||||
dialog = ConfirmDialog(content, **kwargs)
|
dialog = ConfirmDialog(content, **kwargs)
|
||||||
dialog.render()
|
dialog.render()
|
||||||
|
|
||||||
if code is None:
|
if code is None:
|
||||||
code = Other
|
code = Other
|
||||||
ack = await wire.call(ButtonRequest(code=code), ButtonAck)
|
await wire.reply_message(session_id, ButtonRequest(code=code), ButtonAck)
|
||||||
res = await dialog
|
return await dialog == CONFIRMED
|
||||||
|
|
||||||
return res == CONFIRMED
|
|
||||||
|
@unimport
|
||||||
|
async def protect_with_confirm(*args, **kwargs):
|
||||||
|
from trezor.messages.FailureType import ActionCancelled
|
||||||
|
|
||||||
|
confirmed = await confirm(*args, **kwargs)
|
||||||
|
|
||||||
|
if not confirmed:
|
||||||
|
raise wire.FailureError(ActionCancelled, 'Cancelled')
|
||||||
|
@ -26,7 +26,7 @@ async def request_pin(session_id, *args, **kwargs):
|
|||||||
|
|
||||||
|
|
||||||
@unimport
|
@unimport
|
||||||
async def request_new_pin(session_id):
|
async def request_pin_repeatedly(session_id):
|
||||||
from trezor.messages.FailureType import PinInvalid
|
from trezor.messages.FailureType import PinInvalid
|
||||||
|
|
||||||
pin_first = await request_pin(session_id)
|
pin_first = await request_pin(session_id)
|
||||||
|
Loading…
Reference in New Issue
Block a user