| 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 "net/http/http_network_transaction.h" | 5 #include "net/http/http_network_transaction.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/format_macros.h" | 13 #include "base/format_macros.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/metrics/field_trial.h" | 15 #include "base/metrics/field_trial.h" |
| 16 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
| 17 #include "base/metrics/sparse_histogram.h" |
| 17 #include "base/profiler/scoped_tracker.h" | 18 #include "base/profiler/scoped_tracker.h" |
| 18 #include "base/stl_util.h" | 19 #include "base/stl_util.h" |
| 19 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
| 20 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" |
| 21 #include "base/strings/stringprintf.h" | 22 #include "base/strings/stringprintf.h" |
| 22 #include "base/time/time.h" | 23 #include "base/time/time.h" |
| 23 #include "base/values.h" | 24 #include "base/values.h" |
| 24 #include "build/build_config.h" | 25 #include "build/build_config.h" |
| 25 #include "net/base/auth.h" | 26 #include "net/base/auth.h" |
| 26 #include "net/base/host_port_pair.h" | 27 #include "net/base/host_port_pair.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 session->http_stream_factory()->ProcessAlternateProtocol( | 89 session->http_stream_factory()->ProcessAlternateProtocol( |
| 89 session->http_server_properties(), | 90 session->http_server_properties(), |
| 90 alternate_protocol_values, | 91 alternate_protocol_values, |
| 91 http_host_port_pair, | 92 http_host_port_pair, |
| 92 *session); | 93 *session); |
| 93 } | 94 } |
| 94 | 95 |
| 95 base::Value* NetLogSSLVersionFallbackCallback( | 96 base::Value* NetLogSSLVersionFallbackCallback( |
| 96 const GURL* url, | 97 const GURL* url, |
| 97 int net_error, | 98 int net_error, |
| 99 SSLFailureState ssl_failure_state, |
| 98 uint16 version_before, | 100 uint16 version_before, |
| 99 uint16 version_after, | 101 uint16 version_after, |
| 100 NetLogCaptureMode /* capture_mode */) { | 102 NetLogCaptureMode /* capture_mode */) { |
| 101 base::DictionaryValue* dict = new base::DictionaryValue(); | 103 base::DictionaryValue* dict = new base::DictionaryValue(); |
| 102 dict->SetString("host_and_port", GetHostAndPort(*url)); | 104 dict->SetString("host_and_port", GetHostAndPort(*url)); |
| 103 dict->SetInteger("net_error", net_error); | 105 dict->SetInteger("net_error", net_error); |
| 106 dict->SetInteger("ssl_failure_state", ssl_failure_state); |
| 104 dict->SetInteger("version_before", version_before); | 107 dict->SetInteger("version_before", version_before); |
| 105 dict->SetInteger("version_after", version_after); | 108 dict->SetInteger("version_after", version_after); |
| 106 return dict; | 109 return dict; |
| 107 } | 110 } |
| 108 | 111 |
| 109 base::Value* NetLogSSLCipherFallbackCallback( | 112 base::Value* NetLogSSLCipherFallbackCallback( |
| 110 const GURL* url, | 113 const GURL* url, |
| 111 int net_error, | 114 int net_error, |
| 112 NetLogCaptureMode /* capture_mode */) { | 115 NetLogCaptureMode /* capture_mode */) { |
| 113 base::DictionaryValue* dict = new base::DictionaryValue(); | 116 base::DictionaryValue* dict = new base::DictionaryValue(); |
| 114 dict->SetString("host_and_port", GetHostAndPort(*url)); | 117 dict->SetString("host_and_port", GetHostAndPort(*url)); |
| 115 dict->SetInteger("net_error", net_error); | 118 dict->SetInteger("net_error", net_error); |
| 116 return dict; | 119 return dict; |
| 117 } | 120 } |
| 118 | 121 |
| 119 } // namespace | 122 } // namespace |
| 120 | 123 |
| 121 //----------------------------------------------------------------------------- | 124 //----------------------------------------------------------------------------- |
| 122 | 125 |
| 123 HttpNetworkTransaction::HttpNetworkTransaction(RequestPriority priority, | 126 HttpNetworkTransaction::HttpNetworkTransaction(RequestPriority priority, |
| 124 HttpNetworkSession* session) | 127 HttpNetworkSession* session) |
| 125 : pending_auth_target_(HttpAuth::AUTH_NONE), | 128 : pending_auth_target_(HttpAuth::AUTH_NONE), |
| 126 io_callback_(base::Bind(&HttpNetworkTransaction::OnIOComplete, | 129 io_callback_(base::Bind(&HttpNetworkTransaction::OnIOComplete, |
| 127 base::Unretained(this))), | 130 base::Unretained(this))), |
| 128 session_(session), | 131 session_(session), |
| 129 request_(NULL), | 132 request_(NULL), |
| 130 priority_(priority), | 133 priority_(priority), |
| 131 headers_valid_(false), | 134 headers_valid_(false), |
| 135 server_ssl_failure_state_(SSL_FAILURE_NONE), |
| 132 fallback_error_code_(ERR_SSL_INAPPROPRIATE_FALLBACK), | 136 fallback_error_code_(ERR_SSL_INAPPROPRIATE_FALLBACK), |
| 137 fallback_failure_state_(SSL_FAILURE_NONE), |
| 133 request_headers_(), | 138 request_headers_(), |
| 134 read_buf_len_(0), | 139 read_buf_len_(0), |
| 135 total_received_bytes_(0), | 140 total_received_bytes_(0), |
| 136 next_state_(STATE_NONE), | 141 next_state_(STATE_NONE), |
| 137 establishing_tunnel_(false), | 142 establishing_tunnel_(false), |
| 138 websocket_handshake_stream_base_create_helper_(NULL) { | 143 websocket_handshake_stream_base_create_helper_(NULL) { |
| 139 session->ssl_config_service()->GetSSLConfig(&server_ssl_config_); | 144 session->ssl_config_service()->GetSSLConfig(&server_ssl_config_); |
| 140 session->GetNextProtos(&server_ssl_config_.next_protos); | 145 session->GetNextProtos(&server_ssl_config_.next_protos); |
| 141 proxy_ssl_config_ = server_ssl_config_; | 146 proxy_ssl_config_ = server_ssl_config_; |
| 142 } | 147 } |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 } | 500 } |
| 496 | 501 |
| 497 void HttpNetworkTransaction::OnWebSocketHandshakeStreamReady( | 502 void HttpNetworkTransaction::OnWebSocketHandshakeStreamReady( |
| 498 const SSLConfig& used_ssl_config, | 503 const SSLConfig& used_ssl_config, |
| 499 const ProxyInfo& used_proxy_info, | 504 const ProxyInfo& used_proxy_info, |
| 500 WebSocketHandshakeStreamBase* stream) { | 505 WebSocketHandshakeStreamBase* stream) { |
| 501 OnStreamReady(used_ssl_config, used_proxy_info, stream); | 506 OnStreamReady(used_ssl_config, used_proxy_info, stream); |
| 502 } | 507 } |
| 503 | 508 |
| 504 void HttpNetworkTransaction::OnStreamFailed(int result, | 509 void HttpNetworkTransaction::OnStreamFailed(int result, |
| 505 const SSLConfig& used_ssl_config) { | 510 const SSLConfig& used_ssl_config, |
| 511 SSLFailureState ssl_failure_state) { |
| 506 DCHECK_EQ(STATE_CREATE_STREAM_COMPLETE, next_state_); | 512 DCHECK_EQ(STATE_CREATE_STREAM_COMPLETE, next_state_); |
| 507 DCHECK_NE(OK, result); | 513 DCHECK_NE(OK, result); |
| 508 DCHECK(stream_request_.get()); | 514 DCHECK(stream_request_.get()); |
| 509 DCHECK(!stream_.get()); | 515 DCHECK(!stream_.get()); |
| 510 server_ssl_config_ = used_ssl_config; | 516 server_ssl_config_ = used_ssl_config; |
| 517 server_ssl_failure_state_ = ssl_failure_state; |
| 511 | 518 |
| 512 OnIOComplete(result); | 519 OnIOComplete(result); |
| 513 } | 520 } |
| 514 | 521 |
| 515 void HttpNetworkTransaction::OnCertificateError( | 522 void HttpNetworkTransaction::OnCertificateError( |
| 516 int result, | 523 int result, |
| 517 const SSLConfig& used_ssl_config, | 524 const SSLConfig& used_ssl_config, |
| 518 const SSLInfo& ssl_info) { | 525 const SSLInfo& ssl_info) { |
| 519 DCHECK_EQ(STATE_CREATE_STREAM_COMPLETE, next_state_); | 526 DCHECK_EQ(STATE_CREATE_STREAM_COMPLETE, next_state_); |
| 520 DCHECK_NE(OK, result); | 527 DCHECK_NE(OK, result); |
| (...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1344 // could trigger ERR_SSL_INAPPROPRIATE_FALLBACK with the initial | 1351 // could trigger ERR_SSL_INAPPROPRIATE_FALLBACK with the initial |
| 1345 // connection. |fallback_error_code_| is initialised to | 1352 // connection. |fallback_error_code_| is initialised to |
| 1346 // ERR_SSL_INAPPROPRIATE_FALLBACK to catch this case. | 1353 // ERR_SSL_INAPPROPRIATE_FALLBACK to catch this case. |
| 1347 error = fallback_error_code_; | 1354 error = fallback_error_code_; |
| 1348 break; | 1355 break; |
| 1349 } | 1356 } |
| 1350 | 1357 |
| 1351 if (should_fallback) { | 1358 if (should_fallback) { |
| 1352 net_log_.AddEvent( | 1359 net_log_.AddEvent( |
| 1353 NetLog::TYPE_SSL_VERSION_FALLBACK, | 1360 NetLog::TYPE_SSL_VERSION_FALLBACK, |
| 1354 base::Bind(&NetLogSSLVersionFallbackCallback, | 1361 base::Bind(&NetLogSSLVersionFallbackCallback, &request_->url, error, |
| 1355 &request_->url, error, server_ssl_config_.version_max, | 1362 server_ssl_failure_state_, server_ssl_config_.version_max, |
| 1356 version_max)); | 1363 version_max)); |
| 1357 fallback_error_code_ = error; | 1364 fallback_error_code_ = error; |
| 1365 fallback_failure_state_ = server_ssl_failure_state_; |
| 1358 server_ssl_config_.version_max = version_max; | 1366 server_ssl_config_.version_max = version_max; |
| 1359 server_ssl_config_.version_fallback = true; | 1367 server_ssl_config_.version_fallback = true; |
| 1360 ResetConnectionAndRequestForResend(); | 1368 ResetConnectionAndRequestForResend(); |
| 1361 error = OK; | 1369 error = OK; |
| 1362 } | 1370 } |
| 1363 | 1371 |
| 1364 return error; | 1372 return error; |
| 1365 } | 1373 } |
| 1366 | 1374 |
| 1367 // This method determines whether it is safe to resend the request after an | 1375 // This method determines whether it is safe to resend the request after an |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1466 // This helps estimate intolerant locally-configured SSL MITMs. | 1474 // This helps estimate intolerant locally-configured SSL MITMs. |
| 1467 const std::string& host = request_->url.host(); | 1475 const std::string& host = request_->url.host(); |
| 1468 if (EndsWith(host, "google.com", true) && | 1476 if (EndsWith(host, "google.com", true) && |
| 1469 (host.size() == 10 || host[host.size() - 11] == '.')) { | 1477 (host.size() == 10 || host[host.size() - 11] == '.')) { |
| 1470 UMA_HISTOGRAM_ENUMERATION("Net.GoogleConnectionUsedSSLVersionFallback2", | 1478 UMA_HISTOGRAM_ENUMERATION("Net.GoogleConnectionUsedSSLVersionFallback2", |
| 1471 fallback, FALLBACK_MAX); | 1479 fallback, FALLBACK_MAX); |
| 1472 } | 1480 } |
| 1473 | 1481 |
| 1474 UMA_HISTOGRAM_BOOLEAN("Net.ConnectionUsedSSLDeprecatedCipherFallback2", | 1482 UMA_HISTOGRAM_BOOLEAN("Net.ConnectionUsedSSLDeprecatedCipherFallback2", |
| 1475 server_ssl_config_.enable_deprecated_cipher_suites); | 1483 server_ssl_config_.enable_deprecated_cipher_suites); |
| 1484 |
| 1485 if (server_ssl_config_.version_fallback) { |
| 1486 // Record the error code which triggered the fallback and the state the |
| 1487 // handshake was in. |
| 1488 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.SSLFallbackErrorCode", |
| 1489 -fallback_error_code_); |
| 1490 UMA_HISTOGRAM_ENUMERATION("Net.SSLFallbackFailureState", |
| 1491 fallback_failure_state_, SSL_FAILURE_MAX); |
| 1492 } |
| 1476 } | 1493 } |
| 1477 | 1494 |
| 1478 HttpResponseHeaders* HttpNetworkTransaction::GetResponseHeaders() const { | 1495 HttpResponseHeaders* HttpNetworkTransaction::GetResponseHeaders() const { |
| 1479 return response_.headers.get(); | 1496 return response_.headers.get(); |
| 1480 } | 1497 } |
| 1481 | 1498 |
| 1482 bool HttpNetworkTransaction::ShouldResendRequest() const { | 1499 bool HttpNetworkTransaction::ShouldResendRequest() const { |
| 1483 bool connection_is_proven = stream_->IsConnectionReused(); | 1500 bool connection_is_proven = stream_->IsConnectionReused(); |
| 1484 bool has_received_headers = GetResponseHeaders() != NULL; | 1501 bool has_received_headers = GetResponseHeaders() != NULL; |
| 1485 | 1502 |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1622 DCHECK(stream_request_); | 1639 DCHECK(stream_request_); |
| 1623 | 1640 |
| 1624 // Since the transaction can restart with auth credentials, it may create a | 1641 // Since the transaction can restart with auth credentials, it may create a |
| 1625 // stream more than once. Accumulate all of the connection attempts across | 1642 // stream more than once. Accumulate all of the connection attempts across |
| 1626 // those streams by appending them to the vector: | 1643 // those streams by appending them to the vector: |
| 1627 for (const auto& attempt : stream_request_->connection_attempts()) | 1644 for (const auto& attempt : stream_request_->connection_attempts()) |
| 1628 connection_attempts_.push_back(attempt); | 1645 connection_attempts_.push_back(attempt); |
| 1629 } | 1646 } |
| 1630 | 1647 |
| 1631 } // namespace net | 1648 } // namespace net |
| OLD | NEW |