| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 #include "net/socket/ssl_client_socket_openssl.h" | 35 #include "net/socket/ssl_client_socket_openssl.h" |
| 36 #else | 36 #else |
| 37 #include "net/socket/client_socket_factory.h" | 37 #include "net/socket/client_socket_factory.h" |
| 38 #endif | 38 #endif |
| 39 | 39 |
| 40 namespace remoting { | 40 namespace remoting { |
| 41 namespace protocol { | 41 namespace protocol { |
| 42 | 42 |
| 43 namespace { | 43 namespace { |
| 44 | 44 |
| 45 // A CertVerifier which rejects every certificate. | 45 // A CertVerifier which accets all certificate. |
| 46 class FailingCertVerifier : public net::CertVerifier { | 46 class AcceptAllCertVerifier : public net::CertVerifier { |
| 47 public: | 47 public: |
| 48 FailingCertVerifier() {} | 48 AcceptAllCertVerifier() {} |
| 49 ~FailingCertVerifier() override {} | 49 ~AcceptAllCertVerifier() override {} |
| 50 | 50 |
| 51 int Verify(net::X509Certificate* cert, | 51 int Verify(net::X509Certificate* cert, |
| 52 const std::string& hostname, | 52 const std::string& hostname, |
| 53 const std::string& ocsp_response, | 53 const std::string& ocsp_response, |
| 54 int flags, | 54 int flags, |
| 55 net::CRLSet* crl_set, | 55 net::CRLSet* crl_set, |
| 56 net::CertVerifyResult* verify_result, | 56 net::CertVerifyResult* verify_result, |
| 57 const net::CompletionCallback& callback, | 57 const net::CompletionCallback& callback, |
| 58 scoped_ptr<Request>* out_req, | 58 scoped_ptr<Request>* out_req, |
| 59 const net::BoundNetLog& net_log) override { | 59 const net::BoundNetLog& net_log) override { |
| 60 verify_result->verified_cert = cert; | 60 verify_result->verified_cert = cert; |
| 61 verify_result->cert_status = net::CERT_STATUS_INVALID; | 61 verify_result->cert_status = 0; |
| 62 return net::ERR_CERT_INVALID; | 62 return net::OK; |
| 63 } | 63 } |
| 64 }; | 64 }; |
| 65 | 65 |
| 66 // Implements net::StreamSocket interface on top of P2PStreamSocket to be passed | 66 // Implements net::StreamSocket interface on top of P2PStreamSocket to be passed |
| 67 // to net::SSLClientSocket and net::SSLServerSocket. | 67 // to net::SSLClientSocket and net::SSLServerSocket. |
| 68 class NetStreamSocketAdapter : public net::StreamSocket { | 68 class NetStreamSocketAdapter : public net::StreamSocket { |
| 69 public: | 69 public: |
| 70 NetStreamSocketAdapter(scoped_ptr<P2PStreamSocket> socket) | 70 NetStreamSocketAdapter(scoped_ptr<P2PStreamSocket> socket) |
| 71 : socket_(std::move(socket)) {} | 71 : socket_(std::move(socket)) {} |
| 72 ~NetStreamSocketAdapter() override {} | 72 ~NetStreamSocketAdapter() override {} |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 | 166 |
| 167 private: | 167 private: |
| 168 scoped_ptr<net::StreamSocket> socket_; | 168 scoped_ptr<net::StreamSocket> socket_; |
| 169 }; | 169 }; |
| 170 | 170 |
| 171 } // namespace | 171 } // namespace |
| 172 | 172 |
| 173 // static | 173 // static |
| 174 scoped_ptr<SslHmacChannelAuthenticator> | 174 scoped_ptr<SslHmacChannelAuthenticator> |
| 175 SslHmacChannelAuthenticator::CreateForClient( | 175 SslHmacChannelAuthenticator::CreateForClient( |
| 176 const std::string& remote_cert, | |
| 177 const std::string& auth_key) { | 176 const std::string& auth_key) { |
| 178 scoped_ptr<SslHmacChannelAuthenticator> result( | 177 scoped_ptr<SslHmacChannelAuthenticator> result( |
| 179 new SslHmacChannelAuthenticator(auth_key)); | 178 new SslHmacChannelAuthenticator(auth_key)); |
| 180 result->remote_cert_ = remote_cert; | |
| 181 return result; | 179 return result; |
| 182 } | 180 } |
| 183 | 181 |
| 184 scoped_ptr<SslHmacChannelAuthenticator> | 182 scoped_ptr<SslHmacChannelAuthenticator> |
| 185 SslHmacChannelAuthenticator::CreateForHost( | 183 SslHmacChannelAuthenticator::CreateForHost( |
| 186 const std::string& local_cert, | 184 const std::string& local_cert, |
| 187 scoped_refptr<RsaKeyPair> key_pair, | 185 scoped_refptr<RsaKeyPair> key_pair, |
| 188 const std::string& auth_key) { | 186 const std::string& auth_key) { |
| 189 scoped_ptr<SslHmacChannelAuthenticator> result( | 187 scoped_ptr<SslHmacChannelAuthenticator> result( |
| 190 new SslHmacChannelAuthenticator(auth_key)); | 188 new SslHmacChannelAuthenticator(auth_key)); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 scoped_ptr<net::SSLServerSocket> server_socket = net::CreateSSLServerSocket( | 229 scoped_ptr<net::SSLServerSocket> server_socket = net::CreateSSLServerSocket( |
| 232 make_scoped_ptr(new NetStreamSocketAdapter(std::move(socket))), | 230 make_scoped_ptr(new NetStreamSocketAdapter(std::move(socket))), |
| 233 cert.get(), *local_key_pair_->private_key(), ssl_config); | 231 cert.get(), *local_key_pair_->private_key(), ssl_config); |
| 234 net::SSLServerSocket* raw_server_socket = server_socket.get(); | 232 net::SSLServerSocket* raw_server_socket = server_socket.get(); |
| 235 socket_ = std::move(server_socket); | 233 socket_ = std::move(server_socket); |
| 236 result = raw_server_socket->Handshake( | 234 result = raw_server_socket->Handshake( |
| 237 base::Bind(&SslHmacChannelAuthenticator::OnConnected, | 235 base::Bind(&SslHmacChannelAuthenticator::OnConnected, |
| 238 base::Unretained(this))); | 236 base::Unretained(this))); |
| 239 #endif | 237 #endif |
| 240 } else { | 238 } else { |
| 241 transport_security_state_.reset(new net::TransportSecurityState); | 239 transport_security_state_.reset(new net::TransportSecurityState()); |
| 242 cert_verifier_.reset(new FailingCertVerifier); | 240 cert_verifier_.reset(new AcceptAllCertVerifier()); |
| 243 | |
| 244 net::SSLConfig::CertAndStatus cert_and_status; | |
| 245 cert_and_status.cert_status = net::CERT_STATUS_AUTHORITY_INVALID; | |
| 246 cert_and_status.der_cert = remote_cert_; | |
| 247 | 241 |
| 248 net::SSLConfig ssl_config; | 242 net::SSLConfig ssl_config; |
| 249 // Certificate verification and revocation checking are not needed | 243 // Certificate verification and revocation checking are not needed |
| 250 // because we use self-signed certs. Disable it so that the SSL | 244 // because we use self-signed certs. Disable it so that the SSL |
| 251 // layer doesn't try to initialize OCSP (OCSP works only on the IO | 245 // layer doesn't try to initialize OCSP (OCSP works only on the IO |
| 252 // thread). | 246 // thread). |
| 253 ssl_config.cert_io_enabled = false; | 247 ssl_config.cert_io_enabled = false; |
| 254 ssl_config.rev_checking_enabled = false; | 248 ssl_config.rev_checking_enabled = false; |
| 255 ssl_config.allowed_bad_certs.push_back(cert_and_status); | |
| 256 ssl_config.require_ecdhe = true; | 249 ssl_config.require_ecdhe = true; |
| 257 | 250 |
| 258 net::HostPortPair host_and_port(kSslFakeHostName, 0); | 251 net::HostPortPair host_and_port(kSslFakeHostName, 0); |
| 259 net::SSLClientSocketContext context; | 252 net::SSLClientSocketContext context; |
| 260 context.transport_security_state = transport_security_state_.get(); | 253 context.transport_security_state = transport_security_state_.get(); |
| 261 context.cert_verifier = cert_verifier_.get(); | 254 context.cert_verifier = cert_verifier_.get(); |
| 262 scoped_ptr<net::ClientSocketHandle> socket_handle( | 255 scoped_ptr<net::ClientSocketHandle> socket_handle( |
| 263 new net::ClientSocketHandle); | 256 new net::ClientSocketHandle); |
| 264 socket_handle->SetSocket( | 257 socket_handle->SetSocket( |
| 265 make_scoped_ptr(new NetStreamSocketAdapter(std::move(socket)))); | 258 make_scoped_ptr(new NetStreamSocketAdapter(std::move(socket)))); |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 make_scoped_ptr(new P2PStreamSocketAdapter(std::move(socket_)))); | 427 make_scoped_ptr(new P2PStreamSocketAdapter(std::move(socket_)))); |
| 435 } | 428 } |
| 436 } | 429 } |
| 437 | 430 |
| 438 void SslHmacChannelAuthenticator::NotifyError(int error) { | 431 void SslHmacChannelAuthenticator::NotifyError(int error) { |
| 439 base::ResetAndReturn(&done_callback_).Run(error, nullptr); | 432 base::ResetAndReturn(&done_callback_).Run(error, nullptr); |
| 440 } | 433 } |
| 441 | 434 |
| 442 } // namespace protocol | 435 } // namespace protocol |
| 443 } // namespace remoting | 436 } // namespace remoting |
| OLD | NEW |