mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-23 23:08:14 +00:00
src/apps/common: implement passphrase_source and use it
This commit is contained in:
parent
6cf9bb1d93
commit
e6bfd192e5
@ -2,6 +2,7 @@ from trezor import ui, wire
|
||||
from trezor.messages import ButtonRequestType, wire_types
|
||||
from trezor.messages.ButtonRequest import ButtonRequest
|
||||
from trezor.messages.FailureType import ActionCancelled, ProcessError
|
||||
from trezor.messages import PassphraseSourceType
|
||||
from trezor.messages.PassphraseRequest import PassphraseRequest
|
||||
from trezor.messages.PassphraseStateRequest import PassphraseStateRequest
|
||||
from trezor.ui.entry_select import DEVICE, EntrySelector
|
||||
@ -61,7 +62,10 @@ async def request_passphrase_ack(ctx, on_device):
|
||||
|
||||
|
||||
async def request_passphrase(ctx):
|
||||
on_device = await request_passphrase_entry(ctx) == DEVICE
|
||||
if storage.get_passphrase_source() == PassphraseSourceType.ASK:
|
||||
on_device = await request_passphrase_entry(ctx) == DEVICE
|
||||
else:
|
||||
on_device = storage.get_passphrase_source() == PassphraseSourceType.DEVICE
|
||||
passphrase = await request_passphrase_ack(ctx, on_device)
|
||||
return passphrase
|
||||
|
||||
|
@ -8,17 +8,18 @@ HOMESCREEN_MAXSIZE = 16384
|
||||
|
||||
_STORAGE_VERSION = b'\x01'
|
||||
|
||||
_APP = const(0x01) # app namespace
|
||||
_DEVICE_ID = const(0x00) # bytes
|
||||
_VERSION = const(0x01) # int
|
||||
_MNEMONIC = const(0x02) # str
|
||||
_LANGUAGE = const(0x03) # str
|
||||
_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
|
||||
_U2F_COUNTER = const(0x09) # int
|
||||
_APP = const(0x01) # app namespace
|
||||
_DEVICE_ID = const(0x00) # bytes
|
||||
_VERSION = const(0x01) # int
|
||||
_MNEMONIC = const(0x02) # str
|
||||
_LANGUAGE = const(0x03) # str
|
||||
_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
|
||||
_U2F_COUNTER = const(0x09) # int
|
||||
_PASSPHRASE_SOURCE = const(0x0A) # int
|
||||
|
||||
|
||||
def _new_device_id() -> str:
|
||||
@ -70,7 +71,17 @@ def set_backed_up() -> None:
|
||||
config.set(_APP, _NEEDS_BACKUP, b'')
|
||||
|
||||
|
||||
def load_settings(label: str=None, use_passphrase: bool=None, homescreen: bytes=None) -> None:
|
||||
def get_passphrase_source() -> int:
|
||||
b = config.get(_APP, _PASSPHRASE_SOURCE)
|
||||
if b == b'\x01':
|
||||
return 1
|
||||
elif b == b'\x02':
|
||||
return 2
|
||||
else:
|
||||
return 0
|
||||
|
||||
|
||||
def load_settings(label: str=None, use_passphrase: bool=None, homescreen: bytes=None, passphrase_source: int=None) -> None:
|
||||
if label is not None:
|
||||
config.set(_APP, _LABEL, label.encode(), True) # public
|
||||
if use_passphrase is True:
|
||||
@ -83,6 +94,9 @@ def load_settings(label: str=None, use_passphrase: bool=None, homescreen: bytes=
|
||||
config.set(_APP, _HOMESCREEN, homescreen, True) # public
|
||||
else:
|
||||
config.set(_APP, _HOMESCREEN, b'', True) # public
|
||||
if passphrase_source is not None:
|
||||
if passphrase_source in [0, 1, 2]:
|
||||
config.set(_APP, _PASSPHRASE_SOURCE, bytes([passphrase_source]))
|
||||
|
||||
|
||||
def get_flags() -> int:
|
||||
|
@ -1,5 +1,5 @@
|
||||
from trezor import ui, wire
|
||||
from trezor.messages import ButtonRequestType, FailureType
|
||||
from trezor.messages import ButtonRequestType, FailureType, PassphraseSourceType
|
||||
from trezor.messages.Success import Success
|
||||
from trezor.ui.text import Text
|
||||
from apps.common import storage
|
||||
@ -7,7 +7,7 @@ from apps.common.confirm import require_confirm
|
||||
|
||||
|
||||
async def apply_settings(ctx, msg):
|
||||
if msg.homescreen is None and msg.label is None and msg.use_passphrase is None:
|
||||
if msg.homescreen is None and msg.label is None and msg.use_passphrase is None and msg.passphrase_source is None:
|
||||
raise wire.FailureError(FailureType.ProcessError, 'No setting provided')
|
||||
|
||||
if msg.homescreen is not None:
|
||||
@ -35,8 +35,22 @@ async def apply_settings(ctx, msg):
|
||||
'encryption?'),
|
||||
code=ButtonRequestType.ProtectCall)
|
||||
|
||||
if msg.passphrase_source is not None:
|
||||
if msg.passphrase_source == PassphraseSourceType.DEVICE:
|
||||
desc = 'ON DEVICE'
|
||||
elif msg.passphrase_source == PassphraseSourceType.HOST:
|
||||
desc = 'ON HOST'
|
||||
else:
|
||||
desc = 'ASK'
|
||||
await require_confirm(ctx, Text(
|
||||
'Passphrase source', ui.ICON_CONFIG,
|
||||
'Do you really want to', 'change the passphrase', 'source to',
|
||||
ui.BOLD, 'ALWAYS %s?' % desc),
|
||||
code=ButtonRequestType.ProtectCall)
|
||||
|
||||
storage.load_settings(label=msg.label,
|
||||
use_passphrase=msg.use_passphrase,
|
||||
homescreen=msg.homescreen)
|
||||
homescreen=msg.homescreen,
|
||||
passphrase_source=msg.passphrase_source)
|
||||
|
||||
return Success(message='Settings applied')
|
||||
|
@ -8,6 +8,7 @@ class ApplySettings(p.MessageType):
|
||||
2: ('label', p.UnicodeType, 0),
|
||||
3: ('use_passphrase', p.BoolType, 0),
|
||||
4: ('homescreen', p.BytesType, 0),
|
||||
5: ('passphrase_source', p.UVarintType, 0),
|
||||
}
|
||||
MESSAGE_WIRE_TYPE = 25
|
||||
|
||||
@ -17,10 +18,12 @@ class ApplySettings(p.MessageType):
|
||||
label: str = None,
|
||||
use_passphrase: bool = None,
|
||||
homescreen: bytes = None,
|
||||
passphrase_source: int = None,
|
||||
**kwargs,
|
||||
):
|
||||
self.language = language
|
||||
self.label = label
|
||||
self.use_passphrase = use_passphrase
|
||||
self.homescreen = homescreen
|
||||
self.passphrase_source = passphrase_source
|
||||
p.MessageType.__init__(self, **kwargs)
|
||||
|
@ -13,6 +13,7 @@ class EthereumSignTx(p.MessageType):
|
||||
7: ('data_initial_chunk', p.BytesType, 0),
|
||||
8: ('data_length', p.UVarintType, 0),
|
||||
9: ('chain_id', p.UVarintType, 0),
|
||||
10: ('tx_type', p.UVarintType, 0),
|
||||
}
|
||||
MESSAGE_WIRE_TYPE = 58
|
||||
|
||||
@ -27,6 +28,7 @@ class EthereumSignTx(p.MessageType):
|
||||
data_initial_chunk: bytes = None,
|
||||
data_length: int = None,
|
||||
chain_id: int = None,
|
||||
tx_type: int = None,
|
||||
**kwargs,
|
||||
):
|
||||
self.address_n = [] if address_n is None else address_n
|
||||
@ -38,4 +40,5 @@ class EthereumSignTx(p.MessageType):
|
||||
self.data_initial_chunk = data_initial_chunk
|
||||
self.data_length = data_length
|
||||
self.chain_id = chain_id
|
||||
self.tx_type = tx_type
|
||||
p.MessageType.__init__(self, **kwargs)
|
||||
|
6
src/trezor/messages/PassphraseSourceType.py
Normal file
6
src/trezor/messages/PassphraseSourceType.py
Normal file
@ -0,0 +1,6 @@
|
||||
# Automatically generated by pb2py
|
||||
from micropython import const
|
||||
|
||||
ASK = const(0)
|
||||
DEVICE = const(1)
|
||||
HOST = const(2)
|
2
vendor/trezor-common
vendored
2
vendor/trezor-common
vendored
@ -1 +1 @@
|
||||
Subproject commit 0924bd6826bb63f66010e2e511356d54ea733df3
|
||||
Subproject commit 998eb4c7a76bdb5190f5f9f52bf8c53d795fbb25
|
Loading…
Reference in New Issue
Block a user