Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 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 #ifndef CHROME_BROWSER_SSL_COMMON_NAME_MISMATCH_HANDLER_H_ | |
| 6 #define CHROME_BROWSER_SSL_COMMON_NAME_MISMATCH_HANDLER_H_ | |
| 7 | |
| 8 #include "base/basictypes.h" | |
| 9 #include "base/callback.h" | |
| 10 #include "base/compiler_specific.h" | |
|
meacer
2015/07/28 01:18:06
Why do you need this?
Bhanu Dev
2015/07/30 02:39:09
Done.
| |
| 11 #include "base/memory/ref_counted.h" | |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "base/threading/non_thread_safe.h" | |
| 14 #include "base/time/time.h" | |
| 15 #include "net/url_request/url_fetcher.h" | |
| 16 #include "net/url_request/url_fetcher_delegate.h" | |
| 17 #include "net/url_request/url_request_context_getter.h" | |
| 18 #include "url/gurl.h" | |
| 19 | |
| 20 // This class contains methods to get a suggested URL when certificate | |
| 21 // validation fails due to |ERR_CERT_COMMON_NAME_INVALID| and has methods to | |
| 22 // perform a network request to check the validity of new URL. | |
| 23 class CommonNameMismatchHandler : public net::URLFetcherDelegate, | |
| 24 public base::NonThreadSafe { | |
| 25 public: | |
| 26 enum SuggestedUrlCheckResult { | |
| 27 // The request succeeds with good response code i.e. URL exists and its | |
| 28 // certificate is valid. | |
| 29 RESULT_SUGGESTED_URL_VALID, | |
| 30 // Suggested URL is invalid | |
|
meacer
2015/07/28 01:18:05
I still think these should be named AVAILABLE/NOT_
meacer
2015/07/28 01:18:05
nit: Period at the end of comment
Bhanu Dev
2015/07/30 02:39:09
Done.
Bhanu Dev
2015/07/30 02:39:09
Done.
| |
| 31 RESULT_SUGGESTED_URL_INVALID | |
| 32 }; | |
| 33 | |
| 34 enum TestingState { | |
| 35 NOT_TESTING, | |
| 36 // Disables the actual request to the |suggested_url|. | |
| 37 IGNORE_REQUESTS_FOR_TESTING | |
| 38 }; | |
| 39 | |
| 40 struct Results { | |
| 41 Results() : result(RESULT_SUGGESTED_URL_INVALID) {} | |
| 42 | |
| 43 SuggestedUrlCheckResult result; | |
| 44 GURL suggested_url; | |
| 45 }; | |
| 46 | |
| 47 typedef base::Callback<void(const Results& results)> CheckUrlCallback; | |
| 48 | |
| 49 explicit CommonNameMismatchHandler( | |
|
meacer
2015/07/28 01:18:06
No need for explicit with a constructor with more
Bhanu Dev
2015/07/30 02:39:10
Done.
| |
| 50 const GURL request_url, | |
| 51 const scoped_refptr<net::URLRequestContextGetter>& request_context); | |
| 52 ~CommonNameMismatchHandler() override; | |
| 53 | |
| 54 // Triggers a check to validate suggested URL. After completion, runs the | |
| 55 // |callback|. | |
| 56 void CheckSuggestedUrl(const GURL& url, const CheckUrlCallback& callback); | |
| 57 | |
| 58 // Returns true if any other DNS names in the certificate's subject | |
| 59 // alternative names list closely match the original request hostname. | |
| 60 // If such a domain name exists, writes a suggestion for a new URL | |
| 61 // to try into |suggested_url|. | |
| 62 static bool GetSuggestedUrl(const GURL& request_url, | |
| 63 const std::vector<std::string>& dns_names, | |
| 64 GURL* suggested_url); | |
| 65 | |
| 66 static TestingState testing_state_; | |
|
meacer
2015/07/28 01:18:06
Make this private and add a getter/setter.
Bhanu Dev
2015/07/30 02:39:09
Done.
| |
| 67 | |
| 68 private: | |
| 69 // net::URLFetcherDelegate: | |
| 70 void OnURLFetchComplete(const net::URLFetcher* source) override; | |
| 71 | |
| 72 // Takes a |net::URLFetcher| that has finished trying to retrieve the | |
| 73 // suggested URL, and fills a |Results| struct based on its result. | |
| 74 void GetSuggestedUrlCheckResult(const net::URLFetcher* url_fetcher, | |
| 75 Results* results) const; | |
| 76 | |
| 77 const GURL request_url_; | |
| 78 | |
| 79 // Returns true if the check is currently running. | |
| 80 bool CheckingSuggestedUrl() const; | |
|
meacer
2015/07/28 01:18:06
Move this above request_url. Keep methods and memb
Bhanu Dev
2015/07/30 02:39:09
Done.
| |
| 81 | |
| 82 scoped_refptr<net::URLRequestContextGetter> request_context_; | |
| 83 | |
| 84 CheckUrlCallback check_url_callback_; | |
| 85 | |
| 86 scoped_ptr<net::URLFetcher> url_fetcher_; | |
| 87 | |
| 88 DISALLOW_COPY_AND_ASSIGN(CommonNameMismatchHandler); | |
| 89 }; | |
| 90 | |
| 91 #endif // CHROME_BROWSER_SSL_COMMON_NAME_MISMATCH_HANDLER_H_ | |
| OLD | NEW |