| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/ssl/openssl_client_key_store.h" | 5 #include "net/ssl/openssl_client_key_store.h" |
| 6 | 6 |
| 7 #include <openssl/evp.h> | 7 #include <openssl/evp.h> |
| 8 #include <openssl/x509.h> | 8 #include <openssl/x509.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 } // namespace | 33 } // namespace |
| 34 | 34 |
| 35 OpenSSLClientKeyStore::OpenSSLClientKeyStore() { | 35 OpenSSLClientKeyStore::OpenSSLClientKeyStore() { |
| 36 } | 36 } |
| 37 | 37 |
| 38 OpenSSLClientKeyStore::~OpenSSLClientKeyStore() { | 38 OpenSSLClientKeyStore::~OpenSSLClientKeyStore() { |
| 39 } | 39 } |
| 40 | 40 |
| 41 OpenSSLClientKeyStore::KeyPair::KeyPair(EVP_PKEY* pub_key, EVP_PKEY* priv_key) | 41 OpenSSLClientKeyStore::KeyPair::KeyPair(EVP_PKEY* pub_key, EVP_PKEY* priv_key) |
| 42 : public_key(EVP_PKEY_up_ref(pub_key)), | 42 : public_key(pub_key), private_key(priv_key) { |
| 43 private_key(EVP_PKEY_up_ref(priv_key)) { | 43 EVP_PKEY_up_ref(pub_key); |
| 44 EVP_PKEY_up_ref(priv_key); |
| 44 } | 45 } |
| 45 | 46 |
| 46 OpenSSLClientKeyStore::KeyPair::~KeyPair() { | 47 OpenSSLClientKeyStore::KeyPair::~KeyPair() { |
| 47 } | 48 } |
| 48 | 49 |
| 49 OpenSSLClientKeyStore::KeyPair::KeyPair(const KeyPair& other) | 50 OpenSSLClientKeyStore::KeyPair::KeyPair(const KeyPair& other) |
| 50 : public_key(EVP_PKEY_up_ref(other.public_key.get())), | 51 : public_key(other.public_key.get()), private_key(other.private_key.get()) { |
| 51 private_key(EVP_PKEY_up_ref(other.private_key.get())) { | 52 EVP_PKEY_up_ref(public_key.get()); |
| 53 EVP_PKEY_up_ref(private_key.get()); |
| 52 } | 54 } |
| 53 | 55 |
| 54 void OpenSSLClientKeyStore::KeyPair::operator=(KeyPair other) { | 56 void OpenSSLClientKeyStore::KeyPair::operator=(KeyPair other) { |
| 55 swap(other); | 57 swap(other); |
| 56 } | 58 } |
| 57 | 59 |
| 58 void OpenSSLClientKeyStore::KeyPair::swap(KeyPair& other) { | 60 void OpenSSLClientKeyStore::KeyPair::swap(KeyPair& other) { |
| 59 using std::swap; | 61 using std::swap; |
| 60 swap(public_key, other.public_key); | 62 swap(public_key, other.public_key); |
| 61 swap(private_key, other.private_key); | 63 swap(private_key, other.private_key); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 return crypto::ScopedEVP_PKEY(); | 104 return crypto::ScopedEVP_PKEY(); |
| 103 | 105 |
| 104 crypto::ScopedEVP_PKEY pub_key(GetOpenSSLPublicKey(client_cert)); | 106 crypto::ScopedEVP_PKEY pub_key(GetOpenSSLPublicKey(client_cert)); |
| 105 if (!pub_key.get()) | 107 if (!pub_key.get()) |
| 106 return crypto::ScopedEVP_PKEY(); | 108 return crypto::ScopedEVP_PKEY(); |
| 107 | 109 |
| 108 int index = FindKeyPairIndex(pub_key.get()); | 110 int index = FindKeyPairIndex(pub_key.get()); |
| 109 if (index < 0) | 111 if (index < 0) |
| 110 return crypto::ScopedEVP_PKEY(); | 112 return crypto::ScopedEVP_PKEY(); |
| 111 | 113 |
| 112 return crypto::ScopedEVP_PKEY( | 114 EVP_PKEY_up_ref(pairs_[index].private_key.get()); |
| 113 EVP_PKEY_up_ref(pairs_[index].private_key.get())); | 115 return crypto::ScopedEVP_PKEY(pairs_[index].private_key.get()); |
| 114 } | 116 } |
| 115 | 117 |
| 116 void OpenSSLClientKeyStore::Flush() { | 118 void OpenSSLClientKeyStore::Flush() { |
| 117 pairs_.clear(); | 119 pairs_.clear(); |
| 118 } | 120 } |
| 119 | 121 |
| 120 OpenSSLClientKeyStore* OpenSSLClientKeyStore::GetInstance() { | 122 OpenSSLClientKeyStore* OpenSSLClientKeyStore::GetInstance() { |
| 121 return base::Singleton<OpenSSLClientKeyStore>::get(); | 123 return base::Singleton<OpenSSLClientKeyStore>::get(); |
| 122 } | 124 } |
| 123 | 125 |
| 124 } // namespace net | 126 } // namespace net |
| 125 | 127 |
| 126 | 128 |
| OLD | NEW |