1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-21 23:18:13 +00:00

src/apps/homescreen: implement {Initialize,Features}.state field, implement ClearSession handling

This commit is contained in:
Pavol Rusnak 2018-02-09 18:07:47 +01:00
parent e93ef0c296
commit 6fad2f4283
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
5 changed files with 39 additions and 3 deletions

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -3,4 +3,7 @@ import protobuf as p
class Initialize(p.MessageType):
FIELDS = {
1: ('state', p.BytesType, 0),
}
MESSAGE_WIRE_TYPE = 0

@ -1 +1 @@
Subproject commit 8652df0c692ea4f13042539dcb6bde57b79137bc
Subproject commit c7dcca60c724c32ca3a688a6f20a055b0b4b3b1f