File tree Expand file tree Collapse file tree 2 files changed +29
-5
lines changed
Expand file tree Collapse file tree 2 files changed +29
-5
lines changed Original file line number Diff line number Diff line change @@ -152,23 +152,44 @@ bool CCryptoKeyStore::Unlock(const CKeyingMaterial& vMasterKeyIn)
152152 if (!SetCrypted ())
153153 return false ;
154154
155+ bool keyPass = false ;
156+ bool keyFail = false ;
155157 CryptedKeyMap::const_iterator mi = mapCryptedKeys.begin ();
156158 for (; mi != mapCryptedKeys.end (); ++mi)
157159 {
158160 const CPubKey &vchPubKey = (*mi).second .first ;
159161 const std::vector<unsigned char > &vchCryptedSecret = (*mi).second .second ;
160162 CKeyingMaterial vchSecret;
161163 if (!DecryptSecret (vMasterKeyIn, vchCryptedSecret, vchPubKey.GetHash (), vchSecret))
162- return false ;
164+ {
165+ keyFail = true ;
166+ break ;
167+ }
163168 if (vchSecret.size () != 32 )
164- return false ;
169+ {
170+ keyFail = true ;
171+ break ;
172+ }
165173 CKey key;
166174 key.Set (vchSecret.begin (), vchSecret.end (), vchPubKey.IsCompressed ());
167- if (key.GetPubKey () == vchPubKey)
175+ if (key.GetPubKey () != vchPubKey)
176+ {
177+ keyFail = true ;
168178 break ;
169- return false ;
179+ }
180+ keyPass = true ;
181+ if (fDecryptionThoroughlyChecked )
182+ break ;
183+ }
184+ if (keyPass && keyFail)
185+ {
186+ LogPrintf (" The wallet is probably corrupted: Some keys decrypt but not all." );
187+ assert (false );
170188 }
189+ if (keyFail || !keyPass)
190+ return false ;
171191 vMasterKey = vMasterKeyIn;
192+ fDecryptionThoroughlyChecked = true ;
172193 }
173194 NotifyStatusChanged (this );
174195 return true ;
Original file line number Diff line number Diff line change @@ -121,6 +121,9 @@ class CCryptoKeyStore : public CBasicKeyStore
121121 // if fUseCrypto is false, vMasterKey must be empty
122122 bool fUseCrypto ;
123123
124+ // keeps track of whether Unlock has run a thourough check before
125+ bool fDecryptionThoroughlyChecked ;
126+
124127protected:
125128 bool SetCrypted ();
126129
@@ -130,7 +133,7 @@ class CCryptoKeyStore : public CBasicKeyStore
130133 bool Unlock (const CKeyingMaterial& vMasterKeyIn);
131134
132135public:
133- CCryptoKeyStore () : fUseCrypto (false )
136+ CCryptoKeyStore () : fUseCrypto (false ), fDecryptionThoroughlyChecked ( false )
134137 {
135138 }
136139
You can’t perform that action at this time.
0 commit comments