| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/singleton.h" | 7 #include "base/singleton.h" |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 #include "net/base/ssl_host_info.h" |
| 9 #include "net/socket/client_socket_handle.h" | 10 #include "net/socket/client_socket_handle.h" |
| 10 #if defined(OS_WIN) | 11 #if defined(OS_WIN) |
| 11 #include "net/socket/ssl_client_socket_win.h" | 12 #include "net/socket/ssl_client_socket_win.h" |
| 12 #elif defined(USE_OPENSSL) | 13 #elif defined(USE_OPENSSL) |
| 13 #include "net/socket/ssl_client_socket_openssl.h" | 14 #include "net/socket/ssl_client_socket_openssl.h" |
| 14 #elif defined(USE_NSS) | 15 #elif defined(USE_NSS) |
| 15 #include "net/socket/ssl_client_socket_nss.h" | 16 #include "net/socket/ssl_client_socket_nss.h" |
| 16 #elif defined(OS_MACOSX) | 17 #elif defined(OS_MACOSX) |
| 17 #include "net/socket/ssl_client_socket_mac.h" | 18 #include "net/socket/ssl_client_socket_mac.h" |
| 18 #include "net/socket/ssl_client_socket_nss.h" | 19 #include "net/socket/ssl_client_socket_nss.h" |
| 19 #endif | 20 #endif |
| 20 #include "net/socket/tcp_client_socket.h" | 21 #include "net/socket/tcp_client_socket.h" |
| 21 | 22 |
| 22 namespace net { | 23 namespace net { |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 | 26 |
| 26 SSLClientSocket* DefaultSSLClientSocketFactory( | 27 SSLClientSocket* DefaultSSLClientSocketFactory( |
| 27 ClientSocketHandle* transport_socket, | 28 ClientSocketHandle* transport_socket, |
| 28 const std::string& hostname, | 29 const std::string& hostname, |
| 29 const SSLConfig& ssl_config) { | 30 const SSLConfig& ssl_config, |
| 31 SSLHostInfo* ssl_host_info) { |
| 32 scoped_ptr<SSLHostInfo> shi(ssl_host_info); |
| 30 #if defined(OS_WIN) | 33 #if defined(OS_WIN) |
| 31 return new SSLClientSocketWin(transport_socket, hostname, ssl_config); | 34 return new SSLClientSocketWin(transport_socket, hostname, ssl_config); |
| 32 #elif defined(USE_OPENSSL) | 35 #elif defined(USE_OPENSSL) |
| 33 return new SSLClientSocketOpenSSL(transport_socket, hostname, ssl_config); | 36 return new SSLClientSocketOpenSSL(transport_socket, hostname, ssl_config); |
| 34 #elif defined(USE_NSS) | 37 #elif defined(USE_NSS) |
| 35 return new SSLClientSocketNSS(transport_socket, hostname, ssl_config); | 38 return new SSLClientSocketNSS(transport_socket, hostname, ssl_config, |
| 39 shi.release()); |
| 36 #elif defined(OS_MACOSX) | 40 #elif defined(OS_MACOSX) |
| 37 // TODO(wtc): SSLClientSocketNSS can't do SSL client authentication using | 41 // 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 | 42 // Mac OS X CDSA/CSSM yet (http://crbug.com/45369), so fall back on |
| 39 // SSLClientSocketMac. | 43 // SSLClientSocketMac. |
| 40 if (ssl_config.send_client_cert) | 44 if (ssl_config.send_client_cert) |
| 41 return new SSLClientSocketMac(transport_socket, hostname, ssl_config); | 45 return new SSLClientSocketMac(transport_socket, hostname, ssl_config); |
| 42 | 46 |
| 43 return new SSLClientSocketNSS(transport_socket, hostname, ssl_config); | 47 return new SSLClientSocketNSS(transport_socket, hostname, ssl_config |
| 48 shi.release()); |
| 44 #else | 49 #else |
| 45 NOTIMPLEMENTED(); | 50 NOTIMPLEMENTED(); |
| 46 return NULL; | 51 return NULL; |
| 47 #endif | 52 #endif |
| 48 } | 53 } |
| 49 | 54 |
| 50 SSLClientSocketFactory g_ssl_factory = DefaultSSLClientSocketFactory; | 55 SSLClientSocketFactory g_ssl_factory = DefaultSSLClientSocketFactory; |
| 51 | 56 |
| 52 class DefaultClientSocketFactory : public ClientSocketFactory { | 57 class DefaultClientSocketFactory : public ClientSocketFactory { |
| 53 public: | 58 public: |
| 54 virtual ClientSocket* CreateTCPClientSocket( | 59 virtual ClientSocket* CreateTCPClientSocket( |
| 55 const AddressList& addresses, | 60 const AddressList& addresses, |
| 56 NetLog* net_log, | 61 NetLog* net_log, |
| 57 const NetLog::Source& source) { | 62 const NetLog::Source& source) { |
| 58 return new TCPClientSocket(addresses, net_log, source); | 63 return new TCPClientSocket(addresses, net_log, source); |
| 59 } | 64 } |
| 60 | 65 |
| 61 virtual SSLClientSocket* CreateSSLClientSocket( | 66 virtual SSLClientSocket* CreateSSLClientSocket( |
| 62 ClientSocketHandle* transport_socket, | 67 ClientSocketHandle* transport_socket, |
| 63 const std::string& hostname, | 68 const std::string& hostname, |
| 64 const SSLConfig& ssl_config) { | 69 const SSLConfig& ssl_config, |
| 65 return g_ssl_factory(transport_socket, hostname, ssl_config); | 70 SSLHostInfo* ssl_host_info) { |
| 71 return g_ssl_factory(transport_socket, hostname, ssl_config, ssl_host_info); |
| 66 } | 72 } |
| 67 }; | 73 }; |
| 68 | 74 |
| 69 } // namespace | 75 } // namespace |
| 70 | 76 |
| 71 // static | 77 // static |
| 72 ClientSocketFactory* ClientSocketFactory::GetDefaultFactory() { | 78 ClientSocketFactory* ClientSocketFactory::GetDefaultFactory() { |
| 73 return Singleton<DefaultClientSocketFactory>::get(); | 79 return Singleton<DefaultClientSocketFactory>::get(); |
| 74 } | 80 } |
| 75 | 81 |
| 76 // static | 82 // static |
| 77 void ClientSocketFactory::SetSSLClientSocketFactory( | 83 void ClientSocketFactory::SetSSLClientSocketFactory( |
| 78 SSLClientSocketFactory factory) { | 84 SSLClientSocketFactory factory) { |
| 79 g_ssl_factory = factory; | 85 g_ssl_factory = factory; |
| 80 } | 86 } |
| 81 | 87 |
| 82 // Deprecated function (http://crbug.com/37810) that takes a ClientSocket. | 88 // Deprecated function (http://crbug.com/37810) that takes a ClientSocket. |
| 83 SSLClientSocket* ClientSocketFactory::CreateSSLClientSocket( | 89 SSLClientSocket* ClientSocketFactory::CreateSSLClientSocket( |
| 84 ClientSocket* transport_socket, | 90 ClientSocket* transport_socket, |
| 85 const std::string& hostname, | 91 const std::string& hostname, |
| 86 const SSLConfig& ssl_config) { | 92 const SSLConfig& ssl_config, |
| 93 SSLHostInfo* ssl_host_info) { |
| 87 ClientSocketHandle* socket_handle = new ClientSocketHandle(); | 94 ClientSocketHandle* socket_handle = new ClientSocketHandle(); |
| 88 socket_handle->set_socket(transport_socket); | 95 socket_handle->set_socket(transport_socket); |
| 89 return CreateSSLClientSocket(socket_handle, hostname, ssl_config); | 96 return CreateSSLClientSocket(socket_handle, hostname, ssl_config, |
| 97 ssl_host_info); |
| 90 } | 98 } |
| 91 | 99 |
| 92 } // namespace net | 100 } // namespace net |
| OLD | NEW |