From a903e2db6e7d2260a35008cf976a83fccdb541aa Mon Sep 17 00:00:00 2001 From: Alexandre Paillier Date: Fri, 4 Aug 2023 18:17:09 +0200 Subject: [PATCH] Implemented the optional chain ID in the GET_ETH_PUBLIC_ADDRESS apdu --- doc/ethapp.adoc | 1 + src_features/getPublicKey/cmd_getPublicKey.c | 23 +++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/doc/ethapp.adoc b/doc/ethapp.adoc index 6997b9b..d61454a 100644 --- a/doc/ethapp.adoc +++ b/doc/ethapp.adoc @@ -87,6 +87,7 @@ The address can be optionally checked on the device before being returned. | First derivation index (big endian) | 4 | ... | 4 | Last derivation index (big endian) | 4 +| Chain ID (big endian) (optional) | 8 |============================================================================================================================== 'Output data' diff --git a/src_features/getPublicKey/cmd_getPublicKey.c b/src_features/getPublicKey/cmd_getPublicKey.c index bc8bac6..42fc3bd 100644 --- a/src_features/getPublicKey/cmd_getPublicKey.c +++ b/src_features/getPublicKey/cmd_getPublicKey.c @@ -1,6 +1,6 @@ #include "shared_context.h" #include "apdu_constants.h" - +#include "utils.h" #include "feature_getPublicKey.h" #include "ethUtils.h" #include "common_ui.h" @@ -21,16 +21,16 @@ void handleGetPublicKey(uint8_t p1, } if ((p1 != P1_CONFIRM) && (p1 != P1_NON_CONFIRM)) { - THROW(0x6B00); + THROW(APDU_RESPONSE_INVALID_P1_P2); } if ((p2 != P2_CHAINCODE) && (p2 != P2_NO_CHAINCODE)) { - THROW(0x6B00); + THROW(APDU_RESPONSE_INVALID_P1_P2); } dataBuffer = parseBip32(dataBuffer, &dataLength, &bip32); if (dataBuffer == NULL) { - THROW(0x6a80); + THROW(APDU_RESPONSE_INVALID_DATA); } tmpCtx.publicKeyContext.getChaincode = (p2 == P2_CHAINCODE); @@ -51,12 +51,25 @@ void handleGetPublicKey(uint8_t p1, tmpCtx.publicKeyContext.address, &global_sha3, chainConfig->chainId); + + uint64_t chain_id = chainConfig->chainId; + if (dataLength >= sizeof(chain_id)) { + chain_id = u64_from_BE(dataBuffer, sizeof(chain_id)); + dataLength -= sizeof(chain_id); + dataBuffer += sizeof(chain_id); + } + + (void) dataBuffer; // to prevent dead increment warning + if (dataLength > 0) { + THROW(APDU_RESPONSE_INVALID_DATA); + } + #ifndef NO_CONSENT if (p1 == P1_NON_CONFIRM) #endif // NO_CONSENT { *tx = set_result_get_publicKey(); - THROW(0x9000); + THROW(APDU_RESPONSE_OK); } #ifndef NO_CONSENT else {