Chromium Code Reviews| 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 #include "net/socket/client_socket_factory.h" | 5 #include "net/socket/client_socket_factory.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/thread_task_runner_handle.h" | 8 #include "base/thread_task_runner_handle.h" |
| 9 #include "base/threading/sequenced_worker_pool.h" | 9 #include "base/threading/sequenced_worker_pool.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| 11 #include "net/base/cert_database.h" | 11 #include "net/base/cert_database.h" |
| 12 #include "net/socket/client_socket_handle.h" | 12 #include "net/socket/client_socket_handle.h" |
| 13 #if defined(OS_WIN) | 13 #if defined(USE_OPENSSL) |
| 14 #include "net/socket/ssl_client_socket_nss.h" | |
| 15 #include "net/socket/ssl_client_socket_win.h" | |
| 16 #elif defined(USE_OPENSSL) | |
| 17 #include "net/socket/ssl_client_socket_openssl.h" | 14 #include "net/socket/ssl_client_socket_openssl.h" |
| 18 #elif defined(USE_NSS) || defined(OS_IOS) | 15 #elif defined(USE_NSS) || defined(OS_MACOSX) || defined(OS_WIN) |
| 19 #include "net/socket/ssl_client_socket_nss.h" | |
| 20 #elif defined(OS_MACOSX) | |
| 21 #include "net/socket/ssl_client_socket_mac.h" | |
| 22 #include "net/socket/ssl_client_socket_nss.h" | 16 #include "net/socket/ssl_client_socket_nss.h" |
| 23 #endif | 17 #endif |
| 24 #include "net/socket/tcp_client_socket.h" | 18 #include "net/socket/tcp_client_socket.h" |
| 25 #include "net/udp/udp_client_socket.h" | 19 #include "net/udp/udp_client_socket.h" |
| 26 | 20 |
| 27 namespace net { | 21 namespace net { |
| 28 | 22 |
| 29 class X509Certificate; | 23 class X509Certificate; |
| 30 | 24 |
| 31 namespace { | 25 namespace { |
| 32 | 26 |
| 33 bool g_use_system_ssl = false; | 27 bool g_use_system_ssl = false; |
|
wtc
2013/01/15 23:26:35
Remove g_use_system_ssl.
| |
| 34 | 28 |
| 35 // ChromeOS and Linux may require interaction with smart cards or TPMs, which | 29 // ChromeOS and Linux may require interaction with smart cards or TPMs, which |
| 36 // may cause NSS functions to block for upwards of several seconds. To avoid | 30 // may cause NSS functions to block for upwards of several seconds. To avoid |
| 37 // blocking all activity on the current task runner, such as network or IPC | 31 // blocking all activity on the current task runner, such as network or IPC |
| 38 // traffic, run NSS SSL functions on a dedicated thread. | 32 // traffic, run NSS SSL functions on a dedicated thread. |
| 39 #if defined(OS_CHROMEOS) || defined(OS_LINUX) | 33 #if defined(OS_CHROMEOS) || defined(OS_LINUX) |
| 40 bool g_use_dedicated_nss_thread = true; | 34 bool g_use_dedicated_nss_thread = true; |
| 41 #else | 35 #else |
| 42 bool g_use_dedicated_nss_thread = false; | 36 bool g_use_dedicated_nss_thread = false; |
| 43 #endif | 37 #endif |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 // may span multiple tests, and thus the current task runner may change | 99 // may span multiple tests, and thus the current task runner may change |
| 106 // from call to call. | 100 // from call to call. |
| 107 scoped_refptr<base::SequencedTaskRunner> nss_task_runner( | 101 scoped_refptr<base::SequencedTaskRunner> nss_task_runner( |
| 108 nss_thread_task_runner_); | 102 nss_thread_task_runner_); |
| 109 if (!nss_task_runner) | 103 if (!nss_task_runner) |
| 110 nss_task_runner = base::ThreadTaskRunnerHandle::Get(); | 104 nss_task_runner = base::ThreadTaskRunnerHandle::Get(); |
| 111 | 105 |
| 112 #if defined(USE_OPENSSL) | 106 #if defined(USE_OPENSSL) |
| 113 return new SSLClientSocketOpenSSL(transport_socket, host_and_port, | 107 return new SSLClientSocketOpenSSL(transport_socket, host_and_port, |
| 114 ssl_config, context); | 108 ssl_config, context); |
| 115 #elif defined(USE_NSS) || defined(OS_IOS) | 109 #elif defined(USE_NSS) || defined(OS_MACOSX) || defined(OS_WIN) |
| 116 return new SSLClientSocketNSS(nss_task_runner, transport_socket, | 110 return new SSLClientSocketNSS(nss_task_runner, transport_socket, |
| 117 host_and_port, ssl_config, context); | 111 host_and_port, ssl_config, context); |
| 118 #elif defined(OS_WIN) | |
| 119 if (g_use_system_ssl) { | |
| 120 return new SSLClientSocketWin(transport_socket, host_and_port, | |
| 121 ssl_config, context); | |
| 122 } | |
| 123 return new SSLClientSocketNSS(nss_task_runner, transport_socket, | |
| 124 host_and_port, ssl_config, | |
| 125 context); | |
| 126 #elif defined(OS_MACOSX) | |
| 127 if (g_use_system_ssl) { | |
| 128 return new SSLClientSocketMac(transport_socket, host_and_port, | |
| 129 ssl_config, context); | |
| 130 } | |
| 131 return new SSLClientSocketNSS(nss_task_runner, transport_socket, | |
| 132 host_and_port, ssl_config, | |
| 133 context); | |
| 134 #else | 112 #else |
| 135 NOTIMPLEMENTED(); | 113 NOTIMPLEMENTED(); |
| 136 return NULL; | 114 return NULL; |
| 137 #endif | 115 #endif |
| 138 } | 116 } |
| 139 | 117 |
| 140 virtual void ClearSSLSessionCache() OVERRIDE { | 118 virtual void ClearSSLSessionCache() OVERRIDE { |
| 141 SSLClientSocket::ClearSessionCache(); | 119 SSLClientSocket::ClearSessionCache(); |
| 142 } | 120 } |
| 143 | 121 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 161 socket_handle->set_socket(transport_socket); | 139 socket_handle->set_socket(transport_socket); |
| 162 return CreateSSLClientSocket(socket_handle, host_and_port, ssl_config, | 140 return CreateSSLClientSocket(socket_handle, host_and_port, ssl_config, |
| 163 context); | 141 context); |
| 164 } | 142 } |
| 165 | 143 |
| 166 // static | 144 // static |
| 167 ClientSocketFactory* ClientSocketFactory::GetDefaultFactory() { | 145 ClientSocketFactory* ClientSocketFactory::GetDefaultFactory() { |
| 168 return g_default_client_socket_factory.Pointer(); | 146 return g_default_client_socket_factory.Pointer(); |
| 169 } | 147 } |
| 170 | 148 |
| 171 // static | |
| 172 void ClientSocketFactory::UseSystemSSL() { | |
| 173 g_use_system_ssl = true; | |
| 174 | |
| 175 #if defined(OS_WIN) | |
| 176 // Reflect the capability of SSLClientSocketWin. | |
| 177 SSLConfigService::SetDefaultVersionMax(SSL_PROTOCOL_VERSION_TLS1); | |
| 178 #elif defined(OS_MACOSX) && !defined(OS_IOS) | |
| 179 // Reflect the capability of SSLClientSocketMac. | |
| 180 SSLConfigService::SetDefaultVersionMax(SSL_PROTOCOL_VERSION_TLS1); | |
|
wtc
2013/01/15 23:26:35
Please find out if the SSLConfigService::SetDefaul
| |
| 181 #endif | |
| 182 } | |
| 183 | |
| 184 } // namespace net | 149 } // namespace net |
| OLD | NEW |