This source file includes following definitions.
- GetInstance
- StoreKeyPair
- HasPrivateKey
- StoreKeyPair
- HasPrivateKey
#include "net/base/openssl_private_key_store.h"
#include <openssl/evp.h>
#include "base/logging.h"
#include "base/memory/singleton.h"
#include "base/synchronization/lock.h"
namespace net {
namespace {
class MemoryKeyPairStore {
public:
MemoryKeyPairStore() {}
static MemoryKeyPairStore* GetInstance() {
return Singleton<MemoryKeyPairStore>::get();
}
~MemoryKeyPairStore() {
base::AutoLock lock(lock_);
for (std::vector<EVP_PKEY*>::iterator it = keys_.begin();
it != keys_.end(); ++it) {
EVP_PKEY_free(*it);
}
}
bool StoreKeyPair(EVP_PKEY* pkey) {
CRYPTO_add(&pkey->references, 1, CRYPTO_LOCK_EVP_PKEY);
base::AutoLock lock(lock_);
keys_.push_back(pkey);
return true;
}
bool HasPrivateKey(EVP_PKEY* pkey) {
base::AutoLock lock(lock_);
for (std::vector<EVP_PKEY*>::iterator it = keys_.begin();
it != keys_.end(); ++it) {
if (EVP_PKEY_cmp(*it, pkey) == 1)
return true;
}
return false;
}
private:
std::vector<EVP_PKEY*> keys_;
base::Lock lock_;
DISALLOW_COPY_AND_ASSIGN(MemoryKeyPairStore);
};
}
bool OpenSSLPrivateKeyStore::StoreKeyPair(const GURL& url,
EVP_PKEY* pkey) {
return MemoryKeyPairStore::GetInstance()->StoreKeyPair(pkey);
}
bool OpenSSLPrivateKeyStore::HasPrivateKey(EVP_PKEY* pub_key) {
return MemoryKeyPairStore::GetInstance()->HasPrivateKey(pub_key);
}
}