| 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> |
| 11 #include <openssl/bio.h> | 11 #include <openssl/bio.h> |
| 12 #include <openssl/err.h> | 12 #include <openssl/err.h> |
| 13 #include <openssl/ssl.h> | 13 #include <openssl/ssl.h> |
| 14 #include <string.h> | 14 #include <string.h> |
| 15 | 15 |
| 16 #include "base/bind.h" | 16 #include "base/bind.h" |
| 17 #include "base/callback_helpers.h" | 17 #include "base/callback_helpers.h" |
| 18 #include "base/environment.h" | 18 #include "base/environment.h" |
| 19 #include "base/memory/singleton.h" | 19 #include "base/memory/singleton.h" |
| 20 #include "base/metrics/histogram.h" | 20 #include "base/metrics/histogram.h" |
| 21 #include "base/metrics/sparse_histogram.h" |
| 21 #include "base/profiler/scoped_tracker.h" | 22 #include "base/profiler/scoped_tracker.h" |
| 22 #include "base/strings/string_piece.h" | 23 #include "base/strings/string_piece.h" |
| 23 #include "base/synchronization/lock.h" | 24 #include "base/synchronization/lock.h" |
| 24 #include "base/threading/thread_local.h" | 25 #include "base/threading/thread_local.h" |
| 25 #include "crypto/ec_private_key.h" | 26 #include "crypto/ec_private_key.h" |
| 26 #include "crypto/openssl_util.h" | 27 #include "crypto/openssl_util.h" |
| 27 #include "crypto/scoped_openssl_types.h" | 28 #include "crypto/scoped_openssl_types.h" |
| 28 #include "net/base/net_errors.h" | 29 #include "net/base/net_errors.h" |
| 29 #include "net/cert/cert_policy_enforcer.h" | 30 #include "net/cert/cert_policy_enforcer.h" |
| 30 #include "net/cert/cert_verifier.h" | 31 #include "net/cert/cert_verifier.h" |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 // It is an error to create an SSLClientSocket whose context has no | 462 // It is an error to create an SSLClientSocket whose context has no |
| 462 // TransportSecurityState. | 463 // TransportSecurityState. |
| 463 DCHECK(transport_security_state_); | 464 DCHECK(transport_security_state_); |
| 464 | 465 |
| 465 net_log_.BeginEvent(NetLog::TYPE_SSL_CONNECT); | 466 net_log_.BeginEvent(NetLog::TYPE_SSL_CONNECT); |
| 466 | 467 |
| 467 // Set up new ssl object. | 468 // Set up new ssl object. |
| 468 int rv = Init(); | 469 int rv = Init(); |
| 469 if (rv != OK) { | 470 if (rv != OK) { |
| 470 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SSL_CONNECT, rv); | 471 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SSL_CONNECT, rv); |
| 472 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.SSL_Connection_Error", std::abs(rv)); |
| 471 return rv; | 473 return rv; |
| 472 } | 474 } |
| 473 | 475 |
| 474 // Set SSL to client mode. Handshake happens in the loop below. | 476 // Set SSL to client mode. Handshake happens in the loop below. |
| 475 SSL_set_connect_state(ssl_); | 477 SSL_set_connect_state(ssl_); |
| 476 | 478 |
| 477 GotoState(STATE_HANDSHAKE); | 479 GotoState(STATE_HANDSHAKE); |
| 478 rv = DoHandshakeLoop(OK); | 480 rv = DoHandshakeLoop(OK); |
| 479 if (rv == ERR_IO_PENDING) { | 481 if (rv == ERR_IO_PENDING) { |
| 480 user_connect_callback_ = callback; | 482 user_connect_callback_ = callback; |
| 481 } else { | 483 } else { |
| 482 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SSL_CONNECT, rv); | 484 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SSL_CONNECT, rv); |
| 485 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.SSL_Connection_Error", std::abs(rv)); |
| 483 if (rv < OK) | 486 if (rv < OK) |
| 484 OnHandshakeCompletion(); | 487 OnHandshakeCompletion(); |
| 485 } | 488 } |
| 486 | 489 |
| 487 return rv > OK ? OK : rv; | 490 return rv > OK ? OK : rv; |
| 488 } | 491 } |
| 489 | 492 |
| 490 void SSLClientSocketOpenSSL::Disconnect() { | 493 void SSLClientSocketOpenSSL::Disconnect() { |
| 491 // If a handshake was pending (Connect() had been called), notify interested | 494 // If a handshake was pending (Connect() had been called), notify interested |
| 492 // parties that it's been aborted now. If the handshake had already | 495 // parties that it's been aborted now. If the handshake had already |
| (...skipping 859 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1352 server_cert_verify_result_.cert_status &= ~CERT_STATUS_IS_EV; | 1355 server_cert_verify_result_.cert_status &= ~CERT_STATUS_IS_EV; |
| 1353 } | 1356 } |
| 1354 } | 1357 } |
| 1355 } | 1358 } |
| 1356 } | 1359 } |
| 1357 | 1360 |
| 1358 void SSLClientSocketOpenSSL::OnHandshakeIOComplete(int result) { | 1361 void SSLClientSocketOpenSSL::OnHandshakeIOComplete(int result) { |
| 1359 int rv = DoHandshakeLoop(result); | 1362 int rv = DoHandshakeLoop(result); |
| 1360 if (rv != ERR_IO_PENDING) { | 1363 if (rv != ERR_IO_PENDING) { |
| 1361 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SSL_CONNECT, rv); | 1364 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SSL_CONNECT, rv); |
| 1365 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.SSL_Connection_Error", std::abs(rv)); |
| 1362 DoConnectCallback(rv); | 1366 DoConnectCallback(rv); |
| 1363 } | 1367 } |
| 1364 } | 1368 } |
| 1365 | 1369 |
| 1366 void SSLClientSocketOpenSSL::OnSendComplete(int result) { | 1370 void SSLClientSocketOpenSSL::OnSendComplete(int result) { |
| 1367 if (next_handshake_state_ == STATE_HANDSHAKE) { | 1371 if (next_handshake_state_ == STATE_HANDSHAKE) { |
| 1368 // In handshake phase. | 1372 // In handshake phase. |
| 1369 OnHandshakeIOComplete(result); | 1373 OnHandshakeIOComplete(result); |
| 1370 return; | 1374 return; |
| 1371 } | 1375 } |
| (...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2015 ct::SCT_STATUS_LOG_UNKNOWN)); | 2019 ct::SCT_STATUS_LOG_UNKNOWN)); |
| 2016 } | 2020 } |
| 2017 } | 2021 } |
| 2018 | 2022 |
| 2019 scoped_refptr<X509Certificate> | 2023 scoped_refptr<X509Certificate> |
| 2020 SSLClientSocketOpenSSL::GetUnverifiedServerCertificateChain() const { | 2024 SSLClientSocketOpenSSL::GetUnverifiedServerCertificateChain() const { |
| 2021 return server_cert_; | 2025 return server_cert_; |
| 2022 } | 2026 } |
| 2023 | 2027 |
| 2024 } // namespace net | 2028 } // namespace net |
| OLD | NEW |