2021-12-08 09:10:58 +00:00
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
|
2022-09-20 10:22:45 +00:00
|
|
|
import storage.cache as storage_cache
|
|
|
|
import storage.device as storage_device
|
2021-03-22 15:14:24 +00:00
|
|
|
from trezor import config, utils, wire, workflow
|
2022-10-13 11:37:02 +00:00
|
|
|
from trezor.enums import HomescreenFormat, MessageType
|
2022-06-03 09:41:44 +00:00
|
|
|
from trezor.messages import Success, UnlockPath
|
2018-02-27 15:35:21 +00:00
|
|
|
|
2021-03-19 15:41:05 +00:00
|
|
|
from . import workflow_handlers
|
|
|
|
|
2021-12-08 09:10:58 +00:00
|
|
|
if TYPE_CHECKING:
|
2021-03-23 12:35:27 +00:00
|
|
|
from trezor import protobuf
|
|
|
|
from trezor.messages import (
|
|
|
|
Features,
|
|
|
|
Initialize,
|
|
|
|
EndSession,
|
|
|
|
GetFeatures,
|
|
|
|
Cancel,
|
|
|
|
LockDevice,
|
|
|
|
Ping,
|
|
|
|
DoPreauthorized,
|
|
|
|
CancelAuthorization,
|
2022-08-09 16:26:37 +00:00
|
|
|
SetBusy,
|
2021-03-23 12:35:27 +00:00
|
|
|
)
|
2020-07-16 17:10:32 +00:00
|
|
|
|
2019-07-03 13:07:04 +00:00
|
|
|
|
2022-09-20 10:22:45 +00:00
|
|
|
_ALLOW_WHILE_LOCKED = (
|
|
|
|
MessageType.Initialize,
|
|
|
|
MessageType.EndSession,
|
|
|
|
MessageType.GetFeatures,
|
|
|
|
MessageType.Cancel,
|
|
|
|
MessageType.LockDevice,
|
|
|
|
MessageType.DoPreauthorized,
|
|
|
|
MessageType.WipeDevice,
|
|
|
|
MessageType.SetBusy,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-08-09 16:26:37 +00:00
|
|
|
def busy_expiry_ms() -> int:
|
|
|
|
"""
|
|
|
|
Returns the time left until the busy state expires or 0 if the device is not in the busy state.
|
|
|
|
"""
|
|
|
|
|
2022-09-20 10:22:45 +00:00
|
|
|
busy_deadline_ms = storage_cache.get_int(storage_cache.APP_COMMON_BUSY_DEADLINE_MS)
|
2022-10-04 13:39:51 +00:00
|
|
|
if busy_deadline_ms is None:
|
2022-08-09 16:26:37 +00:00
|
|
|
return 0
|
|
|
|
|
|
|
|
import utime
|
|
|
|
|
|
|
|
expiry_ms = utime.ticks_diff(busy_deadline_ms, utime.ticks_ms())
|
|
|
|
return expiry_ms if expiry_ms > 0 else 0
|
|
|
|
|
|
|
|
|
2019-07-03 13:07:04 +00:00
|
|
|
def get_features() -> Features:
|
2022-09-20 10:22:45 +00:00
|
|
|
import storage.recovery as storage_recovery
|
|
|
|
import storage.sd_salt as storage_sd_salt
|
2021-03-22 15:14:24 +00:00
|
|
|
|
|
|
|
from trezor import sdcard
|
2021-03-23 12:35:27 +00:00
|
|
|
from trezor.enums import Capability
|
|
|
|
from trezor.messages import Features
|
2021-03-22 15:14:24 +00:00
|
|
|
|
|
|
|
from apps.common import mnemonic, safety_checks
|
|
|
|
|
2021-01-14 13:18:12 +00:00
|
|
|
f = Features(
|
|
|
|
vendor="trezor.io",
|
2022-05-02 22:16:38 +00:00
|
|
|
fw_vendor=utils.firmware_vendor(),
|
2021-01-14 13:18:12 +00:00
|
|
|
language="en-US",
|
|
|
|
major_version=utils.VERSION_MAJOR,
|
|
|
|
minor_version=utils.VERSION_MINOR,
|
|
|
|
patch_version=utils.VERSION_PATCH,
|
2021-05-21 09:35:43 +00:00
|
|
|
revision=utils.SCM_REVISION,
|
2021-01-14 13:18:12 +00:00
|
|
|
model=utils.MODEL,
|
2022-09-20 10:22:45 +00:00
|
|
|
device_id=storage_device.get_device_id(),
|
|
|
|
label=storage_device.get_label(),
|
2021-01-14 13:18:12 +00:00
|
|
|
pin_protection=config.has_pin(),
|
|
|
|
unlocked=config.is_unlocked(),
|
2022-08-09 16:26:37 +00:00
|
|
|
busy=busy_expiry_ms() > 0,
|
2022-10-13 11:37:02 +00:00
|
|
|
homescreen_format=HomescreenFormat.Jpeg240x240,
|
2021-01-14 13:18:12 +00:00
|
|
|
)
|
2020-04-27 11:15:56 +00:00
|
|
|
|
2019-08-22 18:16:18 +00:00
|
|
|
if utils.BITCOIN_ONLY:
|
2019-08-28 10:42:33 +00:00
|
|
|
f.capabilities = [
|
|
|
|
Capability.Bitcoin,
|
|
|
|
Capability.Crypto,
|
|
|
|
Capability.Shamir,
|
|
|
|
Capability.ShamirGroups,
|
2019-08-28 07:25:11 +00:00
|
|
|
]
|
2019-08-22 18:16:18 +00:00
|
|
|
else:
|
2019-08-28 10:42:33 +00:00
|
|
|
f.capabilities = [
|
|
|
|
Capability.Bitcoin,
|
|
|
|
Capability.Bitcoin_like,
|
|
|
|
Capability.Binance,
|
|
|
|
Capability.Cardano,
|
|
|
|
Capability.Crypto,
|
|
|
|
Capability.EOS,
|
|
|
|
Capability.Ethereum,
|
|
|
|
Capability.Monero,
|
|
|
|
Capability.NEM,
|
|
|
|
Capability.Ripple,
|
|
|
|
Capability.Stellar,
|
|
|
|
Capability.Tezos,
|
|
|
|
Capability.U2F,
|
|
|
|
Capability.Shamir,
|
|
|
|
Capability.ShamirGroups,
|
2019-08-22 18:16:18 +00:00
|
|
|
]
|
2022-05-01 12:05:32 +00:00
|
|
|
|
|
|
|
# Other models are not capable of PassphraseEntry
|
|
|
|
if utils.MODEL in ("T",):
|
|
|
|
f.capabilities.append(Capability.PassphraseEntry)
|
|
|
|
|
2020-02-17 14:51:39 +00:00
|
|
|
f.sd_card_present = sdcard.is_present()
|
2022-09-20 10:22:45 +00:00
|
|
|
f.initialized = storage_device.is_initialized()
|
2020-04-27 11:15:56 +00:00
|
|
|
|
|
|
|
# private fields:
|
|
|
|
if config.is_unlocked():
|
2021-10-20 11:26:02 +00:00
|
|
|
# passphrase_protection is private, see #1807
|
2022-09-20 10:22:45 +00:00
|
|
|
f.passphrase_protection = storage_device.is_passphrase_enabled()
|
|
|
|
f.needs_backup = storage_device.needs_backup()
|
|
|
|
f.unfinished_backup = storage_device.unfinished_backup()
|
|
|
|
f.no_backup = storage_device.no_backup()
|
|
|
|
f.flags = storage_device.get_flags()
|
|
|
|
f.recovery_mode = storage_recovery.is_in_progress()
|
2020-04-27 11:15:56 +00:00
|
|
|
f.backup_type = mnemonic.get_type()
|
2022-09-20 10:22:45 +00:00
|
|
|
f.sd_protection = storage_sd_salt.is_enabled()
|
2020-04-27 11:15:56 +00:00
|
|
|
f.wipe_code_protection = config.has_wipe_code()
|
2022-09-20 10:22:45 +00:00
|
|
|
f.passphrase_always_on_device = storage_device.get_passphrase_always_on_device()
|
2020-09-17 12:27:04 +00:00
|
|
|
f.safety_checks = safety_checks.read_setting()
|
2022-09-20 10:22:45 +00:00
|
|
|
f.auto_lock_delay_ms = storage_device.get_autolock_delay_ms()
|
|
|
|
f.display_rotation = storage_device.get_rotation()
|
|
|
|
f.experimental_features = storage_device.get_experimental_features()
|
2023-02-15 14:43:04 +00:00
|
|
|
f.hide_passphrase_from_host = storage_device.get_hide_passphrase_from_host()
|
2020-04-27 11:15:56 +00:00
|
|
|
|
2016-11-15 10:51:28 +00:00
|
|
|
return f
|
2016-04-28 21:43:34 +00:00
|
|
|
|
|
|
|
|
2019-07-03 13:07:04 +00:00
|
|
|
async def handle_Initialize(ctx: wire.Context, msg: Initialize) -> Features:
|
2022-09-20 10:22:45 +00:00
|
|
|
session_id = storage_cache.start_session(msg.session_id)
|
2021-10-12 11:58:23 +00:00
|
|
|
|
|
|
|
if not utils.BITCOIN_ONLY:
|
2022-09-20 10:22:45 +00:00
|
|
|
derive_cardano = storage_cache.get(storage_cache.APP_COMMON_DERIVE_CARDANO)
|
|
|
|
have_seed = storage_cache.is_set(storage_cache.APP_COMMON_SEED)
|
2021-10-12 11:58:23 +00:00
|
|
|
|
|
|
|
if (
|
|
|
|
have_seed
|
|
|
|
and msg.derive_cardano is not None
|
|
|
|
and msg.derive_cardano != bool(derive_cardano)
|
|
|
|
):
|
|
|
|
# seed is already derived, and host wants to change derive_cardano setting
|
|
|
|
# => create a new session
|
2022-09-20 10:22:45 +00:00
|
|
|
storage_cache.end_current_session()
|
|
|
|
session_id = storage_cache.start_session()
|
2021-10-12 11:58:23 +00:00
|
|
|
have_seed = False
|
|
|
|
|
|
|
|
if not have_seed:
|
2022-09-20 10:22:45 +00:00
|
|
|
storage_cache.set(
|
|
|
|
storage_cache.APP_COMMON_DERIVE_CARDANO,
|
2021-10-12 11:58:23 +00:00
|
|
|
b"\x01" if msg.derive_cardano else b"",
|
|
|
|
)
|
|
|
|
|
2020-02-13 09:19:07 +00:00
|
|
|
features = get_features()
|
2021-10-12 11:58:23 +00:00
|
|
|
features.session_id = session_id
|
2020-02-13 09:19:07 +00:00
|
|
|
return features
|
2018-05-28 13:20:31 +00:00
|
|
|
|
|
|
|
|
2019-07-03 13:07:04 +00:00
|
|
|
async def handle_GetFeatures(ctx: wire.Context, msg: GetFeatures) -> Features:
|
2018-05-28 13:20:31 +00:00
|
|
|
return get_features()
|
|
|
|
|
|
|
|
|
2021-12-08 09:10:58 +00:00
|
|
|
async def handle_Cancel(ctx: wire.Context, msg: Cancel) -> Success:
|
2020-04-21 12:18:53 +00:00
|
|
|
raise wire.ActionCancelled
|
2018-06-06 15:23:27 +00:00
|
|
|
|
|
|
|
|
2020-04-21 13:49:37 +00:00
|
|
|
async def handle_LockDevice(ctx: wire.Context, msg: LockDevice) -> Success:
|
|
|
|
lock_device()
|
2020-02-03 15:28:08 +00:00
|
|
|
return Success()
|
2018-02-27 15:35:21 +00:00
|
|
|
|
|
|
|
|
2022-08-09 16:26:37 +00:00
|
|
|
async def handle_SetBusy(ctx: wire.Context, msg: SetBusy) -> Success:
|
2022-09-20 10:22:45 +00:00
|
|
|
if not storage_device.is_initialized():
|
2022-08-09 16:26:37 +00:00
|
|
|
raise wire.NotInitialized("Device is not initialized")
|
|
|
|
|
|
|
|
if msg.expiry_ms:
|
|
|
|
import utime
|
|
|
|
|
|
|
|
deadline = utime.ticks_add(utime.ticks_ms(), msg.expiry_ms)
|
2022-09-20 10:22:45 +00:00
|
|
|
storage_cache.set_int(storage_cache.APP_COMMON_BUSY_DEADLINE_MS, deadline)
|
2022-08-09 16:26:37 +00:00
|
|
|
else:
|
2022-09-20 10:22:45 +00:00
|
|
|
storage_cache.delete(storage_cache.APP_COMMON_BUSY_DEADLINE_MS)
|
2022-08-09 16:26:37 +00:00
|
|
|
set_homescreen()
|
|
|
|
workflow.close_others()
|
|
|
|
return Success()
|
|
|
|
|
|
|
|
|
2020-08-25 12:51:06 +00:00
|
|
|
async def handle_EndSession(ctx: wire.Context, msg: EndSession) -> Success:
|
2022-09-20 10:22:45 +00:00
|
|
|
storage_cache.end_current_session()
|
2020-08-25 12:51:06 +00:00
|
|
|
return Success()
|
|
|
|
|
|
|
|
|
2019-07-03 13:07:04 +00:00
|
|
|
async def handle_Ping(ctx: wire.Context, msg: Ping) -> Success:
|
2017-09-06 20:53:36 +00:00
|
|
|
if msg.button_protection:
|
2021-03-10 11:56:44 +00:00
|
|
|
from trezor.ui.layouts import confirm_action
|
2021-03-23 12:35:27 +00:00
|
|
|
from trezor.enums import ButtonRequestType as B
|
2018-07-03 14:20:58 +00:00
|
|
|
|
2021-03-23 12:35:27 +00:00
|
|
|
await confirm_action(ctx, "ping", "Confirm", "ping", br_code=B.ProtectCall)
|
2018-02-28 16:04:09 +00:00
|
|
|
return Success(message=msg.message)
|
2018-02-09 17:07:47 +00:00
|
|
|
|
|
|
|
|
2020-07-16 17:10:32 +00:00
|
|
|
async def handle_DoPreauthorized(
|
|
|
|
ctx: wire.Context, msg: DoPreauthorized
|
|
|
|
) -> protobuf.MessageType:
|
2021-03-23 12:35:27 +00:00
|
|
|
from trezor.messages import PreauthorizedRequest
|
2021-03-30 08:57:07 +00:00
|
|
|
from apps.common import authorization
|
2021-03-22 15:14:24 +00:00
|
|
|
|
2021-03-30 08:57:07 +00:00
|
|
|
if not authorization.is_set():
|
2020-07-16 17:10:32 +00:00
|
|
|
raise wire.ProcessError("No preauthorized operation")
|
|
|
|
|
2021-03-30 08:57:07 +00:00
|
|
|
wire_types = authorization.get_wire_types()
|
|
|
|
utils.ensure(bool(wire_types), "Unsupported preauthorization found")
|
|
|
|
|
|
|
|
req = await ctx.call_any(PreauthorizedRequest(), *wire_types)
|
2020-07-16 17:10:32 +00:00
|
|
|
|
2021-03-23 12:36:03 +00:00
|
|
|
assert req.MESSAGE_WIRE_TYPE is not None
|
2021-03-19 15:41:05 +00:00
|
|
|
handler = workflow_handlers.find_registered_handler(
|
|
|
|
ctx.iface, req.MESSAGE_WIRE_TYPE
|
|
|
|
)
|
2020-07-16 17:10:32 +00:00
|
|
|
if handler is None:
|
|
|
|
return wire.unexpected_message()
|
|
|
|
|
2022-03-01 12:55:58 +00:00
|
|
|
return await handler(ctx, req, authorization.get()) # type: ignore [Expected 2 positional arguments]
|
2020-07-16 17:10:32 +00:00
|
|
|
|
|
|
|
|
2022-06-03 09:41:44 +00:00
|
|
|
async def handle_UnlockPath(ctx: wire.Context, msg: UnlockPath) -> protobuf.MessageType:
|
|
|
|
from trezor.crypto import hmac
|
|
|
|
from trezor.messages import UnlockedPathRequest
|
|
|
|
from trezor.ui.layouts import confirm_action
|
|
|
|
from apps.common.paths import SLIP25_PURPOSE
|
|
|
|
from apps.common.seed import Slip21Node, get_seed
|
|
|
|
from apps.common.writers import write_uint32_le
|
|
|
|
|
|
|
|
_KEYCHAIN_MAC_KEY_PATH = [b"TREZOR", b"Keychain MAC key"]
|
|
|
|
|
|
|
|
# UnlockPath is relevant only for SLIP-25 paths.
|
|
|
|
# Note: Currently we only allow unlocking the entire SLIP-25 purpose subtree instead of
|
|
|
|
# per-coin or per-account unlocking in order to avoid UI complexity.
|
|
|
|
if msg.address_n != [SLIP25_PURPOSE]:
|
|
|
|
raise wire.DataError("Invalid path")
|
|
|
|
|
|
|
|
seed = await get_seed(ctx)
|
|
|
|
node = Slip21Node(seed)
|
|
|
|
node.derive_path(_KEYCHAIN_MAC_KEY_PATH)
|
|
|
|
mac = utils.HashWriter(hmac(hmac.SHA256, node.key()))
|
|
|
|
for i in msg.address_n:
|
|
|
|
write_uint32_le(mac, i)
|
|
|
|
expected_mac = mac.get_digest()
|
|
|
|
|
|
|
|
# Require confirmation to access SLIP25 paths unless already authorized.
|
|
|
|
if msg.mac:
|
|
|
|
if len(msg.mac) != len(expected_mac) or not utils.consteq(
|
|
|
|
expected_mac, msg.mac
|
|
|
|
):
|
|
|
|
raise wire.DataError("Invalid MAC")
|
|
|
|
else:
|
|
|
|
await confirm_action(
|
|
|
|
ctx,
|
|
|
|
"confirm_coinjoin_access",
|
2023-01-11 17:03:23 +00:00
|
|
|
title="Coinjoin account",
|
|
|
|
description="Do you want to allow access to your coinjoin account?",
|
2022-06-03 09:41:44 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
wire_types = (MessageType.GetAddress, MessageType.GetPublicKey, MessageType.SignTx)
|
|
|
|
req = await ctx.call_any(UnlockedPathRequest(mac=expected_mac), *wire_types)
|
|
|
|
|
|
|
|
assert req.MESSAGE_WIRE_TYPE in wire_types
|
|
|
|
handler = workflow_handlers.find_registered_handler(
|
|
|
|
ctx.iface, req.MESSAGE_WIRE_TYPE
|
|
|
|
)
|
|
|
|
assert handler is not None
|
|
|
|
return await handler(ctx, req, msg) # type: ignore [Expected 2 positional arguments]
|
|
|
|
|
|
|
|
|
2020-08-03 16:16:12 +00:00
|
|
|
async def handle_CancelAuthorization(
|
|
|
|
ctx: wire.Context, msg: CancelAuthorization
|
|
|
|
) -> protobuf.MessageType:
|
2021-03-30 08:57:07 +00:00
|
|
|
from apps.common import authorization
|
2020-08-03 16:16:12 +00:00
|
|
|
|
2021-03-30 08:57:07 +00:00
|
|
|
authorization.clear()
|
2020-08-03 16:16:12 +00:00
|
|
|
return Success(message="Authorization cancelled")
|
|
|
|
|
|
|
|
|
2020-04-22 08:58:24 +00:00
|
|
|
def set_homescreen() -> None:
|
2022-09-20 10:22:45 +00:00
|
|
|
import storage.recovery as storage_recovery
|
|
|
|
|
|
|
|
set_default = workflow.set_default # local_cache_attribute
|
2021-03-22 15:14:24 +00:00
|
|
|
|
2022-09-20 10:22:45 +00:00
|
|
|
if storage_cache.is_set(storage_cache.APP_COMMON_BUSY_DEADLINE_MS):
|
2022-09-26 21:07:29 +00:00
|
|
|
from apps.homescreen import busyscreen
|
2022-08-09 16:26:37 +00:00
|
|
|
|
2022-09-20 10:22:45 +00:00
|
|
|
set_default(busyscreen)
|
2022-08-09 16:26:37 +00:00
|
|
|
|
|
|
|
elif not config.is_unlocked():
|
2022-09-26 21:07:29 +00:00
|
|
|
from apps.homescreen import lockscreen
|
2020-04-22 08:58:24 +00:00
|
|
|
|
2022-09-20 10:22:45 +00:00
|
|
|
set_default(lockscreen)
|
2020-04-22 08:58:24 +00:00
|
|
|
|
2022-09-20 10:22:45 +00:00
|
|
|
elif storage_recovery.is_in_progress():
|
2020-04-22 08:58:24 +00:00
|
|
|
from apps.management.recovery_device.homescreen import recovery_homescreen
|
|
|
|
|
2022-09-20 10:22:45 +00:00
|
|
|
set_default(recovery_homescreen)
|
2020-04-22 08:58:24 +00:00
|
|
|
|
|
|
|
else:
|
2022-09-26 21:07:29 +00:00
|
|
|
from apps.homescreen import homescreen
|
2020-04-22 08:58:24 +00:00
|
|
|
|
2022-09-20 10:22:45 +00:00
|
|
|
set_default(homescreen)
|
2020-04-22 08:58:24 +00:00
|
|
|
|
|
|
|
|
2020-04-21 13:49:37 +00:00
|
|
|
def lock_device() -> None:
|
2020-04-24 10:16:32 +00:00
|
|
|
if config.has_pin():
|
|
|
|
config.lock()
|
|
|
|
wire.find_handler = get_pinlocked_handler
|
2020-05-19 12:56:22 +00:00
|
|
|
set_homescreen()
|
|
|
|
workflow.close_others()
|
2020-04-21 13:49:37 +00:00
|
|
|
|
|
|
|
|
2021-01-26 16:57:53 +00:00
|
|
|
def lock_device_if_unlocked() -> None:
|
|
|
|
if config.is_unlocked():
|
|
|
|
lock_device()
|
|
|
|
|
|
|
|
|
2020-04-21 13:49:37 +00:00
|
|
|
async def unlock_device(ctx: wire.GenericContext = wire.DUMMY_CONTEXT) -> None:
|
2020-05-28 09:57:04 +00:00
|
|
|
"""Ensure the device is in unlocked state.
|
|
|
|
|
|
|
|
If the storage is locked, attempt to unlock it. Reset the homescreen and the wire
|
|
|
|
handler.
|
|
|
|
"""
|
2021-03-22 15:14:24 +00:00
|
|
|
from apps.common.request_pin import verify_user_pin
|
|
|
|
|
2020-05-28 09:57:04 +00:00
|
|
|
if not config.is_unlocked():
|
|
|
|
# verify_user_pin will raise if the PIN was invalid
|
|
|
|
await verify_user_pin(ctx)
|
|
|
|
|
2020-04-22 08:58:24 +00:00
|
|
|
set_homescreen()
|
2021-03-19 15:41:05 +00:00
|
|
|
wire.find_handler = workflow_handlers.find_registered_handler
|
2020-04-21 13:49:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_pinlocked_handler(
|
|
|
|
iface: wire.WireInterface, msg_type: int
|
2021-03-18 09:48:50 +00:00
|
|
|
) -> wire.Handler[wire.Msg] | None:
|
2021-03-19 15:41:05 +00:00
|
|
|
orig_handler = workflow_handlers.find_registered_handler(iface, msg_type)
|
2020-04-21 13:49:37 +00:00
|
|
|
if orig_handler is None:
|
|
|
|
return None
|
|
|
|
|
|
|
|
if __debug__:
|
|
|
|
import usb
|
|
|
|
|
|
|
|
if iface is usb.iface_debug:
|
|
|
|
return orig_handler
|
|
|
|
|
2022-09-20 10:22:45 +00:00
|
|
|
if msg_type in _ALLOW_WHILE_LOCKED:
|
2020-04-21 13:49:37 +00:00
|
|
|
return orig_handler
|
|
|
|
|
|
|
|
async def wrapper(ctx: wire.Context, msg: wire.Msg) -> protobuf.MessageType:
|
|
|
|
await unlock_device(ctx)
|
|
|
|
return await orig_handler(ctx, msg)
|
|
|
|
|
|
|
|
return wrapper
|
|
|
|
|
|
|
|
|
2021-01-28 11:21:43 +00:00
|
|
|
# this function is also called when handling ApplySettings
|
|
|
|
def reload_settings_from_storage() -> None:
|
2021-03-22 15:14:24 +00:00
|
|
|
from trezor import ui
|
|
|
|
|
2021-01-28 11:21:43 +00:00
|
|
|
workflow.idle_timer.set(
|
2022-09-20 10:22:45 +00:00
|
|
|
storage_device.get_autolock_delay_ms(), lock_device_if_unlocked
|
2021-01-28 11:21:43 +00:00
|
|
|
)
|
2022-09-20 10:22:45 +00:00
|
|
|
wire.experimental_enabled = storage_device.get_experimental_features()
|
|
|
|
ui.display.orientation(storage_device.get_rotation())
|
2021-01-28 11:21:43 +00:00
|
|
|
|
|
|
|
|
2019-10-31 09:27:59 +00:00
|
|
|
def boot() -> None:
|
2022-09-20 10:22:45 +00:00
|
|
|
MT = MessageType # local_cache_global
|
|
|
|
|
|
|
|
# Register workflow handlers
|
|
|
|
for msg_type, handler in (
|
|
|
|
(MT.Initialize, handle_Initialize),
|
|
|
|
(MT.GetFeatures, handle_GetFeatures),
|
|
|
|
(MT.Cancel, handle_Cancel),
|
|
|
|
(MT.LockDevice, handle_LockDevice),
|
|
|
|
(MT.EndSession, handle_EndSession),
|
|
|
|
(MT.Ping, handle_Ping),
|
|
|
|
(MT.DoPreauthorized, handle_DoPreauthorized),
|
|
|
|
(MT.UnlockPath, handle_UnlockPath),
|
|
|
|
(MT.CancelAuthorization, handle_CancelAuthorization),
|
|
|
|
(MT.SetBusy, handle_SetBusy),
|
|
|
|
):
|
|
|
|
workflow_handlers.register(msg_type, handler) # type: ignore [cannot be assigned to type]
|
2020-05-18 12:59:58 +00:00
|
|
|
|
2021-01-28 11:21:43 +00:00
|
|
|
reload_settings_from_storage()
|
2021-03-19 15:41:05 +00:00
|
|
|
if config.is_unlocked():
|
|
|
|
wire.find_handler = workflow_handlers.find_registered_handler
|
|
|
|
else:
|
|
|
|
wire.find_handler = get_pinlocked_handler
|