| 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 "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
| 8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/ssl/ssl_blocking_page.h" | 13 #include "chrome/browser/ssl/ssl_blocking_page.h" |
| 14 #include "chrome/browser/ssl/ssl_cert_reporter.h" | 14 #include "chrome/browser/ssl/ssl_cert_reporter.h" |
| 15 #include "chrome/browser/ssl/ssl_error_classification.h" | 15 #include "chrome/browser/ssl/ssl_error_classification.h" |
| 16 #include "content/public/browser/notification_service.h" | 16 #include "content/public/browser/notification_service.h" |
| 17 #include "content/public/browser/notification_source.h" | 17 #include "content/public/browser/notification_source.h" |
| 18 #include "content/public/browser/render_frame_host.h" | 18 #include "content/public/browser/render_frame_host.h" |
| 19 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
| 20 #include "net/base/net_errors.h" |
| 20 | 21 |
| 21 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) | 22 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) |
| 22 #include "chrome/browser/captive_portal/captive_portal_service.h" | 23 #include "chrome/browser/captive_portal/captive_portal_service.h" |
| 23 #include "chrome/browser/captive_portal/captive_portal_service_factory.h" | 24 #include "chrome/browser/captive_portal/captive_portal_service_factory.h" |
| 24 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h" | 25 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h" |
| 25 #include "chrome/browser/ssl/captive_portal_blocking_page.h" | 26 #include "chrome/browser/ssl/captive_portal_blocking_page.h" |
| 26 #endif | 27 #endif |
| 27 | 28 |
| 28 namespace { | 29 namespace { |
| 29 | 30 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 } | 150 } |
| 150 | 151 |
| 151 void SSLErrorHandler::StartHandlingError() { | 152 void SSLErrorHandler::StartHandlingError() { |
| 152 RecordUMA(HANDLE_ALL); | 153 RecordUMA(HANDLE_ALL); |
| 153 | 154 |
| 154 std::vector<std::string> dns_names; | 155 std::vector<std::string> dns_names; |
| 155 ssl_info_.cert->GetDNSNames(&dns_names); | 156 ssl_info_.cert->GetDNSNames(&dns_names); |
| 156 DCHECK(!dns_names.empty()); | 157 DCHECK(!dns_names.empty()); |
| 157 GURL suggested_url; | 158 GURL suggested_url; |
| 158 if (IsSSLCommonNameMismatchHandlingEnabled() && | 159 if (IsSSLCommonNameMismatchHandlingEnabled() && |
| 159 ssl_info_.cert_status == net::CERT_STATUS_COMMON_NAME_INVALID && | 160 cert_error_ == net::ERR_CERT_COMMON_NAME_INVALID && |
| 160 GetSuggestedUrl(dns_names, &suggested_url)) { | 161 IsErrorOverridable() && GetSuggestedUrl(dns_names, &suggested_url)) { |
| 161 RecordUMA(WWW_MISMATCH_FOUND); | 162 RecordUMA(WWW_MISMATCH_FOUND); |
| 162 net::CertStatus extra_cert_errors = | 163 net::CertStatus extra_cert_errors = |
| 163 ssl_info_.cert_status ^ net::CERT_STATUS_COMMON_NAME_INVALID; | 164 ssl_info_.cert_status ^ net::CERT_STATUS_COMMON_NAME_INVALID; |
| 164 | 165 |
| 165 // Show the SSL intersitial if |CERT_STATUS_COMMON_NAME_INVALID| is not | 166 // Show the SSL intersitial if |CERT_STATUS_COMMON_NAME_INVALID| is not |
| 166 // the only error. Need not check for captive portal in this case. | 167 // the only error. Need not check for captive portal in this case. |
| 167 // (See the comment below). | 168 // (See the comment below). |
| 168 if (net::IsCertStatusError(extra_cert_errors) && | 169 if (net::IsCertStatusError(extra_cert_errors) && |
| 169 !net::IsCertStatusMinorError(ssl_info_.cert_status)) { | 170 !net::IsCertStatusMinorError(ssl_info_.cert_status)) { |
| 170 ShowSSLInterstitial(); | 171 ShowSSLInterstitial(); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 base::Bind(&SSLErrorHandler::CommonNameMismatchHandlerCallback, | 229 base::Bind(&SSLErrorHandler::CommonNameMismatchHandlerCallback, |
| 229 base::Unretained(this))); | 230 base::Unretained(this))); |
| 230 } | 231 } |
| 231 | 232 |
| 232 void SSLErrorHandler::NavigateToSuggestedURL(const GURL& suggested_url) { | 233 void SSLErrorHandler::NavigateToSuggestedURL(const GURL& suggested_url) { |
| 233 content::NavigationController::LoadURLParams load_params(suggested_url); | 234 content::NavigationController::LoadURLParams load_params(suggested_url); |
| 234 load_params.transition_type = ui::PAGE_TRANSITION_TYPED; | 235 load_params.transition_type = ui::PAGE_TRANSITION_TYPED; |
| 235 web_contents()->GetController().LoadURLWithParams(load_params); | 236 web_contents()->GetController().LoadURLWithParams(load_params); |
| 236 } | 237 } |
| 237 | 238 |
| 239 bool SSLErrorHandler::IsErrorOverridable() const { |
| 240 return SSLBlockingPage::IsOverridable(options_mask_, profile_); |
| 241 } |
| 242 |
| 238 void SSLErrorHandler::CheckForCaptivePortal() { | 243 void SSLErrorHandler::CheckForCaptivePortal() { |
| 239 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) | 244 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) |
| 240 CaptivePortalService* captive_portal_service = | 245 CaptivePortalService* captive_portal_service = |
| 241 CaptivePortalServiceFactory::GetForProfile(profile_); | 246 CaptivePortalServiceFactory::GetForProfile(profile_); |
| 242 captive_portal_service->DetectCaptivePortal(); | 247 captive_portal_service->DetectCaptivePortal(); |
| 243 #else | 248 #else |
| 244 NOTREACHED(); | 249 NOTREACHED(); |
| 245 #endif | 250 #endif |
| 246 } | 251 } |
| 247 | 252 |
| 248 void SSLErrorHandler::ShowCaptivePortalInterstitial(const GURL& landing_url) { | 253 void SSLErrorHandler::ShowCaptivePortalInterstitial(const GURL& landing_url) { |
| 249 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) | 254 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) |
| 250 // Show captive portal blocking page. The interstitial owns the blocking page. | 255 // Show captive portal blocking page. The interstitial owns the blocking page. |
| 251 RecordUMA(SSLBlockingPage::IsOverridable(options_mask_, profile_) | 256 RecordUMA(IsErrorOverridable() |
| 252 ? SHOW_CAPTIVE_PORTAL_INTERSTITIAL_OVERRIDABLE | 257 ? SHOW_CAPTIVE_PORTAL_INTERSTITIAL_OVERRIDABLE |
| 253 : SHOW_CAPTIVE_PORTAL_INTERSTITIAL_NONOVERRIDABLE); | 258 : SHOW_CAPTIVE_PORTAL_INTERSTITIAL_NONOVERRIDABLE); |
| 254 (new CaptivePortalBlockingPage(web_contents_, request_url_, landing_url, | 259 (new CaptivePortalBlockingPage(web_contents_, request_url_, landing_url, |
| 255 ssl_cert_reporter_.Pass(), ssl_info_, | 260 ssl_cert_reporter_.Pass(), ssl_info_, |
| 256 callback_))->Show(); | 261 callback_))->Show(); |
| 257 // Once an interstitial is displayed, no need to keep the handler around. | 262 // Once an interstitial is displayed, no need to keep the handler around. |
| 258 // This is the equivalent of "delete this". | 263 // This is the equivalent of "delete this". |
| 259 web_contents_->RemoveUserData(UserDataKey()); | 264 web_contents_->RemoveUserData(UserDataKey()); |
| 260 #else | 265 #else |
| 261 NOTREACHED(); | 266 NOTREACHED(); |
| 262 #endif | 267 #endif |
| 263 } | 268 } |
| 264 | 269 |
| 265 void SSLErrorHandler::ShowSSLInterstitial() { | 270 void SSLErrorHandler::ShowSSLInterstitial() { |
| 266 // Show SSL blocking page. The interstitial owns the blocking page. | 271 // Show SSL blocking page. The interstitial owns the blocking page. |
| 267 RecordUMA(SSLBlockingPage::IsOverridable(options_mask_, profile_) | 272 RecordUMA(IsErrorOverridable() ? SHOW_SSL_INTERSTITIAL_OVERRIDABLE |
| 268 ? SHOW_SSL_INTERSTITIAL_OVERRIDABLE | 273 : SHOW_SSL_INTERSTITIAL_NONOVERRIDABLE); |
| 269 : SHOW_SSL_INTERSTITIAL_NONOVERRIDABLE); | |
| 270 | 274 |
| 271 (new SSLBlockingPage(web_contents_, cert_error_, ssl_info_, request_url_, | 275 (new SSLBlockingPage(web_contents_, cert_error_, ssl_info_, request_url_, |
| 272 options_mask_, base::Time::NowFromSystemTime(), | 276 options_mask_, base::Time::NowFromSystemTime(), |
| 273 ssl_cert_reporter_.Pass(), callback_)) | 277 ssl_cert_reporter_.Pass(), callback_)) |
| 274 ->Show(); | 278 ->Show(); |
| 275 // Once an interstitial is displayed, no need to keep the handler around. | 279 // Once an interstitial is displayed, no need to keep the handler around. |
| 276 // This is the equivalent of "delete this". | 280 // This is the equivalent of "delete this". |
| 277 web_contents_->RemoveUserData(UserDataKey()); | 281 web_contents_->RemoveUserData(UserDataKey()); |
| 278 } | 282 } |
| 279 | 283 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 SUGGESTED_URL_AVAILABLE) { | 390 SUGGESTED_URL_AVAILABLE) { |
| 387 RecordUMA(WWW_MISMATCH_URL_AVAILABLE); | 391 RecordUMA(WWW_MISMATCH_URL_AVAILABLE); |
| 388 CommonNameMismatchRedirectObserver::AddToConsoleAfterNavigation( | 392 CommonNameMismatchRedirectObserver::AddToConsoleAfterNavigation( |
| 389 web_contents(), request_url_.host(), suggested_url.host()); | 393 web_contents(), request_url_.host(), suggested_url.host()); |
| 390 NavigateToSuggestedURL(suggested_url); | 394 NavigateToSuggestedURL(suggested_url); |
| 391 } else { | 395 } else { |
| 392 RecordUMA(WWW_MISMATCH_URL_NOT_AVAILABLE); | 396 RecordUMA(WWW_MISMATCH_URL_NOT_AVAILABLE); |
| 393 ShowSSLInterstitial(); | 397 ShowSSLInterstitial(); |
| 394 } | 398 } |
| 395 } | 399 } |
| OLD | NEW |