Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/scriptpubkeyman.cpp
Show First 20 Lines • Show All 167 Lines • ▼ Show 20 Lines | bool LegacyScriptPubKeyMan::CheckDecryptionKey( | ||||
{ | { | ||||
LOCK(cs_KeyStore); | LOCK(cs_KeyStore); | ||||
assert(mapKeys.empty()); | assert(mapKeys.empty()); | ||||
// Always pass when there are no encrypted keys | // Always pass when there are no encrypted keys | ||||
bool keyPass = mapCryptedKeys.empty(); | bool keyPass = mapCryptedKeys.empty(); | ||||
bool keyFail = false; | bool keyFail = false; | ||||
CryptedKeyMap::const_iterator mi = mapCryptedKeys.begin(); | CryptedKeyMap::const_iterator mi = mapCryptedKeys.begin(); | ||||
WalletBatch batch(m_storage.GetDatabase()); | |||||
for (; mi != mapCryptedKeys.end(); ++mi) { | for (; mi != mapCryptedKeys.end(); ++mi) { | ||||
const CPubKey &vchPubKey = (*mi).second.first; | const CPubKey &vchPubKey = (*mi).second.first; | ||||
const std::vector<uint8_t> &vchCryptedSecret = (*mi).second.second; | const std::vector<uint8_t> &vchCryptedSecret = (*mi).second.second; | ||||
CKey key; | CKey key; | ||||
if (!DecryptKey(master_key, vchCryptedSecret, vchPubKey, key)) { | if (!DecryptKey(master_key, vchCryptedSecret, vchPubKey, key)) { | ||||
keyFail = true; | keyFail = true; | ||||
break; | break; | ||||
} | } | ||||
keyPass = true; | keyPass = true; | ||||
if (fDecryptionThoroughlyChecked) { | if (fDecryptionThoroughlyChecked) { | ||||
break; | break; | ||||
} else { | |||||
// Rewrite these encrypted keys with checksums | |||||
batch.WriteCryptedKey(vchPubKey, vchCryptedSecret, | |||||
mapKeyMetadata[vchPubKey.GetID()]); | |||||
} | } | ||||
} | } | ||||
if (keyPass && keyFail) { | if (keyPass && keyFail) { | ||||
LogPrintf("The wallet is probably corrupted: Some keys decrypt but " | LogPrintf("The wallet is probably corrupted: Some keys decrypt but " | ||||
"not all.\n"); | "not all.\n"); | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"Error unlocking wallet: some keys decrypt but not all. Your " | "Error unlocking wallet: some keys decrypt but not all. Your " | ||||
"wallet file may be corrupt."); | "wallet file may be corrupt."); | ||||
▲ Show 20 Lines • Show All 487 Lines • ▼ Show 20 Lines | bool LegacyScriptPubKeyMan::AddKeyPubKeyInner(const CKey &key, | ||||
if (!AddCryptedKey(pubkey, vchCryptedSecret)) { | if (!AddCryptedKey(pubkey, vchCryptedSecret)) { | ||||
return false; | return false; | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
bool LegacyScriptPubKeyMan::LoadCryptedKey( | bool LegacyScriptPubKeyMan::LoadCryptedKey( | ||||
const CPubKey &vchPubKey, const std::vector<uint8_t> &vchCryptedSecret) { | const CPubKey &vchPubKey, const std::vector<uint8_t> &vchCryptedSecret, | ||||
bool checksum_valid) { | |||||
// Set fDecryptionThoroughlyChecked to false when the checksum is invalid | |||||
if (!checksum_valid) { | |||||
fDecryptionThoroughlyChecked = false; | |||||
} | |||||
return AddCryptedKeyInner(vchPubKey, vchCryptedSecret); | return AddCryptedKeyInner(vchPubKey, vchCryptedSecret); | ||||
} | } | ||||
bool LegacyScriptPubKeyMan::AddCryptedKeyInner( | bool LegacyScriptPubKeyMan::AddCryptedKeyInner( | ||||
const CPubKey &vchPubKey, const std::vector<uint8_t> &vchCryptedSecret) { | const CPubKey &vchPubKey, const std::vector<uint8_t> &vchCryptedSecret) { | ||||
LOCK(cs_KeyStore); | LOCK(cs_KeyStore); | ||||
assert(mapKeys.empty()); | assert(mapKeys.empty()); | ||||
▲ Show 20 Lines • Show All 1,557 Lines • Show Last 20 Lines |