bool CAccount::EncryptKeys(const CKeyingMaterial& vMasterKeyIn) { if (!externalKeyStore.EncryptKeys(vMasterKeyIn)) return false; if (!internalKeyStore.EncryptKeys(vMasterKeyIn)) return false; if (pactiveWallet) { { std::set<CKeyID> setAddress; GetKeys(setAddress); LOCK(pactiveWallet->cs_wallet); for (const auto& keyID : setAddress) { CPubKey pubKey; if (!GetPubKey(keyID, pubKey)) { LogPrintf("CAccount::EncryptKeys(): Failed to get pubkey\n"); return false; } if (pactiveWallet->pwalletdbEncryption) pactiveWallet->pwalletdbEncryption->EraseKey(pubKey); else CWalletDB(*pactiveWallet->dbw).EraseKey(pubKey); std::vector<unsigned char> secret; if (!GetKey(keyID, secret)) { LogPrintf("CAccount::EncryptKeys(): Failed to get crypted key\n"); return false; } if (pactiveWallet->pwalletdbEncryption) { if (!pactiveWallet->pwalletdbEncryption->WriteCryptedKey(pubKey, secret, pactiveWallet->mapKeyMetadata[keyID], getUUIDAsString(getUUID()), KEYCHAIN_EXTERNAL)) { LogPrintf("CAccount::EncryptKeys(): Failed to write key\n"); return false; } } else { if (!CWalletDB(*pactiveWallet->dbw).WriteCryptedKey(pubKey, secret, pactiveWallet->mapKeyMetadata[keyID], getUUIDAsString(getUUID()), KEYCHAIN_EXTERNAL)) { LogPrintf("CAccount::EncryptKeys(): Failed to write key\n"); return false; } } } } } return true; }
bool CAccount::AddCryptedKey(const CPubKey& vchPubKey, const std::vector<unsigned char>& vchCryptedSecret, int64_t nKeyChain) { assert(!IsHD()); if (nKeyChain == KEYCHAIN_EXTERNAL) { if (!externalKeyStore.AddCryptedKey(vchPubKey, vchCryptedSecret)) return false; } else { if (!internalKeyStore.AddCryptedKey(vchPubKey, vchCryptedSecret)) return false; } if (pwalletMain) { if (!pwalletMain->fFileBacked) return true; { LOCK(pwalletMain->cs_wallet); if (pwalletMain->pwalletdbEncryption) return pwalletMain->pwalletdbEncryption->WriteCryptedKey(vchPubKey, vchCryptedSecret, pwalletMain->mapKeyMetadata[vchPubKey.GetID()], getUUID(), nKeyChain); else return CWalletDB(pwalletMain->strWalletFile).WriteCryptedKey(vchPubKey, vchCryptedSecret, pwalletMain->mapKeyMetadata[vchPubKey.GetID()], getUUID(), nKeyChain); } } else { return true; } return false; }
bool CAccount::AddCryptedKeyWithChain(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret, int64_t nKeyChain) { //fixme: (Post-2.1) This is essentially dead code now - it has been replaced at the bottom of CWallet::AddKeyPubKey //For technical reasons (wallet upgrade) //This should never be called on a non-HD wallet assert(!IsHD()); if (nKeyChain == KEYCHAIN_EXTERNAL) { if (!externalKeyStore.AddCryptedKey(vchPubKey, vchCryptedSecret)) return false; } else { if (!internalKeyStore.AddCryptedKey(vchPubKey, vchCryptedSecret)) return false; } // If we don't have a wallet yet (busy during wallet upgrade) - then the below not being called is fine as the wallet does a 'force resave' of all keys at the end of the upgrade. if (pactiveWallet) { { LOCK(pactiveWallet->cs_wallet); if (pactiveWallet->pwalletdbEncryption) return pactiveWallet->pwalletdbEncryption->WriteCryptedKey(vchPubKey, vchCryptedSecret, pactiveWallet->mapKeyMetadata[vchPubKey.GetID()], getUUIDAsString(getUUID()), nKeyChain); else return CWalletDB(*pactiveWallet->dbw).WriteCryptedKey(vchPubKey, vchCryptedSecret, pactiveWallet->mapKeyMetadata[vchPubKey.GetID()], getUUIDAsString(getUUID()), nKeyChain); } } else { return true; } return false; }