OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/ssl_errors/error_classification.h" | 5 #include "components/ssl_errors/error_classification.h" |
6 | 6 |
7 #include <limits.h> | 7 #include <limits.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <vector> | 10 #include <vector> |
(...skipping 20 matching lines...) Expand all Loading... |
31 #include "base/win/windows_version.h" | 31 #include "base/win/windows_version.h" |
32 #endif | 32 #endif |
33 | 33 |
34 using base::Time; | 34 using base::Time; |
35 using base::TimeTicks; | 35 using base::TimeTicks; |
36 using base::TimeDelta; | 36 using base::TimeDelta; |
37 | 37 |
38 namespace ssl_errors { | 38 namespace ssl_errors { |
39 namespace { | 39 namespace { |
40 | 40 |
| 41 // Describes the result of getting network time and if it was |
| 42 // unavailable, why it was unavailable. This enum is being histogrammed |
| 43 // so do not reorder or remove values. |
| 44 enum NetworkClockState { |
| 45 // The clock state relative to network time is unknown because the |
| 46 // NetworkTimeTracker has no information from the network. |
| 47 NETWORK_CLOCK_STATE_UNKNOWN_NO_SYNC = 0, |
| 48 // The clock state relative to network time is unknown because the |
| 49 // user's clock has fallen out of sync with the latest information |
| 50 // from the network (due to e.g. suspend/resume). |
| 51 NETWORK_CLOCK_STATE_UNKNOWN_SYNC_LOST, |
| 52 // The clock is "close enough" to the network time. |
| 53 NETWORK_CLOCK_STATE_OK, |
| 54 // The clock is in the past relative to network time. |
| 55 NETWORK_CLOCK_STATE_CLOCK_IN_PAST, |
| 56 // The clock is in the future relative to network time. |
| 57 NETWORK_CLOCK_STATE_CLOCK_IN_FUTURE, |
| 58 NETWORK_CLOCK_STATE_MAX |
| 59 }; |
| 60 |
41 // Events for UMA. Do not reorder or change! | 61 // Events for UMA. Do not reorder or change! |
42 enum SSLInterstitialCause { | 62 enum SSLInterstitialCause { |
43 CLOCK_PAST, | 63 CLOCK_PAST, |
44 CLOCK_FUTURE, | 64 CLOCK_FUTURE, |
45 WWW_SUBDOMAIN_MATCH, | 65 WWW_SUBDOMAIN_MATCH, |
46 SUBDOMAIN_MATCH, | 66 SUBDOMAIN_MATCH, |
47 SUBDOMAIN_INVERSE_MATCH, | 67 SUBDOMAIN_INVERSE_MATCH, |
48 SUBDOMAIN_OUTSIDE_WILDCARD, | 68 SUBDOMAIN_OUTSIDE_WILDCARD, |
49 HOST_NAME_NOT_KNOWN_TLD, | 69 HOST_NAME_NOT_KNOWN_TLD, |
50 LIKELY_MULTI_TENANT_HOSTING, | 70 LIKELY_MULTI_TENANT_HOSTING, |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 NOTREACHED(); | 220 NOTREACHED(); |
201 } | 221 } |
202 } | 222 } |
203 | 223 |
204 ClockState GetClockState( | 224 ClockState GetClockState( |
205 const base::Time& now_system, | 225 const base::Time& now_system, |
206 const network_time::NetworkTimeTracker* network_time_tracker) { | 226 const network_time::NetworkTimeTracker* network_time_tracker) { |
207 base::Time now_network; | 227 base::Time now_network; |
208 base::TimeDelta uncertainty; | 228 base::TimeDelta uncertainty; |
209 const base::TimeDelta kNetworkTimeFudge = base::TimeDelta::FromMinutes(5); | 229 const base::TimeDelta kNetworkTimeFudge = base::TimeDelta::FromMinutes(5); |
210 ClockState network_state = CLOCK_STATE_UNKNOWN; | 230 NetworkClockState network_state = NETWORK_CLOCK_STATE_MAX; |
211 if (network_time_tracker->GetNetworkTime(&now_network, &uncertainty)) { | 231 network_time::NetworkTimeTracker::NetworkTimeResult network_time_result = |
212 if (now_system < now_network - uncertainty - kNetworkTimeFudge) { | 232 network_time_tracker->GetNetworkTime(&now_network, &uncertainty); |
213 network_state = CLOCK_STATE_PAST; | 233 switch (network_time_result) { |
214 } else if (now_system > now_network + uncertainty + kNetworkTimeFudge) { | 234 case network_time::NetworkTimeTracker::NETWORK_TIME_AVAILABLE: |
215 network_state = CLOCK_STATE_FUTURE; | 235 if (now_system < now_network - uncertainty - kNetworkTimeFudge) { |
216 } else { | 236 network_state = NETWORK_CLOCK_STATE_CLOCK_IN_PAST; |
217 network_state = CLOCK_STATE_OK; | 237 } else if (now_system > now_network + uncertainty + kNetworkTimeFudge) { |
218 } | 238 network_state = NETWORK_CLOCK_STATE_CLOCK_IN_FUTURE; |
| 239 } else { |
| 240 network_state = NETWORK_CLOCK_STATE_OK; |
| 241 } |
| 242 break; |
| 243 case network_time::NetworkTimeTracker::NETWORK_TIME_SYNC_LOST: |
| 244 network_state = NETWORK_CLOCK_STATE_UNKNOWN_SYNC_LOST; |
| 245 break; |
| 246 case network_time::NetworkTimeTracker::NETWORK_TIME_NO_SYNC: |
| 247 network_state = NETWORK_CLOCK_STATE_UNKNOWN_NO_SYNC; |
| 248 break; |
219 } | 249 } |
220 | 250 |
221 ClockState build_time_state = CLOCK_STATE_UNKNOWN; | 251 ClockState build_time_state = CLOCK_STATE_UNKNOWN; |
222 base::Time build_time = g_testing_build_time.Get().is_null() | 252 base::Time build_time = g_testing_build_time.Get().is_null() |
223 ? base::GetBuildTime() | 253 ? base::GetBuildTime() |
224 : g_testing_build_time.Get(); | 254 : g_testing_build_time.Get(); |
225 if (now_system < build_time - base::TimeDelta::FromDays(2)) { | 255 if (now_system < build_time - base::TimeDelta::FromDays(2)) { |
226 build_time_state = CLOCK_STATE_PAST; | 256 build_time_state = CLOCK_STATE_PAST; |
227 } else if (now_system > build_time + base::TimeDelta::FromDays(365)) { | 257 } else if (now_system > build_time + base::TimeDelta::FromDays(365)) { |
228 build_time_state = CLOCK_STATE_FUTURE; | 258 build_time_state = CLOCK_STATE_FUTURE; |
229 } | 259 } |
230 | 260 |
231 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl.clockstate.network", | 261 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl.clockstate.network2", |
232 network_state, CLOCK_STATE_MAX); | 262 network_time_result, NETWORK_CLOCK_STATE_MAX); |
233 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl.clockstate.build_time", | 263 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl.clockstate.build_time", |
234 build_time_state, CLOCK_STATE_MAX); | 264 build_time_state, CLOCK_STATE_MAX); |
235 | 265 |
236 return network_state == CLOCK_STATE_UNKNOWN ? build_time_state | 266 switch (network_state) { |
237 : network_state; | 267 case NETWORK_CLOCK_STATE_UNKNOWN_NO_SYNC: |
| 268 case NETWORK_CLOCK_STATE_UNKNOWN_SYNC_LOST: |
| 269 return build_time_state; |
| 270 case NETWORK_CLOCK_STATE_OK: |
| 271 return CLOCK_STATE_OK; |
| 272 case NETWORK_CLOCK_STATE_CLOCK_IN_PAST: |
| 273 return CLOCK_STATE_PAST; |
| 274 case NETWORK_CLOCK_STATE_CLOCK_IN_FUTURE: |
| 275 return CLOCK_STATE_FUTURE; |
| 276 case NETWORK_CLOCK_STATE_MAX: |
| 277 NOTREACHED(); |
| 278 return CLOCK_STATE_UNKNOWN; |
| 279 } |
| 280 |
| 281 NOTREACHED(); |
| 282 return CLOCK_STATE_UNKNOWN; |
238 } | 283 } |
239 | 284 |
240 void SetBuildTimeForTesting(const base::Time& testing_time) { | 285 void SetBuildTimeForTesting(const base::Time& testing_time) { |
241 g_testing_build_time.Get() = testing_time; | 286 g_testing_build_time.Get() = testing_time; |
242 } | 287 } |
243 | 288 |
244 bool IsHostNameKnownTLD(const std::string& host_name) { | 289 bool IsHostNameKnownTLD(const std::string& host_name) { |
245 size_t tld_length = net::registry_controlled_domains::GetRegistryLength( | 290 size_t tld_length = net::registry_controlled_domains::GetRegistryLength( |
246 host_name, net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES, | 291 host_name, net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES, |
247 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); | 292 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 return std::find(dns_names_domain.begin(), dns_names_domain.end() - 1, | 487 return std::find(dns_names_domain.begin(), dns_names_domain.end() - 1, |
443 host_name_domain) != dns_names_domain.end() - 1; | 488 host_name_domain) != dns_names_domain.end() - 1; |
444 } | 489 } |
445 | 490 |
446 bool IsHostnameNonUniqueOrDotless(const std::string& hostname) { | 491 bool IsHostnameNonUniqueOrDotless(const std::string& hostname) { |
447 return net::IsHostnameNonUnique(hostname) || | 492 return net::IsHostnameNonUnique(hostname) || |
448 hostname.find('.') == std::string::npos; | 493 hostname.find('.') == std::string::npos; |
449 } | 494 } |
450 | 495 |
451 } // namespace ssl_errors | 496 } // namespace ssl_errors |
OLD | NEW |