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 #include "chrome/browser/ssl/ssl_error_handler.h" | 5 #include "chrome/browser/ssl/ssl_error_handler.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <unordered_set> | |
| 8 #include <utility> | 9 #include <utility> |
| 9 | 10 |
| 10 #include "base/callback_helpers.h" | 11 #include "base/callback_helpers.h" |
| 11 #include "base/feature_list.h" | 12 #include "base/feature_list.h" |
| 13 #include "base/files/file_util.h" | |
| 12 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
| 13 #include "base/macros.h" | 15 #include "base/macros.h" |
| 14 #include "base/metrics/histogram_macros.h" | 16 #include "base/metrics/histogram_macros.h" |
| 15 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 16 #include "base/threading/non_thread_safe.h" | 18 #include "base/threading/non_thread_safe.h" |
| 17 #include "base/time/clock.h" | 19 #include "base/time/clock.h" |
| 18 #include "base/time/time.h" | 20 #include "base/time/time.h" |
| 19 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/ssl/bad_clock_blocking_page.h" | 23 #include "chrome/browser/ssl/bad_clock_blocking_page.h" |
| 22 #include "chrome/browser/ssl/ssl_blocking_page.h" | 24 #include "chrome/browser/ssl/ssl_blocking_page.h" |
| 23 #include "chrome/browser/ssl/ssl_cert_reporter.h" | 25 #include "chrome/browser/ssl/ssl_cert_reporter.h" |
| 26 #include "chrome/browser/ssl/ssl_error_assistant.pb.h" | |
| 24 #include "chrome/common/features.h" | 27 #include "chrome/common/features.h" |
| 28 #include "chrome/grit/browser_resources.h" | |
| 25 #include "components/network_time/network_time_tracker.h" | 29 #include "components/network_time/network_time_tracker.h" |
| 26 #include "components/ssl_errors/error_classification.h" | 30 #include "components/ssl_errors/error_classification.h" |
| 27 #include "components/ssl_errors/error_info.h" | 31 #include "components/ssl_errors/error_info.h" |
| 32 #include "content/public/browser/browser_thread.h" | |
| 28 #include "content/public/browser/navigation_handle.h" | 33 #include "content/public/browser/navigation_handle.h" |
| 29 #include "content/public/browser/notification_service.h" | 34 #include "content/public/browser/notification_service.h" |
| 30 #include "content/public/browser/notification_source.h" | 35 #include "content/public/browser/notification_source.h" |
| 31 #include "content/public/browser/render_frame_host.h" | 36 #include "content/public/browser/render_frame_host.h" |
| 32 #include "content/public/browser/web_contents.h" | 37 #include "content/public/browser/web_contents.h" |
| 33 #include "net/base/net_errors.h" | 38 #include "net/base/net_errors.h" |
| 39 #include "ui/base/resource/resource_bundle.h" | |
| 34 | 40 |
| 35 #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) | 41 #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) |
| 36 #include "chrome/browser/captive_portal/captive_portal_service.h" | 42 #include "chrome/browser/captive_portal/captive_portal_service.h" |
| 37 #include "chrome/browser/captive_portal/captive_portal_service_factory.h" | 43 #include "chrome/browser/captive_portal/captive_portal_service_factory.h" |
| 38 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h" | 44 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h" |
| 39 #include "chrome/browser/ssl/captive_portal_blocking_page.h" | 45 #include "chrome/browser/ssl/captive_portal_blocking_page.h" |
| 46 #include "third_party/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite .h" | |
| 40 #endif | 47 #endif |
| 41 | 48 |
| 42 namespace { | 49 namespace { |
| 43 | 50 |
| 44 #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) | 51 #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) |
| 45 const base::Feature kCaptivePortalInterstitial{ | 52 const base::Feature kCaptivePortalInterstitial{ |
| 46 "CaptivePortalInterstitial", base::FEATURE_ENABLED_BY_DEFAULT}; | 53 "CaptivePortalInterstitial", base::FEATURE_ENABLED_BY_DEFAULT}; |
| 54 | |
| 55 const base::Feature kCaptivePortalCertificateList{ | |
| 56 "CaptivePortalCertificateList", base::FEATURE_DISABLED_BY_DEFAULT}; | |
| 47 #endif | 57 #endif |
| 48 | 58 |
| 49 const base::Feature kSSLCommonNameMismatchHandling{ | 59 const base::Feature kSSLCommonNameMismatchHandling{ |
| 50 "SSLCommonNameMismatchHandling", base::FEATURE_ENABLED_BY_DEFAULT}; | 60 "SSLCommonNameMismatchHandling", base::FEATURE_ENABLED_BY_DEFAULT}; |
| 51 | 61 |
| 52 const char kHistogram[] = "interstitial.ssl_error_handler"; | |
| 53 | |
| 54 // Default delay in milliseconds before displaying the SSL interstitial. | 62 // Default delay in milliseconds before displaying the SSL interstitial. |
| 55 // This can be changed in tests. | 63 // This can be changed in tests. |
| 56 // - If there is a name mismatch and a suggested URL available result arrives | 64 // - If there is a name mismatch and a suggested URL available result arrives |
| 57 // during this time, the user is redirected to the suggester URL. | 65 // during this time, the user is redirected to the suggester URL. |
| 58 // - If a "captive portal detected" result arrives during this time, | 66 // - If a "captive portal detected" result arrives during this time, |
| 59 // a captive portal interstitial is displayed. | 67 // a captive portal interstitial is displayed. |
| 60 // - Otherwise, an SSL interstitial is displayed. | 68 // - Otherwise, an SSL interstitial is displayed. |
| 61 const int64_t kInterstitialDelayInMilliseconds = 3000; | 69 const int64_t kInterstitialDelayInMilliseconds = 3000; |
| 62 | 70 |
| 71 const char kHistogram[] = "interstitial.ssl_error_handler"; | |
| 72 | |
| 63 // Adds a message to console after navigation commits and then, deletes itself. | 73 // Adds a message to console after navigation commits and then, deletes itself. |
| 64 // Also deletes itself if the navigation is stopped. | 74 // Also deletes itself if the navigation is stopped. |
| 65 class CommonNameMismatchRedirectObserver | 75 class CommonNameMismatchRedirectObserver |
| 66 : public content::WebContentsObserver, | 76 : public content::WebContentsObserver, |
| 67 public content::WebContentsUserData<CommonNameMismatchRedirectObserver> { | 77 public content::WebContentsUserData<CommonNameMismatchRedirectObserver> { |
| 68 public: | 78 public: |
| 69 static void AddToConsoleAfterNavigation( | 79 static void AddToConsoleAfterNavigation( |
| 70 content::WebContents* web_contents, | 80 content::WebContents* web_contents, |
| 71 const std::string& request_url_hostname, | 81 const std::string& request_url_hostname, |
| 72 const std::string& suggested_url_hostname) { | 82 const std::string& suggested_url_hostname) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 | 129 |
| 120 void RecordUMA(SSLErrorHandler::UMAEvent event) { | 130 void RecordUMA(SSLErrorHandler::UMAEvent event) { |
| 121 UMA_HISTOGRAM_ENUMERATION(kHistogram, event, | 131 UMA_HISTOGRAM_ENUMERATION(kHistogram, event, |
| 122 SSLErrorHandler::SSL_ERROR_HANDLER_EVENT_COUNT); | 132 SSLErrorHandler::SSL_ERROR_HANDLER_EVENT_COUNT); |
| 123 } | 133 } |
| 124 | 134 |
| 125 #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) | 135 #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) |
| 126 bool IsCaptivePortalInterstitialEnabled() { | 136 bool IsCaptivePortalInterstitialEnabled() { |
| 127 return base::FeatureList::IsEnabled(kCaptivePortalInterstitial); | 137 return base::FeatureList::IsEnabled(kCaptivePortalInterstitial); |
| 128 } | 138 } |
| 139 | |
| 140 // Reads the SSL error assistant configuration from the resource bundle. | |
| 141 bool ReadErrorAssistantProtoFromResourceBundle( | |
| 142 chrome_browser_ssl::SSLErrorAssistantConfig* proto) { | |
| 143 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 144 DCHECK(proto); | |
| 145 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | |
| 146 base::StringPiece data = | |
| 147 bundle.GetRawDataResource(IDR_SSL_ERROR_ASSISTANT_PB); | |
| 148 google::protobuf::io::ArrayInputStream stream(data.data(), data.size()); | |
| 149 return proto->ParseFromZeroCopyStream(&stream); | |
| 150 } | |
| 151 | |
| 152 std::unique_ptr<std::unordered_set<std::string>> LoadCaptivePortalCertHashes( | |
| 153 const chrome_browser_ssl::SSLErrorAssistantConfig& proto) { | |
| 154 std::unique_ptr<std::unordered_set<std::string>> hashes( | |
|
Bernhard Bauer
2017/02/07 10:53:03
Nit: auto hashes = base::MakeUnique<std::unordered
meacer
2017/02/07 20:22:50
auto'ed. Returning by value wouldn't work, since t
| |
| 155 new std::unordered_set<std::string>()); | |
| 156 for (const chrome_browser_ssl::CaptivePortalCert& cert : | |
| 157 proto.captive_portal_cert()) { | |
| 158 hashes.get()->insert(cert.sha256_hash()); | |
| 159 } | |
| 160 return hashes; | |
| 161 } | |
| 129 #endif | 162 #endif |
| 130 | 163 |
| 131 bool IsSSLCommonNameMismatchHandlingEnabled() { | 164 bool IsSSLCommonNameMismatchHandlingEnabled() { |
| 132 return base::FeatureList::IsEnabled(kSSLCommonNameMismatchHandling); | 165 return base::FeatureList::IsEnabled(kSSLCommonNameMismatchHandling); |
| 133 } | 166 } |
| 134 | 167 |
| 135 // Configuration for SSLErrorHandler. | 168 // Configuration for SSLErrorHandler. |
| 136 class ConfigSingleton : public base::NonThreadSafe { | 169 class ConfigSingleton : public base::NonThreadSafe { |
| 137 public: | 170 public: |
| 138 ConfigSingleton(); | 171 ConfigSingleton(); |
| 139 | 172 |
| 140 base::TimeDelta interstitial_delay() const; | 173 base::TimeDelta interstitial_delay() const; |
| 141 SSLErrorHandler::TimerStartedCallback* timer_started_callback() const; | 174 SSLErrorHandler::TimerStartedCallback* timer_started_callback() const; |
| 142 base::Clock* clock() const; | 175 base::Clock* clock() const; |
| 143 network_time::NetworkTimeTracker* network_time_tracker() const; | 176 network_time::NetworkTimeTracker* network_time_tracker() const; |
| 144 | 177 |
| 178 #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) | |
| 179 // Returns true if any of the SHA256 hashes in |ssl_info| is of a captive | |
| 180 // portal certificate. The set of captive portal hashes is loaded on first | |
| 181 // use. | |
| 182 bool IsKnownCaptivePortalCert(const net::SSLInfo& ssl_info); | |
| 183 #endif | |
| 184 | |
| 185 // Testing methods: | |
| 186 void ResetForTesting(); | |
| 145 void SetInterstitialDelayForTesting(const base::TimeDelta& delay); | 187 void SetInterstitialDelayForTesting(const base::TimeDelta& delay); |
| 146 void SetTimerStartedCallbackForTesting( | 188 void SetTimerStartedCallbackForTesting( |
| 147 SSLErrorHandler::TimerStartedCallback* callback); | 189 SSLErrorHandler::TimerStartedCallback* callback); |
| 148 void SetClockForTesting(base::Clock* clock); | 190 void SetClockForTesting(base::Clock* clock); |
| 149 void SetNetworkTimeTrackerForTesting( | 191 void SetNetworkTimeTrackerForTesting( |
| 150 network_time::NetworkTimeTracker* tracker); | 192 network_time::NetworkTimeTracker* tracker); |
| 151 | 193 |
| 194 #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) | |
| 195 void SetErrorAssistantProtoForTesting( | |
| 196 const chrome_browser_ssl::SSLErrorAssistantConfig& error_assistant_proto); | |
| 197 #endif | |
| 198 | |
| 152 private: | 199 private: |
| 153 base::TimeDelta interstitial_delay_; | 200 base::TimeDelta interstitial_delay_; |
| 154 | 201 |
| 155 // Callback to call when the interstitial timer is started. Used for | 202 // Callback to call when the interstitial timer is started. Used for |
| 156 // testing. | 203 // testing. |
| 157 SSLErrorHandler::TimerStartedCallback* timer_started_callback_ = nullptr; | 204 SSLErrorHandler::TimerStartedCallback* timer_started_callback_ = nullptr; |
| 158 | 205 |
| 159 // The clock to use when deciding which error type to display. Used for | 206 // The clock to use when deciding which error type to display. Used for |
| 160 // testing. | 207 // testing. |
| 161 base::Clock* testing_clock_ = nullptr; | 208 base::Clock* testing_clock_ = nullptr; |
| 162 | 209 |
| 163 network_time::NetworkTimeTracker* network_time_tracker_ = nullptr; | 210 network_time::NetworkTimeTracker* network_time_tracker_ = nullptr; |
| 211 | |
| 212 #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) | |
| 213 // SPKI hashes belonging to certs treated as captive portals. Null until the | |
| 214 // first time IsKnownCaptivePortalCert() or SetErrorAssistantProtoForTesting() | |
| 215 // is called. | |
| 216 std::unique_ptr<std::unordered_set<std::string>> captive_portal_spki_hashes_; | |
| 217 #endif | |
| 164 }; | 218 }; |
| 165 | 219 |
| 166 ConfigSingleton::ConfigSingleton() | 220 ConfigSingleton::ConfigSingleton() |
| 167 : interstitial_delay_( | 221 : interstitial_delay_( |
| 168 base::TimeDelta::FromMilliseconds(kInterstitialDelayInMilliseconds)) { | 222 base::TimeDelta::FromMilliseconds(kInterstitialDelayInMilliseconds)) { |
| 169 } | 223 } |
| 170 | 224 |
| 171 base::TimeDelta ConfigSingleton::interstitial_delay() const { | 225 base::TimeDelta ConfigSingleton::interstitial_delay() const { |
| 172 return interstitial_delay_; | 226 return interstitial_delay_; |
| 173 } | 227 } |
| 174 | 228 |
| 175 SSLErrorHandler::TimerStartedCallback* ConfigSingleton::timer_started_callback() | 229 SSLErrorHandler::TimerStartedCallback* ConfigSingleton::timer_started_callback() |
| 176 const { | 230 const { |
| 177 return timer_started_callback_; | 231 return timer_started_callback_; |
| 178 } | 232 } |
| 179 | 233 |
| 180 network_time::NetworkTimeTracker* ConfigSingleton::network_time_tracker() | 234 network_time::NetworkTimeTracker* ConfigSingleton::network_time_tracker() |
| 181 const { | 235 const { |
| 182 return network_time_tracker_ ? network_time_tracker_ | 236 return network_time_tracker_ ? network_time_tracker_ |
| 183 : g_browser_process->network_time_tracker(); | 237 : g_browser_process->network_time_tracker(); |
| 184 } | 238 } |
| 185 | 239 |
| 186 base::Clock* ConfigSingleton::clock() const { | 240 base::Clock* ConfigSingleton::clock() const { |
| 187 return testing_clock_; | 241 return testing_clock_; |
| 188 } | 242 } |
| 189 | 243 |
| 244 void ConfigSingleton::ResetForTesting() { | |
| 245 interstitial_delay_ = | |
| 246 base::TimeDelta::FromMilliseconds(kInterstitialDelayInMilliseconds); | |
| 247 timer_started_callback_ = nullptr; | |
| 248 network_time_tracker_ = nullptr; | |
| 249 testing_clock_ = nullptr; | |
| 250 #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) | |
| 251 captive_portal_spki_hashes_.reset(); | |
| 252 #endif | |
| 253 } | |
| 254 | |
| 190 void ConfigSingleton::SetInterstitialDelayForTesting( | 255 void ConfigSingleton::SetInterstitialDelayForTesting( |
| 191 const base::TimeDelta& delay) { | 256 const base::TimeDelta& delay) { |
| 192 interstitial_delay_ = delay; | 257 interstitial_delay_ = delay; |
| 193 } | 258 } |
| 194 | 259 |
| 195 void ConfigSingleton::SetTimerStartedCallbackForTesting( | 260 void ConfigSingleton::SetTimerStartedCallbackForTesting( |
| 196 SSLErrorHandler::TimerStartedCallback* callback) { | 261 SSLErrorHandler::TimerStartedCallback* callback) { |
| 197 DCHECK(!callback || !callback->is_null()); | 262 DCHECK(!callback || !callback->is_null()); |
| 198 timer_started_callback_ = callback; | 263 timer_started_callback_ = callback; |
| 199 } | 264 } |
| 200 | 265 |
| 201 void ConfigSingleton::SetClockForTesting(base::Clock* clock) { | 266 void ConfigSingleton::SetClockForTesting(base::Clock* clock) { |
| 202 testing_clock_ = clock; | 267 testing_clock_ = clock; |
| 203 } | 268 } |
| 204 | 269 |
| 205 void ConfigSingleton::SetNetworkTimeTrackerForTesting( | 270 void ConfigSingleton::SetNetworkTimeTrackerForTesting( |
| 206 network_time::NetworkTimeTracker* tracker) { | 271 network_time::NetworkTimeTracker* tracker) { |
| 207 network_time_tracker_ = tracker; | 272 network_time_tracker_ = tracker; |
| 208 } | 273 } |
| 209 | 274 |
| 275 #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) | |
| 276 void ConfigSingleton::SetErrorAssistantProtoForTesting( | |
| 277 const chrome_browser_ssl::SSLErrorAssistantConfig& error_assistant_proto) { | |
| 278 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 279 DCHECK(!captive_portal_spki_hashes_); | |
| 280 captive_portal_spki_hashes_ = | |
| 281 LoadCaptivePortalCertHashes(error_assistant_proto); | |
| 282 } | |
| 283 | |
| 284 bool ConfigSingleton::IsKnownCaptivePortalCert(const net::SSLInfo& ssl_info) { | |
| 285 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 286 if (!captive_portal_spki_hashes_) { | |
| 287 chrome_browser_ssl::SSLErrorAssistantConfig proto; | |
| 288 CHECK(ReadErrorAssistantProtoFromResourceBundle(&proto)); | |
| 289 captive_portal_spki_hashes_ = LoadCaptivePortalCertHashes(proto); | |
| 290 } | |
| 291 | |
| 292 for (const net::HashValue& hash_value : ssl_info.public_key_hashes) { | |
| 293 if (hash_value.tag != net::HASH_VALUE_SHA256) { | |
| 294 continue; | |
| 295 } | |
| 296 if (captive_portal_spki_hashes_->find(hash_value.ToString()) != | |
| 297 captive_portal_spki_hashes_->end()) { | |
| 298 return true; | |
| 299 } | |
| 300 } | |
| 301 return false; | |
| 302 } | |
| 303 #endif | |
| 304 | |
| 210 class SSLErrorHandlerDelegateImpl : public SSLErrorHandler::Delegate { | 305 class SSLErrorHandlerDelegateImpl : public SSLErrorHandler::Delegate { |
| 211 public: | 306 public: |
| 212 SSLErrorHandlerDelegateImpl( | 307 SSLErrorHandlerDelegateImpl( |
| 213 content::WebContents* web_contents, | 308 content::WebContents* web_contents, |
| 214 const net::SSLInfo& ssl_info, | 309 const net::SSLInfo& ssl_info, |
| 215 Profile* const profile, | 310 Profile* const profile, |
| 216 int cert_error, | 311 int cert_error, |
| 217 int options_mask, | 312 int options_mask, |
| 218 const GURL& request_url, | 313 const GURL& request_url, |
| 219 std::unique_ptr<SSLCertReporter> ssl_cert_reporter, | 314 std::unique_ptr<SSLCertReporter> ssl_cert_reporter, |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 358 std::unique_ptr<SSLErrorHandler::Delegate>( | 453 std::unique_ptr<SSLErrorHandler::Delegate>( |
| 359 new SSLErrorHandlerDelegateImpl( | 454 new SSLErrorHandlerDelegateImpl( |
| 360 web_contents, ssl_info, profile, cert_error, options_mask, | 455 web_contents, ssl_info, profile, cert_error, options_mask, |
| 361 request_url, std::move(ssl_cert_reporter), callback)), | 456 request_url, std::move(ssl_cert_reporter), callback)), |
| 362 web_contents, profile, cert_error, ssl_info, request_url, callback); | 457 web_contents, profile, cert_error, ssl_info, request_url, callback); |
| 363 web_contents->SetUserData(UserDataKey(), error_handler); | 458 web_contents->SetUserData(UserDataKey(), error_handler); |
| 364 error_handler->StartHandlingError(); | 459 error_handler->StartHandlingError(); |
| 365 } | 460 } |
| 366 | 461 |
| 367 // static | 462 // static |
| 463 void SSLErrorHandler::ResetConfigForTesting() { | |
| 464 g_config.Pointer()->ResetForTesting(); | |
| 465 } | |
| 466 | |
| 467 // static | |
| 368 void SSLErrorHandler::SetInterstitialDelayForTesting( | 468 void SSLErrorHandler::SetInterstitialDelayForTesting( |
| 369 const base::TimeDelta& delay) { | 469 const base::TimeDelta& delay) { |
| 370 g_config.Pointer()->SetInterstitialDelayForTesting(delay); | 470 g_config.Pointer()->SetInterstitialDelayForTesting(delay); |
| 371 } | 471 } |
| 372 | 472 |
| 373 // static | 473 // static |
| 374 void SSLErrorHandler::SetInterstitialTimerStartedCallbackForTesting( | 474 void SSLErrorHandler::SetInterstitialTimerStartedCallbackForTesting( |
| 375 TimerStartedCallback* callback) { | 475 TimerStartedCallback* callback) { |
| 376 g_config.Pointer()->SetTimerStartedCallbackForTesting(callback); | 476 g_config.Pointer()->SetTimerStartedCallbackForTesting(callback); |
| 377 } | 477 } |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 389 | 489 |
| 390 // static | 490 // static |
| 391 std::string SSLErrorHandler::GetHistogramNameForTesting() { | 491 std::string SSLErrorHandler::GetHistogramNameForTesting() { |
| 392 return kHistogram; | 492 return kHistogram; |
| 393 } | 493 } |
| 394 | 494 |
| 395 bool SSLErrorHandler::IsTimerRunningForTesting() const { | 495 bool SSLErrorHandler::IsTimerRunningForTesting() const { |
| 396 return timer_.IsRunning(); | 496 return timer_.IsRunning(); |
| 397 } | 497 } |
| 398 | 498 |
| 499 void SSLErrorHandler::SetErrorAssistantProtoForTesting( | |
| 500 const chrome_browser_ssl::SSLErrorAssistantConfig& config_proto) { | |
| 501 #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) | |
| 502 g_config.Pointer()->SetErrorAssistantProtoForTesting(config_proto); | |
| 503 #endif | |
| 504 } | |
| 505 | |
| 399 SSLErrorHandler::SSLErrorHandler( | 506 SSLErrorHandler::SSLErrorHandler( |
| 400 std::unique_ptr<Delegate> delegate, | 507 std::unique_ptr<Delegate> delegate, |
| 401 content::WebContents* web_contents, | 508 content::WebContents* web_contents, |
| 402 Profile* profile, | 509 Profile* profile, |
| 403 int cert_error, | 510 int cert_error, |
| 404 const net::SSLInfo& ssl_info, | 511 const net::SSLInfo& ssl_info, |
| 405 const GURL& request_url, | 512 const GURL& request_url, |
| 406 const base::Callback<void(content::CertificateRequestResultType)>& callback) | 513 const base::Callback<void(content::CertificateRequestResultType)>& callback) |
| 407 : content::WebContentsObserver(web_contents), | 514 : content::WebContentsObserver(web_contents), |
| 408 delegate_(std::move(delegate)), | 515 delegate_(std::move(delegate)), |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 419 | 526 |
| 420 void SSLErrorHandler::StartHandlingError() { | 527 void SSLErrorHandler::StartHandlingError() { |
| 421 RecordUMA(HANDLE_ALL); | 528 RecordUMA(HANDLE_ALL); |
| 422 | 529 |
| 423 if (ssl_errors::ErrorInfo::NetErrorToErrorType(cert_error_) == | 530 if (ssl_errors::ErrorInfo::NetErrorToErrorType(cert_error_) == |
| 424 ssl_errors::ErrorInfo::CERT_DATE_INVALID) { | 531 ssl_errors::ErrorInfo::CERT_DATE_INVALID) { |
| 425 HandleCertDateInvalidError(); | 532 HandleCertDateInvalidError(); |
| 426 return; | 533 return; |
| 427 } | 534 } |
| 428 | 535 |
| 536 #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) | |
| 537 if (base::FeatureList::IsEnabled(kCaptivePortalCertificateList) && | |
| 538 cert_error_ == net::ERR_CERT_COMMON_NAME_INVALID && | |
| 539 g_config.Pointer()->IsKnownCaptivePortalCert(ssl_info_)) { | |
| 540 RecordUMA(CAPTIVE_PORTAL_CERT_FOUND); | |
| 541 ShowCaptivePortalInterstitial( | |
| 542 GURL(captive_portal::CaptivePortalDetector::kDefaultURL)); | |
| 543 return; | |
| 544 } | |
| 545 #endif | |
| 546 | |
| 429 std::vector<std::string> dns_names; | 547 std::vector<std::string> dns_names; |
| 430 ssl_info_.cert->GetDNSNames(&dns_names); | 548 ssl_info_.cert->GetDNSNames(&dns_names); |
| 431 DCHECK(!dns_names.empty()); | 549 DCHECK(!dns_names.empty()); |
| 432 GURL suggested_url; | 550 GURL suggested_url; |
| 433 if (IsSSLCommonNameMismatchHandlingEnabled() && | 551 if (IsSSLCommonNameMismatchHandlingEnabled() && |
| 434 cert_error_ == net::ERR_CERT_COMMON_NAME_INVALID && | 552 cert_error_ == net::ERR_CERT_COMMON_NAME_INVALID && |
| 435 delegate_->IsErrorOverridable() && | 553 delegate_->IsErrorOverridable() && |
| 436 delegate_->GetSuggestedUrl(dns_names, &suggested_url)) { | 554 delegate_->GetSuggestedUrl(dns_names, &suggested_url)) { |
| 437 RecordUMA(WWW_MISMATCH_FOUND); | 555 RecordUMA(WWW_MISMATCH_FOUND); |
| 438 net::CertStatus extra_cert_errors = | 556 net::CertStatus extra_cert_errors = |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 628 network_time::NetworkTimeTracker* tracker = | 746 network_time::NetworkTimeTracker* tracker = |
| 629 g_config.Pointer()->network_time_tracker(); | 747 g_config.Pointer()->network_time_tracker(); |
| 630 ssl_errors::ClockState clock_state = ssl_errors::GetClockState(now, tracker); | 748 ssl_errors::ClockState clock_state = ssl_errors::GetClockState(now, tracker); |
| 631 if (clock_state == ssl_errors::CLOCK_STATE_FUTURE || | 749 if (clock_state == ssl_errors::CLOCK_STATE_FUTURE || |
| 632 clock_state == ssl_errors::CLOCK_STATE_PAST) { | 750 clock_state == ssl_errors::CLOCK_STATE_PAST) { |
| 633 ShowBadClockInterstitial(now, clock_state); | 751 ShowBadClockInterstitial(now, clock_state); |
| 634 return; // |this| is deleted after showing the interstitial. | 752 return; // |this| is deleted after showing the interstitial. |
| 635 } | 753 } |
| 636 ShowSSLInterstitial(); | 754 ShowSSLInterstitial(); |
| 637 } | 755 } |
| OLD | NEW |