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
This commit is contained in:
Wladimir J. van der Laan 2017-05-03 09:10:59 +02:00
commit d3dce0eb67
No known key found for this signature in database
GPG key ID: 74810B012346C9A6
2 changed files with 8 additions and 13 deletions

View file

@ -621,13 +621,10 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
// if we are using HD, replace the HD master key (seed) with a new one // if we are using HD, replace the HD master key (seed) with a new one
if (IsHDEnabled()) { if (IsHDEnabled()) {
CKey key; if (!SetHDMasterKey(GenerateNewHDMasterKey())) {
CPubKey masterPubKey = GenerateNewHDMasterKey();
// preserve the old chains version to not break backward compatibility
CHDChain oldChain = GetHDChain();
if (!SetHDMasterKey(masterPubKey, &oldChain))
return false; return false;
} }
}
NewKeyPool(); NewKeyPool();
Lock(); Lock();
@ -1324,17 +1321,14 @@ CPubKey CWallet::GenerateNewHDMasterKey()
return pubkey; return pubkey;
} }
bool CWallet::SetHDMasterKey(const CPubKey& pubkey, CHDChain *possibleOldChain) bool CWallet::SetHDMasterKey(const CPubKey& pubkey)
{ {
LOCK(cs_wallet); LOCK(cs_wallet);
// store the keyid (hash160) together with // store the keyid (hash160) together with
// the child index counter in the database // the child index counter in the database
// as a hdchain object // as a hdchain object
CHDChain newHdChain; CHDChain newHdChain;
if (possibleOldChain) { newHdChain.nVersion = CanSupportFeature(FEATURE_HD_SPLIT) ? CHDChain::VERSION_HD_CHAIN_SPLIT : CHDChain::VERSION_HD_BASE;
// preserve the old chains version
newHdChain.nVersion = possibleOldChain->nVersion;
}
newHdChain.masterKeyID = pubkey.GetID(); newHdChain.masterKeyID = pubkey.GetID();
SetHDChain(newHdChain, false); SetHDChain(newHdChain, false);

View file

@ -1100,9 +1100,10 @@ public:
CPubKey GenerateNewHDMasterKey(); CPubKey GenerateNewHDMasterKey();
/* Set the current HD master key (will reset the chain child index counters) /* Set the current HD master key (will reset the chain child index counters)
If possibleOldChain is provided, the parameters from the old chain (version) Sets the master key's version based on the current wallet version (so the
will be preserved. */ caller must ensure the current wallet version is correct before calling
bool SetHDMasterKey(const CPubKey& key, CHDChain *possibleOldChain = nullptr); this function). */
bool SetHDMasterKey(const CPubKey& key);
}; };
/** A key allocated from the key pool. */ /** A key allocated from the key pool. */