Browse Source
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)
pull/4/head
Wladimir J. van der Laan
10 years ago
No known key found for this signature in database
GPG Key ID: 74810B012346C9A6
2 changed files with
29 additions and
5 deletions
-
src/crypter.cpp
-
src/crypter.h
|
|
@ -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; |
|
|
|
|
|
@ -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) |
|
|
|
{ |
|
|
|
} |
|
|
|
|
|
|
|