You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
120 lines
4.0 KiB
120 lines
4.0 KiB
5 years ago
|
import storage
|
||
|
import storage.device
|
||
|
import storage.recovery
|
||
|
import storage.sd_salt
|
||
|
from storage import cache
|
||
4 years ago
|
from trezor import config, sdcard, utils, wire
|
||
5 years ago
|
from trezor.messages import Capability, MessageType
|
||
6 years ago
|
from trezor.messages.Features import Features
|
||
|
from trezor.messages.Success import Success
|
||
5 years ago
|
from trezor.wire import register
|
||
6 years ago
|
|
||
5 years ago
|
from apps.common import mnemonic
|
||
8 years ago
|
|
||
5 years ago
|
if False:
|
||
|
from typing import NoReturn
|
||
|
from trezor.messages.Initialize import Initialize
|
||
|
from trezor.messages.GetFeatures import GetFeatures
|
||
|
from trezor.messages.Cancel import Cancel
|
||
|
from trezor.messages.ClearSession import ClearSession
|
||
|
from trezor.messages.Ping import Ping
|
||
8 years ago
|
|
||
5 years ago
|
|
||
|
def get_features() -> Features:
|
||
8 years ago
|
f = Features()
|
||
6 years ago
|
f.vendor = "trezor.io"
|
||
5 years ago
|
f.language = "en-US"
|
||
6 years ago
|
f.major_version = utils.VERSION_MAJOR
|
||
|
f.minor_version = utils.VERSION_MINOR
|
||
|
f.patch_version = utils.VERSION_PATCH
|
||
5 years ago
|
f.revision = utils.GITREV.encode()
|
||
6 years ago
|
f.model = utils.MODEL
|
||
5 years ago
|
f.device_id = storage.device.get_device_id()
|
||
|
f.label = storage.device.get_label()
|
||
8 years ago
|
f.initialized = storage.is_initialized()
|
||
6 years ago
|
f.pin_protection = config.has_pin()
|
||
6 years ago
|
f.pin_cached = config.has_pin()
|
||
5 years ago
|
f.passphrase_protection = storage.device.is_passphrase_enabled()
|
||
5 years ago
|
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()
|
||
5 years ago
|
f.backup_type = mnemonic.get_type()
|
||
5 years ago
|
if utils.BITCOIN_ONLY:
|
||
5 years ago
|
f.capabilities = [
|
||
|
Capability.Bitcoin,
|
||
|
Capability.Crypto,
|
||
|
Capability.Shamir,
|
||
|
Capability.ShamirGroups,
|
||
5 years ago
|
Capability.PassphraseEntry,
|
||
5 years ago
|
]
|
||
5 years ago
|
else:
|
||
5 years ago
|
f.capabilities = [
|
||
|
Capability.Bitcoin,
|
||
|
Capability.Bitcoin_like,
|
||
|
Capability.Binance,
|
||
|
Capability.Cardano,
|
||
|
Capability.Crypto,
|
||
|
Capability.EOS,
|
||
|
Capability.Ethereum,
|
||
|
Capability.Lisk,
|
||
|
Capability.Monero,
|
||
|
Capability.NEM,
|
||
|
Capability.Ripple,
|
||
|
Capability.Stellar,
|
||
|
Capability.Tezos,
|
||
|
Capability.U2F,
|
||
|
Capability.Shamir,
|
||
|
Capability.ShamirGroups,
|
||
5 years ago
|
Capability.PassphraseEntry,
|
||
5 years ago
|
]
|
||
4 years ago
|
f.sd_card_present = sdcard.is_present()
|
||
5 years ago
|
f.sd_protection = storage.sd_salt.is_enabled()
|
||
5 years ago
|
f.wipe_code_protection = config.has_wipe_code()
|
||
5 years ago
|
f.passphrase_always_on_device = storage.device.get_passphrase_always_on_device()
|
||
8 years ago
|
return f
|
||
8 years ago
|
|
||
|
|
||
5 years ago
|
async def handle_Initialize(ctx: wire.Context, msg: Initialize) -> Features:
|
||
4 years ago
|
features = get_features()
|
||
|
if msg.session_id:
|
||
|
msg.session_id = bytes(msg.session_id)
|
||
|
features.session_id = cache.start_session(msg.session_id)
|
||
|
return features
|
||
6 years ago
|
|
||
|
|
||
5 years ago
|
async def handle_GetFeatures(ctx: wire.Context, msg: GetFeatures) -> Features:
|
||
6 years ago
|
return get_features()
|
||
|
|
||
|
|
||
5 years ago
|
async def handle_Cancel(ctx: wire.Context, msg: Cancel) -> NoReturn:
|
||
6 years ago
|
raise wire.ActionCancelled("Cancelled")
|
||
6 years ago
|
|
||
|
|
||
5 years ago
|
async def handle_ClearSession(ctx: wire.Context, msg: ClearSession) -> Success:
|
||
4 years ago
|
"""
|
||
|
This is currently a no-op on T. This should be called LockSession/LockDevice
|
||
|
and lock the device. In other words the cache should stay but the PIN should
|
||
|
be forgotten and required again.
|
||
|
"""
|
||
|
return Success()
|
||
6 years ago
|
|
||
|
|
||
5 years ago
|
async def handle_Ping(ctx: wire.Context, msg: Ping) -> Success:
|
||
7 years ago
|
if msg.button_protection:
|
||
|
from apps.common.confirm import require_confirm
|
||
|
from trezor.messages.ButtonRequestType import ProtectCall
|
||
|
from trezor.ui.text import Text
|
||
6 years ago
|
|
||
|
await require_confirm(ctx, Text("Confirm"), ProtectCall)
|
||
6 years ago
|
return Success(message=msg.message)
|
||
6 years ago
|
|
||
|
|
||
5 years ago
|
def boot() -> None:
|
||
5 years ago
|
register(MessageType.Initialize, handle_Initialize)
|
||
|
register(MessageType.GetFeatures, handle_GetFeatures)
|
||
5 years ago
|
register(MessageType.Cancel, handle_Cancel)
|
||
|
register(MessageType.ClearSession, handle_ClearSession)
|
||
|
register(MessageType.Ping, handle_Ping)
|