Chromium Code Reviews| 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 // 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 <errno.h> | 10 #include <errno.h> |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 32 #include "net/cert/ct_ev_whitelist.h" | 32 #include "net/cert/ct_ev_whitelist.h" |
| 33 #include "net/cert/ct_verifier.h" | 33 #include "net/cert/ct_verifier.h" |
| 34 #include "net/cert/single_request_cert_verifier.h" | 34 #include "net/cert/single_request_cert_verifier.h" |
| 35 #include "net/cert/x509_certificate_net_log_param.h" | 35 #include "net/cert/x509_certificate_net_log_param.h" |
| 36 #include "net/cert/x509_util_openssl.h" | 36 #include "net/cert/x509_util_openssl.h" |
| 37 #include "net/http/transport_security_state.h" | 37 #include "net/http/transport_security_state.h" |
| 38 #include "net/socket/ssl_session_cache_openssl.h" | 38 #include "net/socket/ssl_session_cache_openssl.h" |
| 39 #include "net/ssl/ssl_cert_request_info.h" | 39 #include "net/ssl/ssl_cert_request_info.h" |
| 40 #include "net/ssl/ssl_connection_status_flags.h" | 40 #include "net/ssl/ssl_connection_status_flags.h" |
| 41 #include "net/ssl/ssl_info.h" | 41 #include "net/ssl/ssl_info.h" |
| 42 #include "net/ssl/ssl_socket_config_service.h" | |
| 42 | 43 |
| 43 #if defined(OS_WIN) | 44 #if defined(OS_WIN) |
| 44 #include "base/win/windows_version.h" | 45 #include "base/win/windows_version.h" |
| 45 #endif | 46 #endif |
| 46 | 47 |
| 47 #if defined(USE_OPENSSL_CERTS) | 48 #if defined(USE_OPENSSL_CERTS) |
| 48 #include "net/ssl/openssl_client_key_store.h" | 49 #include "net/ssl/openssl_client_key_store.h" |
| 49 #else | 50 #else |
| 50 #include "net/ssl/openssl_platform_key.h" | 51 #include "net/ssl/openssl_platform_key.h" |
| 51 #endif | 52 #endif |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 367 pending_read_ssl_error_(SSL_ERROR_NONE), | 368 pending_read_ssl_error_(SSL_ERROR_NONE), |
| 368 transport_read_error_(OK), | 369 transport_read_error_(OK), |
| 369 transport_write_error_(OK), | 370 transport_write_error_(OK), |
| 370 server_cert_chain_(new PeerCertificateChain(NULL)), | 371 server_cert_chain_(new PeerCertificateChain(NULL)), |
| 371 completed_connect_(false), | 372 completed_connect_(false), |
| 372 was_ever_used_(false), | 373 was_ever_used_(false), |
| 373 client_auth_cert_needed_(false), | 374 client_auth_cert_needed_(false), |
| 374 cert_verifier_(context.cert_verifier), | 375 cert_verifier_(context.cert_verifier), |
| 375 cert_transparency_verifier_(context.cert_transparency_verifier), | 376 cert_transparency_verifier_(context.cert_transparency_verifier), |
| 376 channel_id_service_(context.channel_id_service), | 377 channel_id_service_(context.channel_id_service), |
| 378 ssl_socket_config_service_(context.ssl_socket_config_service), | |
| 377 ssl_(NULL), | 379 ssl_(NULL), |
| 378 transport_bio_(NULL), | 380 transport_bio_(NULL), |
| 379 transport_(transport_socket.Pass()), | 381 transport_(transport_socket.Pass()), |
| 380 host_and_port_(host_and_port), | 382 host_and_port_(host_and_port), |
| 381 ssl_config_(ssl_config), | 383 ssl_config_(ssl_config), |
| 382 ssl_session_cache_shard_(context.ssl_session_cache_shard), | 384 ssl_session_cache_shard_(context.ssl_session_cache_shard), |
| 383 trying_cached_session_(false), | 385 trying_cached_session_(false), |
| 384 next_handshake_state_(STATE_NONE), | 386 next_handshake_state_(STATE_NONE), |
| 385 npn_status_(kNextProtoUnsupported), | 387 npn_status_(kNextProtoUnsupported), |
| 386 channel_id_xtn_negotiated_(false), | 388 channel_id_xtn_negotiated_(false), |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 463 // TransportSecurityState. | 465 // TransportSecurityState. |
| 464 DCHECK(transport_security_state_); | 466 DCHECK(transport_security_state_); |
| 465 | 467 |
| 466 net_log_.BeginEvent(NetLog::TYPE_SSL_CONNECT); | 468 net_log_.BeginEvent(NetLog::TYPE_SSL_CONNECT); |
| 467 | 469 |
| 468 // Set up new ssl object. | 470 // Set up new ssl object. |
| 469 int rv = Init(); | 471 int rv = Init(); |
| 470 if (rv != OK) { | 472 if (rv != OK) { |
| 471 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SSL_CONNECT, rv); | 473 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SSL_CONNECT, rv); |
| 472 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.SSL_Connection_Error", std::abs(rv)); | 474 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.SSL_Connection_Error", std::abs(rv)); |
| 475 if (ssl_socket_config_service_ && | |
| 476 ssl_socket_config_service_->IsGoogle(host_and_port_)) | |
| 477 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.SSL_Connection_Error_Google", | |
| 478 std::abs(rv)); | |
| 473 return rv; | 479 return rv; |
| 474 } | 480 } |
| 475 | 481 |
| 476 // Set SSL to client mode. Handshake happens in the loop below. | 482 // Set SSL to client mode. Handshake happens in the loop below. |
| 477 SSL_set_connect_state(ssl_); | 483 SSL_set_connect_state(ssl_); |
| 478 | 484 |
| 479 GotoState(STATE_HANDSHAKE); | 485 GotoState(STATE_HANDSHAKE); |
| 480 rv = DoHandshakeLoop(OK); | 486 rv = DoHandshakeLoop(OK); |
| 481 if (rv == ERR_IO_PENDING) { | 487 if (rv == ERR_IO_PENDING) { |
| 482 user_connect_callback_ = callback; | 488 user_connect_callback_ = callback; |
| 483 } else { | 489 } else { |
| 484 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SSL_CONNECT, rv); | 490 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SSL_CONNECT, rv); |
| 485 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.SSL_Connection_Error", std::abs(rv)); | 491 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.SSL_Connection_Error", std::abs(rv)); |
| 492 if (ssl_socket_config_service_ && | |
| 493 ssl_socket_config_service_->IsGoogle(host_and_port_)) | |
| 494 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.SSL_Connection_Error_Google", | |
| 495 std::abs(rv)); | |
| 486 if (rv < OK) | 496 if (rv < OK) |
| 487 OnHandshakeCompletion(); | 497 OnHandshakeCompletion(); |
| 488 } | 498 } |
| 489 | 499 |
| 490 return rv > OK ? OK : rv; | 500 return rv > OK ? OK : rv; |
| 491 } | 501 } |
| 492 | 502 |
| 493 void SSLClientSocketOpenSSL::Disconnect() { | 503 void SSLClientSocketOpenSSL::Disconnect() { |
| 494 // If a handshake was pending (Connect() had been called), notify interested | 504 // If a handshake was pending (Connect() had been called), notify interested |
| 495 // parties that it's been aborted now. If the handshake had already | 505 // parties that it's been aborted now. If the handshake had already |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 875 } | 885 } |
| 876 | 886 |
| 877 if (ssl_config_.signed_cert_timestamps_enabled) { | 887 if (ssl_config_.signed_cert_timestamps_enabled) { |
| 878 SSL_enable_signed_cert_timestamps(ssl_); | 888 SSL_enable_signed_cert_timestamps(ssl_); |
| 879 SSL_enable_ocsp_stapling(ssl_); | 889 SSL_enable_ocsp_stapling(ssl_); |
| 880 } | 890 } |
| 881 | 891 |
| 882 if (IsOCSPStaplingSupported()) | 892 if (IsOCSPStaplingSupported()) |
| 883 SSL_enable_ocsp_stapling(ssl_); | 893 SSL_enable_ocsp_stapling(ssl_); |
| 884 | 894 |
| 895 if (ssl_socket_config_service_) { | |
| 896 if (ssl_socket_config_service_->UseFastRadioPadding(host_and_port_)) { | |
| 897 SSL_enable_fastradio_padding(ssl_, 1); | |
| 898 } else { | |
| 899 SSL_enable_fastradio_padding(ssl_, 0); | |
| 900 } | |
| 901 } | |
| 902 | |
| 885 return OK; | 903 return OK; |
| 886 } | 904 } |
| 887 | 905 |
| 888 void SSLClientSocketOpenSSL::DoReadCallback(int rv) { | 906 void SSLClientSocketOpenSSL::DoReadCallback(int rv) { |
| 889 // Since Run may result in Read being called, clear |user_read_callback_| | 907 // Since Run may result in Read being called, clear |user_read_callback_| |
| 890 // up front. | 908 // up front. |
| 891 if (rv > 0) | 909 if (rv > 0) |
| 892 was_ever_used_ = true; | 910 was_ever_used_ = true; |
| 893 user_read_buf_ = NULL; | 911 user_read_buf_ = NULL; |
| 894 user_read_buf_len_ = 0; | 912 user_read_buf_len_ = 0; |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1356 } | 1374 } |
| 1357 } | 1375 } |
| 1358 } | 1376 } |
| 1359 } | 1377 } |
| 1360 | 1378 |
| 1361 void SSLClientSocketOpenSSL::OnHandshakeIOComplete(int result) { | 1379 void SSLClientSocketOpenSSL::OnHandshakeIOComplete(int result) { |
| 1362 int rv = DoHandshakeLoop(result); | 1380 int rv = DoHandshakeLoop(result); |
| 1363 if (rv != ERR_IO_PENDING) { | 1381 if (rv != ERR_IO_PENDING) { |
| 1364 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SSL_CONNECT, rv); | 1382 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SSL_CONNECT, rv); |
| 1365 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.SSL_Connection_Error", std::abs(rv)); | 1383 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.SSL_Connection_Error", std::abs(rv)); |
| 1384 if (ssl_socket_config_service_ && | |
| 1385 ssl_socket_config_service_->IsGoogle(host_and_port_)) | |
|
Alexei Svitkine (slow)
2015/01/30 18:16:19
Nit: {}
| |
| 1386 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.SSL_Connection_Error_Google", | |
| 1387 std::abs(rv)); | |
| 1366 DoConnectCallback(rv); | 1388 DoConnectCallback(rv); |
| 1367 } | 1389 } |
| 1368 } | 1390 } |
| 1369 | 1391 |
| 1370 void SSLClientSocketOpenSSL::OnSendComplete(int result) { | 1392 void SSLClientSocketOpenSSL::OnSendComplete(int result) { |
| 1371 if (next_handshake_state_ == STATE_HANDSHAKE) { | 1393 if (next_handshake_state_ == STATE_HANDSHAKE) { |
| 1372 // In handshake phase. | 1394 // In handshake phase. |
| 1373 OnHandshakeIOComplete(result); | 1395 OnHandshakeIOComplete(result); |
| 1374 return; | 1396 return; |
| 1375 } | 1397 } |
| (...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2019 ct::SCT_STATUS_LOG_UNKNOWN)); | 2041 ct::SCT_STATUS_LOG_UNKNOWN)); |
| 2020 } | 2042 } |
| 2021 } | 2043 } |
| 2022 | 2044 |
| 2023 scoped_refptr<X509Certificate> | 2045 scoped_refptr<X509Certificate> |
| 2024 SSLClientSocketOpenSSL::GetUnverifiedServerCertificateChain() const { | 2046 SSLClientSocketOpenSSL::GetUnverifiedServerCertificateChain() const { |
| 2025 return server_cert_; | 2047 return server_cert_; |
| 2026 } | 2048 } |
| 2027 | 2049 |
| 2028 } // namespace net | 2050 } // namespace net |
| OLD | NEW |