2018-06-06 15:23:27 +00:00
|
|
|
from trezor import config, utils, wire
|
2018-02-27 15:35:21 +00:00
|
|
|
from trezor.wire import register, protobuf_workflow
|
|
|
|
from trezor.messages import wire_types
|
|
|
|
from trezor.messages.Features import Features
|
|
|
|
from trezor.messages.Success import Success
|
|
|
|
|
2018-05-22 16:52:26 +00:00
|
|
|
from apps.common import storage, cache
|
2016-05-25 12:27:22 +00:00
|
|
|
|
|
|
|
|
2018-05-28 13:20:31 +00:00
|
|
|
def get_features():
|
2016-10-20 13:12:25 +00:00
|
|
|
f = Features()
|
2017-01-10 15:31:30 +00:00
|
|
|
f.vendor = 'trezor.io'
|
2018-02-27 19:48:01 +00:00
|
|
|
f.language = 'english'
|
2018-05-28 13:20:31 +00:00
|
|
|
f.major_version = utils.symbol('VERSION_MAJOR')
|
|
|
|
f.minor_version = utils.symbol('VERSION_MINOR')
|
|
|
|
f.patch_version = utils.symbol('VERSION_PATCH')
|
|
|
|
f.revision = utils.symbol('GITREV')
|
|
|
|
f.model = utils.model()
|
|
|
|
if f.model == 'EMU':
|
|
|
|
f.model = 'T' # emulator currently emulates model T
|
|
|
|
f.device_id = storage.get_device_id()
|
2016-10-20 13:12:25 +00:00
|
|
|
f.label = storage.get_label()
|
|
|
|
f.initialized = storage.is_initialized()
|
2018-05-28 13:20:31 +00:00
|
|
|
f.pin_protection = config.has_pin()
|
2018-02-27 19:48:01 +00:00
|
|
|
f.pin_cached = config.has_pin()
|
2018-05-28 13:20:31 +00:00
|
|
|
f.passphrase_protection = storage.has_passphrase()
|
2018-02-27 19:48:01 +00:00
|
|
|
f.passphrase_cached = cache.has_passphrase()
|
|
|
|
f.needs_backup = storage.needs_backup()
|
2018-03-12 15:22:56 +00:00
|
|
|
f.unfinished_backup = storage.unfinished_backup()
|
2018-05-28 13:20:31 +00:00
|
|
|
f.flags = storage.get_flags()
|
2016-11-15 10:51:28 +00:00
|
|
|
return f
|
2016-04-28 21:43:34 +00:00
|
|
|
|
|
|
|
|
2018-05-28 13:20:31 +00:00
|
|
|
async def handle_Initialize(ctx, msg):
|
2018-06-02 11:11:21 +00:00
|
|
|
if msg.state is None or msg.state != cache.get_state(prev_state=bytes(msg.state)):
|
2018-05-28 13:20:31 +00:00
|
|
|
cache.clear(msg.skip_passphrase)
|
|
|
|
return get_features()
|
|
|
|
|
|
|
|
|
|
|
|
async def handle_GetFeatures(ctx, msg):
|
|
|
|
return get_features()
|
|
|
|
|
|
|
|
|
2018-06-06 15:23:27 +00:00
|
|
|
async def handle_Cancel(ctx, msg):
|
|
|
|
raise wire.ActionCancelled('Cancelled')
|
|
|
|
|
|
|
|
|
2018-05-28 13:20:31 +00:00
|
|
|
async def handle_ClearSession(ctx, msg):
|
2018-02-27 15:35:21 +00:00
|
|
|
cache.clear()
|
|
|
|
return Success(message='Session cleared')
|
|
|
|
|
|
|
|
|
2018-05-28 13:20:31 +00:00
|
|
|
async def handle_Ping(ctx, msg):
|
2017-09-06 20:53:36 +00:00
|
|
|
if msg.button_protection:
|
|
|
|
from apps.common.confirm import require_confirm
|
|
|
|
from trezor.messages.ButtonRequestType import ProtectCall
|
|
|
|
from trezor.ui.text import Text
|
|
|
|
from trezor import ui
|
2018-02-26 22:00:50 +00:00
|
|
|
await require_confirm(ctx, Text('Confirm', ui.ICON_DEFAULT), ProtectCall)
|
2017-01-24 13:11:03 +00:00
|
|
|
if msg.passphrase_protection:
|
|
|
|
from apps.common.request_passphrase import protect_by_passphrase
|
2017-08-15 13:09:09 +00:00
|
|
|
await protect_by_passphrase(ctx)
|
2018-02-28 16:04:09 +00:00
|
|
|
return Success(message=msg.message)
|
2018-02-09 17:07:47 +00:00
|
|
|
|
|
|
|
|
2016-04-28 21:43:34 +00:00
|
|
|
def boot():
|
2018-05-28 13:20:31 +00:00
|
|
|
register(wire_types.Initialize, protobuf_workflow, handle_Initialize)
|
|
|
|
register(wire_types.GetFeatures, protobuf_workflow, handle_GetFeatures)
|
2018-06-06 15:23:27 +00:00
|
|
|
register(wire_types.Cancel, protobuf_workflow, handle_Cancel)
|
2018-05-28 13:20:31 +00:00
|
|
|
register(wire_types.ClearSession, protobuf_workflow, handle_ClearSession)
|
|
|
|
register(wire_types.Ping, protobuf_workflow, handle_Ping)
|