diff --git a/CHANGELOG.md b/CHANGELOG.md index 6dd85d4f21..c7ab4f3ba9 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,20 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/) and this project adheres to [Semantic Versioning](https://semver.org/). +## [5.4.5.0] 2023-04-23, leisure + +### Added +none + +### Changed +none + +### Removed +none + +### Fixed + - key, rpc: fix key parsing #2682 (@div72) + ## [5.4.4.0] 2023-04-21, leisure ### Added diff --git a/configure.ac b/configure.ac index 295ecb2d22..4f0d63ae38 100755 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ dnl require autoconf 2.60 (AS_ECHO/AS_ECHO_N) AC_PREREQ([2.60]) define(_CLIENT_VERSION_MAJOR, 5) define(_CLIENT_VERSION_MINOR, 4) -define(_CLIENT_VERSION_REVISION, 4) +define(_CLIENT_VERSION_REVISION, 5) define(_CLIENT_VERSION_BUILD, 0) define(_CLIENT_VERSION_IS_RELEASE, true) define(_COPYRIGHT_YEAR, 2023) diff --git a/src/key.cpp b/src/key.cpp index cf0f9fb104..68922d2244 100644 --- a/src/key.cpp +++ b/src/key.cpp @@ -284,7 +284,7 @@ bool CKey::SignCompact(const uint256 &hash, std::vector& vchSig) bool CKey::Load(const CPrivKey &seckey, const CPubKey &vchPubKey, bool fSkipCheck=false) { if (!ec_seckey_import_der(secp256k1_context_sign, (unsigned char*)begin(), seckey.data(), seckey.size())) return false; - fCompressed = seckey.size() == CKey::COMPRESSED_SIZE; + fCompressed = vchPubKey.IsCompressed(); fValid = true; if (fSkipCheck) diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index f652cdc716..e6a023bd05 100644 --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -490,7 +490,7 @@ UniValue sendalert(const UniValue& params, bool fHelp) "sendalert [cancelupto]\n" "\n" " ----> is the alert text message\n" - " -> is hex string of alert master private key\n" + " -> is WIF encoded alert master private key\n" " -----> is the minimum applicable internal client version\n" " -----> is the maximum applicable internal client version\n" " ---> is integer priority number\n" @@ -517,8 +517,20 @@ UniValue sendalert(const UniValue& params, bool fHelp) sMsg << (CUnsignedAlert)alert; alert.vchMsg = vector((unsigned char*)&sMsg.begin()[0], (unsigned char*)&sMsg.end()[0]); - vector vchPrivKey = ParseHex(params[1].get_str()); - key.Load(CPrivKey(vchPrivKey.begin(), vchPrivKey.end()), CPubKey(), true); + CBitcoinSecret vchSecret; + + if (!vchSecret.SetString(params[0].get_str())) { + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid private key"); + } + + bool fCompressed; + CSecret secret = vchSecret.GetSecret(fCompressed); + key.Set(secret.begin(), secret.end(), fCompressed); + + if (!key.IsValid()) { + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid private key"); + } + if (!key.Sign(Hash(alert.vchMsg), alert.vchSig)) throw runtime_error( "Unable to sign alert, check private key?\n"); @@ -551,7 +563,7 @@ UniValue sendalert2(const UniValue& params, bool fHelp) // 0 1 2 3 4 5 6 "sendalert2 \n" "\n" - " -> is hex string of alert master private key\n" + " -> is WIF encoded alert master private key\n" " ---------> is the unique alert number\n" " -> comma separated list of versions warning applies to\n" " -> comma separated ids of alerts to cancel\n" @@ -591,8 +603,20 @@ UniValue sendalert2(const UniValue& params, bool fHelp) sMsg << (CUnsignedAlert)alert; alert.vchMsg = vector((unsigned char*)&sMsg.begin()[0], (unsigned char*)&sMsg.end()[0]); - vector vchPrivKey = ParseHex(params[0].get_str()); - key.Load(CPrivKey(vchPrivKey.begin(), vchPrivKey.end()), CPubKey(), true); + CBitcoinSecret vchSecret; + + if (!vchSecret.SetString(params[0].get_str())) { + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid private key"); + } + + bool fCompressed; + CSecret secret = vchSecret.GetSecret(fCompressed); + key.Set(secret.begin(), secret.end(), fCompressed); + + if (!key.IsValid()) { + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid private key"); + } + if (!key.Sign(Hash(alert.vchMsg), alert.vchSig)) throw runtime_error( "Unable to sign alert, check private key?\n"); diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index b806e0378a..b229dc7880 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -125,20 +125,17 @@ UniValue importprivkey(const UniValue& params, bool fHelp) CBitcoinSecret vchSecret; CKey key; - bool fGood = vchSecret.SetString(strSecret); - // If CBitcoinSecret key decode failed, try to decode the key as hex - if(!fGood) - { - auto vecsecret = ParseHex(strSecret); - if (!key.Load(CPrivKey(vecsecret.begin(), vecsecret.end()), CPubKey(), /*fSkipCheck=*/true)) - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid private key"); + if (!vchSecret.SetString(strSecret)) { + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid private key."); } - else - { - bool fCompressed; - CSecret secret = vchSecret.GetSecret(fCompressed); - key.Set(secret.begin(), secret.end(), fCompressed); + + bool fCompressed; + CSecret secret = vchSecret.GetSecret(fCompressed); + key.Set(secret.begin(), secret.end(), fCompressed); + + if (!key.IsValid()) { + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid private key."); } if (fWalletUnlockStakingOnly)