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:
parent
e93ef0c296
commit
6fad2f4283
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -3,4 +3,7 @@ import protobuf as p
|
||||
|
||||
|
||||
class Initialize(p.MessageType):
|
||||
FIELDS = {
|
||||
1: ('state', p.BytesType, 0),
|
||||
}
|
||||
MESSAGE_WIRE_TYPE = 0
|
||||
|
2
vendor/trezor-common
vendored
2
vendor/trezor-common
vendored
@ -1 +1 @@
|
||||
Subproject commit 8652df0c692ea4f13042539dcb6bde57b79137bc
|
||||
Subproject commit c7dcca60c724c32ca3a688a6f20a055b0b4b3b1f
|
Loading…
Reference in New Issue
Block a user