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 "remoting/protocol/ssl_hmac_channel_authenticator.h" | 5 #include "remoting/protocol/ssl_hmac_channel_authenticator.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "crypto/secure_util.h" | 9 #include "crypto/secure_util.h" |
10 #include "net/base/host_port_pair.h" | 10 #include "net/base/host_port_pair.h" |
11 #include "net/base/io_buffer.h" | 11 #include "net/base/io_buffer.h" |
12 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
13 #include "net/cert/x509_certificate.h" | 13 #include "net/cert/x509_certificate.h" |
14 #include "net/http/transport_security_state.h" | 14 #include "net/http/transport_security_state.h" |
15 #include "net/socket/client_socket_factory.h" | 15 #include "net/socket/client_socket_factory.h" |
16 #include "net/socket/client_socket_handle.h" | 16 #include "net/socket/client_socket_handle.h" |
17 #include "net/socket/ssl_client_socket.h" | 17 #include "net/socket/ssl_client_socket.h" |
| 18 #include "net/socket/ssl_client_socket_openssl.h" |
18 #include "net/socket/ssl_server_socket.h" | 19 #include "net/socket/ssl_server_socket.h" |
19 #include "net/ssl/ssl_config_service.h" | 20 #include "net/ssl/ssl_config_service.h" |
20 #include "remoting/base/rsa_key_pair.h" | 21 #include "remoting/base/rsa_key_pair.h" |
21 #include "remoting/protocol/auth_util.h" | 22 #include "remoting/protocol/auth_util.h" |
22 | 23 |
23 namespace remoting { | 24 namespace remoting { |
24 namespace protocol { | 25 namespace protocol { |
25 | 26 |
26 // static | 27 // static |
27 scoped_ptr<SslHmacChannelAuthenticator> | 28 scoped_ptr<SslHmacChannelAuthenticator> |
(...skipping 28 matching lines...) Expand all Loading... |
56 | 57 |
57 void SslHmacChannelAuthenticator::SecureAndAuthenticate( | 58 void SslHmacChannelAuthenticator::SecureAndAuthenticate( |
58 scoped_ptr<net::StreamSocket> socket, const DoneCallback& done_callback) { | 59 scoped_ptr<net::StreamSocket> socket, const DoneCallback& done_callback) { |
59 DCHECK(CalledOnValidThread()); | 60 DCHECK(CalledOnValidThread()); |
60 DCHECK(socket->IsConnected()); | 61 DCHECK(socket->IsConnected()); |
61 | 62 |
62 done_callback_ = done_callback; | 63 done_callback_ = done_callback; |
63 | 64 |
64 int result; | 65 int result; |
65 if (is_ssl_server()) { | 66 if (is_ssl_server()) { |
| 67 #if defined(OS_NACL) |
| 68 // Client plugin doesn't use server SSL sockets, and so SSLServerSocket |
| 69 // implementation is not compiled for NaCl as part of net_nacl. |
| 70 NOTREACHED(); |
| 71 result = net::ERR_FAILED; |
| 72 #else |
66 scoped_refptr<net::X509Certificate> cert = | 73 scoped_refptr<net::X509Certificate> cert = |
67 net::X509Certificate::CreateFromBytes( | 74 net::X509Certificate::CreateFromBytes( |
68 local_cert_.data(), local_cert_.length()); | 75 local_cert_.data(), local_cert_.length()); |
69 if (!cert.get()) { | 76 if (!cert.get()) { |
70 LOG(ERROR) << "Failed to parse X509Certificate"; | 77 LOG(ERROR) << "Failed to parse X509Certificate"; |
71 NotifyError(net::ERR_FAILED); | 78 NotifyError(net::ERR_FAILED); |
72 return; | 79 return; |
73 } | 80 } |
74 | 81 |
75 net::SSLConfig ssl_config; | 82 net::SSLConfig ssl_config; |
76 ssl_config.require_forward_secrecy = true; | 83 ssl_config.require_forward_secrecy = true; |
77 | 84 |
78 scoped_ptr<net::SSLServerSocket> server_socket = | 85 scoped_ptr<net::SSLServerSocket> server_socket = |
79 net::CreateSSLServerSocket(socket.Pass(), | 86 net::CreateSSLServerSocket(socket.Pass(), |
80 cert.get(), | 87 cert.get(), |
81 local_key_pair_->private_key(), | 88 local_key_pair_->private_key(), |
82 ssl_config); | 89 ssl_config); |
83 net::SSLServerSocket* raw_server_socket = server_socket.get(); | 90 net::SSLServerSocket* raw_server_socket = server_socket.get(); |
84 socket_ = server_socket.Pass(); | 91 socket_ = server_socket.Pass(); |
85 result = raw_server_socket->Handshake( | 92 result = raw_server_socket->Handshake( |
86 base::Bind(&SslHmacChannelAuthenticator::OnConnected, | 93 base::Bind(&SslHmacChannelAuthenticator::OnConnected, |
87 base::Unretained(this))); | 94 base::Unretained(this))); |
| 95 #endif |
88 } else { | 96 } else { |
89 transport_security_state_.reset(new net::TransportSecurityState); | 97 transport_security_state_.reset(new net::TransportSecurityState); |
90 | 98 |
91 net::SSLConfig::CertAndStatus cert_and_status; | 99 net::SSLConfig::CertAndStatus cert_and_status; |
92 cert_and_status.cert_status = net::CERT_STATUS_AUTHORITY_INVALID; | 100 cert_and_status.cert_status = net::CERT_STATUS_AUTHORITY_INVALID; |
93 cert_and_status.der_cert = remote_cert_; | 101 cert_and_status.der_cert = remote_cert_; |
94 | 102 |
95 net::SSLConfig ssl_config; | 103 net::SSLConfig ssl_config; |
96 // Certificate verification and revocation checking are not needed | 104 // Certificate verification and revocation checking are not needed |
97 // because we use self-signed certs. Disable it so that the SSL | 105 // because we use self-signed certs. Disable it so that the SSL |
98 // layer doesn't try to initialize OCSP (OCSP works only on the IO | 106 // layer doesn't try to initialize OCSP (OCSP works only on the IO |
99 // thread). | 107 // thread). |
100 ssl_config.cert_io_enabled = false; | 108 ssl_config.cert_io_enabled = false; |
101 ssl_config.rev_checking_enabled = false; | 109 ssl_config.rev_checking_enabled = false; |
102 ssl_config.allowed_bad_certs.push_back(cert_and_status); | 110 ssl_config.allowed_bad_certs.push_back(cert_and_status); |
103 | 111 |
104 net::HostPortPair host_and_port(kSslFakeHostName, 0); | 112 net::HostPortPair host_and_port(kSslFakeHostName, 0); |
105 net::SSLClientSocketContext context; | 113 net::SSLClientSocketContext context; |
106 context.transport_security_state = transport_security_state_.get(); | 114 context.transport_security_state = transport_security_state_.get(); |
107 scoped_ptr<net::ClientSocketHandle> connection(new net::ClientSocketHandle); | 115 scoped_ptr<net::ClientSocketHandle> socket_handle( |
108 connection->SetSocket(socket.Pass()); | 116 new net::ClientSocketHandle); |
| 117 socket_handle->SetSocket(socket.Pass()); |
| 118 |
| 119 #if defined(OS_NACL) |
| 120 // net_nacl doesn't include ClientSocketFactory. |
| 121 socket_.reset(new net::SSLClientSocketOpenSSL( |
| 122 socket_handle.Pass(), host_and_port, ssl_config, context)); |
| 123 #else |
109 socket_ = | 124 socket_ = |
110 net::ClientSocketFactory::GetDefaultFactory()->CreateSSLClientSocket( | 125 net::ClientSocketFactory::GetDefaultFactory()->CreateSSLClientSocket( |
111 connection.Pass(), host_and_port, ssl_config, context); | 126 socket_handle.Pass(), host_and_port, ssl_config, context); |
| 127 #endif |
112 | 128 |
113 result = socket_->Connect( | 129 result = socket_->Connect( |
114 base::Bind(&SslHmacChannelAuthenticator::OnConnected, | 130 base::Bind(&SslHmacChannelAuthenticator::OnConnected, |
115 base::Unretained(this))); | 131 base::Unretained(this))); |
116 } | 132 } |
117 | 133 |
118 if (result == net::ERR_IO_PENDING) | 134 if (result == net::ERR_IO_PENDING) |
119 return; | 135 return; |
120 | 136 |
121 OnConnected(result); | 137 OnConnected(result); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 } | 283 } |
268 } | 284 } |
269 | 285 |
270 void SslHmacChannelAuthenticator::NotifyError(int error) { | 286 void SslHmacChannelAuthenticator::NotifyError(int error) { |
271 done_callback_.Run(static_cast<net::Error>(error), | 287 done_callback_.Run(static_cast<net::Error>(error), |
272 scoped_ptr<net::StreamSocket>()); | 288 scoped_ptr<net::StreamSocket>()); |
273 } | 289 } |
274 | 290 |
275 } // namespace protocol | 291 } // namespace protocol |
276 } // namespace remoting | 292 } // namespace remoting |
OLD | NEW |