OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | |
meacer
2015/07/09 17:58:55
nit: New style uses "Copyright 2015" instead of "C
Bhanu Dev
2015/07/11 04:00:42
Done.
| |
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 scoped_refptr<net::URLRequestContextGetter>& request_context) | |
17 : 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::CancelUrlCheck() { | |
46 url_fetcher_.reset(); | |
47 check_url_callback_.Reset(); | |
48 } | |
49 | |
50 void CommonNameMismatchHandler::OnURLFetchComplete( | |
51 const net::URLFetcher* source) { | |
52 DCHECK(CalledOnValidThread()); | |
53 DCHECK(CheckingSuggestedUrl()); | |
54 DCHECK_EQ(url_fetcher_.get(), source); | |
55 DCHECK(!check_url_callback_.is_null()); | |
56 | |
57 Results results; | |
58 GetSuggestedUrlCheckResult(url_fetcher_.get(), &results); | |
59 CheckUrlCallback callback = check_url_callback_; | |
60 url_fetcher_.reset(); | |
61 check_url_callback_.Reset(); | |
62 callback.Run(results); | |
63 } | |
64 | |
65 // Takes a net::URLFetcher that has finished trying to retrieve the test | |
66 // URL, and returns a CaptivePortalService::Result based on its result. | |
67 void CommonNameMismatchHandler::GetSuggestedUrlCheckResult( | |
68 const net::URLFetcher* url_fetcher, | |
69 Results* results) const { | |
70 DCHECK(results); | |
71 DCHECK(!url_fetcher->GetStatus().is_io_pending()); | |
72 | |
73 results->result = RESULT_SUGGESTED_URL_INVALID; | |
74 results->new_url = url_fetcher->GetURL(); | |
75 | |
76 if (url_fetcher->GetResponseCode() == 200) { | |
palmer
2015/07/09 19:13:01
Eventually, we will want to accept response codes
Bhanu Dev
2015/07/11 04:00:42
Thanks for the code. |url_fetcher| is automaticall
| |
77 results->result = RESULT_SUGGESTED_URL_VALID; | |
78 return; | |
meacer
2015/07/09 17:58:55
no need for |return|
Bhanu Dev
2015/07/11 04:00:42
Done.
| |
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)) { | |
meacer
2015/07/09 17:58:55
Early exit from here:
if (!...)
return false;
Bhanu Dev
2015/07/11 04:00:42
Done.
| |
90 // Replaces the hostname in the request url with new host name. | |
palmer
2015/07/09 19:13:01
This comment is superfluous.
Bhanu Dev
2015/07/11 04:00:42
Done.
| |
91 GURL::Replacements replacements; | |
92 replacements.SetHostStr(www_mismatch_host_name); | |
93 suggested_url = request_url.ReplaceComponents(replacements); | |
94 return true; | |
95 } else { | |
96 return false; | |
97 } | |
98 } | |
OLD | NEW |