Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_SSL_SSL_ERROR_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_SSL_SSL_ERROR_HANDLER_H_ |
| 6 #define CHROME_BROWSER_SSL_SSL_ERROR_HANDLER_H_ | 6 #define CHROME_BROWSER_SSL_SSL_ERROR_HANDLER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/timer/timer.h" | 13 #include "base/timer/timer.h" |
| 14 #include "chrome/browser/chrome_notification_types.h" | 14 #include "chrome/browser/chrome_notification_types.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/ssl/common_name_mismatch_handler.h" | 16 #include "chrome/browser/ssl/common_name_mismatch_handler.h" |
| 17 #include "chrome/browser/ssl/ssl_cert_reporter.h" | 17 #include "chrome/browser/ssl/ssl_cert_reporter.h" |
| 18 #include "chrome/browser/ssl/ssl_error_assistant.pb.h" | |
| 18 #include "components/ssl_errors/error_classification.h" | 19 #include "components/ssl_errors/error_classification.h" |
| 19 #include "content/public/browser/notification_observer.h" | 20 #include "content/public/browser/notification_observer.h" |
| 20 #include "content/public/browser/notification_registrar.h" | 21 #include "content/public/browser/notification_registrar.h" |
| 21 #include "content/public/browser/restore_type.h" | 22 #include "content/public/browser/restore_type.h" |
| 22 #include "content/public/browser/web_contents_observer.h" | 23 #include "content/public/browser/web_contents_observer.h" |
| 23 #include "content/public/browser/web_contents_user_data.h" | 24 #include "content/public/browser/web_contents_user_data.h" |
| 24 #include "net/ssl/ssl_info.h" | 25 #include "net/ssl/ssl_info.h" |
| 25 #include "url/gurl.h" | 26 #include "url/gurl.h" |
| 26 | 27 |
| 27 class CommonNameMismatchHandler; | 28 class CommonNameMismatchHandler; |
| 28 class Profile; | 29 class Profile; |
| 29 | 30 |
| 30 namespace base { | 31 namespace base { |
| 31 class Clock; | 32 class Clock; |
| 32 class TimeDelta; | 33 class TimeDelta; |
| 33 } | 34 } |
| 34 | 35 |
| 35 namespace content { | 36 namespace content { |
| 36 class WebContents; | 37 class WebContents; |
| 37 } | 38 } |
| 38 | 39 |
| 39 namespace network_time { | 40 namespace network_time { |
| 40 class NetworkTimeTracker; | 41 class NetworkTimeTracker; |
| 41 } | 42 } |
| 42 | 43 |
| 43 // This class is responsible for deciding what type of interstitial to show for | 44 // This class is responsible for deciding what type of interstitial to display |
| 44 // an SSL validation error. The display of the interstitial might be delayed by | 45 // for an SSL validation error and actually display it. The display of the |
| 45 // a few seconds while trying to determine the cause of the error. During this | 46 // interstitial might be delayed by a few seconds while trying to determine the |
| 46 // window, the class will: check for a clock error, wait for a name-mismatch | 47 // cause of the error. During this window, the class will: |
| 47 // suggested URL, or wait for a captive portal result to arrive. If there is a | 48 // - Check for a clock error |
| 48 // name mismatch error and a corresponding suggested URL result arrives in this | 49 // - Check for a known captive portal certificate SPKI |
| 49 // window, the user is redirected to the suggested URL. | 50 // - Wait for a name-mismatch suggested URL |
| 50 // Failing that, if a captive portal detected result arrives in the time window, | 51 // - or Wait for a captive portal result to arrive. |
| 51 // a captive portal error page is shown. If none of these potential error | 52 // Based on the result of these checks, SSLErrorHandler will show a customized |
| 52 // causes match, an SSL interstitial is shown. | 53 // interstitial, redirect to a different suggested URL, or, if all else fails, |
| 54 // show the normal SSL interstitial. | |
| 53 // | 55 // |
| 54 // This class should only be used on the UI thread because its implementation | 56 // This class should only be used on the UI thread because its implementation |
| 55 // uses captive_portal::CaptivePortalService which can only be accessed on the | 57 // uses captive_portal::CaptivePortalService which can only be accessed on the |
| 56 // UI thread. | 58 // UI thread. |
| 57 class SSLErrorHandler : public content::WebContentsUserData<SSLErrorHandler>, | 59 class SSLErrorHandler : public content::WebContentsUserData<SSLErrorHandler>, |
| 58 public content::WebContentsObserver, | 60 public content::WebContentsObserver, |
| 59 public content::NotificationObserver { | 61 public content::NotificationObserver { |
| 60 public: | 62 public: |
| 61 typedef base::Callback<void(content::WebContents*)> TimerStartedCallback; | 63 typedef base::Callback<void(content::WebContents*)> TimerStartedCallback; |
| 62 | 64 |
| 63 // Events for UMA. Do not rename or remove values, add new values to the end. | 65 // Events for UMA. Do not rename or remove values, add new values to the end. |
| 64 // Public for testing. | 66 // Public for testing. |
| 65 enum UMAEvent { | 67 enum UMAEvent { |
| 66 HANDLE_ALL = 0, | 68 HANDLE_ALL = 0, |
| 67 SHOW_CAPTIVE_PORTAL_INTERSTITIAL_NONOVERRIDABLE, | 69 SHOW_CAPTIVE_PORTAL_INTERSTITIAL_NONOVERRIDABLE, |
| 68 SHOW_CAPTIVE_PORTAL_INTERSTITIAL_OVERRIDABLE, | 70 SHOW_CAPTIVE_PORTAL_INTERSTITIAL_OVERRIDABLE, |
| 69 SHOW_SSL_INTERSTITIAL_NONOVERRIDABLE, | 71 SHOW_SSL_INTERSTITIAL_NONOVERRIDABLE, |
| 70 SHOW_SSL_INTERSTITIAL_OVERRIDABLE, | 72 SHOW_SSL_INTERSTITIAL_OVERRIDABLE, |
| 71 WWW_MISMATCH_FOUND, | 73 WWW_MISMATCH_FOUND, |
| 72 WWW_MISMATCH_URL_AVAILABLE, | 74 WWW_MISMATCH_URL_AVAILABLE, |
| 73 WWW_MISMATCH_URL_NOT_AVAILABLE, | 75 WWW_MISMATCH_URL_NOT_AVAILABLE, |
| 74 SHOW_BAD_CLOCK, | 76 SHOW_BAD_CLOCK, |
| 77 CAPTIVE_PORTAL_CERT_FOUND, | |
| 75 SSL_ERROR_HANDLER_EVENT_COUNT | 78 SSL_ERROR_HANDLER_EVENT_COUNT |
| 76 }; | 79 }; |
| 77 | 80 |
| 78 // This delegate allows unit tests to provide their own Chrome specific | 81 // This delegate allows unit tests to provide their own Chrome specific |
| 79 // actions. | 82 // actions. |
| 80 class Delegate { | 83 class Delegate { |
| 81 public: | 84 public: |
| 82 virtual ~Delegate() {} | 85 virtual ~Delegate() {} |
| 83 virtual void CheckForCaptivePortal() = 0; | 86 virtual void CheckForCaptivePortal() = 0; |
| 84 virtual bool GetSuggestedUrl(const std::vector<std::string>& dns_names, | 87 virtual bool GetSuggestedUrl(const std::vector<std::string>& dns_names, |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 101 content::WebContents* web_contents, | 104 content::WebContents* web_contents, |
| 102 int cert_error, | 105 int cert_error, |
| 103 const net::SSLInfo& ssl_info, | 106 const net::SSLInfo& ssl_info, |
| 104 const GURL& request_url, | 107 const GURL& request_url, |
| 105 int options_mask, | 108 int options_mask, |
| 106 std::unique_ptr<SSLCertReporter> ssl_cert_reporter, | 109 std::unique_ptr<SSLCertReporter> ssl_cert_reporter, |
| 107 const base::Callback<void(content::CertificateRequestResultType)>& | 110 const base::Callback<void(content::CertificateRequestResultType)>& |
| 108 callback); | 111 callback); |
| 109 | 112 |
| 110 // Testing methods. | 113 // Testing methods. |
| 114 static void ResetConfigForTesting(); | |
|
Ryan Sleevi
2017/02/01 22:06:06
Usually when I see a much of ForTesting() (or FRIE
meacer
2017/02/02 01:56:05
Agreed, this class accumulated some cruft since it
| |
| 111 static void SetInterstitialDelayForTesting(const base::TimeDelta& delay); | 115 static void SetInterstitialDelayForTesting(const base::TimeDelta& delay); |
| 112 // The callback pointer must remain valid for the duration of error handling. | 116 // The callback pointer must remain valid for the duration of error handling. |
| 113 static void SetInterstitialTimerStartedCallbackForTesting( | 117 static void SetInterstitialTimerStartedCallbackForTesting( |
| 114 TimerStartedCallback* callback); | 118 TimerStartedCallback* callback); |
| 115 static void SetClockForTesting(base::Clock* testing_clock); | 119 static void SetClockForTesting(base::Clock* testing_clock); |
| 116 static void SetNetworkTimeTrackerForTesting( | 120 static void SetNetworkTimeTrackerForTesting( |
| 117 network_time::NetworkTimeTracker* tracker); | 121 network_time::NetworkTimeTracker* tracker); |
| 122 static void SetErrorAssistantProtoForTesting( | |
| 123 const chrome_browser_ssl::SSLErrorAssistantConfig& config_proto); | |
| 118 static std::string GetHistogramNameForTesting(); | 124 static std::string GetHistogramNameForTesting(); |
| 125 static void SetErrorAssistantConfig( | |
| 126 std::unique_ptr<chrome_browser_ssl::SSLErrorAssistantConfig> | |
| 127 config_proto); | |
| 119 bool IsTimerRunningForTesting() const; | 128 bool IsTimerRunningForTesting() const; |
| 120 | 129 |
| 121 protected: | 130 protected: |
| 122 SSLErrorHandler( | 131 SSLErrorHandler( |
| 123 std::unique_ptr<Delegate> delegate, | 132 std::unique_ptr<Delegate> delegate, |
| 124 content::WebContents* web_contents, | 133 content::WebContents* web_contents, |
| 125 Profile* profile, | 134 Profile* profile, |
| 126 int cert_error, | 135 int cert_error, |
| 127 const net::SSLInfo& ssl_info, | 136 const net::SSLInfo& ssl_info, |
| 128 const GURL& request_url, | 137 const GURL& request_url, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 180 base::OneShotTimer timer_; | 189 base::OneShotTimer timer_; |
| 181 | 190 |
| 182 std::unique_ptr<CommonNameMismatchHandler> common_name_mismatch_handler_; | 191 std::unique_ptr<CommonNameMismatchHandler> common_name_mismatch_handler_; |
| 183 | 192 |
| 184 base::WeakPtrFactory<SSLErrorHandler> weak_ptr_factory_; | 193 base::WeakPtrFactory<SSLErrorHandler> weak_ptr_factory_; |
| 185 | 194 |
| 186 DISALLOW_COPY_AND_ASSIGN(SSLErrorHandler); | 195 DISALLOW_COPY_AND_ASSIGN(SSLErrorHandler); |
| 187 }; | 196 }; |
| 188 | 197 |
| 189 #endif // CHROME_BROWSER_SSL_SSL_ERROR_HANDLER_H_ | 198 #endif // CHROME_BROWSER_SSL_SSL_ERROR_HANDLER_H_ |
| OLD | NEW |