| 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; | |
| 34 | |
| 35 // ChromeOS and Linux may require interaction with smart cards or TPMs, which | 27 // 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 | 28 // 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 | 29 // blocking all activity on the current task runner, such as network or IPC |
| 38 // traffic, run NSS SSL functions on a dedicated thread. | 30 // traffic, run NSS SSL functions on a dedicated thread. |
| 39 #if defined(OS_CHROMEOS) || defined(OS_LINUX) | 31 #if defined(OS_CHROMEOS) || defined(OS_LINUX) |
| 40 bool g_use_dedicated_nss_thread = true; | 32 bool g_use_dedicated_nss_thread = true; |
| 41 #else | 33 #else |
| 42 bool g_use_dedicated_nss_thread = false; | 34 bool g_use_dedicated_nss_thread = false; |
| 43 #endif | 35 #endif |
| 44 | 36 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 // may span multiple tests, and thus the current task runner may change | 97 // may span multiple tests, and thus the current task runner may change |
| 106 // from call to call. | 98 // from call to call. |
| 107 scoped_refptr<base::SequencedTaskRunner> nss_task_runner( | 99 scoped_refptr<base::SequencedTaskRunner> nss_task_runner( |
| 108 nss_thread_task_runner_); | 100 nss_thread_task_runner_); |
| 109 if (!nss_task_runner) | 101 if (!nss_task_runner) |
| 110 nss_task_runner = base::ThreadTaskRunnerHandle::Get(); | 102 nss_task_runner = base::ThreadTaskRunnerHandle::Get(); |
| 111 | 103 |
| 112 #if defined(USE_OPENSSL) | 104 #if defined(USE_OPENSSL) |
| 113 return new SSLClientSocketOpenSSL(transport_socket, host_and_port, | 105 return new SSLClientSocketOpenSSL(transport_socket, host_and_port, |
| 114 ssl_config, context); | 106 ssl_config, context); |
| 115 #elif defined(USE_NSS) || defined(OS_IOS) | 107 #elif defined(USE_NSS) || defined(OS_MACOSX) || defined(OS_WIN) |
| 116 return new SSLClientSocketNSS(nss_task_runner, transport_socket, | 108 return new SSLClientSocketNSS(nss_task_runner, transport_socket, |
| 117 host_and_port, ssl_config, context); | 109 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 | 110 #else |
| 135 NOTIMPLEMENTED(); | 111 NOTIMPLEMENTED(); |
| 136 return NULL; | 112 return NULL; |
| 137 #endif | 113 #endif |
| 138 } | 114 } |
| 139 | 115 |
| 140 virtual void ClearSSLSessionCache() OVERRIDE { | 116 virtual void ClearSSLSessionCache() OVERRIDE { |
| 141 SSLClientSocket::ClearSessionCache(); | 117 SSLClientSocket::ClearSessionCache(); |
| 142 } | 118 } |
| 143 | 119 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 161 socket_handle->set_socket(transport_socket); | 137 socket_handle->set_socket(transport_socket); |
| 162 return CreateSSLClientSocket(socket_handle, host_and_port, ssl_config, | 138 return CreateSSLClientSocket(socket_handle, host_and_port, ssl_config, |
| 163 context); | 139 context); |
| 164 } | 140 } |
| 165 | 141 |
| 166 // static | 142 // static |
| 167 ClientSocketFactory* ClientSocketFactory::GetDefaultFactory() { | 143 ClientSocketFactory* ClientSocketFactory::GetDefaultFactory() { |
| 168 return g_default_client_socket_factory.Pointer(); | 144 return g_default_client_socket_factory.Pointer(); |
| 169 } | 145 } |
| 170 | 146 |
| 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); | |
| 181 #endif | |
| 182 } | |
| 183 | |
| 184 } // namespace net | 147 } // namespace net |
| OLD | NEW |