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 "base/callback_helpers.h" |
| 10 #include "base/logging.h" |
9 #include "crypto/secure_util.h" | 11 #include "crypto/secure_util.h" |
10 #include "net/base/host_port_pair.h" | 12 #include "net/base/host_port_pair.h" |
11 #include "net/base/io_buffer.h" | 13 #include "net/base/io_buffer.h" |
12 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
| 15 #include "net/cert/cert_status_flags.h" |
| 16 #include "net/cert/cert_verifier.h" |
13 #include "net/cert/x509_certificate.h" | 17 #include "net/cert/x509_certificate.h" |
14 #include "net/http/transport_security_state.h" | 18 #include "net/http/transport_security_state.h" |
15 #include "net/socket/client_socket_factory.h" | 19 #include "net/socket/client_socket_factory.h" |
16 #include "net/socket/client_socket_handle.h" | 20 #include "net/socket/client_socket_handle.h" |
17 #include "net/socket/ssl_client_socket.h" | 21 #include "net/socket/ssl_client_socket.h" |
18 #include "net/socket/ssl_client_socket_openssl.h" | 22 #include "net/socket/ssl_client_socket_openssl.h" |
19 #include "net/socket/ssl_server_socket.h" | 23 #include "net/socket/ssl_server_socket.h" |
20 #include "net/ssl/ssl_config_service.h" | 24 #include "net/ssl/ssl_config_service.h" |
21 #include "remoting/base/rsa_key_pair.h" | 25 #include "remoting/base/rsa_key_pair.h" |
22 #include "remoting/protocol/auth_util.h" | 26 #include "remoting/protocol/auth_util.h" |
23 | 27 |
24 namespace remoting { | 28 namespace remoting { |
25 namespace protocol { | 29 namespace protocol { |
26 | 30 |
| 31 namespace { |
| 32 |
| 33 // A CertVerifier which rejects every certificate. |
| 34 class FailingCertVerifier : public net::CertVerifier { |
| 35 public: |
| 36 FailingCertVerifier() {} |
| 37 ~FailingCertVerifier() override {} |
| 38 |
| 39 int Verify(net::X509Certificate* cert, |
| 40 const std::string& hostname, |
| 41 int flags, |
| 42 net::CRLSet* crl_set, |
| 43 net::CertVerifyResult* verify_result, |
| 44 const net::CompletionCallback& callback, |
| 45 RequestHandle* out_req, |
| 46 const net::BoundNetLog& net_log) override { |
| 47 verify_result->verified_cert = cert; |
| 48 verify_result->cert_status = net::CERT_STATUS_INVALID; |
| 49 return net::ERR_CERT_INVALID; |
| 50 } |
| 51 |
| 52 void CancelRequest(RequestHandle req) override { |
| 53 NOTIMPLEMENTED(); |
| 54 } |
| 55 }; |
| 56 |
| 57 } // namespace |
| 58 |
27 // static | 59 // static |
28 scoped_ptr<SslHmacChannelAuthenticator> | 60 scoped_ptr<SslHmacChannelAuthenticator> |
29 SslHmacChannelAuthenticator::CreateForClient( | 61 SslHmacChannelAuthenticator::CreateForClient( |
30 const std::string& remote_cert, | 62 const std::string& remote_cert, |
31 const std::string& auth_key) { | 63 const std::string& auth_key) { |
32 scoped_ptr<SslHmacChannelAuthenticator> result( | 64 scoped_ptr<SslHmacChannelAuthenticator> result( |
33 new SslHmacChannelAuthenticator(auth_key)); | 65 new SslHmacChannelAuthenticator(auth_key)); |
34 result->remote_cert_ = remote_cert; | 66 result->remote_cert_ = remote_cert; |
35 return result.Pass(); | 67 return result.Pass(); |
36 } | 68 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 local_key_pair_->private_key(), | 120 local_key_pair_->private_key(), |
89 ssl_config); | 121 ssl_config); |
90 net::SSLServerSocket* raw_server_socket = server_socket.get(); | 122 net::SSLServerSocket* raw_server_socket = server_socket.get(); |
91 socket_ = server_socket.Pass(); | 123 socket_ = server_socket.Pass(); |
92 result = raw_server_socket->Handshake( | 124 result = raw_server_socket->Handshake( |
93 base::Bind(&SslHmacChannelAuthenticator::OnConnected, | 125 base::Bind(&SslHmacChannelAuthenticator::OnConnected, |
94 base::Unretained(this))); | 126 base::Unretained(this))); |
95 #endif | 127 #endif |
96 } else { | 128 } else { |
97 transport_security_state_.reset(new net::TransportSecurityState); | 129 transport_security_state_.reset(new net::TransportSecurityState); |
| 130 cert_verifier_.reset(new FailingCertVerifier); |
98 | 131 |
99 net::SSLConfig::CertAndStatus cert_and_status; | 132 net::SSLConfig::CertAndStatus cert_and_status; |
100 cert_and_status.cert_status = net::CERT_STATUS_AUTHORITY_INVALID; | 133 cert_and_status.cert_status = net::CERT_STATUS_AUTHORITY_INVALID; |
101 cert_and_status.der_cert = remote_cert_; | 134 cert_and_status.der_cert = remote_cert_; |
102 | 135 |
103 net::SSLConfig ssl_config; | 136 net::SSLConfig ssl_config; |
104 // Certificate verification and revocation checking are not needed | 137 // Certificate verification and revocation checking are not needed |
105 // because we use self-signed certs. Disable it so that the SSL | 138 // because we use self-signed certs. Disable it so that the SSL |
106 // layer doesn't try to initialize OCSP (OCSP works only on the IO | 139 // layer doesn't try to initialize OCSP (OCSP works only on the IO |
107 // thread). | 140 // thread). |
108 ssl_config.cert_io_enabled = false; | 141 ssl_config.cert_io_enabled = false; |
109 ssl_config.rev_checking_enabled = false; | 142 ssl_config.rev_checking_enabled = false; |
110 ssl_config.allowed_bad_certs.push_back(cert_and_status); | 143 ssl_config.allowed_bad_certs.push_back(cert_and_status); |
111 | 144 |
112 net::HostPortPair host_and_port(kSslFakeHostName, 0); | 145 net::HostPortPair host_and_port(kSslFakeHostName, 0); |
113 net::SSLClientSocketContext context; | 146 net::SSLClientSocketContext context; |
114 context.transport_security_state = transport_security_state_.get(); | 147 context.transport_security_state = transport_security_state_.get(); |
| 148 context.cert_verifier = cert_verifier_.get(); |
115 scoped_ptr<net::ClientSocketHandle> socket_handle( | 149 scoped_ptr<net::ClientSocketHandle> socket_handle( |
116 new net::ClientSocketHandle); | 150 new net::ClientSocketHandle); |
117 socket_handle->SetSocket(socket.Pass()); | 151 socket_handle->SetSocket(socket.Pass()); |
118 | 152 |
119 #if defined(OS_NACL) | 153 #if defined(OS_NACL) |
120 // net_nacl doesn't include ClientSocketFactory. | 154 // net_nacl doesn't include ClientSocketFactory. |
121 socket_.reset(new net::SSLClientSocketOpenSSL( | 155 socket_.reset(new net::SSLClientSocketOpenSSL( |
122 socket_handle.Pass(), host_and_port, ssl_config, context)); | 156 socket_handle.Pass(), host_and_port, ssl_config, context)); |
123 #else | 157 #else |
124 socket_ = | 158 socket_ = |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 return crypto::SecureMemEqual(received_auth_bytes.data(), | 307 return crypto::SecureMemEqual(received_auth_bytes.data(), |
274 &(auth_bytes[0]), kAuthDigestLength); | 308 &(auth_bytes[0]), kAuthDigestLength); |
275 } | 309 } |
276 | 310 |
277 void SslHmacChannelAuthenticator::CheckDone(bool* callback_called) { | 311 void SslHmacChannelAuthenticator::CheckDone(bool* callback_called) { |
278 if (auth_write_buf_.get() == nullptr && auth_read_buf_.get() == nullptr) { | 312 if (auth_write_buf_.get() == nullptr && auth_read_buf_.get() == nullptr) { |
279 DCHECK(socket_.get() != nullptr); | 313 DCHECK(socket_.get() != nullptr); |
280 if (callback_called) | 314 if (callback_called) |
281 *callback_called = true; | 315 *callback_called = true; |
282 | 316 |
283 CallDoneCallback(net::OK, socket_.Pass()); | 317 base::ResetAndReturn(&done_callback_).Run(net::OK, socket_.Pass()); |
284 } | 318 } |
285 } | 319 } |
286 | 320 |
287 void SslHmacChannelAuthenticator::NotifyError(int error) { | 321 void SslHmacChannelAuthenticator::NotifyError(int error) { |
288 CallDoneCallback(error, nullptr); | 322 base::ResetAndReturn(&done_callback_).Run(error, nullptr); |
289 } | |
290 | |
291 void SslHmacChannelAuthenticator::CallDoneCallback( | |
292 int error, | |
293 scoped_ptr<net::StreamSocket> socket) { | |
294 DoneCallback callback = done_callback_; | |
295 done_callback_.Reset(); | |
296 callback.Run(error, socket.Pass()); | |
297 } | 323 } |
298 | 324 |
299 } // namespace protocol | 325 } // namespace protocol |
300 } // namespace remoting | 326 } // namespace remoting |
OLD | NEW |