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" |
| 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 |
| 31 RESULT_SUGGESTED_URL_INVALID |
| 32 }; |
| 33 |
| 34 struct Results { |
| 35 Results() : result(RESULT_SUGGESTED_URL_INVALID) {} |
| 36 |
| 37 SuggestedUrlCheckResult result; |
| 38 GURL new_url; |
| 39 }; |
| 40 |
| 41 typedef base::Callback<void(const Results& results)> CheckUrlCallback; |
| 42 |
| 43 explicit CommonNameMismatchHandler( |
| 44 const GURL request_url, |
| 45 const scoped_refptr<net::URLRequestContextGetter>& request_context); |
| 46 ~CommonNameMismatchHandler() override; |
| 47 |
| 48 // Triggers a check to validate suggested URL. After completion, runs the |
| 49 // |callback|. |
| 50 void CheckSuggestedUrl(const GURL& url, |
| 51 const CheckUrlCallback& callback); |
| 52 |
| 53 // Returns true if any other DNS names in the certificate's subject |
| 54 // alternative names list closely match the original request hostname. |
| 55 // If such a domain name exists, writes a suggestion for a new URL |
| 56 // to try into |suggested_url|. |
| 57 static bool GetSuggestedUrl(const GURL& request_url, |
| 58 const std::vector<std::string>& dns_names, |
| 59 GURL* suggested_url); |
| 60 |
| 61 private: |
| 62 // net::URLFetcherDelegate: |
| 63 void OnURLFetchComplete(const net::URLFetcher* source) override; |
| 64 |
| 65 // Takes a |net::URLFetcher| that has finished trying to retrieve the |
| 66 // suggested URL, and fills a |Results| struct based on its result. |
| 67 void GetSuggestedUrlCheckResult(const net::URLFetcher* url_fetcher, |
| 68 Results* results) const; |
| 69 |
| 70 const GURL request_url_; |
| 71 |
| 72 // Returns true if the check is currently running. |
| 73 bool CheckingSuggestedUrl() const; |
| 74 |
| 75 scoped_refptr<net::URLRequestContextGetter> request_context_; |
| 76 |
| 77 CheckUrlCallback check_url_callback_; |
| 78 |
| 79 scoped_ptr<net::URLFetcher> url_fetcher_; |
| 80 |
| 81 DISALLOW_COPY_AND_ASSIGN(CommonNameMismatchHandler); |
| 82 }; |
| 83 |
| 84 #endif // CHROME_BROWSER_SSL_COMMON_NAME_MISMATCH_HANDLER_H_ |
OLD | NEW |