| 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/ssl_client_socket_win.h" | 5 #include "net/socket/ssl_client_socket_win.h" | 
| 6 | 6 | 
| 7 #include <schnlsp.h> | 7 #include <schnlsp.h> | 
| 8 #include <map> | 8 #include <map> | 
| 9 | 9 | 
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" | 
| 11 #include "base/lock.h" | 11 #include "base/lock.h" | 
| 12 #include "base/singleton.h" | 12 #include "base/singleton.h" | 
| 13 #include "base/stl_util-inl.h" | 13 #include "base/stl_util-inl.h" | 
| 14 #include "base/string_util.h" | 14 #include "base/string_util.h" | 
| 15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" | 
| 16 #include "net/base/cert_verifier.h" | 16 #include "net/base/cert_verifier.h" | 
| 17 #include "net/base/connection_type_histograms.h" | 17 #include "net/base/connection_type_histograms.h" | 
|  | 18 #include "net/base/host_port_pair.h" | 
| 18 #include "net/base/io_buffer.h" | 19 #include "net/base/io_buffer.h" | 
| 19 #include "net/base/net_log.h" | 20 #include "net/base/net_log.h" | 
| 20 #include "net/base/net_errors.h" | 21 #include "net/base/net_errors.h" | 
| 21 #include "net/base/ssl_cert_request_info.h" | 22 #include "net/base/ssl_cert_request_info.h" | 
| 22 #include "net/base/ssl_connection_status_flags.h" | 23 #include "net/base/ssl_connection_status_flags.h" | 
| 23 #include "net/base/ssl_info.h" | 24 #include "net/base/ssl_info.h" | 
| 24 #include "net/socket/client_socket_handle.h" | 25 #include "net/socket/client_socket_handle.h" | 
| 25 | 26 | 
| 26 #pragma comment(lib, "secur32.lib") | 27 #pragma comment(lib, "secur32.lib") | 
| 27 | 28 | 
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 364 // | 365 // | 
| 365 // Ciphertext is decrypted one SSL record at a time, so recv_buffer_ needs to | 366 // Ciphertext is decrypted one SSL record at a time, so recv_buffer_ needs to | 
| 366 // have room for a full SSL record, with the header and trailer.  Here is the | 367 // have room for a full SSL record, with the header and trailer.  Here is the | 
| 367 // breakdown of the size: | 368 // breakdown of the size: | 
| 368 //   5: SSL record header | 369 //   5: SSL record header | 
| 369 //   16K: SSL record maximum size | 370 //   16K: SSL record maximum size | 
| 370 //   64: >= SSL record trailer (16 or 20 have been observed) | 371 //   64: >= SSL record trailer (16 or 20 have been observed) | 
| 371 static const int kRecvBufferSize = (5 + 16*1024 + 64); | 372 static const int kRecvBufferSize = (5 + 16*1024 + 64); | 
| 372 | 373 | 
| 373 SSLClientSocketWin::SSLClientSocketWin(ClientSocketHandle* transport_socket, | 374 SSLClientSocketWin::SSLClientSocketWin(ClientSocketHandle* transport_socket, | 
| 374                                        const std::string& hostname, | 375                                        const HostPortPair& host_and_port, | 
| 375                                        const SSLConfig& ssl_config) | 376                                        const SSLConfig& ssl_config) | 
| 376     : ALLOW_THIS_IN_INITIALIZER_LIST( | 377     : ALLOW_THIS_IN_INITIALIZER_LIST( | 
| 377         handshake_io_callback_(this, | 378         handshake_io_callback_(this, | 
| 378                                &SSLClientSocketWin::OnHandshakeIOComplete)), | 379                                &SSLClientSocketWin::OnHandshakeIOComplete)), | 
| 379       ALLOW_THIS_IN_INITIALIZER_LIST( | 380       ALLOW_THIS_IN_INITIALIZER_LIST( | 
| 380         read_callback_(this, &SSLClientSocketWin::OnReadComplete)), | 381         read_callback_(this, &SSLClientSocketWin::OnReadComplete)), | 
| 381       ALLOW_THIS_IN_INITIALIZER_LIST( | 382       ALLOW_THIS_IN_INITIALIZER_LIST( | 
| 382         write_callback_(this, &SSLClientSocketWin::OnWriteComplete)), | 383         write_callback_(this, &SSLClientSocketWin::OnWriteComplete)), | 
| 383       transport_(transport_socket), | 384       transport_(transport_socket), | 
| 384       hostname_(hostname), | 385       host_and_port_(host_and_port), | 
| 385       ssl_config_(ssl_config), | 386       ssl_config_(ssl_config), | 
| 386       user_connect_callback_(NULL), | 387       user_connect_callback_(NULL), | 
| 387       user_read_callback_(NULL), | 388       user_read_callback_(NULL), | 
| 388       user_read_buf_len_(0), | 389       user_read_buf_len_(0), | 
| 389       user_write_callback_(NULL), | 390       user_write_callback_(NULL), | 
| 390       user_write_buf_len_(0), | 391       user_write_buf_len_(0), | 
| 391       next_state_(STATE_NONE), | 392       next_state_(STATE_NONE), | 
| 392       creds_(NULL), | 393       creds_(NULL), | 
| 393       isc_status_(SEC_E_OK), | 394       isc_status_(SEC_E_OK), | 
| 394       payload_send_buffer_len_(0), | 395       payload_send_buffer_len_(0), | 
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 446     // SChannel doesn't support TLS compression, so cipher_info doesn't have | 447     // SChannel doesn't support TLS compression, so cipher_info doesn't have | 
| 447     // any field related to the compression method. | 448     // any field related to the compression method. | 
| 448   } | 449   } | 
| 449 | 450 | 
| 450   if (ssl_config_.ssl3_fallback) | 451   if (ssl_config_.ssl3_fallback) | 
| 451     ssl_info->connection_status |= SSL_CONNECTION_SSL3_FALLBACK; | 452     ssl_info->connection_status |= SSL_CONNECTION_SSL3_FALLBACK; | 
| 452 } | 453 } | 
| 453 | 454 | 
| 454 void SSLClientSocketWin::GetSSLCertRequestInfo( | 455 void SSLClientSocketWin::GetSSLCertRequestInfo( | 
| 455     SSLCertRequestInfo* cert_request_info) { | 456     SSLCertRequestInfo* cert_request_info) { | 
| 456   cert_request_info->host_and_port = hostname_;  // TODO(wtc): no port! | 457   cert_request_info->host_and_port = host_and_port_.ToString(); | 
| 457   cert_request_info->client_certs.clear(); | 458   cert_request_info->client_certs.clear(); | 
| 458 | 459 | 
| 459   // Get the certificate_authorities field of the CertificateRequest message. | 460   // Get the certificate_authorities field of the CertificateRequest message. | 
| 460   // Schannel doesn't return the certificate_types field of the | 461   // Schannel doesn't return the certificate_types field of the | 
| 461   // CertificateRequest message to us, so we can't filter the client | 462   // CertificateRequest message to us, so we can't filter the client | 
| 462   // certificates properly. :-( | 463   // certificates properly. :-( | 
| 463   SecPkgContext_IssuerListInfoEx issuer_list; | 464   SecPkgContext_IssuerListInfoEx issuer_list; | 
| 464   SECURITY_STATUS status = QueryContextAttributes( | 465   SECURITY_STATUS status = QueryContextAttributes( | 
| 465       &ctxt_, SECPKG_ATTR_ISSUER_LIST_EX, &issuer_list); | 466       &ctxt_, SECPKG_ATTR_ISSUER_LIST_EX, &issuer_list); | 
| 466   if (status != SEC_E_OK) { | 467   if (status != SEC_E_OK) { | 
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 594   buffer_desc.cBuffers = 1; | 595   buffer_desc.cBuffers = 1; | 
| 595   buffer_desc.pBuffers = &send_buffer_; | 596   buffer_desc.pBuffers = &send_buffer_; | 
| 596   buffer_desc.ulVersion = SECBUFFER_VERSION; | 597   buffer_desc.ulVersion = SECBUFFER_VERSION; | 
| 597 | 598 | 
| 598   TimeStamp expiry; | 599   TimeStamp expiry; | 
| 599   SECURITY_STATUS status; | 600   SECURITY_STATUS status; | 
| 600 | 601 | 
| 601   status = InitializeSecurityContext( | 602   status = InitializeSecurityContext( | 
| 602       creds_, | 603       creds_, | 
| 603       NULL,  // NULL on the first call | 604       NULL,  // NULL on the first call | 
| 604       const_cast<wchar_t*>(ASCIIToWide(hostname_).c_str()), | 605       const_cast<wchar_t*>(ASCIIToWide(host_and_port_.host()).c_str()), | 
| 605       flags, | 606       flags, | 
| 606       0,  // Reserved | 607       0,  // Reserved | 
| 607       0,  // Not used with Schannel. | 608       0,  // Not used with Schannel. | 
| 608       NULL,  // NULL on the first call | 609       NULL,  // NULL on the first call | 
| 609       0,  // Reserved | 610       0,  // Reserved | 
| 610       &ctxt_,  // Receives the new context handle | 611       &ctxt_,  // Receives the new context handle | 
| 611       &buffer_desc, | 612       &buffer_desc, | 
| 612       &out_flags, | 613       &out_flags, | 
| 613       &expiry); | 614       &expiry); | 
| 614   if (status != SEC_I_CONTINUE_NEEDED) { | 615   if (status != SEC_I_CONTINUE_NEEDED) { | 
| (...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1116   next_state_ = STATE_VERIFY_CERT_COMPLETE; | 1117   next_state_ = STATE_VERIFY_CERT_COMPLETE; | 
| 1117 | 1118 | 
| 1118   DCHECK(server_cert_); | 1119   DCHECK(server_cert_); | 
| 1119 | 1120 | 
| 1120   int flags = 0; | 1121   int flags = 0; | 
| 1121   if (ssl_config_.rev_checking_enabled) | 1122   if (ssl_config_.rev_checking_enabled) | 
| 1122     flags |= X509Certificate::VERIFY_REV_CHECKING_ENABLED; | 1123     flags |= X509Certificate::VERIFY_REV_CHECKING_ENABLED; | 
| 1123   if (ssl_config_.verify_ev_cert) | 1124   if (ssl_config_.verify_ev_cert) | 
| 1124     flags |= X509Certificate::VERIFY_EV_CERT; | 1125     flags |= X509Certificate::VERIFY_EV_CERT; | 
| 1125   verifier_.reset(new CertVerifier); | 1126   verifier_.reset(new CertVerifier); | 
| 1126   return verifier_->Verify(server_cert_, hostname_, flags, | 1127   return verifier_->Verify(server_cert_, host_and_port_.host(), flags, | 
| 1127                            &server_cert_verify_result_, | 1128                            &server_cert_verify_result_, | 
| 1128                            &handshake_io_callback_); | 1129                            &handshake_io_callback_); | 
| 1129 } | 1130 } | 
| 1130 | 1131 | 
| 1131 int SSLClientSocketWin::DoVerifyCertComplete(int result) { | 1132 int SSLClientSocketWin::DoVerifyCertComplete(int result) { | 
| 1132   DCHECK(verifier_.get()); | 1133   DCHECK(verifier_.get()); | 
| 1133   verifier_.reset(); | 1134   verifier_.reset(); | 
| 1134 | 1135 | 
| 1135   // If we have been explicitly told to accept this certificate, override the | 1136   // If we have been explicitly told to accept this certificate, override the | 
| 1136   // result of verifier_.Verify. | 1137   // result of verifier_.Verify. | 
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1509     UpdateConnectionTypeHistograms(CONNECTION_SSL_MD2_CA); | 1510     UpdateConnectionTypeHistograms(CONNECTION_SSL_MD2_CA); | 
| 1510 } | 1511 } | 
| 1511 | 1512 | 
| 1512 void SSLClientSocketWin::FreeSendBuffer() { | 1513 void SSLClientSocketWin::FreeSendBuffer() { | 
| 1513   SECURITY_STATUS status = FreeContextBuffer(send_buffer_.pvBuffer); | 1514   SECURITY_STATUS status = FreeContextBuffer(send_buffer_.pvBuffer); | 
| 1514   DCHECK(status == SEC_E_OK); | 1515   DCHECK(status == SEC_E_OK); | 
| 1515   memset(&send_buffer_, 0, sizeof(send_buffer_)); | 1516   memset(&send_buffer_, 0, sizeof(send_buffer_)); | 
| 1516 } | 1517 } | 
| 1517 | 1518 | 
| 1518 }  // namespace net | 1519 }  // namespace net | 
| OLD | NEW | 
|---|