| 220 | } |
| 221 | |
| 222 | bool CCryptoKeyStore::Unlock(const CKeyingMaterial& vMasterKeyIn) |
| 223 | { |
| 224 | { |
| 225 | LOCK(cs_KeyStore); |
| 226 | if (!SetCrypted()) |
| 227 | return false; |
| 228 | |
| 229 | bool keyPass = false; |
| 230 | bool keyFail = false; |
| 231 | CryptedKeyMap::const_iterator mi = mapCryptedKeys.begin(); |
| 232 | for (; mi != mapCryptedKeys.end(); ++mi) { |
| 233 | const CPubKey& vchPubKey = (*mi).second.first; |
| 234 | const std::vector<unsigned char>& vchCryptedSecret = (*mi).second.second; |
| 235 | CKeyingMaterial vchSecret; |
| 236 | if (!DecryptSecret(vMasterKeyIn, vchCryptedSecret, vchPubKey.GetHash(), vchSecret)) { |
| 237 | keyFail = true; |
| 238 | break; |
| 239 | } |
| 240 | if (vchSecret.size() != 32) { |
| 241 | keyFail = true; |
| 242 | break; |
| 243 | } |
| 244 | CKey key; |
| 245 | key.Set(vchSecret.begin(), vchSecret.end(), vchPubKey.IsCompressed()); |
| 246 | if (key.GetPubKey() != vchPubKey) { |
| 247 | keyFail = true; |
| 248 | break; |
| 249 | } |
| 250 | keyPass = true; |
| 251 | if (fDecryptionThoroughlyChecked) |
| 252 | break; |
| 253 | } |
| 254 | if (keyPass && keyFail) { |
| 255 | LogPrintf("The wallet is probably corrupted: Some keys decrypt but not all."); |
| 256 | //assert(false); |
| 257 | } |
| 258 | if (keyFail || (!keyPass && cryptedHDChain.IsNull())) |
| 259 | return false; |
| 260 | vMasterKey = vMasterKeyIn; |
| 261 | if(!cryptedHDChain.IsNull()) { |
| 262 | bool chainPass = false; |
| 263 | // try to decrypt seed and make sure it matches |
| 264 | CHDChain hdChainTmp; |
| 265 | if (DecryptHDChain(hdChainTmp)) { |
| 266 | // make sure seed matches this chain |
| 267 | chainPass = cryptedHDChain.GetID() == hdChainTmp.GetSeedHash(); |
| 268 | } |
| 269 | if (!chainPass) { |
| 270 | vMasterKey.clear(); |
| 271 | return false; |
| 272 | } |
| 273 | } |
| 274 | fDecryptionThoroughlyChecked = true; |
| 275 | } |
| 276 | NotifyStatusChanged(this); |
| 277 | return true; |
| 278 | } |
| 279 |
nothing calls this directly
no test coverage detected