Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ssl/common_name_mismatch_handler.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "base/strings/string_number_conversions.h" | |
| 9 #include "chrome/browser/ssl/ssl_error_classification.h" | |
| 10 #include "net/base/load_flags.h" | |
| 11 #include "net/http/http_response_headers.h" | |
| 12 #include "net/http/http_util.h" | |
| 13 #include "net/url_request/url_request_status.h" | |
| 14 | |
| 15 CommonNameMismatchHandler::CommonNameMismatchHandler(const GURL request_url, | |
| 16 const scoped_refptr<net::URLRequestContextGetter>& request_context) | |
| 17 : request_url_(request_url), request_context_(request_context) { | |
| 18 } | |
| 19 | |
| 20 CommonNameMismatchHandler::~CommonNameMismatchHandler() { | |
| 21 } | |
| 22 | |
| 23 void CommonNameMismatchHandler::CheckSuggestedUrl( | |
| 24 const GURL& url, | |
| 25 const CheckUrlCallback& check_url_callback) { | |
| 26 DCHECK(CalledOnValidThread()); | |
| 27 DCHECK(!CheckingSuggestedUrl()); | |
| 28 DCHECK(check_url_callback_.is_null()); | |
| 29 | |
| 30 check_url_callback_ = check_url_callback; | |
| 31 | |
| 32 // The first 0 means this can use a TestURLFetcherFactory in unit tests. | |
| 33 url_fetcher_ = net::URLFetcher::Create(0, url, net::URLFetcher::HEAD, this); | |
| 34 url_fetcher_->SetAutomaticallyRetryOn5xx(false); | |
| 35 url_fetcher_->SetRequestContext(request_context_.get()); | |
| 36 | |
| 37 // Can't safely use net::LOAD_DISABLE_CERT_REVOCATION_CHECKING here, | |
| 38 // since then the connection may be reused without checking the cert. | |
| 39 url_fetcher_->SetLoadFlags( | |
| 40 net::LOAD_BYPASS_CACHE | net::LOAD_DO_NOT_SAVE_COOKIES | | |
| 41 net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SEND_AUTH_DATA); | |
| 42 url_fetcher_->Start(); | |
| 43 } | |
| 44 | |
| 45 void CommonNameMismatchHandler::OnURLFetchComplete( | |
| 46 const net::URLFetcher* source) { | |
| 47 DCHECK(CalledOnValidThread()); | |
| 48 DCHECK(CheckingSuggestedUrl()); | |
| 49 DCHECK_EQ(url_fetcher_.get(), source); | |
| 50 DCHECK(!check_url_callback_.is_null()); | |
| 51 | |
| 52 Results results; | |
| 53 GetSuggestedUrlCheckResult(url_fetcher_.get(), &results); | |
| 54 CheckUrlCallback callback = check_url_callback_; | |
| 55 url_fetcher_.reset(); | |
| 56 check_url_callback_.Reset(); | |
| 57 callback.Run(results); | |
| 58 } | |
| 59 | |
| 60 // Takes a net::URLFetcher that has finished trying to retrieve the test | |
| 61 // URL, and returns a CaptivePortalService::Result based on its result. | |
| 62 void CommonNameMismatchHandler::GetSuggestedUrlCheckResult( | |
| 63 const net::URLFetcher* url_fetcher, | |
| 64 Results* results) const { | |
| 65 DCHECK(results); | |
| 66 DCHECK(!url_fetcher->GetStatus().is_io_pending()); | |
| 67 | |
| 68 results->result = RESULT_SUGGESTED_URL_INVALID; | |
| 69 | |
| 70 const GURL landing_url = url_fetcher->GetURL(); | |
| 71 | |
| 72 if (url_fetcher->GetResponseCode() == 200 | |
| 73 && landing_url.SchemeIsCryptographic() | |
| 74 && landing_url.host() != request_url_.host()) { | |
| 75 | |
|
meacer
2015/07/15 20:11:46
Remove extra line
Bhanu Dev
2015/07/16 23:38:05
Done.
| |
| 76 results->result = RESULT_SUGGESTED_URL_VALID; | |
| 77 results->new_url = url_fetcher->GetURL(); | |
| 78 } | |
| 79 } | |
| 80 | |
| 81 bool CommonNameMismatchHandler::GetSuggestedUrl( | |
| 82 const GURL& request_url, | |
| 83 const std::vector<std::string>& dns_names, | |
| 84 GURL* suggested_url) { | |
| 85 std::string host_name = request_url.host(); | |
| 86 std::string www_mismatch_host_name; | |
| 87 if (!SSLErrorClassification::GetWWWSubDomainMatch(host_name, dns_names, | |
| 88 &www_mismatch_host_name)) { | |
| 89 return false; | |
| 90 } else { | |
| 91 GURL::Replacements replacements; | |
| 92 replacements.SetHostStr(www_mismatch_host_name); | |
|
meacer
2015/07/15 20:11:45
You might want to document that you are pinging th
Bhanu Dev
2015/07/16 23:38:05
Done.
| |
| 93 *suggested_url = request_url.ReplaceComponents(replacements); | |
| 94 return true; | |
| 95 } | |
| 96 } | |
| OLD | NEW |