[email protected] | a2006ece | 2010-04-23 16:44:02 | [diff] [blame] | 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 4 | |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 5 | #include "net/socket/client_socket_factory.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 6 | |
| 7 | #include "base/singleton.h" |
[email protected] | 68bf915 | 2008-09-25 19:47:30 | [diff] [blame] | 8 | #include "build/build_config.h" |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9 | #include "net/socket/client_socket_handle.h" |
[email protected] | 68bf915 | 2008-09-25 19:47:30 | [diff] [blame] | 10 | #if defined(OS_WIN) |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 11 | #include "net/socket/ssl_client_socket_win.h" |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 12 | #elif defined(USE_OPENSSL) |
| 13 | #include "net/socket/ssl_client_socket_openssl.h" |
[email protected] | 1a15730 | 2010-01-29 03:36:45 | [diff] [blame] | 14 | #elif defined(USE_NSS) |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 15 | #include "net/socket/ssl_client_socket_nss.h" |
[email protected] | b75523f | 2008-10-17 14:49:07 | [diff] [blame] | 16 | #elif defined(OS_MACOSX) |
[email protected] | fd4f139f | 2010-06-11 17:02:20 | [diff] [blame] | 17 | #include "net/socket/ssl_client_socket_nss.h" |
[email protected] | 68bf915 | 2008-09-25 19:47:30 | [diff] [blame] | 18 | #endif |
[email protected] | d0672be | 2010-10-20 16:30:19 | [diff] [blame] | 19 | #include "net/socket/ssl_host_info.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 20 | #include "net/socket/tcp_client_socket.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 21 | |
| 22 | namespace net { |
| 23 | |
[email protected] | d8fbf58 | 2010-11-04 21:51:12 | [diff] [blame] | 24 | class DnsRRResolver; |
| 25 | |
[email protected] | abe48d3 | 2010-02-03 02:09:36 | [diff] [blame] | 26 | namespace { |
| 27 | |
| 28 | SSLClientSocket* DefaultSSLClientSocketFactory( |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 29 | ClientSocketHandle* transport_socket, |
[email protected] | 4f4de7e6 | 2010-11-12 19:55:27 | [diff] [blame^] | 30 | const HostPortPair& host_and_port, |
[email protected] | 7ab5bbd1 | 2010-10-19 13:33:21 | [diff] [blame] | 31 | const SSLConfig& ssl_config, |
[email protected] | d8fbf58 | 2010-11-04 21:51:12 | [diff] [blame] | 32 | SSLHostInfo* ssl_host_info, |
| 33 | DnsRRResolver* dnsrr_resolver) { |
[email protected] | 7ab5bbd1 | 2010-10-19 13:33:21 | [diff] [blame] | 34 | scoped_ptr<SSLHostInfo> shi(ssl_host_info); |
[email protected] | abe48d3 | 2010-02-03 02:09:36 | [diff] [blame] | 35 | #if defined(OS_WIN) |
[email protected] | 4f4de7e6 | 2010-11-12 19:55:27 | [diff] [blame^] | 36 | return new SSLClientSocketWin(transport_socket, host_and_port, ssl_config); |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 37 | #elif defined(USE_OPENSSL) |
[email protected] | 4f4de7e6 | 2010-11-12 19:55:27 | [diff] [blame^] | 38 | return new SSLClientSocketOpenSSL(transport_socket, host_and_port, |
| 39 | ssl_config); |
[email protected] | abe48d3 | 2010-02-03 02:09:36 | [diff] [blame] | 40 | #elif defined(USE_NSS) |
[email protected] | 4f4de7e6 | 2010-11-12 19:55:27 | [diff] [blame^] | 41 | return new SSLClientSocketNSS(transport_socket, host_and_port, ssl_config, |
[email protected] | d8fbf58 | 2010-11-04 21:51:12 | [diff] [blame] | 42 | shi.release(), dnsrr_resolver); |
[email protected] | abe48d3 | 2010-02-03 02:09:36 | [diff] [blame] | 43 | #elif defined(OS_MACOSX) |
[email protected] | 4f4de7e6 | 2010-11-12 19:55:27 | [diff] [blame^] | 44 | return new SSLClientSocketNSS(transport_socket, host_and_port, ssl_config, |
[email protected] | d8fbf58 | 2010-11-04 21:51:12 | [diff] [blame] | 45 | shi.release(), dnsrr_resolver); |
[email protected] | abe48d3 | 2010-02-03 02:09:36 | [diff] [blame] | 46 | #else |
| 47 | NOTIMPLEMENTED(); |
| 48 | return NULL; |
| 49 | #endif |
| 50 | } |
| 51 | |
[email protected] | abe48d3 | 2010-02-03 02:09:36 | [diff] [blame] | 52 | SSLClientSocketFactory g_ssl_factory = DefaultSSLClientSocketFactory; |
| 53 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 54 | class DefaultClientSocketFactory : public ClientSocketFactory { |
| 55 | public: |
| 56 | virtual ClientSocket* CreateTCPClientSocket( |
[email protected] | 0a0b768 | 2010-08-25 17:08:07 | [diff] [blame] | 57 | const AddressList& addresses, |
| 58 | NetLog* net_log, |
| 59 | const NetLog::Source& source) { |
| 60 | return new TCPClientSocket(addresses, net_log, source); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 61 | } |
| 62 | |
[email protected] | aaead50 | 2008-10-15 00:20:11 | [diff] [blame] | 63 | virtual SSLClientSocket* CreateSSLClientSocket( |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 64 | ClientSocketHandle* transport_socket, |
[email protected] | 4f4de7e6 | 2010-11-12 19:55:27 | [diff] [blame^] | 65 | const HostPortPair& host_and_port, |
[email protected] | 7ab5bbd1 | 2010-10-19 13:33:21 | [diff] [blame] | 66 | const SSLConfig& ssl_config, |
[email protected] | d8fbf58 | 2010-11-04 21:51:12 | [diff] [blame] | 67 | SSLHostInfo* ssl_host_info, |
| 68 | DnsRRResolver* dnsrr_resolver) { |
[email protected] | 4f4de7e6 | 2010-11-12 19:55:27 | [diff] [blame^] | 69 | return g_ssl_factory(transport_socket, host_and_port, ssl_config, |
| 70 | ssl_host_info, dnsrr_resolver); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 71 | } |
| 72 | }; |
| 73 | |
[email protected] | abe48d3 | 2010-02-03 02:09:36 | [diff] [blame] | 74 | } // namespace |
| 75 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 76 | // static |
| 77 | ClientSocketFactory* ClientSocketFactory::GetDefaultFactory() { |
| 78 | return Singleton<DefaultClientSocketFactory>::get(); |
| 79 | } |
| 80 | |
[email protected] | abe48d3 | 2010-02-03 02:09:36 | [diff] [blame] | 81 | // static |
| 82 | void ClientSocketFactory::SetSSLClientSocketFactory( |
| 83 | SSLClientSocketFactory factory) { |
| 84 | g_ssl_factory = factory; |
| 85 | } |
| 86 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 87 | // Deprecated function (http://crbug.com/37810) that takes a ClientSocket. |
| 88 | SSLClientSocket* ClientSocketFactory::CreateSSLClientSocket( |
| 89 | ClientSocket* transport_socket, |
[email protected] | 4f4de7e6 | 2010-11-12 19:55:27 | [diff] [blame^] | 90 | const HostPortPair& host_and_port, |
[email protected] | 7ab5bbd1 | 2010-10-19 13:33:21 | [diff] [blame] | 91 | const SSLConfig& ssl_config, |
| 92 | SSLHostInfo* ssl_host_info) { |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 93 | ClientSocketHandle* socket_handle = new ClientSocketHandle(); |
| 94 | socket_handle->set_socket(transport_socket); |
[email protected] | 4f4de7e6 | 2010-11-12 19:55:27 | [diff] [blame^] | 95 | return CreateSSLClientSocket(socket_handle, host_and_port, ssl_config, |
[email protected] | d8fbf58 | 2010-11-04 21:51:12 | [diff] [blame] | 96 | ssl_host_info, NULL /* DnsRRResolver */); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 97 | } |
| 98 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 99 | } // namespace net |