From 0600d87c8c2e910919c8093481901412fe2163f9 Mon Sep 17 00:00:00 2001 From: matejcik Date: Tue, 21 Apr 2020 15:33:46 +0200 Subject: [PATCH] common: rename ClearSession to LockDevice, introduce EndSession --- common/protob/messages-management.proto | 14 ++++++++++++-- common/protob/messages.proto | 3 ++- core/src/trezor/messages/EndSession.py | 14 ++++++++++++++ .../messages/{ClearSession.py => LockDevice.py} | 2 +- core/src/trezor/messages/MessageType.py | 3 ++- legacy/firmware/fsm.h | 3 ++- legacy/firmware/fsm_msg_common.h | 10 +++++++--- python/src/trezorlib/client.py | 2 +- python/src/trezorlib/messages/EndSession.py | 14 ++++++++++++++ .../messages/{ClearSession.py => LockDevice.py} | 2 +- python/src/trezorlib/messages/MessageType.py | 3 ++- python/src/trezorlib/messages/__init__.py | 3 ++- 12 files changed, 60 insertions(+), 13 deletions(-) create mode 100644 core/src/trezor/messages/EndSession.py rename core/src/trezor/messages/{ClearSession.py => LockDevice.py} (88%) create mode 100644 python/src/trezorlib/messages/EndSession.py rename python/src/trezorlib/messages/{ClearSession.py => LockDevice.py} (88%) diff --git a/common/protob/messages-management.proto b/common/protob/messages-management.proto index be936f60fe..cb0abf368d 100644 --- a/common/protob/messages-management.proto +++ b/common/protob/messages-management.proto @@ -93,11 +93,21 @@ message Features { } /** - * Request: clear session (removes cached PIN, passphrase, etc). + * Request: soft-lock the device. Following actions will require PIN. Passphrases remain cached. * @start * @next Success */ -message ClearSession { +message LockDevice { +} + +/** + * Request: end the current sesson. Following actions must call Initialize again. + * Cache for the current session is discarded, other sessions remain intact. + * Device is not PIN-locked. + * @start + * @next Success + */ +message EndSession { } /** diff --git a/common/protob/messages.proto b/common/protob/messages.proto index 879aa1fcb7..35727ba7c2 100644 --- a/common/protob/messages.proto +++ b/common/protob/messages.proto @@ -44,7 +44,7 @@ enum MessageType { MessageType_PinMatrixRequest = 18 [(wire_out) = true]; MessageType_PinMatrixAck = 19 [(wire_in) = true, (wire_tiny) = true, (wire_no_fsm) = true]; MessageType_Cancel = 20 [(wire_in) = true, (wire_tiny) = true]; - MessageType_ClearSession = 24 [(wire_in) = true]; + MessageType_LockDevice = 24 [(wire_in) = true]; MessageType_ApplySettings = 25 [(wire_in) = true]; MessageType_ButtonRequest = 26 [(wire_out) = true]; MessageType_ButtonAck = 27 [(wire_in) = true, (wire_tiny) = true, (wire_no_fsm) = true]; @@ -63,6 +63,7 @@ enum MessageType { MessageType_GetNextU2FCounter = 80 [(wire_in) = true]; MessageType_NextU2FCounter = 81 [(wire_out) = true]; MessageType_ChangeWipeCode = 82 [(wire_in) = true]; + MessageType_EndSession = 83 [(wire_in) = true]; // Deprecated messages, kept for protobuf compatibility. // Both are marked wire_out so that we don't need to implement incoming handler for legacy diff --git a/core/src/trezor/messages/EndSession.py b/core/src/trezor/messages/EndSession.py new file mode 100644 index 0000000000..71169244d7 --- /dev/null +++ b/core/src/trezor/messages/EndSession.py @@ -0,0 +1,14 @@ +# Automatically generated by pb2py +# fmt: off +import protobuf as p + +if __debug__: + try: + from typing import Dict, List # noqa: F401 + from typing_extensions import Literal # noqa: F401 + except ImportError: + pass + + +class EndSession(p.MessageType): + MESSAGE_WIRE_TYPE = 83 diff --git a/core/src/trezor/messages/ClearSession.py b/core/src/trezor/messages/LockDevice.py similarity index 88% rename from core/src/trezor/messages/ClearSession.py rename to core/src/trezor/messages/LockDevice.py index 149b001406..4489ec3827 100644 --- a/core/src/trezor/messages/ClearSession.py +++ b/core/src/trezor/messages/LockDevice.py @@ -10,5 +10,5 @@ if __debug__: pass -class ClearSession(p.MessageType): +class LockDevice(p.MessageType): MESSAGE_WIRE_TYPE = 24 diff --git a/core/src/trezor/messages/MessageType.py b/core/src/trezor/messages/MessageType.py index 94e5be334b..c613f7b534 100644 --- a/core/src/trezor/messages/MessageType.py +++ b/core/src/trezor/messages/MessageType.py @@ -19,7 +19,7 @@ Features = 17 # type: Literal[17] PinMatrixRequest = 18 # type: Literal[18] PinMatrixAck = 19 # type: Literal[19] Cancel = 20 # type: Literal[20] -ClearSession = 24 # type: Literal[24] +LockDevice = 24 # type: Literal[24] ApplySettings = 25 # type: Literal[25] ButtonRequest = 26 # type: Literal[26] ButtonAck = 27 # type: Literal[27] @@ -38,6 +38,7 @@ SdProtect = 79 # type: Literal[79] GetNextU2FCounter = 80 # type: Literal[80] NextU2FCounter = 81 # type: Literal[81] ChangeWipeCode = 82 # type: Literal[82] +EndSession = 83 # type: Literal[83] Deprecated_PassphraseStateRequest = 77 # type: Literal[77] Deprecated_PassphraseStateAck = 78 # type: Literal[78] FirmwareErase = 6 # type: Literal[6] diff --git a/legacy/firmware/fsm.h b/legacy/firmware/fsm.h index 23c4ffe47c..10c15f5126 100644 --- a/legacy/firmware/fsm.h +++ b/legacy/firmware/fsm.h @@ -62,7 +62,8 @@ void fsm_msgResetDevice(const ResetDevice *msg); void fsm_msgEntropyAck(const EntropyAck *msg); void fsm_msgBackupDevice(const BackupDevice *msg); void fsm_msgCancel(const Cancel *msg); -void fsm_msgClearSession(const ClearSession *msg); +void fsm_msgLockDevice(const LockDevice *msg); +void fsm_msgEndSession(const EndSession *msg); void fsm_msgApplySettings(const ApplySettings *msg); void fsm_msgApplyFlags(const ApplyFlags *msg); void fsm_msgRecoveryDevice(const RecoveryDevice *msg); diff --git a/legacy/firmware/fsm_msg_common.h b/legacy/firmware/fsm_msg_common.h index 0b8ba8da99..32b9594176 100644 --- a/legacy/firmware/fsm_msg_common.h +++ b/legacy/firmware/fsm_msg_common.h @@ -345,15 +345,19 @@ void fsm_msgCancel(const Cancel *msg) { fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); } -void fsm_msgClearSession(const ClearSession *msg) { +void fsm_msgLockDevice(const LockDevice *msg) { (void)msg; - // we do not actually clear the session, we just lock it - // TODO: the message should be called LockSession see #819 config_lockDevice(); layoutScreensaver(); fsm_sendSuccess(_("Session cleared")); } +void fsm_msgEndSession(const EndSession *msg) { + (void)msg; + // TODO + fsm_sendFailure(FailureType_Failure_FirmwareError, "Not implemented"); +} + void fsm_msgApplySettings(const ApplySettings *msg) { CHECK_PARAM( !msg->has_passphrase_always_on_device, diff --git a/python/src/trezorlib/client.py b/python/src/trezorlib/client.py index 2846f95378..b74535bbce 100644 --- a/python/src/trezorlib/client.py +++ b/python/src/trezorlib/client.py @@ -285,7 +285,7 @@ class TrezorClient: @tools.session def clear_session(self): - resp = self.call_raw(messages.ClearSession()) + resp = self.call_raw(messages.LockDevice()) # TODO fix this if isinstance(resp, messages.Success): self.session_id = None self.init_device() diff --git a/python/src/trezorlib/messages/EndSession.py b/python/src/trezorlib/messages/EndSession.py new file mode 100644 index 0000000000..667213f68a --- /dev/null +++ b/python/src/trezorlib/messages/EndSession.py @@ -0,0 +1,14 @@ +# Automatically generated by pb2py +# fmt: off +from .. import protobuf as p + +if __debug__: + try: + from typing import Dict, List # noqa: F401 + from typing_extensions import Literal # noqa: F401 + except ImportError: + pass + + +class EndSession(p.MessageType): + MESSAGE_WIRE_TYPE = 83 diff --git a/python/src/trezorlib/messages/ClearSession.py b/python/src/trezorlib/messages/LockDevice.py similarity index 88% rename from python/src/trezorlib/messages/ClearSession.py rename to python/src/trezorlib/messages/LockDevice.py index 48e2d36aaf..cc12262232 100644 --- a/python/src/trezorlib/messages/ClearSession.py +++ b/python/src/trezorlib/messages/LockDevice.py @@ -10,5 +10,5 @@ if __debug__: pass -class ClearSession(p.MessageType): +class LockDevice(p.MessageType): MESSAGE_WIRE_TYPE = 24 diff --git a/python/src/trezorlib/messages/MessageType.py b/python/src/trezorlib/messages/MessageType.py index 5bd0e8fc51..5729cc1109 100644 --- a/python/src/trezorlib/messages/MessageType.py +++ b/python/src/trezorlib/messages/MessageType.py @@ -17,7 +17,7 @@ Features = 17 # type: Literal[17] PinMatrixRequest = 18 # type: Literal[18] PinMatrixAck = 19 # type: Literal[19] Cancel = 20 # type: Literal[20] -ClearSession = 24 # type: Literal[24] +LockDevice = 24 # type: Literal[24] ApplySettings = 25 # type: Literal[25] ButtonRequest = 26 # type: Literal[26] ButtonAck = 27 # type: Literal[27] @@ -36,6 +36,7 @@ SdProtect = 79 # type: Literal[79] GetNextU2FCounter = 80 # type: Literal[80] NextU2FCounter = 81 # type: Literal[81] ChangeWipeCode = 82 # type: Literal[82] +EndSession = 83 # type: Literal[83] Deprecated_PassphraseStateRequest = 77 # type: Literal[77] Deprecated_PassphraseStateAck = 78 # type: Literal[78] FirmwareErase = 6 # type: Literal[6] diff --git a/python/src/trezorlib/messages/__init__.py b/python/src/trezorlib/messages/__init__.py index a218abe540..765b5338e4 100644 --- a/python/src/trezorlib/messages/__init__.py +++ b/python/src/trezorlib/messages/__init__.py @@ -34,7 +34,6 @@ from .ChangePin import ChangePin from .ChangeWipeCode import ChangeWipeCode from .CipherKeyValue import CipherKeyValue from .CipheredKeyValue import CipheredKeyValue -from .ClearSession import ClearSession from .CosiCommit import CosiCommit from .CosiCommitment import CosiCommitment from .CosiSign import CosiSign @@ -59,6 +58,7 @@ from .DebugMoneroDiagRequest import DebugMoneroDiagRequest from .Deprecated_PassphraseStateAck import Deprecated_PassphraseStateAck from .Deprecated_PassphraseStateRequest import Deprecated_PassphraseStateRequest from .ECDHSessionKey import ECDHSessionKey +from .EndSession import EndSession from .Entropy import Entropy from .EntropyAck import EntropyAck from .EntropyRequest import EntropyRequest @@ -130,6 +130,7 @@ from .LiskTransactionAsset import LiskTransactionAsset from .LiskTransactionCommon import LiskTransactionCommon from .LiskVerifyMessage import LiskVerifyMessage from .LoadDevice import LoadDevice +from .LockDevice import LockDevice from .MessageSignature import MessageSignature from .MoneroAccountPublicAddress import MoneroAccountPublicAddress from .MoneroAddress import MoneroAddress