Skip to content

Commit d3dce0e

Browse files
committed
Merge #10115: Avoid reading the old hd master key during wallet encryption
185c7f0 Avoid reading the old hd master key during wallet encryption (Matt Corallo) Tree-SHA512: b744e8490c0e948355bb77b2695902bb99f89a68af46aa2be9120bd2ccf3c340eb8a56340fec117f9a935192298028945c9b18120ee6b8b23e7da8ffdb635745
2 parents 83073de + 185c7f0 commit d3dce0e

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

src/wallet/wallet.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -621,12 +621,9 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
621621

622622
// if we are using HD, replace the HD master key (seed) with a new one
623623
if (IsHDEnabled()) {
624-
CKey key;
625-
CPubKey masterPubKey = GenerateNewHDMasterKey();
626-
// preserve the old chains version to not break backward compatibility
627-
CHDChain oldChain = GetHDChain();
628-
if (!SetHDMasterKey(masterPubKey, &oldChain))
624+
if (!SetHDMasterKey(GenerateNewHDMasterKey())) {
629625
return false;
626+
}
630627
}
631628

632629
NewKeyPool();
@@ -1324,17 +1321,14 @@ CPubKey CWallet::GenerateNewHDMasterKey()
13241321
return pubkey;
13251322
}
13261323

1327-
bool CWallet::SetHDMasterKey(const CPubKey& pubkey, CHDChain *possibleOldChain)
1324+
bool CWallet::SetHDMasterKey(const CPubKey& pubkey)
13281325
{
13291326
LOCK(cs_wallet);
13301327
// store the keyid (hash160) together with
13311328
// the child index counter in the database
13321329
// as a hdchain object
13331330
CHDChain newHdChain;
1334-
if (possibleOldChain) {
1335-
// preserve the old chains version
1336-
newHdChain.nVersion = possibleOldChain->nVersion;
1337-
}
1331+
newHdChain.nVersion = CanSupportFeature(FEATURE_HD_SPLIT) ? CHDChain::VERSION_HD_CHAIN_SPLIT : CHDChain::VERSION_HD_BASE;
13381332
newHdChain.masterKeyID = pubkey.GetID();
13391333
SetHDChain(newHdChain, false);
13401334

src/wallet/wallet.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,9 +1100,10 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
11001100
CPubKey GenerateNewHDMasterKey();
11011101

11021102
/* Set the current HD master key (will reset the chain child index counters)
1103-
If possibleOldChain is provided, the parameters from the old chain (version)
1104-
will be preserved. */
1105-
bool SetHDMasterKey(const CPubKey& key, CHDChain *possibleOldChain = nullptr);
1103+
Sets the master key's version based on the current wallet version (so the
1104+
caller must ensure the current wallet version is correct before calling
1105+
this function). */
1106+
bool SetHDMasterKey(const CPubKey& key);
11061107
};
11071108

11081109
/** A key allocated from the key pool. */

0 commit comments

Comments
 (0)