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/callback_helpers.h" | |
8 #include "base/logging.h" | |
9 #include "base/strings/string_number_conversions.h" | |
10 #include "chrome/browser/ssl/ssl_error_classification.h" | |
11 #include "net/base/load_flags.h" | |
12 #include "net/http/http_response_headers.h" | |
13 #include "net/http/http_util.h" | |
14 #include "net/url_request/url_request_status.h" | |
15 | |
16 CommonNameMismatchHandler::CommonNameMismatchHandler( | |
17 const GURL& request_url, | |
18 const scoped_refptr<net::URLRequestContextGetter>& request_context) | |
19 : request_url_(request_url), request_context_(request_context) {} | |
20 | |
21 CommonNameMismatchHandler::~CommonNameMismatchHandler() {} | |
22 | |
23 // static | |
24 CommonNameMismatchHandler::TestingState | |
25 CommonNameMismatchHandler::testing_state_ = NOT_TESTING; | |
26 | |
27 void CommonNameMismatchHandler::CheckSuggestedUrl( | |
28 const GURL& url, | |
29 const CheckUrlCallback& callback) { | |
30 // Should be used only in tests. | |
31 if (testing_state_ == IGNORE_REQUESTS_FOR_TESTING) | |
32 return; | |
33 | |
34 DCHECK(CalledOnValidThread()); | |
35 DCHECK(!IsCheckingSuggestedUrl()); | |
36 DCHECK(check_url_callback_.is_null()); | |
37 | |
38 check_url_callback_ = callback; | |
39 | |
40 url_fetcher_ = net::URLFetcher::Create(0 /* testing ID */, url, | |
41 net::URLFetcher::HEAD, this); | |
davidben
2015/08/17 18:59:18
If you're always passing zero, you can use the ID-
Bhanu Dev
2015/08/18 05:09:09
Done.
| |
42 url_fetcher_->SetAutomaticallyRetryOn5xx(false); | |
43 url_fetcher_->SetRequestContext(request_context_.get()); | |
44 | |
45 // Can't safely use net::LOAD_DISABLE_CERT_REVOCATION_CHECKING here, | |
46 // since then the connection may be reused without checking the cert. | |
47 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | | |
48 net::LOAD_DO_NOT_SEND_COOKIES | | |
49 net::LOAD_DO_NOT_SEND_AUTH_DATA); | |
50 url_fetcher_->Start(); | |
51 } | |
52 | |
53 // static | |
54 bool CommonNameMismatchHandler::GetSuggestedUrl( | |
55 const GURL& request_url, | |
56 const std::vector<std::string>& dns_names, | |
57 GURL* suggested_url) { | |
58 std::string host_name = request_url.host(); | |
59 std::string www_mismatch_hostname; | |
60 if (!SSLErrorClassification::GetWWWSubDomainMatch(host_name, dns_names, | |
61 &www_mismatch_hostname)) { | |
62 return false; | |
63 } | |
64 // The full URL should be pinged, not just the new hostname. So, get the | |
65 // |suggested_url| with the |request_url|'s hostname replaced with | |
66 // new hostname. Keep resource path, query params the same. | |
67 GURL::Replacements replacements; | |
68 replacements.SetHostStr(www_mismatch_hostname); | |
69 *suggested_url = request_url.ReplaceComponents(replacements); | |
70 return true; | |
71 } | |
72 | |
73 void CommonNameMismatchHandler::Cancel() { | |
74 url_fetcher_.reset(); | |
75 check_url_callback_.Reset(); | |
76 } | |
77 | |
78 void CommonNameMismatchHandler::OnURLFetchComplete( | |
79 const net::URLFetcher* source) { | |
80 DCHECK(CalledOnValidThread()); | |
81 DCHECK(IsCheckingSuggestedUrl()); | |
82 DCHECK_EQ(url_fetcher_.get(), source); | |
83 DCHECK(!check_url_callback_.is_null()); | |
84 DCHECK(!url_fetcher_.get()->GetStatus().is_io_pending()); | |
85 | |
86 SuggestedUrlCheckResult result = SUGGESTED_URL_NOT_AVAILABLE; | |
87 // |suggested_url| and |landing_url| can be different in case of a redirect. | |
88 const GURL& suggested_url = url_fetcher_.get()->GetOriginalURL(); | |
89 const GURL& landing_url = url_fetcher_.get()->GetURL(); | |
davidben
2015/08/17 18:59:18
url_fetcher_->GetOriginalURL(), url_fetcher_->GetU
Bhanu Dev
2015/08/18 05:09:09
Done.
| |
90 | |
91 // Make sure the |landing_url| is a HTTPS page and returns a proper response | |
92 // code. | |
93 if (url_fetcher_.get()->GetResponseCode() == 200 && | |
94 landing_url.SchemeIsCryptographic() && | |
95 landing_url.host() != request_url_.host()) { | |
96 result = SUGGESTED_URL_AVAILABLE; | |
97 } | |
98 url_fetcher_.reset(); | |
99 base::ResetAndReturn(&check_url_callback_).Run(result, suggested_url); | |
davidben
2015/08/17 18:59:18
Using suggested_url here is a UAF since you called
Bhanu Dev
2015/08/18 05:09:09
Done.
| |
100 } | |
101 | |
102 bool CommonNameMismatchHandler::IsCheckingSuggestedUrl() const { | |
103 return url_fetcher_; | |
davidben
2015/08/17 18:59:18
You should run a try job to check, but I think MSV
Ryan Sleevi
2015/08/18 04:31:55
You've raised this before David ;)
No, pointer->b
Bhanu Dev
2015/08/18 05:09:09
Done.
| |
104 } | |
OLD | NEW |