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 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 19 matching lines...) Expand all Loading... |
30 } | 30 } |
31 | 31 |
32 } // namespace | 32 } // namespace |
33 | 33 |
34 OpenSSLClientKeyStore::OpenSSLClientKeyStore() { | 34 OpenSSLClientKeyStore::OpenSSLClientKeyStore() { |
35 } | 35 } |
36 | 36 |
37 OpenSSLClientKeyStore::~OpenSSLClientKeyStore() { | 37 OpenSSLClientKeyStore::~OpenSSLClientKeyStore() { |
38 } | 38 } |
39 | 39 |
40 OpenSSLClientKeyStore::KeyPair::KeyPair(EVP_PKEY* pub_key, | 40 OpenSSLClientKeyStore::KeyPair::KeyPair(EVP_PKEY* pub_key, EVP_PKEY* priv_key) |
41 EVP_PKEY* priv_key) | 41 : public_key(EVP_PKEY_up_ref(pub_key)), |
42 : public_key(EVP_PKEY_dup(pub_key)), | 42 private_key(EVP_PKEY_up_ref(priv_key)) { |
43 private_key(EVP_PKEY_dup(priv_key)) { | |
44 } | 43 } |
45 | 44 |
46 OpenSSLClientKeyStore::KeyPair::~KeyPair() { | 45 OpenSSLClientKeyStore::KeyPair::~KeyPair() { |
47 } | 46 } |
48 | 47 |
49 OpenSSLClientKeyStore::KeyPair::KeyPair(const KeyPair& other) | 48 OpenSSLClientKeyStore::KeyPair::KeyPair(const KeyPair& other) |
50 : public_key(EVP_PKEY_dup(other.public_key.get())), | 49 : public_key(EVP_PKEY_up_ref(other.public_key.get())), |
51 private_key(EVP_PKEY_dup(other.private_key.get())) { | 50 private_key(EVP_PKEY_up_ref(other.private_key.get())) { |
52 } | 51 } |
53 | 52 |
54 void OpenSSLClientKeyStore::KeyPair::operator=(KeyPair other) { | 53 void OpenSSLClientKeyStore::KeyPair::operator=(KeyPair other) { |
55 swap(other); | 54 swap(other); |
56 } | 55 } |
57 | 56 |
58 void OpenSSLClientKeyStore::KeyPair::swap(KeyPair& other) { | 57 void OpenSSLClientKeyStore::KeyPair::swap(KeyPair& other) { |
59 using std::swap; | 58 using std::swap; |
60 swap(public_key, other.public_key); | 59 swap(public_key, other.public_key); |
61 swap(private_key, other.private_key); | 60 swap(private_key, other.private_key); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 return crypto::ScopedEVP_PKEY(); | 101 return crypto::ScopedEVP_PKEY(); |
103 | 102 |
104 crypto::ScopedEVP_PKEY pub_key(GetOpenSSLPublicKey(client_cert)); | 103 crypto::ScopedEVP_PKEY pub_key(GetOpenSSLPublicKey(client_cert)); |
105 if (!pub_key.get()) | 104 if (!pub_key.get()) |
106 return crypto::ScopedEVP_PKEY(); | 105 return crypto::ScopedEVP_PKEY(); |
107 | 106 |
108 int index = FindKeyPairIndex(pub_key.get()); | 107 int index = FindKeyPairIndex(pub_key.get()); |
109 if (index < 0) | 108 if (index < 0) |
110 return crypto::ScopedEVP_PKEY(); | 109 return crypto::ScopedEVP_PKEY(); |
111 | 110 |
112 return crypto::ScopedEVP_PKEY(EVP_PKEY_dup(pairs_[index].private_key.get())); | 111 return crypto::ScopedEVP_PKEY( |
| 112 EVP_PKEY_up_ref(pairs_[index].private_key.get())); |
113 } | 113 } |
114 | 114 |
115 void OpenSSLClientKeyStore::Flush() { | 115 void OpenSSLClientKeyStore::Flush() { |
116 pairs_.clear(); | 116 pairs_.clear(); |
117 } | 117 } |
118 | 118 |
119 OpenSSLClientKeyStore* OpenSSLClientKeyStore::GetInstance() { | 119 OpenSSLClientKeyStore* OpenSSLClientKeyStore::GetInstance() { |
120 return Singleton<OpenSSLClientKeyStore>::get(); | 120 return Singleton<OpenSSLClientKeyStore>::get(); |
121 } | 121 } |
122 | 122 |
123 } // namespace net | 123 } // namespace net |
124 | 124 |
125 | 125 |
OLD | NEW |