From 5aa356f044a6dd84029ef832297dce485143f4c5 Mon Sep 17 00:00:00 2001 From: Andrew Kozlik Date: Fri, 3 Jun 2022 11:38:22 +0200 Subject: [PATCH] feat(common): Add UnlockPath message. [no changelog] --- common/protob/messages-bitcoin.proto | 1 + common/protob/messages-management.proto | 23 +++++++++++++ common/protob/messages.proto | 2 ++ core/src/trezor/enums/MessageType.py | 2 ++ core/src/trezor/enums/__init__.py | 2 ++ core/src/trezor/messages.py | 30 +++++++++++++++++ legacy/firmware/protob/Makefile | 2 +- .../protob/messages-management.options | 5 +++ python/src/trezorlib/messages.py | 33 +++++++++++++++++++ 9 files changed, 99 insertions(+), 1 deletion(-) diff --git a/common/protob/messages-bitcoin.proto b/common/protob/messages-bitcoin.proto index 864093764..5c4b639df 100644 --- a/common/protob/messages-bitcoin.proto +++ b/common/protob/messages-bitcoin.proto @@ -607,3 +607,4 @@ message AuthorizeCoinJoin { optional InputScriptType script_type = 7 [default=SPENDADDRESS]; // used to distinguish between various address formats (non-segwit, segwit, etc.) optional AmountUnit amount_unit = 8 [default=BITCOIN]; // show amounts in } + diff --git a/common/protob/messages-management.proto b/common/protob/messages-management.proto index 8cab05d26..3e896d5e4 100644 --- a/common/protob/messages-management.proto +++ b/common/protob/messages-management.proto @@ -441,6 +441,7 @@ message DoPreauthorized { * @start * @next SignTx * @next GetOwnershipProof + * @next GetPublicKey */ message PreauthorizedRequest { } @@ -480,3 +481,25 @@ message Nonce { required bytes nonce = 1; // a 32-byte random value generated by Trezor } + +/** + * Request: Ask device to unlock a subtree of the keychain. + * @start + * @next UnlockedPathRequest + * @next Failure + */ +message UnlockPath { + repeated uint32 address_n = 1; // prefix of the BIP-32 path leading to the account (m / purpose' / coin_type' / account') + optional bytes mac = 2; // the MAC returned by UnlockedPathRequest +} + +/** + * Request: Device awaits an operation. + * @start + * @next SignTx + * @next GetPublicKey + * @next GetAddress + */ +message UnlockedPathRequest { + optional bytes mac = 1; // authentication code for future UnlockPath calls +} diff --git a/common/protob/messages.proto b/common/protob/messages.proto index a9cc50ef3..341d1d729 100644 --- a/common/protob/messages.proto +++ b/common/protob/messages.proto @@ -119,6 +119,8 @@ enum MessageType { MessageType_GetFirmware = 90 [(bitcoin_only) = true, (wire_in) = true]; MessageType_FirmwareChunk = 91 [(bitcoin_only) = true, (wire_out) = true]; MessageType_FirmwareChunkAck = 92 [(bitcoin_only) = true, (wire_in) = true]; + MessageType_UnlockPath = 93 [(bitcoin_only) = true, (wire_in) = true]; + MessageType_UnlockedPathRequest = 94 [(bitcoin_only) = true, (wire_out) = true]; MessageType_SetU2FCounter = 63 [(wire_in) = true]; MessageType_GetNextU2FCounter = 80 [(wire_in) = true]; diff --git a/core/src/trezor/enums/MessageType.py b/core/src/trezor/enums/MessageType.py index 7f3e9aa40..d57cbf4ec 100644 --- a/core/src/trezor/enums/MessageType.py +++ b/core/src/trezor/enums/MessageType.py @@ -46,6 +46,8 @@ FirmwareHash = 89 GetFirmware = 90 FirmwareChunk = 91 FirmwareChunkAck = 92 +UnlockPath = 93 +UnlockedPathRequest = 94 FirmwareErase = 6 FirmwareUpload = 7 FirmwareRequest = 8 diff --git a/core/src/trezor/enums/__init__.py b/core/src/trezor/enums/__init__.py index 1435ff4ea..f45a7f715 100644 --- a/core/src/trezor/enums/__init__.py +++ b/core/src/trezor/enums/__init__.py @@ -63,6 +63,8 @@ if TYPE_CHECKING: GetFirmware = 90 FirmwareChunk = 91 FirmwareChunkAck = 92 + UnlockPath = 93 + UnlockedPathRequest = 94 SetU2FCounter = 63 GetNextU2FCounter = 80 NextU2FCounter = 81 diff --git a/core/src/trezor/messages.py b/core/src/trezor/messages.py index 2f870cdb4..fdff39ee5 100644 --- a/core/src/trezor/messages.py +++ b/core/src/trezor/messages.py @@ -2475,6 +2475,36 @@ if TYPE_CHECKING: def is_type_of(cls, msg: protobuf.MessageType) -> TypeGuard["Nonce"]: return isinstance(msg, cls) + class UnlockPath(protobuf.MessageType): + address_n: "list[int]" + mac: "bytes | None" + + def __init__( + self, + *, + address_n: "list[int] | None" = None, + mac: "bytes | None" = None, + ) -> None: + pass + + @classmethod + def is_type_of(cls, msg: protobuf.MessageType) -> TypeGuard["UnlockPath"]: + return isinstance(msg, cls) + + class UnlockedPathRequest(protobuf.MessageType): + mac: "bytes | None" + + def __init__( + self, + *, + mac: "bytes | None" = None, + ) -> None: + pass + + @classmethod + def is_type_of(cls, msg: protobuf.MessageType) -> TypeGuard["UnlockedPathRequest"]: + return isinstance(msg, cls) + class DebugLinkDecision(protobuf.MessageType): button: "DebugButton | None" swipe: "DebugSwipeDirection | None" diff --git a/legacy/firmware/protob/Makefile b/legacy/firmware/protob/Makefile index d6950d136..306b4da32 100644 --- a/legacy/firmware/protob/Makefile +++ b/legacy/firmware/protob/Makefile @@ -5,7 +5,7 @@ endif SKIPPED_MESSAGES := Binance Cardano DebugMonero Eos Monero Ontology Ripple SdProtect Tezos WebAuthn \ DebugLinkRecordScreen DebugLinkEraseSdCard DebugLinkWatchLayout \ GetOwnershipProof OwnershipProof GetOwnershipId OwnershipId AuthorizeCoinJoin DoPreauthorized \ - CancelAuthorization DebugLinkLayout GetNonce \ + CancelAuthorization DebugLinkLayout GetNonce UnlockPath \ TxAckInput TxAckOutput TxAckPrev TxAckPaymentRequest \ EthereumSignTypedData EthereumTypedDataStructRequest EthereumTypedDataStructAck \ EthereumTypedDataValueRequest EthereumTypedDataValueAck diff --git a/legacy/firmware/protob/messages-management.options b/legacy/firmware/protob/messages-management.options index bc3fb56d9..0f56f5dfa 100644 --- a/legacy/firmware/protob/messages-management.options +++ b/legacy/firmware/protob/messages-management.options @@ -40,3 +40,8 @@ GetFirmwareHash.challenge max_size:32 FirmwareHash.hash max_size:32 FirmwareChunk.chunk max_size:2048 + +UnlockPath.address_n max_count:8 +UnlockPath.mac max_size:32 + +UnlockedPathRequest.mac max_size:32 diff --git a/python/src/trezorlib/messages.py b/python/src/trezorlib/messages.py index f16d1982d..2b8c7e197 100644 --- a/python/src/trezorlib/messages.py +++ b/python/src/trezorlib/messages.py @@ -71,6 +71,8 @@ class MessageType(IntEnum): GetFirmware = 90 FirmwareChunk = 91 FirmwareChunkAck = 92 + UnlockPath = 93 + UnlockedPathRequest = 94 SetU2FCounter = 63 GetNextU2FCounter = 80 NextU2FCounter = 81 @@ -3521,6 +3523,37 @@ class Nonce(protobuf.MessageType): self.nonce = nonce +class UnlockPath(protobuf.MessageType): + MESSAGE_WIRE_TYPE = 93 + FIELDS = { + 1: protobuf.Field("address_n", "uint32", repeated=True, required=False), + 2: protobuf.Field("mac", "bytes", repeated=False, required=False), + } + + def __init__( + self, + *, + address_n: Optional[Sequence["int"]] = None, + mac: Optional["bytes"] = None, + ) -> None: + self.address_n: Sequence["int"] = address_n if address_n is not None else [] + self.mac = mac + + +class UnlockedPathRequest(protobuf.MessageType): + MESSAGE_WIRE_TYPE = 94 + FIELDS = { + 1: protobuf.Field("mac", "bytes", repeated=False, required=False), + } + + def __init__( + self, + *, + mac: Optional["bytes"] = None, + ) -> None: + self.mac = mac + + class DebugLinkDecision(protobuf.MessageType): MESSAGE_WIRE_TYPE = 100 FIELDS = {