mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-02 09:46:52 -05:00
Upgrade or rewrite encrypted key checksums
If fDecryptionThoroughlyChecked is false, after a key has been checked, write (or rewrite) its checksum. This serves to upgrade wallets and correct those which have the checksum corrupted but not the key.
This commit is contained in:
parent
c9a9ddb414
commit
d67055e00d
2 changed files with 13 additions and 1 deletions
|
@ -210,6 +210,7 @@ bool LegacyScriptPubKeyMan::CheckDecryptionKey(const CKeyingMaterial& master_key
|
|||
bool keyPass = mapCryptedKeys.empty(); // Always pass when there are no encrypted keys
|
||||
bool keyFail = false;
|
||||
CryptedKeyMap::const_iterator mi = mapCryptedKeys.begin();
|
||||
WalletBatch batch(m_storage.GetDatabase());
|
||||
for (; mi != mapCryptedKeys.end(); ++mi)
|
||||
{
|
||||
const CPubKey &vchPubKey = (*mi).second.first;
|
||||
|
@ -223,6 +224,10 @@ bool LegacyScriptPubKeyMan::CheckDecryptionKey(const CKeyingMaterial& master_key
|
|||
keyPass = true;
|
||||
if (fDecryptionThoroughlyChecked)
|
||||
break;
|
||||
else {
|
||||
// Rewrite these encrypted keys with checksums
|
||||
batch.WriteCryptedKey(vchPubKey, vchCryptedSecret, mapKeyMetadata[vchPubKey.GetID()]);
|
||||
}
|
||||
}
|
||||
if (keyPass && keyFail)
|
||||
{
|
||||
|
|
|
@ -114,7 +114,14 @@ bool WalletBatch::WriteCryptedKey(const CPubKey& vchPubKey,
|
|||
|
||||
const auto key = std::make_pair(DBKeys::CRYPTED_KEY, vchPubKey);
|
||||
if (!WriteIC(key, std::make_pair(vchCryptedSecret, checksum), false)) {
|
||||
return false;
|
||||
// It may already exist, so try writing just the checksum
|
||||
std::vector<unsigned char> val;
|
||||
if (!m_batch.Read(key, val)) {
|
||||
return false;
|
||||
}
|
||||
if (!WriteIC(key, std::make_pair(val, checksum), true)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
EraseIC(std::make_pair(DBKeys::KEY, vchPubKey));
|
||||
return true;
|
||||
|
|
Loading…
Add table
Reference in a new issue