2019-09-01 18:12:49 +00:00
|
|
|
from trezor import config, io, log, loop, res, ui, utils
|
2017-12-15 20:06:29 +00:00
|
|
|
from trezor.pin import pin_to_int, show_pin_timeout
|
2018-07-03 14:20:26 +00:00
|
|
|
|
2019-01-04 15:23:14 +00:00
|
|
|
from apps.common import storage
|
2019-01-11 19:57:12 +00:00
|
|
|
from apps.common.request_pin import request_pin
|
2019-08-13 15:50:06 +00:00
|
|
|
from apps.common.sd_salt import request_sd_salt
|
|
|
|
from apps.common.storage import device
|
|
|
|
|
|
|
|
if False:
|
|
|
|
from typing import Optional
|
2017-12-14 16:14:15 +00:00
|
|
|
|
|
|
|
|
2019-07-03 13:07:04 +00:00
|
|
|
async def bootscreen() -> None:
|
2019-07-01 07:45:30 +00:00
|
|
|
ui.display.orientation(storage.device.get_rotation())
|
2019-08-13 15:50:06 +00:00
|
|
|
salt_auth_key = device.get_sd_salt_auth_key()
|
|
|
|
|
2017-10-24 11:59:09 +00:00
|
|
|
while True:
|
2018-02-19 19:36:12 +00:00
|
|
|
try:
|
2019-08-13 15:50:06 +00:00
|
|
|
if salt_auth_key is not None or config.has_pin():
|
|
|
|
await lockscreen()
|
|
|
|
|
|
|
|
if salt_auth_key is not None:
|
|
|
|
salt = await request_sd_salt(
|
|
|
|
None, salt_auth_key
|
|
|
|
) # type: Optional[bytearray]
|
|
|
|
else:
|
|
|
|
salt = None
|
|
|
|
|
2018-02-19 19:36:12 +00:00
|
|
|
if not config.has_pin():
|
2019-08-13 15:50:06 +00:00
|
|
|
config.unlock(pin_to_int(""), salt)
|
2019-01-04 15:23:14 +00:00
|
|
|
storage.init_unlocked()
|
2018-02-19 19:36:12 +00:00
|
|
|
return
|
2019-08-13 15:50:06 +00:00
|
|
|
|
2019-05-13 13:06:34 +00:00
|
|
|
label = "Enter your PIN"
|
2018-02-19 19:36:12 +00:00
|
|
|
while True:
|
2018-12-28 16:10:16 +00:00
|
|
|
pin = await request_pin(label, config.get_pin_rem())
|
2019-08-13 15:50:06 +00:00
|
|
|
if config.unlock(pin_to_int(pin), salt):
|
2019-01-04 15:23:14 +00:00
|
|
|
storage.init_unlocked()
|
2018-02-19 19:36:12 +00:00
|
|
|
return
|
2018-02-27 19:21:54 +00:00
|
|
|
else:
|
2018-07-03 14:20:58 +00:00
|
|
|
label = "Wrong PIN, enter again"
|
2018-10-10 13:43:33 +00:00
|
|
|
except Exception as e:
|
|
|
|
if __debug__:
|
|
|
|
log.exception(__name__, e)
|
2018-02-19 19:36:12 +00:00
|
|
|
|
|
|
|
|
2019-07-03 13:07:04 +00:00
|
|
|
async def lockscreen() -> None:
|
2019-07-01 07:45:30 +00:00
|
|
|
label = storage.device.get_label()
|
|
|
|
image = storage.device.get_homescreen()
|
2018-02-19 19:36:12 +00:00
|
|
|
if not label:
|
2019-06-17 18:27:55 +00:00
|
|
|
label = "My Trezor"
|
2018-02-19 19:36:12 +00:00
|
|
|
if not image:
|
2018-07-03 14:20:58 +00:00
|
|
|
image = res.load("apps/homescreen/res/bg.toif")
|
2018-02-19 19:36:12 +00:00
|
|
|
|
2019-05-13 13:06:34 +00:00
|
|
|
ui.backlight_fade(ui.BACKLIGHT_DIM)
|
2018-02-19 19:36:12 +00:00
|
|
|
|
2018-02-27 14:34:13 +00:00
|
|
|
ui.display.clear()
|
|
|
|
ui.display.avatar(48, 48, image, ui.TITLE_GREY, ui.BG)
|
2018-03-01 00:13:26 +00:00
|
|
|
ui.display.text_center(ui.WIDTH // 2, 35, label, ui.BOLD, ui.TITLE_GREY, ui.BG)
|
2018-02-27 14:34:13 +00:00
|
|
|
|
|
|
|
ui.display.bar_radius(40, 100, 160, 40, ui.TITLE_GREY, ui.BG, 4)
|
|
|
|
ui.display.bar_radius(42, 102, 156, 36, ui.BG, ui.TITLE_GREY, 4)
|
2018-07-03 14:20:58 +00:00
|
|
|
ui.display.text_center(ui.WIDTH // 2, 128, "Locked", ui.BOLD, ui.TITLE_GREY, ui.BG)
|
2018-02-27 14:34:13 +00:00
|
|
|
|
2018-07-03 14:20:58 +00:00
|
|
|
ui.display.text_center(
|
|
|
|
ui.WIDTH // 2 + 10, 220, "Tap to unlock", ui.BOLD, ui.TITLE_GREY, ui.BG
|
|
|
|
)
|
2018-02-27 14:34:13 +00:00
|
|
|
ui.display.icon(45, 202, res.load(ui.ICON_CLICK), ui.TITLE_GREY, ui.BG)
|
2017-10-24 11:59:09 +00:00
|
|
|
|
2019-05-13 13:06:34 +00:00
|
|
|
ui.backlight_fade(ui.BACKLIGHT_NORMAL)
|
|
|
|
|
2018-02-19 19:36:12 +00:00
|
|
|
await ui.click()
|
2017-10-24 11:59:09 +00:00
|
|
|
|
|
|
|
|
2019-09-01 18:12:49 +00:00
|
|
|
if utils.EMULATOR:
|
|
|
|
# Ensure the emulated SD card is FAT32 formatted.
|
|
|
|
sd = io.SDCard()
|
|
|
|
sd.power(True)
|
2019-09-24 19:02:46 +00:00
|
|
|
fs = io.FatFS()
|
2019-09-01 18:12:49 +00:00
|
|
|
try:
|
|
|
|
fs.mount()
|
|
|
|
except OSError:
|
|
|
|
fs.mkfs()
|
|
|
|
else:
|
|
|
|
fs.unmount()
|
|
|
|
sd.power(False)
|
|
|
|
|
2018-02-19 19:36:12 +00:00
|
|
|
ui.display.backlight(ui.BACKLIGHT_NONE)
|
2019-05-13 13:06:34 +00:00
|
|
|
ui.backlight_fade(ui.BACKLIGHT_NORMAL)
|
2019-02-21 13:06:20 +00:00
|
|
|
config.init(show_pin_timeout)
|
2018-02-19 19:36:12 +00:00
|
|
|
loop.schedule(bootscreen())
|
2017-10-24 11:59:09 +00:00
|
|
|
loop.run()
|