Skip to content

Commit

Permalink
Make CCryptoKeyStore::Unlock check all keys.
Browse files Browse the repository at this point in the history
CCryptoKeyStore::Unlock has a loop to attempt decrypting each key which
 only executes once, likely due to a simple mistake when the code was
 originally written.

This patch fixes the behavior by making it check all keys. It also adds
 a fatal assertion in the case some decrypt but some do not, since that
 indicates that the wallet is in some kind of really bad state.

This may make unlocking noticeably slower on wallets with many keys.
  • Loading branch information
gmaxwell authored and TheBlueMatt committed Aug 11, 2014
1 parent 36065cc commit 1e21c17
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/crypter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,22 +152,40 @@ 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)
{
const CPubKey &vchPubKey = (*mi).second.first;
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 (keyPass && keyFail)
{
LogPrintf("The wallet is probably corrupted: Some keys decrypt but not all.");
assert(false);
}
if (keyFail || !keyPass)
return false;
vMasterKey = vMasterKeyIn;
}
NotifyStatusChanged(this);
Expand Down

0 comments on commit 1e21c17

Please sign in to comment.