OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // OpenSSL binding for SSLClientSocket. The class layout and general principle | 5 // OpenSSL binding for SSLClientSocket. The class layout and general principle |
6 // of operation is derived from SSLClientSocketNSS. | 6 // of operation is derived from SSLClientSocketNSS. |
7 | 7 |
8 #include "net/socket/ssl_client_socket_openssl.h" | 8 #include "net/socket/ssl_client_socket_openssl.h" |
9 | 9 |
10 #include <errno.h> | 10 #include <errno.h> |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 }; | 193 }; |
194 | 194 |
195 base::LazyInstance<PlatformKeyTaskRunner>::Leaky g_platform_key_task_runner = | 195 base::LazyInstance<PlatformKeyTaskRunner>::Leaky g_platform_key_task_runner = |
196 LAZY_INSTANCE_INITIALIZER; | 196 LAZY_INSTANCE_INITIALIZER; |
197 #endif | 197 #endif |
198 | 198 |
199 } // namespace | 199 } // namespace |
200 | 200 |
201 class SSLClientSocketOpenSSL::SSLContext { | 201 class SSLClientSocketOpenSSL::SSLContext { |
202 public: | 202 public: |
203 static SSLContext* GetInstance() { return Singleton<SSLContext>::get(); } | 203 static SSLContext* GetInstance() { |
| 204 return base::Singleton<SSLContext>::get(); |
| 205 } |
204 SSL_CTX* ssl_ctx() { return ssl_ctx_.get(); } | 206 SSL_CTX* ssl_ctx() { return ssl_ctx_.get(); } |
205 SSLClientSessionCacheOpenSSL* session_cache() { return &session_cache_; } | 207 SSLClientSessionCacheOpenSSL* session_cache() { return &session_cache_; } |
206 | 208 |
207 SSLClientSocketOpenSSL* GetClientSocketFromSSL(const SSL* ssl) { | 209 SSLClientSocketOpenSSL* GetClientSocketFromSSL(const SSL* ssl) { |
208 DCHECK(ssl); | 210 DCHECK(ssl); |
209 SSLClientSocketOpenSSL* socket = static_cast<SSLClientSocketOpenSSL*>( | 211 SSLClientSocketOpenSSL* socket = static_cast<SSLClientSocketOpenSSL*>( |
210 SSL_get_ex_data(ssl, ssl_socket_data_index_)); | 212 SSL_get_ex_data(ssl, ssl_socket_data_index_)); |
211 DCHECK(socket); | 213 DCHECK(socket); |
212 return socket; | 214 return socket; |
213 } | 215 } |
214 | 216 |
215 bool SetClientSocketForSSL(SSL* ssl, SSLClientSocketOpenSSL* socket) { | 217 bool SetClientSocketForSSL(SSL* ssl, SSLClientSocketOpenSSL* socket) { |
216 return SSL_set_ex_data(ssl, ssl_socket_data_index_, socket) != 0; | 218 return SSL_set_ex_data(ssl, ssl_socket_data_index_, socket) != 0; |
217 } | 219 } |
218 | 220 |
219 static const SSL_PRIVATE_KEY_METHOD kPrivateKeyMethod; | 221 static const SSL_PRIVATE_KEY_METHOD kPrivateKeyMethod; |
220 | 222 |
221 private: | 223 private: |
222 friend struct DefaultSingletonTraits<SSLContext>; | 224 friend struct base::DefaultSingletonTraits<SSLContext>; |
223 | 225 |
224 SSLContext() : session_cache_(SSLClientSessionCacheOpenSSL::Config()) { | 226 SSLContext() : session_cache_(SSLClientSessionCacheOpenSSL::Config()) { |
225 crypto::EnsureOpenSSLInit(); | 227 crypto::EnsureOpenSSLInit(); |
226 ssl_socket_data_index_ = SSL_get_ex_new_index(0, 0, 0, 0, 0); | 228 ssl_socket_data_index_ = SSL_get_ex_new_index(0, 0, 0, 0, 0); |
227 DCHECK_NE(ssl_socket_data_index_, -1); | 229 DCHECK_NE(ssl_socket_data_index_, -1); |
228 ssl_ctx_.reset(SSL_CTX_new(SSLv23_client_method())); | 230 ssl_ctx_.reset(SSL_CTX_new(SSLv23_client_method())); |
229 SSL_CTX_set_cert_verify_callback(ssl_ctx_.get(), CertVerifyCallback, NULL); | 231 SSL_CTX_set_cert_verify_callback(ssl_ctx_.get(), CertVerifyCallback, NULL); |
230 SSL_CTX_set_cert_cb(ssl_ctx_.get(), ClientCertRequestCallback, NULL); | 232 SSL_CTX_set_cert_cb(ssl_ctx_.get(), ClientCertRequestCallback, NULL); |
231 SSL_CTX_set_verify(ssl_ctx_.get(), SSL_VERIFY_PEER, NULL); | 233 SSL_CTX_set_verify(ssl_ctx_.get(), SSL_VERIFY_PEER, NULL); |
232 // This stops |SSL_shutdown| from generating the close_notify message, which | 234 // This stops |SSL_shutdown| from generating the close_notify message, which |
(...skipping 1902 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2135 OnHandshakeIOComplete(signature_result_); | 2137 OnHandshakeIOComplete(signature_result_); |
2136 return; | 2138 return; |
2137 } | 2139 } |
2138 | 2140 |
2139 // During a renegotiation, either Read or Write calls may be blocked on an | 2141 // During a renegotiation, either Read or Write calls may be blocked on an |
2140 // asynchronous private key operation. | 2142 // asynchronous private key operation. |
2141 PumpReadWriteEvents(); | 2143 PumpReadWriteEvents(); |
2142 } | 2144 } |
2143 | 2145 |
2144 } // namespace net | 2146 } // namespace net |
OLD | NEW |