| 177 | } |
| 178 | |
| 179 | bool CCryptoKeyStore::AddKeyCombi(const CKeyID& keyId, const CKeyCombi& keyCombi) { |
| 180 | { |
| 181 | LOCK(cs_KeyStore); |
| 182 | |
| 183 | if (!IsEncrypted()) |
| 184 | return CBasicKeyStore::AddKeyCombi(keyId, keyCombi); |
| 185 | |
| 186 | if (IsLocked()) |
| 187 | return false; |
| 188 | |
| 189 | CKey mainKey; |
| 190 | keyCombi.GetCKey(mainKey, false); |
| 191 | CKeyCombi newkeyCombi = keyCombi; |
| 192 | newkeyCombi.PurgeMainKey(); |
| 193 | CBasicKeyStore::AddKeyCombi(keyId, keyCombi); |
| 194 | |
| 195 | vector<unsigned char> vchCryptedSecret; |
| 196 | CKeyingMaterial vchSecret(mainKey.begin(), mainKey.end()); |
| 197 | CPubKey pubKey; |
| 198 | pubKey = mainKey.GetPubKey(); |
| 199 | if (!EncryptSecret(vMasterKey, vchSecret, pubKey.GetHash(), vchCryptedSecret)) |
| 200 | return false; |
| 201 | |
| 202 | if (!AddCryptedKey(pubKey, vchCryptedSecret)) |
| 203 | return false; |
| 204 | } |
| 205 | return true; |
| 206 | } |
| 207 | |
| 208 | bool CCryptoKeyStore::AddCryptedKey(const CPubKey& vchPubKey, const vector<unsigned char>& vchCryptedSecret) { |
| 209 | { |
nothing calls this directly
no test coverage detected