[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] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 17 | #include "net/socket/ssl_client_socket_mac.h" |
[email protected] | fd4f139f | 2010-06-11 17:02:20 | [diff] [blame] | 18 | #include "net/socket/ssl_client_socket_nss.h" |
[email protected] | 68bf915 | 2008-09-25 19:47:30 | [diff] [blame] | 19 | #endif |
[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] | abe48d3 | 2010-02-03 02:09:36 | [diff] [blame] | 24 | namespace { |
| 25 | |
| 26 | SSLClientSocket* DefaultSSLClientSocketFactory( |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 27 | ClientSocketHandle* transport_socket, |
[email protected] | abe48d3 | 2010-02-03 02:09:36 | [diff] [blame] | 28 | const std::string& hostname, |
| 29 | const SSLConfig& ssl_config) { |
| 30 | #if defined(OS_WIN) |
| 31 | return new SSLClientSocketWin(transport_socket, hostname, ssl_config); |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame^] | 32 | #elif defined(USE_OPENSSL) |
| 33 | return new SSLClientSocketOpenSSL(transport_socket, hostname, ssl_config); |
[email protected] | abe48d3 | 2010-02-03 02:09:36 | [diff] [blame] | 34 | #elif defined(USE_NSS) |
| 35 | return new SSLClientSocketNSS(transport_socket, hostname, ssl_config); |
| 36 | #elif defined(OS_MACOSX) |
[email protected] | fd4f139f | 2010-06-11 17:02:20 | [diff] [blame] | 37 | // TODO(wtc): SSLClientSocketNSS can't do SSL client authentication using |
| 38 | // Mac OS X CDSA/CSSM yet (http://crbug.com/45369), so fall back on |
| 39 | // SSLClientSocketMac. |
[email protected] | 3c241bc | 2010-08-13 18:34:53 | [diff] [blame] | 40 | if (ssl_config.send_client_cert) |
[email protected] | fd4f139f | 2010-06-11 17:02:20 | [diff] [blame] | 41 | return new SSLClientSocketMac(transport_socket, hostname, ssl_config); |
| 42 | |
| 43 | return new SSLClientSocketNSS(transport_socket, hostname, ssl_config); |
[email protected] | abe48d3 | 2010-02-03 02:09:36 | [diff] [blame] | 44 | #else |
| 45 | NOTIMPLEMENTED(); |
| 46 | return NULL; |
| 47 | #endif |
| 48 | } |
| 49 | |
[email protected] | abe48d3 | 2010-02-03 02:09:36 | [diff] [blame] | 50 | SSLClientSocketFactory g_ssl_factory = DefaultSSLClientSocketFactory; |
| 51 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 52 | class DefaultClientSocketFactory : public ClientSocketFactory { |
| 53 | public: |
| 54 | virtual ClientSocket* CreateTCPClientSocket( |
[email protected] | 0a0b768 | 2010-08-25 17:08:07 | [diff] [blame] | 55 | const AddressList& addresses, |
| 56 | NetLog* net_log, |
| 57 | const NetLog::Source& source) { |
| 58 | return new TCPClientSocket(addresses, net_log, source); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 59 | } |
| 60 | |
[email protected] | aaead50 | 2008-10-15 00:20:11 | [diff] [blame] | 61 | virtual SSLClientSocket* CreateSSLClientSocket( |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 62 | ClientSocketHandle* transport_socket, |
[email protected] | c5949a3 | 2008-10-08 17:28:23 | [diff] [blame] | 63 | const std::string& hostname, |
[email protected] | aaead50 | 2008-10-15 00:20:11 | [diff] [blame] | 64 | const SSLConfig& ssl_config) { |
[email protected] | abe48d3 | 2010-02-03 02:09:36 | [diff] [blame] | 65 | return g_ssl_factory(transport_socket, hostname, ssl_config); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 66 | } |
| 67 | }; |
| 68 | |
[email protected] | abe48d3 | 2010-02-03 02:09:36 | [diff] [blame] | 69 | } // namespace |
| 70 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 71 | // static |
| 72 | ClientSocketFactory* ClientSocketFactory::GetDefaultFactory() { |
| 73 | return Singleton<DefaultClientSocketFactory>::get(); |
| 74 | } |
| 75 | |
[email protected] | abe48d3 | 2010-02-03 02:09:36 | [diff] [blame] | 76 | // static |
| 77 | void ClientSocketFactory::SetSSLClientSocketFactory( |
| 78 | SSLClientSocketFactory factory) { |
| 79 | g_ssl_factory = factory; |
| 80 | } |
| 81 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 82 | // Deprecated function (http://crbug.com/37810) that takes a ClientSocket. |
| 83 | SSLClientSocket* ClientSocketFactory::CreateSSLClientSocket( |
| 84 | ClientSocket* transport_socket, |
| 85 | const std::string& hostname, |
| 86 | const SSLConfig& ssl_config) { |
| 87 | ClientSocketHandle* socket_handle = new ClientSocketHandle(); |
| 88 | socket_handle->set_socket(transport_socket); |
| 89 | return CreateSSLClientSocket(socket_handle, hostname, ssl_config); |
| 90 | } |
| 91 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 92 | } // namespace net |