Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(192)

Side by Side Diff: net/socket/ssl_client_socket_openssl.cc

Issue 1308823002: Move Singleton and related structs to namespace base (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: git cl format Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 }; 195 };
196 196
197 base::LazyInstance<PlatformKeyTaskRunner>::Leaky g_platform_key_task_runner = 197 base::LazyInstance<PlatformKeyTaskRunner>::Leaky g_platform_key_task_runner =
198 LAZY_INSTANCE_INITIALIZER; 198 LAZY_INSTANCE_INITIALIZER;
199 #endif // !USE_OPENSSL_CERTS 199 #endif // !USE_OPENSSL_CERTS
200 200
201 } // namespace 201 } // namespace
202 202
203 class SSLClientSocketOpenSSL::SSLContext { 203 class SSLClientSocketOpenSSL::SSLContext {
204 public: 204 public:
205 static SSLContext* GetInstance() { return Singleton<SSLContext>::get(); } 205 static SSLContext* GetInstance() {
206 return base::Singleton<SSLContext>::get();
207 }
206 SSL_CTX* ssl_ctx() { return ssl_ctx_.get(); } 208 SSL_CTX* ssl_ctx() { return ssl_ctx_.get(); }
207 SSLClientSessionCacheOpenSSL* session_cache() { return &session_cache_; } 209 SSLClientSessionCacheOpenSSL* session_cache() { return &session_cache_; }
208 210
209 SSLClientSocketOpenSSL* GetClientSocketFromSSL(const SSL* ssl) { 211 SSLClientSocketOpenSSL* GetClientSocketFromSSL(const SSL* ssl) {
210 DCHECK(ssl); 212 DCHECK(ssl);
211 SSLClientSocketOpenSSL* socket = static_cast<SSLClientSocketOpenSSL*>( 213 SSLClientSocketOpenSSL* socket = static_cast<SSLClientSocketOpenSSL*>(
212 SSL_get_ex_data(ssl, ssl_socket_data_index_)); 214 SSL_get_ex_data(ssl, ssl_socket_data_index_));
213 DCHECK(socket); 215 DCHECK(socket);
214 return socket; 216 return socket;
215 } 217 }
216 218
217 bool SetClientSocketForSSL(SSL* ssl, SSLClientSocketOpenSSL* socket) { 219 bool SetClientSocketForSSL(SSL* ssl, SSLClientSocketOpenSSL* socket) {
218 return SSL_set_ex_data(ssl, ssl_socket_data_index_, socket) != 0; 220 return SSL_set_ex_data(ssl, ssl_socket_data_index_, socket) != 0;
219 } 221 }
220 222
221 static const SSL_PRIVATE_KEY_METHOD kPrivateKeyMethod; 223 static const SSL_PRIVATE_KEY_METHOD kPrivateKeyMethod;
222 224
223 private: 225 private:
224 friend struct DefaultSingletonTraits<SSLContext>; 226 friend struct base::DefaultSingletonTraits<SSLContext>;
225 227
226 SSLContext() : session_cache_(SSLClientSessionCacheOpenSSL::Config()) { 228 SSLContext() : session_cache_(SSLClientSessionCacheOpenSSL::Config()) {
227 crypto::EnsureOpenSSLInit(); 229 crypto::EnsureOpenSSLInit();
228 ssl_socket_data_index_ = SSL_get_ex_new_index(0, 0, 0, 0, 0); 230 ssl_socket_data_index_ = SSL_get_ex_new_index(0, 0, 0, 0, 0);
229 DCHECK_NE(ssl_socket_data_index_, -1); 231 DCHECK_NE(ssl_socket_data_index_, -1);
230 ssl_ctx_.reset(SSL_CTX_new(SSLv23_client_method())); 232 ssl_ctx_.reset(SSL_CTX_new(SSLv23_client_method()));
231 SSL_CTX_set_cert_verify_callback(ssl_ctx_.get(), CertVerifyCallback, NULL); 233 SSL_CTX_set_cert_verify_callback(ssl_ctx_.get(), CertVerifyCallback, NULL);
232 SSL_CTX_set_cert_cb(ssl_ctx_.get(), ClientCertRequestCallback, NULL); 234 SSL_CTX_set_cert_cb(ssl_ctx_.get(), ClientCertRequestCallback, NULL);
233 SSL_CTX_set_verify(ssl_ctx_.get(), SSL_VERIFY_PEER, NULL); 235 SSL_CTX_set_verify(ssl_ctx_.get(), SSL_VERIFY_PEER, NULL);
234 // This stops |SSL_shutdown| from generating the close_notify message, which 236 // This stops |SSL_shutdown| from generating the close_notify message, which
(...skipping 1916 matching lines...) Expand 10 before | Expand all | Expand 10 after
2151 OnHandshakeIOComplete(signature_result_); 2153 OnHandshakeIOComplete(signature_result_);
2152 return; 2154 return;
2153 } 2155 }
2154 2156
2155 // During a renegotiation, either Read or Write calls may be blocked on an 2157 // During a renegotiation, either Read or Write calls may be blocked on an
2156 // asynchronous private key operation. 2158 // asynchronous private key operation.
2157 PumpReadWriteEvents(); 2159 PumpReadWriteEvents();
2158 } 2160 }
2159 2161
2160 } // namespace net 2162 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698