From 6e06ad8a5ff13edb768b1009b66e83482f9b1c10 Mon Sep 17 00:00:00 2001 From: Rafael Korbas Date: Mon, 14 Dec 2020 13:47:49 +0100 Subject: [PATCH] Refactor derivation path prefix validation --- src/bip44.c | 2 +- src/bip44.h | 2 +- src/keyDerivation.c | 2 +- src/messageSigning.c | 3 +++ src/securityPolicy.c | 4 ++-- src/uiScreens.c | 2 +- 6 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/bip44.c b/src/bip44.c index 7dc387dd5..be8d81f06 100644 --- a/src/bip44.c +++ b/src/bip44.c @@ -68,7 +68,7 @@ bool bip44_hasShelleyPrefix(const bip44_path_t* pathSpec) #undef CHECK } -bool bip44_hasValidCardanoPrefix(const bip44_path_t* pathSpec) +bool bip44_hasValidCardanoWalletPrefix(const bip44_path_t* pathSpec) { return bip44_hasByronPrefix(pathSpec) || bip44_hasShelleyPrefix(pathSpec); } diff --git a/src/bip44.h b/src/bip44.h index 592095702..30163ace1 100644 --- a/src/bip44.h +++ b/src/bip44.h @@ -45,7 +45,7 @@ enum { bool bip44_hasByronPrefix(const bip44_path_t* pathSpec); bool bip44_hasShelleyPrefix(const bip44_path_t* pathSpec); bool bip44_hasPoolColdKeyPrefix(const bip44_path_t* pathSpec); -bool bip44_hasValidCardanoPrefix(const bip44_path_t* pathSpec); +bool bip44_hasValidCardanoWalletPrefix(const bip44_path_t* pathSpec); bool bip44_containsAccount(const bip44_path_t* pathSpec); uint32_t bip44_getAccount(const bip44_path_t* pathSpec); diff --git a/src/keyDerivation.c b/src/keyDerivation.c index e8bc4b443..0e11afb5c 100644 --- a/src/keyDerivation.c +++ b/src/keyDerivation.c @@ -18,7 +18,7 @@ void derivePrivateKey( privateKey_t* privateKey ) { - if (!bip44_hasValidCardanoPrefix(pathSpec) && !bip44_isValidPoolColdKeyPath(pathSpec)) { + if (!bip44_hasValidCardanoWalletPrefix(pathSpec) && !bip44_isValidPoolColdKeyPath(pathSpec)) { THROW(ERR_INVALID_BIP44_PATH); } // Sanity check diff --git a/src/messageSigning.c b/src/messageSigning.c index 177d24afe..23d76995f 100644 --- a/src/messageSigning.c +++ b/src/messageSigning.c @@ -1,6 +1,7 @@ #include "messageSigning.h" #include "cardano.h" #include "keyDerivation.h" +#include "bip44.h" void signRawMessage(privateKey_t* privateKey, const uint8_t* messageBuffer, size_t messageSize, @@ -61,6 +62,7 @@ void getTxWitness(bip44_path_t* pathSpec, uint8_t* outBuffer, size_t outSize) { ASSERT(txHashSize == TX_HASH_LENGTH); + ASSERT(bip44_hasValidCardanoWalletPrefix(pathSpec)); signRawMessageWithPath(pathSpec, txHashBuffer, txHashSize, outBuffer, outSize); } @@ -69,5 +71,6 @@ void getOpCertSignature(bip44_path_t* pathSpec, uint8_t* outBuffer, size_t outSize) { ASSERT(opCertBodySize == OP_CERT_BODY_LENGTH); + ASSERT(bip44_isValidPoolColdKeyPath(pathSpec)); signRawMessageWithPath(pathSpec, opCertBodyBuffer, opCertBodySize, outBuffer, outSize); } diff --git a/src/securityPolicy.c b/src/securityPolicy.c index b4c15b747..e3fa2f058 100644 --- a/src/securityPolicy.c +++ b/src/securityPolicy.c @@ -58,7 +58,7 @@ static inline bool staking_info_is_valid(const addressParams_t* addressParams) static inline bool has_cardano_prefix_and_any_account(const bip44_path_t* pathSpec) { - return bip44_hasValidCardanoPrefix(pathSpec) && + return bip44_hasValidCardanoWalletPrefix(pathSpec) && bip44_containsAccount(pathSpec); } @@ -70,7 +70,7 @@ static inline bool is_valid_stake_pool_owner_path(const bip44_path_t* pathSpec) // general requirements on witnesses static inline bool is_valid_witness(const bip44_path_t* pathSpec) { - if (!bip44_hasValidCardanoPrefix(pathSpec)) + if (!bip44_hasValidCardanoWalletPrefix(pathSpec)) return false; if (bip44_isValidStakingKeyPath(pathSpec)) diff --git a/src/uiScreens.c b/src/uiScreens.c index 7af0b8299..506c4d2e9 100644 --- a/src/uiScreens.c +++ b/src/uiScreens.c @@ -33,7 +33,7 @@ void ui_displayAccountScreen( ASSERT(strlen(screenHeader) > 0); ASSERT(strlen(screenHeader) < BUFFER_SIZE_PARANOIA); - ASSERT(bip44_hasValidCardanoPrefix(path)); + ASSERT(bip44_hasValidCardanoWalletPrefix(path)); ASSERT(bip44_containsAccount(path)); char accountDescription[160];