Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/walletdb.cpp
Show First 20 Lines • Show All 113 Lines • ▼ Show 20 Lines | bool WalletBatch::WriteKey(const CPubKey &vchPubKey, const CPrivKey &vchPrivKey, | ||||
} | } | ||||
// hash pubkey/privkey to accelerate wallet load | // hash pubkey/privkey to accelerate wallet load | ||||
std::vector<uint8_t> vchKey; | std::vector<uint8_t> vchKey; | ||||
vchKey.reserve(vchPubKey.size() + vchPrivKey.size()); | vchKey.reserve(vchPubKey.size() + vchPrivKey.size()); | ||||
vchKey.insert(vchKey.end(), vchPubKey.begin(), vchPubKey.end()); | vchKey.insert(vchKey.end(), vchPubKey.begin(), vchPubKey.end()); | ||||
vchKey.insert(vchKey.end(), vchPrivKey.begin(), vchPrivKey.end()); | vchKey.insert(vchKey.end(), vchPrivKey.begin(), vchPrivKey.end()); | ||||
return WriteIC( | return WriteIC(std::make_pair(DBKeys::KEY, vchPubKey), | ||||
std::make_pair(DBKeys::KEY, vchPubKey), | std::make_pair(vchPrivKey, Hash(vchKey)), false); | ||||
std::make_pair(vchPrivKey, Hash(vchKey.begin(), vchKey.end())), false); | |||||
} | } | ||||
bool WalletBatch::WriteCryptedKey(const CPubKey &vchPubKey, | bool WalletBatch::WriteCryptedKey(const CPubKey &vchPubKey, | ||||
const std::vector<uint8_t> &vchCryptedSecret, | const std::vector<uint8_t> &vchCryptedSecret, | ||||
const CKeyMetadata &keyMeta) { | const CKeyMetadata &keyMeta) { | ||||
if (!WriteKeyMetadata(keyMeta, vchPubKey, true)) { | if (!WriteKeyMetadata(keyMeta, vchPubKey, true)) { | ||||
return false; | return false; | ||||
} | } | ||||
// When backporting PR16946, use: | |||||
// uint256 checksum = Hash(vchCryptedSecret); | |||||
majcosta: D9156 | |||||
if (!WriteIC(std::make_pair(DBKeys::CRYPTED_KEY, vchPubKey), | if (!WriteIC(std::make_pair(DBKeys::CRYPTED_KEY, vchPubKey), | ||||
vchCryptedSecret, false)) { | vchCryptedSecret, false)) { | ||||
return false; | return false; | ||||
} | } | ||||
EraseIC(std::make_pair(DBKeys::KEY, vchPubKey)); | EraseIC(std::make_pair(DBKeys::KEY, vchPubKey)); | ||||
return true; | return true; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | bool WalletBatch::WriteDescriptorKey(const uint256 &desc_id, | ||||
// hash pubkey/privkey to accelerate wallet load | // hash pubkey/privkey to accelerate wallet load | ||||
std::vector<uint8_t> key; | std::vector<uint8_t> key; | ||||
key.reserve(pubkey.size() + privkey.size()); | key.reserve(pubkey.size() + privkey.size()); | ||||
key.insert(key.end(), pubkey.begin(), pubkey.end()); | key.insert(key.end(), pubkey.begin(), pubkey.end()); | ||||
key.insert(key.end(), privkey.begin(), privkey.end()); | key.insert(key.end(), privkey.begin(), privkey.end()); | ||||
return WriteIC(std::make_pair(DBKeys::WALLETDESCRIPTORKEY, | return WriteIC(std::make_pair(DBKeys::WALLETDESCRIPTORKEY, | ||||
std::make_pair(desc_id, pubkey)), | std::make_pair(desc_id, pubkey)), | ||||
std::make_pair(privkey, Hash(key.begin(), key.end())), | std::make_pair(privkey, Hash(key)), false); | ||||
false); | |||||
} | } | ||||
bool WalletBatch::WriteCryptedDescriptorKey( | bool WalletBatch::WriteCryptedDescriptorKey( | ||||
const uint256 &desc_id, const CPubKey &pubkey, | const uint256 &desc_id, const CPubKey &pubkey, | ||||
const std::vector<uint8_t> &secret) { | const std::vector<uint8_t> &secret) { | ||||
if (!WriteIC(std::make_pair(DBKeys::WALLETDESCRIPTORCKEY, | if (!WriteIC(std::make_pair(DBKeys::WALLETDESCRIPTORCKEY, | ||||
std::make_pair(desc_id, pubkey)), | std::make_pair(desc_id, pubkey)), | ||||
secret, false)) { | secret, false)) { | ||||
▲ Show 20 Lines • Show All 159 Lines • ▼ Show 20 Lines | try { | ||||
if (!hash.IsNull()) { | if (!hash.IsNull()) { | ||||
// hash pubkey/privkey to accelerate wallet load | // hash pubkey/privkey to accelerate wallet load | ||||
std::vector<uint8_t> vchKey; | std::vector<uint8_t> vchKey; | ||||
vchKey.reserve(vchPubKey.size() + pkey.size()); | vchKey.reserve(vchPubKey.size() + pkey.size()); | ||||
vchKey.insert(vchKey.end(), vchPubKey.begin(), vchPubKey.end()); | vchKey.insert(vchKey.end(), vchPubKey.begin(), vchPubKey.end()); | ||||
vchKey.insert(vchKey.end(), pkey.begin(), pkey.end()); | vchKey.insert(vchKey.end(), pkey.begin(), pkey.end()); | ||||
if (Hash(vchKey.begin(), vchKey.end()) != hash) { | if (Hash(vchKey) != hash) { | ||||
strErr = "Error reading wallet database: CPubKey/CPrivKey " | strErr = "Error reading wallet database: CPubKey/CPrivKey " | ||||
"corrupt"; | "corrupt"; | ||||
return false; | return false; | ||||
} | } | ||||
fSkipCheck = true; | fSkipCheck = true; | ||||
} | } | ||||
Show All 30 Lines | try { | ||||
if (!vchPubKey.IsValid()) { | if (!vchPubKey.IsValid()) { | ||||
strErr = "Error reading wallet database: CPubKey corrupt"; | strErr = "Error reading wallet database: CPubKey corrupt"; | ||||
return false; | return false; | ||||
} | } | ||||
std::vector<uint8_t> vchPrivKey; | std::vector<uint8_t> vchPrivKey; | ||||
ssValue >> vchPrivKey; | ssValue >> vchPrivKey; | ||||
wss.nCKeys++; | wss.nCKeys++; | ||||
// When backporting PR16946, use: | |||||
// if ((checksum_valid = Hash(vchPrivKey) != checksum)) { | |||||
majcostaUnsubmitted Not Done Inline Actionsmajcosta: D9156 | |||||
if (!pwallet->GetOrCreateLegacyScriptPubKeyMan()->LoadCryptedKey( | if (!pwallet->GetOrCreateLegacyScriptPubKeyMan()->LoadCryptedKey( | ||||
vchPubKey, vchPrivKey)) { | vchPubKey, vchPrivKey)) { | ||||
strErr = "Error reading wallet database: " | strErr = "Error reading wallet database: " | ||||
"LegacyScriptPubKeyMan::LoadCryptedKey failed"; | "LegacyScriptPubKeyMan::LoadCryptedKey failed"; | ||||
return false; | return false; | ||||
} | } | ||||
wss.fIsEncrypted = true; | wss.fIsEncrypted = true; | ||||
} else if (strType == DBKeys::KEYMETA) { | } else if (strType == DBKeys::KEYMETA) { | ||||
▲ Show 20 Lines • Show All 140 Lines • ▼ Show 20 Lines | try { | ||||
ssValue >> hash; | ssValue >> hash; | ||||
// hash pubkey/privkey to accelerate wallet load | // hash pubkey/privkey to accelerate wallet load | ||||
std::vector<uint8_t> to_hash; | std::vector<uint8_t> to_hash; | ||||
to_hash.reserve(pubkey.size() + pkey.size()); | to_hash.reserve(pubkey.size() + pkey.size()); | ||||
to_hash.insert(to_hash.end(), pubkey.begin(), pubkey.end()); | to_hash.insert(to_hash.end(), pubkey.begin(), pubkey.end()); | ||||
to_hash.insert(to_hash.end(), pkey.begin(), pkey.end()); | to_hash.insert(to_hash.end(), pkey.begin(), pkey.end()); | ||||
if (Hash(to_hash.begin(), to_hash.end()) != hash) { | if (Hash(to_hash) != hash) { | ||||
strErr = | strErr = | ||||
"Error reading wallet database: CPubKey/CPrivKey corrupt"; | "Error reading wallet database: CPubKey/CPrivKey corrupt"; | ||||
return false; | return false; | ||||
} | } | ||||
if (!key.Load(pkey, pubkey, true)) { | if (!key.Load(pkey, pubkey, true)) { | ||||
strErr = "Error reading wallet database: CPrivKey corrupt"; | strErr = "Error reading wallet database: CPrivKey corrupt"; | ||||
return false; | return false; | ||||
▲ Show 20 Lines • Show All 403 Lines • Show Last 20 Lines |
D9156