| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chrome/browser/ssl/common_name_mismatch_handler.h" | 5 #include "chrome/browser/ssl/common_name_mismatch_handler.h" |
| 6 | 6 |
| 7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "components/ssl_errors/error_classification.h" | 10 #include "components/ssl_errors/error_classification.h" |
| 11 #include "net/base/load_flags.h" | 11 #include "net/base/load_flags.h" |
| 12 #include "net/http/http_response_headers.h" | 12 #include "net/http/http_response_headers.h" |
| 13 #include "net/http/http_util.h" | 13 #include "net/http/http_util.h" |
| 14 #include "net/traffic_annotation/network_traffic_annotation.h" | 14 #include "net/traffic_annotation/network_traffic_annotation.h" |
| 15 #include "net/url_request/url_request_status.h" | 15 #include "net/url_request/url_request_status.h" |
| 16 | 16 |
| 17 CommonNameMismatchHandler::CommonNameMismatchHandler( | 17 CommonNameMismatchHandler::CommonNameMismatchHandler( |
| 18 const GURL& request_url, | 18 const GURL& request_url, |
| 19 const scoped_refptr<net::URLRequestContextGetter>& request_context) | 19 const scoped_refptr<net::URLRequestContextGetter>& request_context) |
| 20 : request_url_(request_url), request_context_(request_context) {} | 20 : request_url_(request_url), request_context_(request_context) {} |
| 21 | 21 |
| 22 CommonNameMismatchHandler::~CommonNameMismatchHandler() {} | 22 CommonNameMismatchHandler::~CommonNameMismatchHandler() { |
| 23 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 24 } |
| 23 | 25 |
| 24 // static | 26 // static |
| 25 CommonNameMismatchHandler::TestingState | 27 CommonNameMismatchHandler::TestingState |
| 26 CommonNameMismatchHandler::testing_state_ = NOT_TESTING; | 28 CommonNameMismatchHandler::testing_state_ = NOT_TESTING; |
| 27 | 29 |
| 28 void CommonNameMismatchHandler::CheckSuggestedUrl( | 30 void CommonNameMismatchHandler::CheckSuggestedUrl( |
| 29 const GURL& url, | 31 const GURL& url, |
| 30 const CheckUrlCallback& callback) { | 32 const CheckUrlCallback& callback) { |
| 31 // Should be used only in tests. | 33 // Should be used only in tests. |
| 32 if (testing_state_ == IGNORE_REQUESTS_FOR_TESTING) | 34 if (testing_state_ == IGNORE_REQUESTS_FOR_TESTING) |
| 33 return; | 35 return; |
| 34 | 36 |
| 35 DCHECK(CalledOnValidThread()); | 37 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 36 DCHECK(!IsCheckingSuggestedUrl()); | 38 DCHECK(!IsCheckingSuggestedUrl()); |
| 37 DCHECK(check_url_callback_.is_null()); | 39 DCHECK(check_url_callback_.is_null()); |
| 38 | 40 |
| 39 check_url_callback_ = callback; | 41 check_url_callback_ = callback; |
| 40 | 42 |
| 41 // Create traffic annotation tag. | 43 // Create traffic annotation tag. |
| 42 net::NetworkTrafficAnnotationTag traffic_annotation = | 44 net::NetworkTrafficAnnotationTag traffic_annotation = |
| 43 net::DefineNetworkTrafficAnnotation("ssl_name_mismatch_lookup", R"( | 45 net::DefineNetworkTrafficAnnotation("ssl_name_mismatch_lookup", R"( |
| 44 semantics { | 46 semantics { |
| 45 sender: "SSL Name Mismatch Handler" | 47 sender: "SSL Name Mismatch Handler" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 return true; | 100 return true; |
| 99 } | 101 } |
| 100 | 102 |
| 101 void CommonNameMismatchHandler::Cancel() { | 103 void CommonNameMismatchHandler::Cancel() { |
| 102 url_fetcher_.reset(); | 104 url_fetcher_.reset(); |
| 103 check_url_callback_.Reset(); | 105 check_url_callback_.Reset(); |
| 104 } | 106 } |
| 105 | 107 |
| 106 void CommonNameMismatchHandler::OnURLFetchComplete( | 108 void CommonNameMismatchHandler::OnURLFetchComplete( |
| 107 const net::URLFetcher* source) { | 109 const net::URLFetcher* source) { |
| 108 DCHECK(CalledOnValidThread()); | 110 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 109 DCHECK(IsCheckingSuggestedUrl()); | 111 DCHECK(IsCheckingSuggestedUrl()); |
| 110 DCHECK_EQ(url_fetcher_.get(), source); | 112 DCHECK_EQ(url_fetcher_.get(), source); |
| 111 DCHECK(!check_url_callback_.is_null()); | 113 DCHECK(!check_url_callback_.is_null()); |
| 112 DCHECK(!url_fetcher_.get()->GetStatus().is_io_pending()); | 114 DCHECK(!url_fetcher_.get()->GetStatus().is_io_pending()); |
| 113 | 115 |
| 114 SuggestedUrlCheckResult result = SUGGESTED_URL_NOT_AVAILABLE; | 116 SuggestedUrlCheckResult result = SUGGESTED_URL_NOT_AVAILABLE; |
| 115 // Save a copy of |suggested_url| so it can be used after |url_fetcher_| | 117 // Save a copy of |suggested_url| so it can be used after |url_fetcher_| |
| 116 // is destroyed. | 118 // is destroyed. |
| 117 const GURL suggested_url = url_fetcher_->GetOriginalURL(); | 119 const GURL suggested_url = url_fetcher_->GetOriginalURL(); |
| 118 const GURL& landing_url = url_fetcher_->GetURL(); | 120 const GURL& landing_url = url_fetcher_->GetURL(); |
| 119 | 121 |
| 120 // Make sure the |landing_url| is a HTTPS page and returns a proper response | 122 // Make sure the |landing_url| is a HTTPS page and returns a proper response |
| 121 // code. | 123 // code. |
| 122 if (url_fetcher_.get()->GetResponseCode() == 200 && | 124 if (url_fetcher_.get()->GetResponseCode() == 200 && |
| 123 landing_url.SchemeIsCryptographic() && | 125 landing_url.SchemeIsCryptographic() && |
| 124 landing_url.host() != request_url_.host()) { | 126 landing_url.host() != request_url_.host()) { |
| 125 result = SUGGESTED_URL_AVAILABLE; | 127 result = SUGGESTED_URL_AVAILABLE; |
| 126 } | 128 } |
| 127 url_fetcher_.reset(); | 129 url_fetcher_.reset(); |
| 128 base::ResetAndReturn(&check_url_callback_).Run(result, suggested_url); | 130 base::ResetAndReturn(&check_url_callback_).Run(result, suggested_url); |
| 129 } | 131 } |
| 130 | 132 |
| 131 bool CommonNameMismatchHandler::IsCheckingSuggestedUrl() const { | 133 bool CommonNameMismatchHandler::IsCheckingSuggestedUrl() const { |
| 132 return !!url_fetcher_; | 134 return !!url_fetcher_; |
| 133 } | 135 } |
| OLD | NEW |