OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_blocking_page.h" | 5 #include "chrome/browser/ssl/ssl_blocking_page.h" |
6 | 6 |
7 #include "base/build_time.h" | 7 #include "base/build_time.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
10 #include "base/i18n/time_formatting.h" | 10 #include "base/i18n/time_formatting.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 #include "grit/chromium_strings.h" | 39 #include "grit/chromium_strings.h" |
40 #include "grit/generated_resources.h" | 40 #include "grit/generated_resources.h" |
41 #include "net/base/hash_value.h" | 41 #include "net/base/hash_value.h" |
42 #include "net/base/net_errors.h" | 42 #include "net/base/net_errors.h" |
43 #include "net/base/net_util.h" | 43 #include "net/base/net_util.h" |
44 #include "ui/base/l10n/l10n_util.h" | 44 #include "ui/base/l10n/l10n_util.h" |
45 #include "ui/base/resource/resource_bundle.h" | 45 #include "ui/base/resource/resource_bundle.h" |
46 #include "ui/base/webui/jstemplate_builder.h" | 46 #include "ui/base/webui/jstemplate_builder.h" |
47 #include "ui/base/webui/web_ui_util.h" | 47 #include "ui/base/webui/web_ui_util.h" |
48 | 48 |
49 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) | |
50 #include "chrome/browser/captive_portal/captive_portal_service.h" | |
51 #include "chrome/browser/captive_portal/captive_portal_service_factory.h" | |
52 #endif | |
53 | |
54 #if defined(ENABLE_EXTENSIONS) | 49 #if defined(ENABLE_EXTENSIONS) |
55 #include "chrome/browser/extensions/api/experience_sampling_private/experience_s
ampling.h" | 50 #include "chrome/browser/extensions/api/experience_sampling_private/experience_s
ampling.h" |
56 #endif | 51 #endif |
57 | 52 |
58 #if defined(OS_WIN) | 53 #if defined(OS_WIN) |
59 #include "base/base_paths_win.h" | 54 #include "base/base_paths_win.h" |
60 #include "base/path_service.h" | 55 #include "base/path_service.h" |
61 #include "base/strings/string16.h" | 56 #include "base/strings/string16.h" |
62 #include "base/win/windows_version.h" | 57 #include "base/win/windows_version.h" |
63 #endif | 58 #endif |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 DONT_PROCEED_NAME, | 94 DONT_PROCEED_NAME, |
100 DONT_PROCEED_DATE, | 95 DONT_PROCEED_DATE, |
101 DONT_PROCEED_AUTHORITY, | 96 DONT_PROCEED_AUTHORITY, |
102 MORE, | 97 MORE, |
103 SHOW_UNDERSTAND, // Used by the summer 2013 Finch trial. Deprecated. | 98 SHOW_UNDERSTAND, // Used by the summer 2013 Finch trial. Deprecated. |
104 SHOW_INTERNAL_HOSTNAME, | 99 SHOW_INTERNAL_HOSTNAME, |
105 PROCEED_INTERNAL_HOSTNAME, | 100 PROCEED_INTERNAL_HOSTNAME, |
106 SHOW_NEW_SITE, | 101 SHOW_NEW_SITE, |
107 PROCEED_NEW_SITE, | 102 PROCEED_NEW_SITE, |
108 PROCEED_MANUAL_NONOVERRIDABLE, | 103 PROCEED_MANUAL_NONOVERRIDABLE, |
109 CAPTIVE_PORTAL_DETECTION_ENABLED, | 104 // Captive Portal errors moved to ssl_error_classification. |
110 CAPTIVE_PORTAL_DETECTION_ENABLED_OVERRIDABLE, | 105 DEPRECATED_CAPTIVE_PORTAL_DETECTION_ENABLED, |
111 CAPTIVE_PORTAL_PROBE_COMPLETED, | 106 DEPRECATED_CAPTIVE_PORTAL_DETECTION_ENABLED_OVERRIDABLE, |
112 CAPTIVE_PORTAL_PROBE_COMPLETED_OVERRIDABLE, | 107 DEPRECATED_CAPTIVE_PORTAL_PROBE_COMPLETED, |
113 CAPTIVE_PORTAL_NO_RESPONSE, | 108 DEPRECATED_CAPTIVE_PORTAL_PROBE_COMPLETED_OVERRIDABLE, |
114 CAPTIVE_PORTAL_NO_RESPONSE_OVERRIDABLE, | 109 DEPRECATED_CAPTIVE_PORTAL_NO_RESPONSE, |
115 CAPTIVE_PORTAL_DETECTED, | 110 DEPRECATED_CAPTIVE_PORTAL_NO_RESPONSE_OVERRIDABLE, |
116 CAPTIVE_PORTAL_DETECTED_OVERRIDABLE, | 111 DEPRECATED_CAPTIVE_PORTAL_DETECTED, |
| 112 DEPRECATED_CAPTIVE_PORTAL_DETECTED_OVERRIDABLE, |
117 UNUSED_BLOCKING_PAGE_EVENT, | 113 UNUSED_BLOCKING_PAGE_EVENT, |
118 }; | 114 }; |
119 | 115 |
120 // Events for UMA. Do not reorder or change! | 116 // Events for UMA. Do not reorder or change! |
121 enum SSLExpirationAndDecision { | 117 enum SSLExpirationAndDecision { |
122 EXPIRED_AND_PROCEED, | 118 EXPIRED_AND_PROCEED, |
123 EXPIRED_AND_DO_NOT_PROCEED, | 119 EXPIRED_AND_DO_NOT_PROCEED, |
124 NOT_EXPIRED_AND_PROCEED, | 120 NOT_EXPIRED_AND_PROCEED, |
125 NOT_EXPIRED_AND_DO_NOT_PROCEED, | 121 NOT_EXPIRED_AND_DO_NOT_PROCEED, |
126 END_OF_SSL_EXPIRATION_AND_DECISION, | 122 END_OF_SSL_EXPIRATION_AND_DECISION, |
(...skipping 29 matching lines...) Expand all Loading... |
156 event, | 152 event, |
157 END_OF_SSL_EXPIRATION_AND_DECISION); | 153 END_OF_SSL_EXPIRATION_AND_DECISION); |
158 } | 154 } |
159 } | 155 } |
160 | 156 |
161 void RecordSSLBlockingPageDetailedStats(bool proceed, | 157 void RecordSSLBlockingPageDetailedStats(bool proceed, |
162 int cert_error, | 158 int cert_error, |
163 bool overridable, | 159 bool overridable, |
164 bool internal, | 160 bool internal, |
165 int num_visits, | 161 int num_visits, |
166 bool captive_portal_detection_enabled, | |
167 bool captive_portal_probe_completed, | |
168 bool captive_portal_no_response, | |
169 bool captive_portal_detected, | |
170 bool expired_but_previously_allowed) { | 162 bool expired_but_previously_allowed) { |
171 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl_error_type", | 163 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl_error_type", |
172 SSLErrorInfo::NetErrorToErrorType(cert_error), SSLErrorInfo::END_OF_ENUM); | 164 SSLErrorInfo::NetErrorToErrorType(cert_error), SSLErrorInfo::END_OF_ENUM); |
173 RecordSSLExpirationPageEventState( | 165 RecordSSLExpirationPageEventState( |
174 expired_but_previously_allowed, proceed, overridable); | 166 expired_but_previously_allowed, proceed, overridable); |
175 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) | |
176 if (captive_portal_detection_enabled) | |
177 RecordSSLBlockingPageEventStats( | |
178 overridable ? | |
179 CAPTIVE_PORTAL_DETECTION_ENABLED_OVERRIDABLE : | |
180 CAPTIVE_PORTAL_DETECTION_ENABLED); | |
181 if (captive_portal_probe_completed) | |
182 RecordSSLBlockingPageEventStats( | |
183 overridable ? | |
184 CAPTIVE_PORTAL_PROBE_COMPLETED_OVERRIDABLE : | |
185 CAPTIVE_PORTAL_PROBE_COMPLETED); | |
186 // Log only one of portal detected and no response results. | |
187 if (captive_portal_detected) | |
188 RecordSSLBlockingPageEventStats( | |
189 overridable ? | |
190 CAPTIVE_PORTAL_DETECTED_OVERRIDABLE : | |
191 CAPTIVE_PORTAL_DETECTED); | |
192 else if (captive_portal_no_response) | |
193 RecordSSLBlockingPageEventStats( | |
194 overridable ? | |
195 CAPTIVE_PORTAL_NO_RESPONSE_OVERRIDABLE : | |
196 CAPTIVE_PORTAL_NO_RESPONSE); | |
197 #endif | |
198 if (!overridable) { | 167 if (!overridable) { |
199 if (proceed) { | 168 if (proceed) { |
200 RecordSSLBlockingPageEventStats(PROCEED_MANUAL_NONOVERRIDABLE); | 169 RecordSSLBlockingPageEventStats(PROCEED_MANUAL_NONOVERRIDABLE); |
201 } | 170 } |
202 // Overridable is false if the user didn't have any option except to turn | 171 // Overridable is false if the user didn't have any option except to turn |
203 // back. If that's the case, don't record some of the metrics. | 172 // back. If that's the case, don't record some of the metrics. |
204 return; | 173 return; |
205 } | 174 } |
206 if (num_visits == 0) | 175 if (num_visits == 0) |
207 RecordSSLBlockingPageEventStats(SHOW_NEW_SITE); | 176 RecordSSLBlockingPageEventStats(SHOW_NEW_SITE); |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 web_contents_(web_contents), | 300 web_contents_(web_contents), |
332 cert_error_(cert_error), | 301 cert_error_(cert_error), |
333 ssl_info_(ssl_info), | 302 ssl_info_(ssl_info), |
334 request_url_(request_url), | 303 request_url_(request_url), |
335 overridable_(options_mask & OVERRIDABLE && | 304 overridable_(options_mask & OVERRIDABLE && |
336 !(options_mask & STRICT_ENFORCEMENT)), | 305 !(options_mask & STRICT_ENFORCEMENT)), |
337 strict_enforcement_((options_mask & STRICT_ENFORCEMENT) != 0), | 306 strict_enforcement_((options_mask & STRICT_ENFORCEMENT) != 0), |
338 interstitial_page_(NULL), | 307 interstitial_page_(NULL), |
339 internal_(false), | 308 internal_(false), |
340 num_visits_(-1), | 309 num_visits_(-1), |
341 captive_portal_detection_enabled_(false), | |
342 captive_portal_probe_completed_(false), | |
343 captive_portal_no_response_(false), | |
344 captive_portal_detected_(false), | |
345 expired_but_previously_allowed_( | 310 expired_but_previously_allowed_( |
346 (options_mask & EXPIRED_BUT_PREVIOUSLY_ALLOWED) != 0) { | 311 (options_mask & EXPIRED_BUT_PREVIOUSLY_ALLOWED) != 0) { |
347 Profile* profile = Profile::FromBrowserContext( | 312 Profile* profile = Profile::FromBrowserContext( |
348 web_contents->GetBrowserContext()); | 313 web_contents->GetBrowserContext()); |
349 // For UMA stats. | 314 // For UMA stats. |
350 if (net::IsHostnameNonUnique(request_url_.HostNoBrackets())) | 315 if (net::IsHostnameNonUnique(request_url_.HostNoBrackets())) |
351 internal_ = true; | 316 internal_ = true; |
352 RecordSSLBlockingPageEventStats(SHOW_ALL); | 317 RecordSSLBlockingPageEventStats(SHOW_ALL); |
353 if (overridable_) { | 318 if (overridable_) { |
354 RecordSSLBlockingPageEventStats(SHOW_OVERRIDABLE); | 319 RecordSSLBlockingPageEventStats(SHOW_OVERRIDABLE); |
355 if (internal_) | 320 if (internal_) |
356 RecordSSLBlockingPageEventStats(SHOW_INTERNAL_HOSTNAME); | 321 RecordSSLBlockingPageEventStats(SHOW_INTERNAL_HOSTNAME); |
357 HistoryService* history_service = HistoryServiceFactory::GetForProfile( | 322 HistoryService* history_service = HistoryServiceFactory::GetForProfile( |
358 profile, Profile::EXPLICIT_ACCESS); | 323 profile, Profile::EXPLICIT_ACCESS); |
359 if (history_service) { | 324 if (history_service) { |
360 history_service->GetVisibleVisitCountToHost( | 325 history_service->GetVisibleVisitCountToHost( |
361 request_url_, | 326 request_url_, |
362 base::Bind(&SSLBlockingPage::OnGotHistoryCount, | 327 base::Bind(&SSLBlockingPage::OnGotHistoryCount, |
363 base::Unretained(this)), | 328 base::Unretained(this)), |
364 &request_tracker_); | 329 &request_tracker_); |
365 } | 330 } |
366 } | 331 } |
367 | 332 |
368 SSLErrorClassification ssl_error_classification( | 333 SSLErrorClassification ssl_error_classification( |
| 334 web_contents_, |
369 base::Time::NowFromSystemTime(), | 335 base::Time::NowFromSystemTime(), |
370 request_url_, | 336 request_url_, |
| 337 cert_error_, |
371 *ssl_info_.cert.get()); | 338 *ssl_info_.cert.get()); |
372 ssl_error_classification.RecordUMAStatistics(overridable_, cert_error_); | 339 ssl_error_classification.RecordUMAStatistics(overridable_); |
373 | 340 |
374 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) | 341 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) |
375 CaptivePortalService* captive_portal_service = | 342 ssl_error_classification.RecordCaptivePortalUMAStatistics(overridable_); |
376 CaptivePortalServiceFactory::GetForProfile(profile); | |
377 captive_portal_detection_enabled_ = captive_portal_service ->enabled(); | |
378 captive_portal_service ->DetectCaptivePortal(); | |
379 registrar_.Add(this, | |
380 chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT, | |
381 content::Source<Profile>(profile)); | |
382 #endif | 343 #endif |
383 | 344 |
384 #if defined(ENABLE_EXTENSIONS) | 345 #if defined(ENABLE_EXTENSIONS) |
385 // ExperienceSampling: Set up new sampling event for this interstitial. | 346 // ExperienceSampling: Set up new sampling event for this interstitial. |
386 std::string event_name(kEventNameBase); | 347 std::string event_name(kEventNameBase); |
387 if (overridable_ && !strict_enforcement_) | 348 if (overridable_ && !strict_enforcement_) |
388 event_name.append(kEventOverridable); | 349 event_name.append(kEventOverridable); |
389 else | 350 else |
390 event_name.append(kEventNotOverridable); | 351 event_name.append(kEventNotOverridable); |
391 event_name.append(net::ErrorToString(cert_error_)); | 352 event_name.append(net::ErrorToString(cert_error_)); |
392 sampling_event_.reset(new ExperienceSamplingEvent( | 353 sampling_event_.reset(new ExperienceSamplingEvent( |
393 event_name, | 354 event_name, |
394 request_url_, | 355 request_url_, |
395 web_contents_->GetLastCommittedURL(), | 356 web_contents_->GetLastCommittedURL(), |
396 web_contents_->GetBrowserContext())); | 357 web_contents_->GetBrowserContext())); |
397 #endif | 358 #endif |
398 | 359 |
399 // Creating an interstitial without showing (e.g. from chrome://interstitials) | 360 // Creating an interstitial without showing (e.g. from chrome://interstitials) |
400 // it leaks memory, so don't create it here. | 361 // it leaks memory, so don't create it here. |
401 } | 362 } |
402 | 363 |
403 SSLBlockingPage::~SSLBlockingPage() { | 364 SSLBlockingPage::~SSLBlockingPage() { |
| 365 // InvalidCommonNameSeverityScore() and InvalidDateSeverityScore() are in the |
| 366 // destructor because they depend on knowing whether captive portal detection |
| 367 // happened before the user made a decision. |
| 368 SSLErrorClassification ssl_error_classification( |
| 369 web_contents_, |
| 370 base::Time::NowFromSystemTime(), |
| 371 request_url_, |
| 372 cert_error_, |
| 373 *ssl_info_.cert.get()); |
| 374 SSLErrorInfo::ErrorType type = |
| 375 SSLErrorInfo::NetErrorToErrorType(cert_error_); |
| 376 switch (type) { |
| 377 case SSLErrorInfo::CERT_DATE_INVALID: { |
| 378 ssl_error_classification.InvalidDateSeverityScore(); |
| 379 break; |
| 380 } |
| 381 case SSLErrorInfo::CERT_COMMON_NAME_INVALID: { |
| 382 ssl_error_classification.InvalidCommonNameSeverityScore(); |
| 383 break; |
| 384 } |
| 385 default: |
| 386 break; |
| 387 } |
404 if (!callback_.is_null()) { | 388 if (!callback_.is_null()) { |
405 RecordSSLBlockingPageDetailedStats(false, | 389 RecordSSLBlockingPageDetailedStats(false, |
406 cert_error_, | 390 cert_error_, |
407 overridable_, | 391 overridable_, |
408 internal_, | 392 internal_, |
409 num_visits_, | 393 num_visits_, |
410 captive_portal_detection_enabled_, | |
411 captive_portal_probe_completed_, | |
412 captive_portal_no_response_, | |
413 captive_portal_detected_, | |
414 expired_but_previously_allowed_); | 394 expired_but_previously_allowed_); |
415 // The page is closed without the user having chosen what to do, default to | 395 // The page is closed without the user having chosen what to do, default to |
416 // deny. | 396 // deny. |
417 NotifyDenyCertificate(); | 397 NotifyDenyCertificate(); |
418 } | 398 } |
419 } | 399 } |
420 | 400 |
421 void SSLBlockingPage::Show() { | 401 void SSLBlockingPage::Show() { |
422 DCHECK(!interstitial_page_); | 402 DCHECK(!interstitial_page_); |
423 interstitial_page_ = InterstitialPage::Create( | 403 interstitial_page_ = InterstitialPage::Create( |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 web_contents_->GetBrowserContext()); | 570 web_contents_->GetBrowserContext()); |
591 renderer_preferences_util::UpdateFromSystemSettings(prefs, profile); | 571 renderer_preferences_util::UpdateFromSystemSettings(prefs, profile); |
592 } | 572 } |
593 | 573 |
594 void SSLBlockingPage::OnProceed() { | 574 void SSLBlockingPage::OnProceed() { |
595 RecordSSLBlockingPageDetailedStats(true, | 575 RecordSSLBlockingPageDetailedStats(true, |
596 cert_error_, | 576 cert_error_, |
597 overridable_, | 577 overridable_, |
598 internal_, | 578 internal_, |
599 num_visits_, | 579 num_visits_, |
600 captive_portal_detection_enabled_, | |
601 captive_portal_probe_completed_, | |
602 captive_portal_no_response_, | |
603 captive_portal_detected_, | |
604 expired_but_previously_allowed_); | 580 expired_but_previously_allowed_); |
605 #if defined(ENABLE_EXTENSIONS) | 581 #if defined(ENABLE_EXTENSIONS) |
606 // ExperienceSampling: Notify that user decided to proceed. | 582 // ExperienceSampling: Notify that user decided to proceed. |
607 if (sampling_event_.get()) | 583 if (sampling_event_.get()) |
608 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kProceed); | 584 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kProceed); |
609 #endif | 585 #endif |
| 586 |
610 // Accepting the certificate resumes the loading of the page. | 587 // Accepting the certificate resumes the loading of the page. |
611 NotifyAllowCertificate(); | 588 NotifyAllowCertificate(); |
612 } | 589 } |
613 | 590 |
614 void SSLBlockingPage::OnDontProceed() { | 591 void SSLBlockingPage::OnDontProceed() { |
615 RecordSSLBlockingPageDetailedStats(false, | 592 RecordSSLBlockingPageDetailedStats(false, |
616 cert_error_, | 593 cert_error_, |
617 overridable_, | 594 overridable_, |
618 internal_, | 595 internal_, |
619 num_visits_, | 596 num_visits_, |
620 captive_portal_detection_enabled_, | |
621 captive_portal_probe_completed_, | |
622 captive_portal_no_response_, | |
623 captive_portal_detected_, | |
624 expired_but_previously_allowed_); | 597 expired_but_previously_allowed_); |
625 #if defined(ENABLE_EXTENSIONS) | 598 #if defined(ENABLE_EXTENSIONS) |
626 // ExperienceSampling: Notify that user decided to not proceed. | 599 // ExperienceSampling: Notify that user decided to not proceed. |
627 // This also occurs if the user navigates away or closes the tab. | 600 // This also occurs if the user navigates away or closes the tab. |
628 if (sampling_event_.get()) | 601 if (sampling_event_.get()) |
629 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kDeny); | 602 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kDeny); |
630 #endif | 603 #endif |
631 NotifyDenyCertificate(); | 604 NotifyDenyCertificate(); |
632 } | 605 } |
633 | 606 |
(...skipping 30 matching lines...) Expand all Loading... |
664 for (; i < 5; i++) { | 637 for (; i < 5; i++) { |
665 strings->SetString(keys[i], std::string()); | 638 strings->SetString(keys[i], std::string()); |
666 } | 639 } |
667 } | 640 } |
668 | 641 |
669 void SSLBlockingPage::OnGotHistoryCount(bool success, | 642 void SSLBlockingPage::OnGotHistoryCount(bool success, |
670 int num_visits, | 643 int num_visits, |
671 base::Time first_visit) { | 644 base::Time first_visit) { |
672 num_visits_ = num_visits; | 645 num_visits_ = num_visits; |
673 } | 646 } |
674 | |
675 void SSLBlockingPage::Observe( | |
676 int type, | |
677 const content::NotificationSource& source, | |
678 const content::NotificationDetails& details) { | |
679 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) | |
680 // When detection is disabled, captive portal service always sends | |
681 // RESULT_INTERNET_CONNECTED. Ignore any probe results in that case. | |
682 if (!captive_portal_detection_enabled_) | |
683 return; | |
684 if (type == chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT) { | |
685 captive_portal_probe_completed_ = true; | |
686 CaptivePortalService::Results* results = | |
687 content::Details<CaptivePortalService::Results>( | |
688 details).ptr(); | |
689 // If a captive portal was detected at any point when the interstitial was | |
690 // displayed, assume that the interstitial was caused by a captive portal. | |
691 // Example scenario: | |
692 // 1- Interstitial displayed and captive portal detected, setting the flag. | |
693 // 2- Captive portal detection automatically opens portal login page. | |
694 // 3- User logs in on the portal login page. | |
695 // A notification will be received here for RESULT_INTERNET_CONNECTED. Make | |
696 // sure we don't clear the captive portal flag, since the interstitial was | |
697 // potentially caused by the captive portal. | |
698 captive_portal_detected_ = captive_portal_detected_ || | |
699 (results->result == captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL); | |
700 // Also keep track of non-HTTP portals and error cases. | |
701 captive_portal_no_response_ = captive_portal_no_response_ || | |
702 (results->result == captive_portal::RESULT_NO_RESPONSE); | |
703 } | |
704 #endif | |
705 } | |
OLD | NEW |