|
|
@ -280,7 +280,7 @@ bool CWallet::LoadWatchOnly(const CScript &dest) |
|
|
|
bool CWallet::Unlock(const SecureString& strWalletPassphrase) |
|
|
|
bool CWallet::Unlock(const SecureString& strWalletPassphrase) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CCrypter crypter; |
|
|
|
CCrypter crypter; |
|
|
|
CKeyingMaterial vMasterKey; |
|
|
|
CKeyingMaterial _vMasterKey; |
|
|
|
|
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
LOCK(cs_wallet); |
|
|
|
LOCK(cs_wallet); |
|
|
@ -288,9 +288,9 @@ bool CWallet::Unlock(const SecureString& strWalletPassphrase) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if(!crypter.SetKeyFromPassphrase(strWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod)) |
|
|
|
if(!crypter.SetKeyFromPassphrase(strWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod)) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
if (!crypter.Decrypt(pMasterKey.second.vchCryptedKey, vMasterKey)) |
|
|
|
if (!crypter.Decrypt(pMasterKey.second.vchCryptedKey, _vMasterKey)) |
|
|
|
continue; // try another master key
|
|
|
|
continue; // try another master key
|
|
|
|
if (CCryptoKeyStore::Unlock(vMasterKey)) |
|
|
|
if (CCryptoKeyStore::Unlock(_vMasterKey)) |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -306,14 +306,14 @@ bool CWallet::ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase, |
|
|
|
Lock(); |
|
|
|
Lock(); |
|
|
|
|
|
|
|
|
|
|
|
CCrypter crypter; |
|
|
|
CCrypter crypter; |
|
|
|
CKeyingMaterial vMasterKey; |
|
|
|
CKeyingMaterial _vMasterKey; |
|
|
|
BOOST_FOREACH(MasterKeyMap::value_type& pMasterKey, mapMasterKeys) |
|
|
|
BOOST_FOREACH(MasterKeyMap::value_type& pMasterKey, mapMasterKeys) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if(!crypter.SetKeyFromPassphrase(strOldWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod)) |
|
|
|
if(!crypter.SetKeyFromPassphrase(strOldWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod)) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
if (!crypter.Decrypt(pMasterKey.second.vchCryptedKey, vMasterKey)) |
|
|
|
if (!crypter.Decrypt(pMasterKey.second.vchCryptedKey, _vMasterKey)) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
if (CCryptoKeyStore::Unlock(vMasterKey)) |
|
|
|
if (CCryptoKeyStore::Unlock(_vMasterKey)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int64_t nStartTime = GetTimeMillis(); |
|
|
|
int64_t nStartTime = GetTimeMillis(); |
|
|
|
crypter.SetKeyFromPassphrase(strNewWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod); |
|
|
|
crypter.SetKeyFromPassphrase(strNewWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod); |
|
|
@ -330,7 +330,7 @@ bool CWallet::ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase, |
|
|
|
|
|
|
|
|
|
|
|
if (!crypter.SetKeyFromPassphrase(strNewWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod)) |
|
|
|
if (!crypter.SetKeyFromPassphrase(strNewWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod)) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
if (!crypter.Encrypt(vMasterKey, pMasterKey.second.vchCryptedKey)) |
|
|
|
if (!crypter.Encrypt(_vMasterKey, pMasterKey.second.vchCryptedKey)) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
CWalletDB(strWalletFile).WriteMasterKey(pMasterKey.first, pMasterKey.second); |
|
|
|
CWalletDB(strWalletFile).WriteMasterKey(pMasterKey.first, pMasterKey.second); |
|
|
|
if (fWasLocked) |
|
|
|
if (fWasLocked) |
|
|
@ -561,10 +561,10 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase) |
|
|
|
if (IsCrypted()) |
|
|
|
if (IsCrypted()) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
CKeyingMaterial vMasterKey; |
|
|
|
CKeyingMaterial _vMasterKey; |
|
|
|
|
|
|
|
|
|
|
|
vMasterKey.resize(WALLET_CRYPTO_KEY_SIZE); |
|
|
|
_vMasterKey.resize(WALLET_CRYPTO_KEY_SIZE); |
|
|
|
GetStrongRandBytes(&vMasterKey[0], WALLET_CRYPTO_KEY_SIZE); |
|
|
|
GetStrongRandBytes(&_vMasterKey[0], WALLET_CRYPTO_KEY_SIZE); |
|
|
|
|
|
|
|
|
|
|
|
CMasterKey kMasterKey; |
|
|
|
CMasterKey kMasterKey; |
|
|
|
|
|
|
|
|
|
|
@ -587,7 +587,7 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase) |
|
|
|
|
|
|
|
|
|
|
|
if (!crypter.SetKeyFromPassphrase(strWalletPassphrase, kMasterKey.vchSalt, kMasterKey.nDeriveIterations, kMasterKey.nDerivationMethod)) |
|
|
|
if (!crypter.SetKeyFromPassphrase(strWalletPassphrase, kMasterKey.vchSalt, kMasterKey.nDeriveIterations, kMasterKey.nDerivationMethod)) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
if (!crypter.Encrypt(vMasterKey, kMasterKey.vchCryptedKey)) |
|
|
|
if (!crypter.Encrypt(_vMasterKey, kMasterKey.vchCryptedKey)) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
@ -605,7 +605,7 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase) |
|
|
|
pwalletdbEncryption->WriteMasterKey(nMasterKeyMaxID, kMasterKey); |
|
|
|
pwalletdbEncryption->WriteMasterKey(nMasterKeyMaxID, kMasterKey); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!EncryptKeys(vMasterKey)) |
|
|
|
if (!EncryptKeys(_vMasterKey)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (fFileBacked) { |
|
|
|
if (fFileBacked) { |
|
|
|
pwalletdbEncryption->TxnAbort(); |
|
|
|
pwalletdbEncryption->TxnAbort(); |
|
|
|