mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-19 12:58:13 +00:00
apps/management/reset_device: minor fixes
This commit is contained in:
parent
5701e57b48
commit
57e350fbbf
@ -12,8 +12,8 @@ def dispatch_LoadDevice(*args, **kwargs):
|
|||||||
|
|
||||||
@unimport
|
@unimport
|
||||||
def dispatch_ResetDevice(*args, **kwargs):
|
def dispatch_ResetDevice(*args, **kwargs):
|
||||||
from .reset_device import layout_reset_device
|
from .reset_device import reset_device
|
||||||
return layout_reset_device(*args, **kwargs)
|
return reset_device(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
@unimport
|
@unimport
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
from micropython import const
|
from micropython import const
|
||||||
from trezor import wire, ui
|
from trezor import config, ui, wire
|
||||||
from trezor.ui.container import Container
|
|
||||||
from trezor.utils import unimport, chunks
|
from trezor.utils import unimport, chunks
|
||||||
from ubinascii import hexlify
|
from ubinascii import hexlify
|
||||||
|
|
||||||
@ -8,11 +7,11 @@ if __debug__:
|
|||||||
internal_entropy = None
|
internal_entropy = None
|
||||||
current_word = None
|
current_word = None
|
||||||
|
|
||||||
|
|
||||||
@unimport
|
@unimport
|
||||||
async def layout_reset_device(ctx, msg):
|
async def reset_device(ctx, msg):
|
||||||
from trezor import config
|
|
||||||
from trezor.ui.text import Text
|
from trezor.ui.text import Text
|
||||||
from trezor.crypto import hashlib, random, bip39, random
|
from trezor.crypto import hashlib, random, bip39
|
||||||
from trezor.ui.keyboard import MnemonicKeyboard
|
from trezor.ui.keyboard import MnemonicKeyboard
|
||||||
from trezor.messages.EntropyRequest import EntropyRequest
|
from trezor.messages.EntropyRequest import EntropyRequest
|
||||||
from trezor.messages.Success import Success
|
from trezor.messages.Success import Success
|
||||||
@ -36,11 +35,13 @@ async def layout_reset_device(ctx, msg):
|
|||||||
|
|
||||||
internal_entropy = random.bytes(32)
|
internal_entropy = random.bytes(32)
|
||||||
|
|
||||||
|
# display internal entropy
|
||||||
if msg.display_random:
|
if msg.display_random:
|
||||||
entropy_lines = chunks(hexlify(internal_entropy).decode(), 16)
|
entropy_lines = chunks(hexlify(internal_entropy).decode(), 16)
|
||||||
entropy_content = Text('Internal entropy', ui.ICON_RESET, ui.MONO, *entropy_lines)
|
entropy_content = Text('Internal entropy', ui.ICON_RESET, ui.MONO, *entropy_lines)
|
||||||
await require_confirm(ctx, entropy_content, ButtonRequestType.ResetDevice)
|
await require_confirm(ctx, entropy_content, ButtonRequestType.ResetDevice)
|
||||||
|
|
||||||
|
# request new PIN
|
||||||
if msg.pin_protection:
|
if msg.pin_protection:
|
||||||
curpin = ''
|
curpin = ''
|
||||||
newpin = await request_pin_confirm(ctx)
|
newpin = await request_pin_confirm(ctx)
|
||||||
@ -48,6 +49,7 @@ async def layout_reset_device(ctx, msg):
|
|||||||
curpin = ''
|
curpin = ''
|
||||||
newpin = ''
|
newpin = ''
|
||||||
|
|
||||||
|
# request external entropy and compute mnemonic
|
||||||
external_entropy_ack = await ctx.call(EntropyRequest(), EntropyAck)
|
external_entropy_ack = await ctx.call(EntropyRequest(), EntropyAck)
|
||||||
ehash = hashlib.sha256()
|
ehash = hashlib.sha256()
|
||||||
ehash.update(internal_entropy)
|
ehash.update(internal_entropy)
|
||||||
@ -55,79 +57,62 @@ async def layout_reset_device(ctx, msg):
|
|||||||
entropy = ehash.digest()
|
entropy = ehash.digest()
|
||||||
mnemonic = bip39.from_data(entropy[:msg.strength // 8])
|
mnemonic = bip39.from_data(entropy[:msg.strength // 8])
|
||||||
|
|
||||||
# seed-copy warning
|
# mnemonic safety warning
|
||||||
warning_content = Text('Backup your seed', ui.ICON_NOCOPY, ui.NORMAL,
|
warning_content = Text(
|
||||||
|
'Backup your seed', ui.ICON_NOCOPY, ui.NORMAL,
|
||||||
'Never make a digital',
|
'Never make a digital',
|
||||||
'copy of your recovery',
|
'copy of your recovery',
|
||||||
'seed and never upload',
|
'seed and never upload',
|
||||||
'it online!')
|
'it online!')
|
||||||
await require_confirm(ctx, warning_content, ButtonRequestType.ResetDevice)
|
await require_confirm(
|
||||||
|
ctx,
|
||||||
|
warning_content,
|
||||||
|
ButtonRequestType.ResetDevice,
|
||||||
|
confirm='I understand',
|
||||||
|
cancel=None)
|
||||||
|
|
||||||
# ask to write down mnemonic
|
# ask to write down mnemonic
|
||||||
await show_mnemonic(mnemonic)
|
await show_mnemonic(mnemonic)
|
||||||
|
|
||||||
# ask for random number to check correctness
|
# ask for random word to check correctness
|
||||||
words = list(enumerate(mnemonic.split()))
|
words = mnemonic.split()
|
||||||
index = random.uniform(len(words))
|
index = random.uniform(len(words))
|
||||||
word = words[index][1]
|
res = await MnemonicKeyboard('Type %s. word' % (index + 1))
|
||||||
board = MnemonicKeyboard()
|
if res != words[index]:
|
||||||
board.prompt = ('Type %s. word' % (index + 1))
|
content = Text(
|
||||||
res = await board
|
'Wrong entry!', ui.ICON_CLEAR,
|
||||||
if res != word:
|
|
||||||
fail_content = Text('Wrong entry!', ui.ICON_CLEAR, ui.NORMAL,
|
|
||||||
'You have entered',
|
'You have entered',
|
||||||
'wrong seed word.',
|
'wrong seed word.',
|
||||||
'Please, reconnect',
|
'Please, reconnect',
|
||||||
'device and try again.', icon_color=ui.RED)
|
'the device and try again.', icon_color=ui.RED)
|
||||||
# todo redesign dialog to single cancel button with text 'Reconnect' or something else (no icon)
|
ui.display.clear()
|
||||||
await require_confirm(ctx, fail_content, ButtonRequestType.ResetDevice)
|
await content
|
||||||
|
raise wire.FailureError(FailureType.DataError, 'Wrong entry')
|
||||||
|
|
||||||
|
# write into storage
|
||||||
if curpin != newpin:
|
if curpin != newpin:
|
||||||
config.change_pin(curpin, newpin)
|
config.change_pin(curpin, newpin)
|
||||||
storage.load_settings(label=msg.label,
|
storage.load_settings(
|
||||||
use_passphrase=msg.passphrase_protection)
|
label=msg.label, use_passphrase=msg.passphrase_protection)
|
||||||
storage.load_mnemonic(mnemonic)
|
storage.load_mnemonic(mnemonic)
|
||||||
|
|
||||||
fail_content = Text('Backup is done!', ui.ICON_CONFIRM, ui.NORMAL,
|
# show success message
|
||||||
|
content = Text(
|
||||||
|
'Backup is done!', ui.ICON_CONFIRM,
|
||||||
'Never make a digital',
|
'Never make a digital',
|
||||||
'copy of your recovery',
|
'copy of your recovery',
|
||||||
'seed and never upload',
|
'seed and never upload',
|
||||||
'it online!', icon_color=ui.GREEN)
|
'it online!', icon_color=ui.GREEN)
|
||||||
# todo redesign dialog to single cancel button with text 'Finish?' or something else (no icon)
|
await require_confirm(
|
||||||
await require_confirm(ctx, fail_content, ButtonRequestType.ResetDevice)
|
ctx,
|
||||||
|
content,
|
||||||
|
ButtonRequestType.ResetDevice,
|
||||||
|
confirm='Finish setup',
|
||||||
|
cancel=None)
|
||||||
|
|
||||||
return Success(message='Initialized')
|
return Success(message='Initialized')
|
||||||
|
|
||||||
|
|
||||||
async def show_mnemonic_by_word(ctx, mnemonic):
|
|
||||||
from trezor.ui.text import Text
|
|
||||||
from trezor.messages.ButtonRequestType import ConfirmWord
|
|
||||||
from apps.common.confirm import confirm
|
|
||||||
|
|
||||||
words = mnemonic.split()
|
|
||||||
|
|
||||||
if __debug__:
|
|
||||||
global current_word
|
|
||||||
|
|
||||||
for index, word in enumerate(words):
|
|
||||||
if __debug__:
|
|
||||||
current_word = word
|
|
||||||
await confirm(ctx,
|
|
||||||
Text('Recovery seed setup', ui.ICON_RESET,
|
|
||||||
ui.NORMAL, 'Write down seed word', '',
|
|
||||||
ui.BOLD, '%d. %s' % (index + 1, word)),
|
|
||||||
ConfirmWord, confirm='Next', cancel=None)
|
|
||||||
|
|
||||||
for index, word in enumerate(words):
|
|
||||||
if __debug__:
|
|
||||||
current_word = word
|
|
||||||
await confirm(ctx,
|
|
||||||
Text('Recovery seed setup', ui.ICON_RESET,
|
|
||||||
ui.NORMAL, 'Confirm seed word', '',
|
|
||||||
ui.BOLD, '%d. %s' % (index + 1, word)),
|
|
||||||
ConfirmWord, confirm='Next', cancel=None)
|
|
||||||
|
|
||||||
|
|
||||||
async def show_mnemonic(mnemonic):
|
async def show_mnemonic(mnemonic):
|
||||||
from trezor.ui.scroll import paginate
|
from trezor.ui.scroll import paginate
|
||||||
|
|
||||||
@ -143,17 +128,18 @@ async def show_mnemonic_page(page, page_count, mnemonic):
|
|||||||
from trezor.ui.text import Text
|
from trezor.ui.text import Text
|
||||||
from trezor.ui.scroll import Scrollpage, animate_swipe
|
from trezor.ui.scroll import Scrollpage, animate_swipe
|
||||||
|
|
||||||
lines = []
|
lines = ['%d. %s' % (wi + 1, word) for wi, word in mnemonic[page]]
|
||||||
for pi, (wi, word) in enumerate(mnemonic[page]):
|
scroll_page = Scrollpage(
|
||||||
pos = wi + 1
|
Text('Recovery seed setup', ui.ICON_RESET, ui.MONO, lines),
|
||||||
lines.append(str('%d. %s' % (pos, word)))
|
page,
|
||||||
|
page_count)
|
||||||
ui.display.clear()
|
ui.display.clear()
|
||||||
scroll_page = Scrollpage(Text('Recovery seed setup', ui.ICON_RESET, ui.MONO, lines), page, page_count)
|
|
||||||
scroll_page.render()
|
scroll_page.render()
|
||||||
|
|
||||||
if page + 1 == page_count:
|
if page + 1 == page_count:
|
||||||
await Button(
|
await Button(
|
||||||
(0, 240 - 48, 240, 48),
|
ui.grid(4, n_x=1),
|
||||||
'Finalize',
|
"I'm done",
|
||||||
normal_style=ui.BTN_CONFIRM,
|
normal_style=ui.BTN_CONFIRM,
|
||||||
active_style=ui.BTN_CONFIRM_ACTIVE)
|
active_style=ui.BTN_CONFIRM_ACTIVE)
|
||||||
ui.display.clear()
|
ui.display.clear()
|
||||||
|
Loading…
Reference in New Issue
Block a user