1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-07-29 18:08:19 +00:00

fix(legacy): added whole definitions to EthereumSignTypedData

This commit is contained in:
Martin Novak 2022-10-26 11:27:47 +02:00
parent 30cdde6902
commit 2af14f9897
10 changed files with 43 additions and 42 deletions

View File

@ -141,6 +141,7 @@ OBJS += protob/messages-management.pb.o
ifneq ($(BITCOIN_ONLY),1)
OBJS += ../vendor/trezor-crypto/cash_addr.o
OBJS += protob/messages-ethereum.pb.o
OBJS += protob/messages-ethereum-definitions.pb.o
OBJS += protob/messages-nem.pb.o
OBJS += protob/messages-stellar.pb.o
endif

View File

@ -555,8 +555,8 @@ static bool ethereum_signing_init_common(struct signing_params *params) {
return true;
}
static void ethereum_signing_handle_erc20(struct signing_params *params,
const EthereumDefinitionsDecoded *defs) {
static void ethereum_signing_handle_erc20(
struct signing_params *params, const EthereumDefinitionsDecoded *defs) {
if (params->has_to && ethereum_parse(params->to, params->pubkeyhash)) {
params->pubkeyhash_set = true;
} else {
@ -1052,7 +1052,8 @@ bool ethereum_parse(const char *address, uint8_t pubkeyhash[20]) {
}
bool ethereum_path_check(uint32_t address_n_count, const uint32_t *address_n,
bool pubkey_export, const EthereumDefinitionsDecoded *defs) {
bool pubkey_export,
const EthereumDefinitionsDecoded *defs) {
bool valid = (address_n_count >= 3);
valid = valid && (address_n[0] == (PATH_HARDENED | 44));
valid = valid && (address_n[1] & PATH_HARDENED);

View File

@ -45,5 +45,6 @@ void ethereum_typed_hash_sign(const EthereumSignTypedHash *msg,
bool ethereum_parse(const char *address, uint8_t pubkeyhash[20]);
bool ethereum_path_check(uint32_t address_n_count, const uint32_t *address_n,
bool pubkey_export, const EthereumDefinitionsDecoded *defs);
bool pubkey_export,
const EthereumDefinitionsDecoded *defs);
#endif

View File

@ -146,8 +146,7 @@ bool _decode_definition(const pb_size_t size, const pb_byte_t *bytes,
}
if (MIN_DATA_VERSION > parsed_def->data_version) {
fsm_sendFailure(FailureType_Failure_DataError,
_("Definition is outdated"));
fsm_sendFailure(FailureType_Failure_DataError, _("Definition is outdated"));
return false;
}

View File

@ -20,7 +20,7 @@
#ifndef __ETHEREUM_DEFINITIONS_H__
#define __ETHEREUM_DEFINITIONS_H__
#include "messages-ethereum.pb.h"
#include "messages-ethereum-definitions.pb.h"
typedef struct {
EthereumNetworkInfo network;

View File

@ -96,9 +96,8 @@ void fsm_msgEthereumSignTx(const EthereumSignTx *msg) {
const EthereumDefinitions_encoded_token_t *encoded_token = NULL;
if (msg->has_definitions) {
if (msg->definitions.has_encoded_network) {
encoded_network =
(const EthereumDefinitions_encoded_network_t *)&msg
->definitions.encoded_network;
encoded_network = (const EthereumDefinitions_encoded_network_t *)&msg
->definitions.encoded_network;
}
if (msg->definitions.has_encoded_token) {
encoded_token = (const EthereumDefinitions_encoded_token_t *)&msg
@ -106,9 +105,9 @@ void fsm_msgEthereumSignTx(const EthereumSignTx *msg) {
}
}
const EthereumDefinitionsDecoded *defs =
get_EthereumDefinitionsDecoded(encoded_network, encoded_token, msg->chain_id,
msg->has_to ? msg->to : NULL);
const EthereumDefinitionsDecoded *defs = get_EthereumDefinitionsDecoded(
encoded_network, encoded_token, msg->chain_id,
msg->has_to ? msg->to : NULL);
if (!defs || !fsm_ethereumCheckPath(msg->address_n_count, msg->address_n,
false, defs)) {
@ -132,9 +131,8 @@ void fsm_msgEthereumSignTxEIP1559(const EthereumSignTxEIP1559 *msg) {
const EthereumDefinitions_encoded_token_t *encoded_token = NULL;
if (msg->has_definitions) {
if (msg->definitions.has_encoded_network) {
encoded_network =
(const EthereumDefinitions_encoded_network_t *)&msg
->definitions.encoded_network;
encoded_network = (const EthereumDefinitions_encoded_network_t *)&msg
->definitions.encoded_network;
}
if (msg->definitions.has_encoded_token) {
encoded_token = (const EthereumDefinitions_encoded_token_t *)&msg
@ -142,9 +140,9 @@ void fsm_msgEthereumSignTxEIP1559(const EthereumSignTxEIP1559 *msg) {
}
}
const EthereumDefinitionsDecoded *defs =
get_EthereumDefinitionsDecoded(encoded_network, encoded_token, msg->chain_id,
msg->has_to ? msg->to : NULL);
const EthereumDefinitionsDecoded *defs = get_EthereumDefinitionsDecoded(
encoded_network, encoded_token, msg->chain_id,
msg->has_to ? msg->to : NULL);
if (!defs || !fsm_ethereumCheckPath(msg->address_n_count, msg->address_n,
false, defs)) {
@ -174,12 +172,12 @@ void fsm_msgEthereumGetAddress(const EthereumGetAddress *msg) {
const EthereumDefinitions_encoded_network_t *encoded_network = NULL;
if (msg->has_encoded_network) {
encoded_network = (const EthereumDefinitions_encoded_network_t *)&msg
->encoded_network;
encoded_network =
(const EthereumDefinitions_encoded_network_t *)&msg->encoded_network;
}
const EthereumDefinitionsDecoded *defs =
get_EthereumDefinitionsDecoded(encoded_network, NULL, CHAIN_ID_UNKNOWN, NULL);
const EthereumDefinitionsDecoded *defs = get_EthereumDefinitionsDecoded(
encoded_network, NULL, CHAIN_ID_UNKNOWN, NULL);
if (!defs || !fsm_ethereumCheckPath(msg->address_n_count, msg->address_n,
false, defs)) {
@ -247,12 +245,12 @@ void fsm_msgEthereumSignMessage(const EthereumSignMessage *msg) {
const EthereumDefinitions_encoded_network_t *encoded_network = NULL;
if (msg->has_encoded_network) {
encoded_network = (const EthereumDefinitions_encoded_network_t *)&msg
->encoded_network;
encoded_network =
(const EthereumDefinitions_encoded_network_t *)&msg->encoded_network;
}
const EthereumDefinitionsDecoded *defs =
get_EthereumDefinitionsDecoded(encoded_network, NULL, CHAIN_ID_UNKNOWN, NULL);
const EthereumDefinitionsDecoded *defs = get_EthereumDefinitionsDecoded(
encoded_network, NULL, CHAIN_ID_UNKNOWN, NULL);
if (!defs || !fsm_ethereumCheckPath(msg->address_n_count, msg->address_n,
false, defs)) {
@ -343,12 +341,12 @@ void fsm_msgEthereumSignTypedHash(const EthereumSignTypedHash *msg) {
const EthereumDefinitions_encoded_network_t *encoded_network = NULL;
if (msg->has_encoded_network) {
encoded_network = (const EthereumDefinitions_encoded_network_t *)&msg
->encoded_network;
encoded_network =
(const EthereumDefinitions_encoded_network_t *)&msg->encoded_network;
}
const EthereumDefinitionsDecoded *defs =
get_EthereumDefinitionsDecoded(encoded_network, NULL, CHAIN_ID_UNKNOWN, NULL);
const EthereumDefinitionsDecoded *defs = get_EthereumDefinitionsDecoded(
encoded_network, NULL, CHAIN_ID_UNKNOWN, NULL);
if (!defs || !fsm_ethereumCheckPath(msg->address_n_count, msg->address_n,
false, defs)) {

View File

@ -15,7 +15,8 @@ SKIPPED_MESSAGES += Ethereum NEM Stellar
endif
PROTO_NAMES = messages messages-bitcoin messages-common messages-crypto messages-debug \
messages-ethereum messages-management messages-nem messages-stellar
messages-ethereum messages-ethereum-definitions messages-management messages-nem \
messages-stellar
PROTO_OPTIONS = $(PROTO_NAMES:=.options)
PROTO_COMPILED = $(PROTO_NAMES:=.pb)

View File

@ -0,0 +1,9 @@
EthereumNetworkInfo.name max_size:256
EthereumNetworkInfo.shortcut max_size:256
EthereumTokenInfo.name max_size:256
EthereumTokenInfo.address max_size:20
EthereumTokenInfo.symbol max_size:256
EthereumDefinitions.encoded_network max_size:1024
EthereumDefinitions.encoded_token max_size:1024

View File

@ -0,0 +1 @@
../../vendor/trezor-common/protob/messages-ethereum-definitions.proto

View File

@ -51,13 +51,3 @@ EthereumGetPublicKey.address_n max_count:8
EthereumAddress._old_address max_size:20
EthereumAddress.address max_size:43
EthereumPublicKey.xpub max_size:113
EthereumTokenInfo.name max_size:256
EthereumTokenInfo.address max_size:20
EthereumTokenInfo.symbol max_size:256
EthereumNetworkInfo.name max_size:256
EthereumNetworkInfo.shortcut max_size:256
EthereumDefinitions.encoded_network max_size:1024
EthereumDefinitions.encoded_token max_size:1024