| 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 // OpenSSL binding for SSLClientSocket. The class layout and general principle | 5 // OpenSSL binding for SSLClientSocket. The class layout and general principle |
| 6 // of operation is derived from SSLClientSocketNSS. | 6 // of operation is derived from SSLClientSocketNSS. |
| 7 | 7 |
| 8 #include "net/socket/ssl_client_socket_openssl.h" | 8 #include "net/socket/ssl_client_socket_openssl.h" |
| 9 | 9 |
| 10 #include <openssl/ssl.h> | 10 #include <openssl/ssl.h> |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 LOG(WARNING) << "Unknown OpenSSL error " << err; | 55 LOG(WARNING) << "Unknown OpenSSL error " << err; |
| 56 MaybeLogSSLError(); | 56 MaybeLogSSLError(); |
| 57 return ERR_SSL_PROTOCOL_ERROR; | 57 return ERR_SSL_PROTOCOL_ERROR; |
| 58 } | 58 } |
| 59 } | 59 } |
| 60 | 60 |
| 61 } // namespace | 61 } // namespace |
| 62 | 62 |
| 63 SSLClientSocketOpenSSL::SSLClientSocketOpenSSL( | 63 SSLClientSocketOpenSSL::SSLClientSocketOpenSSL( |
| 64 ClientSocketHandle* transport_socket, | 64 ClientSocketHandle* transport_socket, |
| 65 const std::string& hostname, | 65 const HostPortPair& host_and_port, |
| 66 uint16 port, | |
| 67 const SSLConfig& ssl_config) | 66 const SSLConfig& ssl_config) |
| 68 : ALLOW_THIS_IN_INITIALIZER_LIST(buffer_send_callback_( | 67 : ALLOW_THIS_IN_INITIALIZER_LIST(buffer_send_callback_( |
| 69 this, &SSLClientSocketOpenSSL::BufferSendComplete)), | 68 this, &SSLClientSocketOpenSSL::BufferSendComplete)), |
| 70 ALLOW_THIS_IN_INITIALIZER_LIST(buffer_recv_callback_( | 69 ALLOW_THIS_IN_INITIALIZER_LIST(buffer_recv_callback_( |
| 71 this, &SSLClientSocketOpenSSL::BufferRecvComplete)), | 70 this, &SSLClientSocketOpenSSL::BufferRecvComplete)), |
| 72 transport_send_busy_(false), | 71 transport_send_busy_(false), |
| 73 transport_recv_busy_(false), | 72 transport_recv_busy_(false), |
| 74 user_connect_callback_(NULL), | 73 user_connect_callback_(NULL), |
| 75 user_read_callback_(NULL), | 74 user_read_callback_(NULL), |
| 76 user_write_callback_(NULL), | 75 user_write_callback_(NULL), |
| 77 client_auth_cert_needed_(false), | 76 client_auth_cert_needed_(false), |
| 78 ALLOW_THIS_IN_INITIALIZER_LIST(handshake_io_callback_( | 77 ALLOW_THIS_IN_INITIALIZER_LIST(handshake_io_callback_( |
| 79 this, &SSLClientSocketOpenSSL::OnHandshakeIOComplete)), | 78 this, &SSLClientSocketOpenSSL::OnHandshakeIOComplete)), |
| 80 ssl_(NULL), | 79 ssl_(NULL), |
| 81 transport_bio_(NULL), | 80 transport_bio_(NULL), |
| 82 transport_(transport_socket), | 81 transport_(transport_socket), |
| 83 hostname_(hostname), | 82 host_and_port_(host_and_port), |
| 84 port_(port), | |
| 85 ssl_config_(ssl_config), | 83 ssl_config_(ssl_config), |
| 86 completed_handshake_(false), | 84 completed_handshake_(false), |
| 87 net_log_(transport_socket->socket()->NetLog()) { | 85 net_log_(transport_socket->socket()->NetLog()) { |
| 88 } | 86 } |
| 89 | 87 |
| 90 SSLClientSocketOpenSSL::~SSLClientSocketOpenSSL() { | 88 SSLClientSocketOpenSSL::~SSLClientSocketOpenSSL() { |
| 91 Disconnect(); | 89 Disconnect(); |
| 92 } | 90 } |
| 93 | 91 |
| 94 bool SSLClientSocketOpenSSL::Init() { | 92 bool SSLClientSocketOpenSSL::Init() { |
| 95 DCHECK(!ssl_); | 93 DCHECK(!ssl_); |
| 96 DCHECK(!transport_bio_); | 94 DCHECK(!transport_bio_); |
| 97 | 95 |
| 98 ssl_ = SSL_new(GetOpenSSLInitSingleton()->ssl_ctx()); | 96 ssl_ = SSL_new(GetOpenSSLInitSingleton()->ssl_ctx()); |
| 99 if (!ssl_) { | 97 if (!ssl_) { |
| 100 MaybeLogSSLError(); | 98 MaybeLogSSLError(); |
| 101 return false; | 99 return false; |
| 102 } | 100 } |
| 103 | 101 |
| 104 if (!SSL_set_tlsext_host_name(ssl_, hostname_.c_str())) { | 102 if (!SSL_set_tlsext_host_name(ssl_, host_and_port_.host().c_str())) { |
| 105 MaybeLogSSLError(); | 103 MaybeLogSSLError(); |
| 106 return false; | 104 return false; |
| 107 } | 105 } |
| 108 | 106 |
| 109 BIO* ssl_bio = NULL; | 107 BIO* ssl_bio = NULL; |
| 110 // TODO(joth): Provide explicit write buffer sizes, rather than use defaults? | 108 // TODO(joth): Provide explicit write buffer sizes, rather than use defaults? |
| 111 if (!BIO_new_bio_pair(&ssl_bio, 0, &transport_bio_, 0)) { | 109 if (!BIO_new_bio_pair(&ssl_bio, 0, &transport_bio_, 0)) { |
| 112 MaybeLogSSLError(); | 110 MaybeLogSSLError(); |
| 113 return false; | 111 return false; |
| 114 } | 112 } |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 int SSLClientSocketOpenSSL::DoVerifyCert(int result) { | 341 int SSLClientSocketOpenSSL::DoVerifyCert(int result) { |
| 344 DCHECK(server_cert_); | 342 DCHECK(server_cert_); |
| 345 GotoState(STATE_VERIFY_CERT_COMPLETE); | 343 GotoState(STATE_VERIFY_CERT_COMPLETE); |
| 346 int flags = 0; | 344 int flags = 0; |
| 347 | 345 |
| 348 if (ssl_config_.rev_checking_enabled) | 346 if (ssl_config_.rev_checking_enabled) |
| 349 flags |= X509Certificate::VERIFY_REV_CHECKING_ENABLED; | 347 flags |= X509Certificate::VERIFY_REV_CHECKING_ENABLED; |
| 350 if (ssl_config_.verify_ev_cert) | 348 if (ssl_config_.verify_ev_cert) |
| 351 flags |= X509Certificate::VERIFY_EV_CERT; | 349 flags |= X509Certificate::VERIFY_EV_CERT; |
| 352 verifier_.reset(new CertVerifier); | 350 verifier_.reset(new CertVerifier); |
| 353 return verifier_->Verify(server_cert_, hostname_, flags, | 351 return verifier_->Verify(server_cert_, host_and_port_.host(), flags, |
| 354 &server_cert_verify_result_, | 352 &server_cert_verify_result_, |
| 355 &handshake_io_callback_); | 353 &handshake_io_callback_); |
| 356 } | 354 } |
| 357 | 355 |
| 358 int SSLClientSocketOpenSSL::DoVerifyCertComplete(int result) { | 356 int SSLClientSocketOpenSSL::DoVerifyCertComplete(int result) { |
| 359 verifier_.reset(); | 357 verifier_.reset(); |
| 360 | 358 |
| 361 if (result == OK) { | 359 if (result == OK) { |
| 362 // TODO(joth): Work out if we need to remember the intermediate CA certs | 360 // TODO(joth): Work out if we need to remember the intermediate CA certs |
| 363 // when the server sends them to us, and do so here. | 361 // when the server sends them to us, and do so here. |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 int rv = SSL_write(ssl_, user_write_buf_->data(), user_write_buf_len_); | 731 int rv = SSL_write(ssl_, user_write_buf_->data(), user_write_buf_len_); |
| 734 | 732 |
| 735 if (rv >= 0) | 733 if (rv >= 0) |
| 736 return rv; | 734 return rv; |
| 737 | 735 |
| 738 int err = SSL_get_error(ssl_, rv); | 736 int err = SSL_get_error(ssl_, rv); |
| 739 return MapOpenSSLError(err); | 737 return MapOpenSSLError(err); |
| 740 } | 738 } |
| 741 | 739 |
| 742 } // namespace net | 740 } // namespace net |
| OLD | NEW |