1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-22 06:18:07 +00:00

src/apps/common: implement unfinished_backup flag in the storage

This commit is contained in:
Pavol Rusnak 2018-03-12 16:22:56 +01:00
parent e6bfd192e5
commit b83ffee3af
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
6 changed files with 27 additions and 4 deletions

View File

@ -14,12 +14,13 @@ _VERSION = const(0x01) # int
_MNEMONIC = const(0x02) # str
_LANGUAGE = const(0x03) # str
_LABEL = const(0x04) # str
_USE_PASSPHRASE = const(0x05) # 0x01 or empty
_USE_PASSPHRASE = const(0x05) # bool (0x01 or empty)
_HOMESCREEN = const(0x06) # bytes
_NEEDS_BACKUP = const(0x07) # 0x01 or empty
_NEEDS_BACKUP = const(0x07) # bool (0x01 or empty)
_FLAGS = const(0x08) # int
_U2F_COUNTER = const(0x09) # int
_PASSPHRASE_SOURCE = const(0x0A) # int
_UNFINISHED_BACKUP = const(0x0B) # bool (0x01 or empty)
def _new_device_id() -> str:
@ -71,6 +72,17 @@ def set_backed_up() -> None:
config.set(_APP, _NEEDS_BACKUP, b'')
def unfinished_backup() -> bool:
return bool(config.get(_APP, _UNFINISHED_BACKUP))
def set_unfinished_backup(state: bool) -> None:
if state:
config.set(_APP, _UNFINISHED_BACKUP, b'\x01')
else:
config.set(_APP, _UNFINISHED_BACKUP, b'')
def get_passphrase_source() -> int:
b = config.get(_APP, _PASSPHRASE_SOURCE)
if b == b'\x01':

View File

@ -33,6 +33,7 @@ async def respond_Features(ctx, msg):
f.flags = storage.get_flags()
if model() in ['T', 'EMU']: # emulator currently emulates model T
f.model = 'T'
f.unfinished_backup = storage.unfinished_backup()
return f

View File

@ -22,7 +22,11 @@ def display_homescreen():
if not image:
image = res.load('apps/homescreen/res/bg.toif')
if storage.is_initialized() and storage.needs_backup():
if storage.is_initialized() and storage.unfinished_backup():
ui.display.bar(0, 0, ui.WIDTH, 30, ui.RED)
ui.display.text_center(ui.WIDTH // 2, 22, 'BROKEN BACKUP!', ui.BOLD, ui.WHITE, ui.RED)
ui.display.bar(0, 30, ui.WIDTH, ui.HEIGHT - 30, ui.BG)
elif storage.is_initialized() and storage.needs_backup():
ui.display.bar(0, 0, ui.WIDTH, 30, ui.YELLOW)
ui.display.text_center(ui.WIDTH // 2, 22, 'NEEDS BACKUP!', ui.BOLD, ui.BLACK, ui.YELLOW)
ui.display.bar(0, 30, ui.WIDTH, ui.HEIGHT - 30, ui.BG)

View File

@ -17,6 +17,7 @@ async def backup_device(ctx, msg):
# warn user about mnemonic safety
await show_warning(ctx)
storage.set_unfinished_backup(True)
storage.set_backed_up()
while True:
@ -26,4 +27,6 @@ async def backup_device(ctx, msg):
break
await show_wrong_entry(ctx)
storage.set_unfinished_backup(False)
return Success(message='Seed successfully backed up')

View File

@ -31,6 +31,7 @@ class Features(p.MessageType):
24: ('fw_patch', p.UVarintType, 0),
25: ('fw_vendor', p.UnicodeType, 0),
26: ('fw_vendor_keys', p.BytesType, 0),
27: ('unfinished_backup', p.BoolType, 0),
}
MESSAGE_WIRE_TYPE = 17
@ -62,6 +63,7 @@ class Features(p.MessageType):
fw_patch: int = None,
fw_vendor: str = None,
fw_vendor_keys: bytes = None,
unfinished_backup: bool = None,
**kwargs,
):
self.vendor = vendor
@ -90,4 +92,5 @@ class Features(p.MessageType):
self.fw_patch = fw_patch
self.fw_vendor = fw_vendor
self.fw_vendor_keys = fw_vendor_keys
self.unfinished_backup = unfinished_backup
p.MessageType.__init__(self, **kwargs)

@ -1 +1 @@
Subproject commit 998eb4c7a76bdb5190f5f9f52bf8c53d795fbb25
Subproject commit d83bb5464c4efc1e90c9575dd3088333d1066f5f