1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-27 16:48:09 +00:00

src/apps/management: implement ApplyFlags message

This commit is contained in:
Pavol Rusnak 2018-02-14 23:50:08 +01:00
parent 3c738b62c4
commit 736dec1419
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
4 changed files with 38 additions and 3 deletions

View File

@ -13,6 +13,7 @@ _LABEL = const(0x04) # str
_USE_PASSPHRASE = const(0x05) # 0x01 or empty
_HOMESCREEN = const(0x06) # bytes
_NEEDS_BACKUP = const(0x07) # 0x01 or empty
_FLAGS = const(0x08) # int
def get_device_id() -> str:
@ -43,7 +44,7 @@ def get_homescreen() -> bytes:
return config.get(_APP, _HOMESCREEN, True) # public
def load_mnemonic(mnemonic: str, needs_backup: bool):
def load_mnemonic(mnemonic: str, needs_backup: bool) -> None:
config.set(_APP, _MNEMONIC, mnemonic.encode())
config.set(_APP, _VERSION, _STORAGE_VERSION)
if needs_backup:
@ -52,7 +53,7 @@ def load_mnemonic(mnemonic: str, needs_backup: bool):
config.set(_APP, _NEEDS_BACKUP, b'')
def load_settings(label: str=None, use_passphrase: bool=None, homescreen: bytes=None):
def load_settings(label: str=None, use_passphrase: bool=None, homescreen: bytes=None) -> None:
if label is not None:
config.set(_APP, _LABEL, label.encode(), True) # public
if use_passphrase is True:
@ -66,6 +67,25 @@ def load_settings(label: str=None, use_passphrase: bool=None, homescreen: bytes=
config.set(_APP, _HOMESCREEN, b'', True) # public
def get_flags() -> int:
b = config.get(_APP, _FLAGS)
if b is None:
return 0
else:
return int.from_bytes(b, 'big')
def set_flags(flags: int) -> None:
b = config.get(_APP, _FLAGS)
if b is None:
b = 0
else:
b = int.from_bytes(b, 'big')
flags = (flags | b) & 0xFFFFFFFF
if flags != b:
config.set(_APP, _FLAGS, flags.to_bytes(4, 'big'))
def wipe():
from . import cache
config.wipe()

View File

@ -28,6 +28,7 @@ async def respond_Features(ctx, msg):
f.initialized = storage.is_initialized()
f.passphrase_protection = storage.has_passphrase()
f.pin_protection = config.has_pin()
f.flags = storage.get_flags()
f.language = 'english'
f.state = cache.get_state()

View File

@ -1,7 +1,7 @@
from trezor.wire import register, protobuf_workflow
from trezor.utils import unimport
from trezor.messages.wire_types import \
LoadDevice, ResetDevice, WipeDevice, RecoveryDevice, ApplySettings, ChangePin
LoadDevice, ResetDevice, WipeDevice, RecoveryDevice, ApplySettings, ApplyFlags, ChangePin
@unimport
@ -34,6 +34,12 @@ def dispatch_ApplySettings(*args, **kwargs):
return layout_apply_settings(*args, **kwargs)
@unimport
def dispatch_ApplyFlags(*args, **kwargs):
from .apply_flags import layout_apply_flags
return layout_apply_flags(*args, **kwargs)
@unimport
def dispatch_ChangePin(*args, **kwargs):
from .change_pin import layout_change_pin
@ -48,4 +54,5 @@ def boot():
register(WipeDevice, protobuf_workflow, dispatch_WipeDevice)
register(RecoveryDevice, protobuf_workflow, dispatch_RecoveryDevice)
register(ApplySettings, protobuf_workflow, dispatch_ApplySettings)
register(ApplyFlags, protobuf_workflow, dispatch_ApplyFlags)
register(ChangePin, protobuf_workflow, dispatch_ChangePin)

View File

@ -0,0 +1,7 @@
async def layout_apply_flags(ctx, msg):
from trezor.messages.Success import Success
from ..common import storage
storage.set_flags(msg.flags)
return Success(message='Flags applied')