diff --git a/src/apps/common/cache.py b/src/apps/common/cache.py index 04272187a..5d81189c9 100644 --- a/src/apps/common/cache.py +++ b/src/apps/common/cache.py @@ -1,6 +1,18 @@ seed = None +def get_state(): + global seed + if seed is None: + return None + else: + from trezor.crypto import bip32 + from trezor.crypto.hashlib import blake2s + node = bip32.from_seed(seed, 'secp256k1') + state = blake2s(node.public_key()).digest() + return state + + def clear(): global seed seed = None diff --git a/src/apps/homescreen/__init__.py b/src/apps/homescreen/__init__.py index 7927adc03..710b11a87 100644 --- a/src/apps/homescreen/__init__.py +++ b/src/apps/homescreen/__init__.py @@ -1,14 +1,18 @@ from trezor import config from trezor.wire import register, protobuf_workflow from trezor.utils import unimport -from trezor.messages.wire_types import Initialize, GetFeatures, Ping +from trezor.messages.wire_types import Initialize, GetFeatures, Ping, ClearSession @unimport async def respond_Features(ctx, msg): - from apps.common import storage, coins + from apps.common import storage, coins, cache from trezor.messages.Features import Features + if msg.__qualname__ == 'Initialize': + if not hasattr(msg, 'state') or msg.state != cache.get_state(): + cache.clear() + f = Features() f.vendor = 'trezor.io' f.revision = '0123456789' @@ -26,6 +30,8 @@ async def respond_Features(ctx, msg): f.pin_protection = config.has_pin() f.language = 'english' + f.state = cache.get_state() + return f @@ -50,7 +56,16 @@ async def respond_Pong(ctx, msg): return s +@unimport +async def respond_ClearSession(ctx, msg): + from apps.common import cache + from trezor.messages.Success import Success + cache.clear() + return Success(message='Session cleared') + + def boot(): register(Initialize, protobuf_workflow, respond_Features) register(GetFeatures, protobuf_workflow, respond_Features) register(Ping, protobuf_workflow, respond_Pong) + register(ClearSession, protobuf_workflow, respond_ClearSession) diff --git a/src/trezor/messages/Features.py b/src/trezor/messages/Features.py index 1daf2e02a..b6c5014a7 100644 --- a/src/trezor/messages/Features.py +++ b/src/trezor/messages/Features.py @@ -26,5 +26,11 @@ class Features(p.MessageType): 19: ('needs_backup', p.BoolType, 0), 20: ('flags', p.UVarintType, 0), 21: ('model', p.UnicodeType, 0), + 22: ('fw_major', p.UVarintType, 0), + 23: ('fw_minor', p.UVarintType, 0), + 24: ('fw_patch', p.UVarintType, 0), + 25: ('fw_vendor', p.UnicodeType, 0), + 26: ('fw_vendor_keys', p.BytesType, 0), + 27: ('state', p.BytesType, 0), } MESSAGE_WIRE_TYPE = 17 diff --git a/src/trezor/messages/Initialize.py b/src/trezor/messages/Initialize.py index 53203eb5a..3aaa84567 100644 --- a/src/trezor/messages/Initialize.py +++ b/src/trezor/messages/Initialize.py @@ -3,4 +3,7 @@ import protobuf as p class Initialize(p.MessageType): + FIELDS = { + 1: ('state', p.BytesType, 0), + } MESSAGE_WIRE_TYPE = 0 diff --git a/vendor/trezor-common b/vendor/trezor-common index 8652df0c6..c7dcca60c 160000 --- a/vendor/trezor-common +++ b/vendor/trezor-common @@ -1 +1 @@ -Subproject commit 8652df0c692ea4f13042539dcb6bde57b79137bc +Subproject commit c7dcca60c724c32ca3a688a6f20a055b0b4b3b1f