aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2014-08-19 12:23:28 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2014-08-19 12:23:56 +0200
commitdd2819701a1a4481ae06b24924b75d55b9feb115 (patch)
tree84c6ae39d6e2d6e426c7115c70a0ee9dfdc8839f /src
parentc5a91216ae7807430e388d946b22b066c09759b6 (diff)
parenta35b55b522da8eeaed895f0ed43ba595fc083498 (diff)
Merge pull request #4670
a35b55b Dont run full check every time we decrypt wallet. (Matt Corallo) 1e21c17 Make CCryptoKeyStore::Unlock check all keys. (Gregory Maxwell)
Diffstat (limited to 'src')
-rw-r--r--src/crypter.cpp29
-rw-r--r--src/crypter.h5
2 files changed, 29 insertions, 5 deletions
diff --git a/src/crypter.cpp b/src/crypter.cpp
index 4c43e3a798..122e06d97e 100644
--- a/src/crypter.cpp
+++ b/src/crypter.cpp
@@ -152,6 +152,8 @@ bool CCryptoKeyStore::Unlock(const CKeyingMaterial& vMasterKeyIn)
if (!SetCrypted())
return false;
+ bool keyPass = false;
+ bool keyFail = false;
CryptedKeyMap::const_iterator mi = mapCryptedKeys.begin();
for (; mi != mapCryptedKeys.end(); ++mi)
{
@@ -159,16 +161,35 @@ bool CCryptoKeyStore::Unlock(const CKeyingMaterial& vMasterKeyIn)
const std::vector<unsigned char> &vchCryptedSecret = (*mi).second.second;
CKeyingMaterial vchSecret;
if(!DecryptSecret(vMasterKeyIn, vchCryptedSecret, vchPubKey.GetHash(), vchSecret))
- return false;
+ {
+ keyFail = true;
+ break;
+ }
if (vchSecret.size() != 32)
- return false;
+ {
+ keyFail = true;
+ break;
+ }
CKey key;
key.Set(vchSecret.begin(), vchSecret.end(), vchPubKey.IsCompressed());
- if (key.GetPubKey() == vchPubKey)
+ if (key.GetPubKey() != vchPubKey)
+ {
+ keyFail = true;
break;
- return false;
+ }
+ keyPass = true;
+ if (fDecryptionThoroughlyChecked)
+ break;
+ }
+ if (keyPass && keyFail)
+ {
+ LogPrintf("The wallet is probably corrupted: Some keys decrypt but not all.");
+ assert(false);
}
+ if (keyFail || !keyPass)
+ return false;
vMasterKey = vMasterKeyIn;
+ fDecryptionThoroughlyChecked = true;
}
NotifyStatusChanged(this);
return true;
diff --git a/src/crypter.h b/src/crypter.h
index 4791428b48..f16fcef9c7 100644
--- a/src/crypter.h
+++ b/src/crypter.h
@@ -121,6 +121,9 @@ private:
// if fUseCrypto is false, vMasterKey must be empty
bool fUseCrypto;
+ // keeps track of whether Unlock has run a thourough check before
+ bool fDecryptionThoroughlyChecked;
+
protected:
bool SetCrypted();
@@ -130,7 +133,7 @@ protected:
bool Unlock(const CKeyingMaterial& vMasterKeyIn);
public:
- CCryptoKeyStore() : fUseCrypto(false)
+ CCryptoKeyStore() : fUseCrypto(false), fDecryptionThoroughlyChecked(false)
{
}