Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Side by Side Diff: chrome/browser/ssl/common_name_mismatch_handler.cc

Issue 1223233002: Common Name Mismatch Handler For WWW Subdomain Mismatch case (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Resolving Comments Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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(
16 const GURL request_url,
17 const scoped_refptr<net::URLRequestContextGetter>& request_context)
18 : request_url_(request_url), request_context_(request_context) {
19 }
20
21 CommonNameMismatchHandler::~CommonNameMismatchHandler() {
22 }
23
24 void CommonNameMismatchHandler::CheckSuggestedUrl(
25 const GURL& url,
26 const CheckUrlCallback& callback) {
27 DCHECK(CalledOnValidThread());
28 DCHECK(!CheckingSuggestedUrl());
29 DCHECK(check_url_callback_.is_null());
30
31 check_url_callback_ = callback;
32
33 // The first 0 means this can use a TestURLFetcherFactory in unit tests.
34 url_fetcher_ = net::URLFetcher::Create(0, url, net::URLFetcher::HEAD, this);
35 url_fetcher_->SetAutomaticallyRetryOn5xx(false);
36 url_fetcher_->SetRequestContext(request_context_.get());
37
38 // Can't safely use net::LOAD_DISABLE_CERT_REVOCATION_CHECKING here,
39 // since then the connection may be reused without checking the cert.
40 url_fetcher_->SetLoadFlags(
41 net::LOAD_BYPASS_CACHE | net::LOAD_DO_NOT_SAVE_COOKIES |
42 net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SEND_AUTH_DATA);
43 url_fetcher_->Start();
44 }
45
46 void CommonNameMismatchHandler::OnURLFetchComplete(
47 const net::URLFetcher* source) {
48 DCHECK(CalledOnValidThread());
49 DCHECK(CheckingSuggestedUrl());
50 DCHECK_EQ(url_fetcher_.get(), source);
51 DCHECK(!check_url_callback_.is_null());
52
53 Results results;
54 GetSuggestedUrlCheckResult(url_fetcher_.get(), &results);
55 CheckUrlCallback callback = check_url_callback_;
56 url_fetcher_.reset();
57 check_url_callback_.Reset();
58 callback.Run(results);
59 }
60
61 // Takes a net::URLFetcher that has finished trying to retrieve the test
62 // URL, and returns a CaptivePortalService::Result based on its result.
63 void CommonNameMismatchHandler::GetSuggestedUrlCheckResult(
64 const net::URLFetcher* url_fetcher,
65 Results* results) const {
66 DCHECK(results);
67 DCHECK(!url_fetcher->GetStatus().is_io_pending());
68
69 results->result = RESULT_SUGGESTED_URL_INVALID;
70
71 const GURL landing_url = url_fetcher->GetURL();
palmer 2015/07/17 00:15:59 This could be a reference, to avoid an unnecessary
Bhanu Dev 2015/07/23 20:11:06 Done.
72
73 // Make sure that the |landing_url| is a valid https page.
74 if (url_fetcher->GetResponseCode() == 200 &&
75 landing_url.SchemeIsCryptographic() &&
76 landing_url.host() != request_url_.host()) {
77 results->result = RESULT_SUGGESTED_URL_VALID;
78 results->new_url = url_fetcher->GetURL();
79 }
80 }
81
82 bool CommonNameMismatchHandler::GetSuggestedUrl(
83 const GURL& request_url,
84 const std::vector<std::string>& dns_names,
85 GURL* suggested_url) {
86 std::string host_name = request_url.host();
87 std::string www_mismatch_host_name;
88 if (!SSLErrorClassification::GetWWWSubDomainMatch(host_name, dns_names,
89 &www_mismatch_host_name)) {
90 return false;
91 } else {
92 // The full URL should be pinged, not just the new host name. So, get the
93 // |suggested_url| with the |request_url|'s host name replaced with
94 // new hostname. Keep resource path, query params the same.
95 GURL::Replacements replacements;
96 replacements.SetHostStr(www_mismatch_host_name);
97 *suggested_url = request_url.ReplaceComponents(replacements);
98 return true;
99 }
100 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698