2018-01-17 15:22:56 +00:00
|
|
|
from trezor import config
|
2018-03-04 11:59:16 +00:00
|
|
|
from trezor.utils import unimport, symbol, model
|
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
|
|
|
|
|
|
|
|
from apps.common import storage, coins, cache
|
2016-05-25 12:27:22 +00:00
|
|
|
|
|
|
|
|
2017-08-15 13:09:09 +00:00
|
|
|
async def respond_Features(ctx, msg):
|
2016-10-20 13:12:25 +00:00
|
|
|
|
2018-02-09 17:07:47 +00:00
|
|
|
if msg.__qualname__ == 'Initialize':
|
2018-03-01 02:06:33 +00:00
|
|
|
if msg.state is None or bytes(msg.state) != cache.get_state(state=bytes(msg.state)):
|
2018-02-09 17:07:47 +00:00
|
|
|
cache.clear()
|
|
|
|
|
2016-10-20 13:12:25 +00:00
|
|
|
f = Features()
|
2017-01-10 15:31:30 +00:00
|
|
|
f.vendor = 'trezor.io'
|
2018-02-23 20:27:26 +00:00
|
|
|
f.major_version = symbol('VERSION_MAJOR')
|
|
|
|
f.minor_version = symbol('VERSION_MINOR')
|
|
|
|
f.patch_version = symbol('VERSION_PATCH')
|
2016-10-20 13:12:25 +00:00
|
|
|
f.device_id = storage.get_device_id()
|
2018-02-27 19:48:01 +00:00
|
|
|
f.pin_protection = config.has_pin()
|
|
|
|
f.passphrase_protection = storage.has_passphrase()
|
|
|
|
f.language = 'english'
|
2016-10-20 13:12:25 +00:00
|
|
|
f.label = storage.get_label()
|
2018-02-27 19:48:01 +00:00
|
|
|
f.coins = coins.COINS
|
2016-10-20 13:12:25 +00:00
|
|
|
f.initialized = storage.is_initialized()
|
2018-02-27 19:48:01 +00:00
|
|
|
f.revision = symbol('GITREV')
|
|
|
|
f.pin_cached = config.has_pin()
|
|
|
|
f.passphrase_cached = cache.has_passphrase()
|
|
|
|
f.needs_backup = storage.needs_backup()
|
2018-02-14 22:50:08 +00:00
|
|
|
f.flags = storage.get_flags()
|
2018-03-04 11:59:16 +00:00
|
|
|
if model() in ['T', 'EMU']: # emulator currently emulates model T
|
|
|
|
f.model = 'T'
|
2018-02-09 17:07:47 +00:00
|
|
|
|
2016-11-15 10:51:28 +00:00
|
|
|
return f
|
2016-04-28 21:43:34 +00:00
|
|
|
|
|
|
|
|
2018-02-27 15:35:21 +00:00
|
|
|
async def respond_ClearSession(ctx, msg):
|
|
|
|
cache.clear()
|
|
|
|
return Success(message='Session cleared')
|
|
|
|
|
|
|
|
|
2016-12-15 11:48:33 +00:00
|
|
|
@unimport
|
2017-08-15 13:09:09 +00:00
|
|
|
async def respond_Pong(ctx, msg):
|
2016-12-15 11:35:18 +00:00
|
|
|
|
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-09-06 20:53:36 +00:00
|
|
|
|
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)
|
2017-01-24 13:11:03 +00:00
|
|
|
|
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-02-27 15:35:21 +00:00
|
|
|
register(wire_types.Initialize, protobuf_workflow, respond_Features)
|
|
|
|
register(wire_types.GetFeatures, protobuf_workflow, respond_Features)
|
|
|
|
register(wire_types.ClearSession, protobuf_workflow, respond_ClearSession)
|
|
|
|
register(wire_types.Ping, protobuf_workflow, respond_Pong)
|