Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <util/fs_helpers.h>
#include <util/moneystr.h>
#include <util/string.h>
#include <util/strencodings.h>
#include <util/time.h>
#include <util/translation.h>
#ifdef USE_BDB
Expand Down Expand Up @@ -4187,20 +4188,22 @@ bool CWallet::Lock(bool fAllowMixing)

bool CWallet::Unlock(const SecureString& strWalletPassphrase, bool fForMixingOnly)
{
if (!IsLocked()) // was already fully unlocked, not only for mixing
return true;

CCrypter crypter;
CKeyingMaterial _vMasterKey;

{
LOCK(cs_wallet);
if (!IsCrypted()) return true;
for (const MasterKeyMap::value_type& pMasterKey : mapMasterKeys)
{
if (!crypter.SetKeyFromPassphrase(strWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod))
return false;
if (!crypter.Decrypt(pMasterKey.second.vchCryptedKey, _vMasterKey))
continue; // try another master key
if (!vMasterKey.empty() && !TimingResistantEqual(_vMasterKey, vMasterKey)) {
continue;
}
if (!IsLocked()) return true;
if (Unlock(_vMasterKey, fForMixingOnly)) {
// Now that we've unlocked, upgrade the key metadata
UpgradeKeyMetadata();
Expand Down
7 changes: 7 additions & 0 deletions test/functional/wallet_encryption.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ def run_test(self):
assert self.nodes[0].verifymessage(address, sig, msg)
self.nodes[0].walletlock()

self.log.info("Check that a wrong passphrase cannot extend a full unlock")
self.nodes[0].walletpassphrase(passphrase_with_nulls, 100)
unlocked_until = self.nodes[0].getwalletinfo()['unlocked_until']
assert_raises_rpc_error(-14, "wallet passphrase entered", self.nodes[0].walletpassphrase, "incorrect passphrase", 1000)
assert_equal(self.nodes[0].getwalletinfo()['unlocked_until'], unlocked_until)
self.nodes[0].walletlock()


if __name__ == '__main__':
WalletEncryptionTest().main()
Loading