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