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_classification.h" | 5 #include "chrome/browser/ssl/ssl_error_classification.h" |
6 | 6 |
7 #include "base/build_time.h" | 7 #include "base/build_time.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/time/time.h" | 10 #include "base/time/time.h" |
11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
12 #include "components/network_time/network_time_tracker.h" | 12 #include "chrome/browser/chrome_notification_types.h" |
13 #include "chrome/browser/profiles/profile.h" | |
14 #include "content/public/browser/notification_service.h" | |
15 #include "content/public/browser/web_contents.h" | |
16 #include "net/base/network_change_notifier.h" | |
13 #include "net/cert/x509_certificate.h" | 17 #include "net/cert/x509_certificate.h" |
14 | 18 |
19 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) | |
20 #include "chrome/browser/captive_portal/captive_portal_service.h" | |
21 #include "chrome/browser/captive_portal/captive_portal_service_factory.h" | |
22 #endif | |
23 | |
15 using base::Time; | 24 using base::Time; |
16 using base::TimeTicks; | 25 using base::TimeTicks; |
17 using base::TimeDelta; | 26 using base::TimeDelta; |
18 | 27 |
19 namespace { | 28 namespace { |
20 | 29 |
21 // Events for UMA. Do not reorder or change! | 30 // Events for UMA. Do not reorder or change! |
22 enum SSLInterstitialCause { | 31 enum SSLInterstitialCause { |
23 CLOCK_PAST, | 32 CLOCK_PAST, |
24 CLOCK_FUTURE, | 33 CLOCK_FUTURE, |
25 UNUSED_INTERSTITIAL_CAUSE_ENTRY, | 34 UNUSED_INTERSTITIAL_CAUSE_ENTRY, |
26 }; | 35 }; |
27 | 36 |
37 // Events for UMA. Do not reorder or change! | |
38 enum SSLInterstitialCauseCaptivePortal { | |
39 CAPTIVE_PORTAL_DETECTION_ENABLED, | |
40 CAPTIVE_PORTAL_DETECTION_ENABLED_OVERRIDABLE, | |
41 CAPTIVE_PORTAL_PROBE_COMPLETED, | |
42 CAPTIVE_PORTAL_PROBE_COMPLETED_OVERRIDABLE, | |
43 CAPTIVE_PORTAL_NO_RESPONSE, | |
44 CAPTIVE_PORTAL_NO_RESPONSE_OVERRIDABLE, | |
45 CAPTIVE_PORTAL_DETECTED, | |
46 CAPTIVE_PORTAL_DETECTED_OVERRIDABLE, | |
47 UNUSED_CAPTIVE_PORTAL_EVENT, | |
48 }; | |
49 | |
28 void RecordSSLInterstitialCause(bool overridable, SSLInterstitialCause event) { | 50 void RecordSSLInterstitialCause(bool overridable, SSLInterstitialCause event) { |
29 if (overridable) { | 51 if (overridable) { |
30 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl.cause.overridable", event, | 52 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl.cause.overridable", event, |
31 UNUSED_INTERSTITIAL_CAUSE_ENTRY); | 53 UNUSED_INTERSTITIAL_CAUSE_ENTRY); |
32 } else { | 54 } else { |
33 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl.cause.nonoverridable", event, | 55 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl.cause.nonoverridable", event, |
34 UNUSED_INTERSTITIAL_CAUSE_ENTRY); | 56 UNUSED_INTERSTITIAL_CAUSE_ENTRY); |
35 } | 57 } |
36 } | 58 } |
37 | 59 |
60 void RecordCaptivePortalEventStats(SSLInterstitialCauseCaptivePortal event) { | |
61 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl.captive_portal", | |
62 event, | |
63 UNUSED_CAPTIVE_PORTAL_EVENT); | |
64 } | |
65 | |
38 } // namespace | 66 } // namespace |
39 | 67 |
40 SSLErrorClassification::SSLErrorClassification( | 68 SSLErrorClassification::SSLErrorClassification( |
69 content::WebContents* web_contents, | |
41 base::Time current_time, | 70 base::Time current_time, |
42 const net::X509Certificate& cert) | 71 const net::X509Certificate& cert) |
43 : current_time_(current_time), | 72 : web_contents_(web_contents), |
44 cert_(cert) { } | 73 current_time_(current_time), |
74 cert_(cert), | |
75 captive_portal_detection_enabled_(false), | |
76 captive_portal_probe_completed_(false), | |
77 captive_portal_no_response_(false), | |
78 captive_portal_detected_(false) { | |
79 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) | |
80 Profile* profile = Profile::FromBrowserContext( | |
81 web_contents_->GetBrowserContext()); | |
82 CaptivePortalService* captive_portal_service = | |
83 CaptivePortalServiceFactory::GetForProfile(profile); | |
84 captive_portal_detection_enabled_ = captive_portal_service ->enabled(); | |
85 captive_portal_service ->DetectCaptivePortal(); | |
86 registrar_.Add(this, | |
87 chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT, | |
88 content::Source<Profile>(profile)); | |
89 #endif | |
90 } | |
45 | 91 |
46 SSLErrorClassification::~SSLErrorClassification() { } | 92 SSLErrorClassification::~SSLErrorClassification() { } |
47 | 93 |
48 float SSLErrorClassification::InvalidDateSeverityScore() const { | 94 float SSLErrorClassification::InvalidDateSeverityScore() const { |
49 // Client-side characterisitics. Check whether the system's clock is wrong or | 95 // Client-side characteristics. Check whether or not the system's clock is |
50 // not and whether the user has encountered this error before or not. | 96 // wrong and whether or not the user has already encountered this error |
97 // before. | |
51 float severity_date_score = 0.0f; | 98 float severity_date_score = 0.0f; |
52 | 99 |
53 static const float kClientWeight = 0.5f; | 100 static const float kClientWeight = 0.5f; |
54 static const float kSystemClockWeight = 0.75f; | 101 static const float kSystemClockWeight = 0.75f; |
55 static const float kSystemClockWrongWeight = 0.1f; | 102 static const float kSystemClockWrongWeight = 0.1f; |
56 static const float kSystemClockRightWeight = 1.0f; | 103 static const float kSystemClockRightWeight = 1.0f; |
57 | 104 |
58 static const float kServerWeight = 0.5f; | 105 static const float kServerWeight = 0.5f; |
59 static const float kCertificateExpiredWeight = 0.3f; | 106 static const float kCertificateExpiredWeight = 0.3f; |
60 static const float kNotYetValidWeight = 0.2f; | 107 static const float kNotYetValidWeight = 0.2f; |
(...skipping 13 matching lines...) Expand all Loading... | |
74 // has passed since expiry. | 121 // has passed since expiry. |
75 if (cert_.HasExpired()) { | 122 if (cert_.HasExpired()) { |
76 severity_date_score += kServerWeight * kCertificateExpiredWeight * | 123 severity_date_score += kServerWeight * kCertificateExpiredWeight * |
77 CalculateScoreTimePassedSinceExpiry(); | 124 CalculateScoreTimePassedSinceExpiry(); |
78 } | 125 } |
79 if (current_time_ < cert_.valid_start()) | 126 if (current_time_ < cert_.valid_start()) |
80 severity_date_score += kServerWeight * kNotYetValidWeight; | 127 severity_date_score += kServerWeight * kNotYetValidWeight; |
81 return severity_date_score; | 128 return severity_date_score; |
82 } | 129 } |
83 | 130 |
131 void SSLErrorClassification::RecordUMAStatistics(bool overridable) { | |
132 if (IsUserClockInThePast(base::Time::NowFromSystemTime())) | |
133 RecordSSLInterstitialCause(overridable, CLOCK_PAST); | |
134 if (IsUserClockInTheFuture(base::Time::NowFromSystemTime())) | |
135 RecordSSLInterstitialCause(overridable, CLOCK_FUTURE); | |
136 } | |
137 | |
138 void SSLErrorClassification::RecordCaptivePortalUMAStatistics( | |
139 bool overridable) { | |
140 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) | |
141 if (captive_portal_detection_enabled_) | |
142 RecordCaptivePortalEventStats( | |
143 overridable ? | |
144 CAPTIVE_PORTAL_DETECTION_ENABLED_OVERRIDABLE : | |
145 CAPTIVE_PORTAL_DETECTION_ENABLED); | |
146 if (captive_portal_probe_completed_) | |
147 RecordCaptivePortalEventStats( | |
148 overridable ? | |
149 CAPTIVE_PORTAL_PROBE_COMPLETED_OVERRIDABLE : | |
150 CAPTIVE_PORTAL_PROBE_COMPLETED); | |
151 // Log only one of portal detected and no response results. | |
152 if (captive_portal_detected_) | |
153 RecordCaptivePortalEventStats( | |
154 overridable ? | |
155 CAPTIVE_PORTAL_DETECTED_OVERRIDABLE : | |
156 CAPTIVE_PORTAL_DETECTED); | |
157 else if (captive_portal_no_response_) | |
158 RecordCaptivePortalEventStats( | |
159 overridable ? | |
160 CAPTIVE_PORTAL_NO_RESPONSE_OVERRIDABLE : | |
161 CAPTIVE_PORTAL_NO_RESPONSE); | |
162 #endif | |
163 } | |
164 | |
165 | |
meacer
2014/07/21 18:45:15
extra line
radhikabhar
2014/07/23 21:41:29
Done.
| |
84 base::TimeDelta SSLErrorClassification::TimePassedSinceExpiry() const { | 166 base::TimeDelta SSLErrorClassification::TimePassedSinceExpiry() const { |
85 base::TimeDelta delta = current_time_ - cert_.valid_expiry(); | 167 base::TimeDelta delta = current_time_ - cert_.valid_expiry(); |
86 return delta; | 168 return delta; |
87 } | 169 } |
88 | 170 |
89 float SSLErrorClassification::CalculateScoreTimePassedSinceExpiry() const { | 171 float SSLErrorClassification::CalculateScoreTimePassedSinceExpiry() const { |
90 base::TimeDelta delta = TimePassedSinceExpiry(); | 172 base::TimeDelta delta = TimePassedSinceExpiry(); |
91 int64 time_passed = delta.InDays(); | 173 int64 time_passed = delta.InDays(); |
92 const int64 kHighThreshold = 7; | 174 const int64 kHighThreshold = 7; |
93 const int64 kLowThreshold = 4; | 175 const int64 kLowThreshold = 4; |
94 static const float kHighThresholdWeight = 0.4f; | 176 static const float kHighThresholdWeight = 0.4f; |
95 static const float kMediumThresholdWeight = 0.3f; | 177 static const float kMediumThresholdWeight = 0.3f; |
96 static const float kLowThresholdWeight = 0.2f; | 178 static const float kLowThresholdWeight = 0.2f; |
97 if (time_passed >= kHighThreshold) | 179 if (time_passed >= kHighThreshold) |
98 return kHighThresholdWeight; | 180 return kHighThresholdWeight; |
99 else if (time_passed >= kLowThreshold) | 181 else if (time_passed >= kLowThreshold) |
100 return kMediumThresholdWeight; | 182 return kMediumThresholdWeight; |
101 else | 183 else |
102 return kLowThresholdWeight; | 184 return kLowThresholdWeight; |
103 } | 185 } |
104 | 186 |
187 float SSLErrorClassification::CalculateScoreEnvironments() const { | |
188 static const float kWifiWeight = 0.7f; | |
189 static const float kCellularWeight = 0.7f; | |
190 static const float kHotspotWeight = 0.2f; | |
191 static const float kEthernetWeight = 0.7f; | |
192 static const float kOtherWeight = 0.7f; | |
193 net::NetworkChangeNotifier::ConnectionType type = | |
194 net::NetworkChangeNotifier::GetConnectionType(); | |
195 if (type == net::NetworkChangeNotifier::CONNECTION_WIFI) | |
196 return kWifiWeight; | |
197 if (type == net::NetworkChangeNotifier::CONNECTION_2G || | |
198 type == net::NetworkChangeNotifier::CONNECTION_3G || | |
199 type == net::NetworkChangeNotifier::CONNECTION_4G ) { | |
200 return kCellularWeight; | |
201 } | |
202 if (type == net::NetworkChangeNotifier::CONNECTION_ETHERNET) | |
203 return kEthernetWeight; | |
204 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) | |
205 // Assume if captive portals are detected then the user is connected using a | |
206 // hot spot. | |
207 if (captive_portal_detected_) | |
208 return kHotspotWeight; | |
209 #endif | |
210 return kOtherWeight; | |
211 } | |
212 | |
105 bool SSLErrorClassification::IsUserClockInThePast(base::Time time_now) { | 213 bool SSLErrorClassification::IsUserClockInThePast(base::Time time_now) { |
106 base::Time build_time = base::GetBuildTime(); | 214 base::Time build_time = base::GetBuildTime(); |
107 if (time_now < build_time - base::TimeDelta::FromDays(2)) | 215 if (time_now < build_time - base::TimeDelta::FromDays(2)) |
108 return true; | 216 return true; |
109 return false; | 217 return false; |
110 } | 218 } |
111 | 219 |
112 bool SSLErrorClassification::IsUserClockInTheFuture(base::Time time_now) { | 220 bool SSLErrorClassification::IsUserClockInTheFuture(base::Time time_now) { |
113 base::Time build_time = base::GetBuildTime(); | 221 base::Time build_time = base::GetBuildTime(); |
114 if (time_now > build_time + base::TimeDelta::FromDays(365)) | 222 if (time_now > build_time + base::TimeDelta::FromDays(365)) |
115 return true; | 223 return true; |
116 return false; | 224 return false; |
117 } | 225 } |
118 | 226 |
119 void SSLErrorClassification::RecordUMAStatistics(bool overridable) { | 227 void SSLErrorClassification::Observe( |
120 if (IsUserClockInThePast(base::Time::NowFromSystemTime())) | 228 int type, |
121 RecordSSLInterstitialCause(overridable, CLOCK_PAST); | 229 const content::NotificationSource& source, |
122 if (IsUserClockInTheFuture(base::Time::NowFromSystemTime())) | 230 const content::NotificationDetails& details) { |
123 RecordSSLInterstitialCause(overridable, CLOCK_FUTURE); | 231 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) |
232 // When detection is disabled, captive portal service always sends | |
233 // RESULT_INTERNET_CONNECTED. Ignore any probe results in that case. | |
234 if (!captive_portal_detection_enabled_) | |
235 return; | |
236 if (type == chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT) { | |
237 captive_portal_probe_completed_ = true; | |
238 CaptivePortalService::Results* results = | |
239 content::Details<CaptivePortalService::Results>( | |
240 details).ptr(); | |
241 // If a captive portal was detected at any point when the interstitial was | |
242 // displayed, assume that the interstitial was caused by a captive portal. | |
243 // Example scenario: | |
244 // 1- Interstitial displayed and captive portal detected, setting the flag. | |
245 // 2- Captive portal detection automatically opens portal login page. | |
246 // 3- User logs in on the portal login page. | |
247 // A notification will be received here for RESULT_INTERNET_CONNECTED. Make | |
248 // sure we don't clear the captive protal flag, since the interstitial was | |
249 // potentially caused by the captive portal. | |
250 captive_portal_detected_ = captive_portal_detected_ || | |
251 (results->result == captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL); | |
252 // Also keep track of non-HTTP portals and error cases. | |
253 captive_portal_no_response_ = captive_portal_no_response_ || | |
254 (results->result == captive_portal::RESULT_NO_RESPONSE); | |
255 } | |
256 #endif | |
124 } | 257 } |
OLD | NEW |