Chromium Code Reviews| Index: net/ssl/openssl_client_key_store.cc |
| diff --git a/net/ssl/openssl_client_key_store.cc b/net/ssl/openssl_client_key_store.cc |
| index ef38da6e12770ebc186d8488073b212923906d9e..67f2de9041d29eb8f5097a4a43cb2b1af8ea262a 100644 |
| --- a/net/ssl/openssl_client_key_store.cc |
| +++ b/net/ssl/openssl_client_key_store.cc |
| @@ -15,17 +15,6 @@ namespace net { |
| namespace { |
| -// Increment the reference count of a given EVP_PKEY. This function |
| -// is similar to EVP_PKEY_dup which is not available from the OpenSSL |
| -// version used by Chromium at the moment. Its name is distinct to |
| -// avoid compiler warnings about ambiguous function calls at caller |
| -// sites. |
| -EVP_PKEY* CopyEVP_PKEY(EVP_PKEY* key) { |
| - if (key) |
| - CRYPTO_add(&key->references, 1, CRYPTO_LOCK_EVP_PKEY); |
| - return key; |
| -} |
| - |
| // Return the EVP_PKEY holding the public key of a given certificate. |
| // |cert| is a certificate. |
| // Returns a scoped EVP_PKEY for it. |
| @@ -48,35 +37,29 @@ OpenSSLClientKeyStore::~OpenSSLClientKeyStore() { |
| } |
| OpenSSLClientKeyStore::KeyPair::KeyPair(EVP_PKEY* pub_key, |
| - EVP_PKEY* priv_key) { |
| - public_key = CopyEVP_PKEY(pub_key); |
| - private_key = CopyEVP_PKEY(priv_key); |
| + EVP_PKEY* priv_key) |
| + : public_key(EVP_PKEY_dup(pub_key)), |
| + private_key(EVP_PKEY_dup(priv_key)) { |
| } |
| OpenSSLClientKeyStore::KeyPair::~KeyPair() { |
| - EVP_PKEY_free(public_key); |
| - EVP_PKEY_free(private_key); |
| } |
| -OpenSSLClientKeyStore::KeyPair::KeyPair(const KeyPair& other) { |
| - public_key = CopyEVP_PKEY(other.public_key); |
| - private_key = CopyEVP_PKEY(other.private_key); |
| +OpenSSLClientKeyStore::KeyPair::KeyPair(const KeyPair& other) |
| + : public_key(EVP_PKEY_dup(other.public_key.get())), |
| + private_key(EVP_PKEY_dup(other.private_key.get())) { |
| } |
| void OpenSSLClientKeyStore::KeyPair::operator=(const KeyPair& other) { |
| - EVP_PKEY* old_public_key = public_key; |
| - EVP_PKEY* old_private_key = private_key; |
| - public_key = CopyEVP_PKEY(other.public_key); |
| - private_key = CopyEVP_PKEY(other.private_key); |
| - EVP_PKEY_free(old_private_key); |
| - EVP_PKEY_free(old_public_key); |
| + public_key.reset(EVP_PKEY_dup(other.public_key.get())); |
| + private_key.reset(EVP_PKEY_dup(other.private_key.get())); |
|
Ryan Sleevi
2014/08/13 22:49:38
Are you sure this is safe w/r/t the scoped_ptr iss
davidben
2014/08/13 23:41:39
Mrrrf. That's obnoxious. I guess whether it's fine
|
| } |
| int OpenSSLClientKeyStore::FindKeyPairIndex(EVP_PKEY* public_key) { |
| if (!public_key) |
| return -1; |
| for (size_t n = 0; n < pairs_.size(); ++n) { |
| - if (EVP_PKEY_cmp(pairs_[n].public_key, public_key) == 1) |
| + if (EVP_PKEY_cmp(pairs_[n].public_key.get(), public_key) == 1) |
| return static_cast<int>(n); |
| } |
| return -1; |
| @@ -120,7 +103,7 @@ crypto::ScopedEVP_PKEY OpenSSLClientKeyStore::FetchClientCertPrivateKey( |
| if (index < 0) |
| return crypto::ScopedEVP_PKEY(); |
| - return crypto::ScopedEVP_PKEY(CopyEVP_PKEY(pairs_[index].private_key)); |
| + return crypto::ScopedEVP_PKEY(EVP_PKEY_dup(pairs_[index].private_key.get())); |
| } |
| void OpenSSLClientKeyStore::Flush() { |