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> |
11 | 11 |
12 #include "base/build_time.h" | 12 #include "base/build_time.h" |
13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
14 #include "base/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" |
15 #include "base/strings/string_split.h" | 15 #include "base/strings/string_split.h" |
16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
19 #include "components/network_time/network_time_tracker.h" | |
19 #include "components/ssl_errors/error_info.h" | 20 #include "components/ssl_errors/error_info.h" |
20 #include "components/url_formatter/url_formatter.h" | 21 #include "components/url_formatter/url_formatter.h" |
21 #include "net/base/network_change_notifier.h" | 22 #include "net/base/network_change_notifier.h" |
22 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 23 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
23 #include "net/base/url_util.h" | 24 #include "net/base/url_util.h" |
24 #include "net/cert/x509_cert_types.h" | 25 #include "net/cert/x509_cert_types.h" |
25 #include "net/cert/x509_certificate.h" | 26 #include "net/cert/x509_certificate.h" |
26 #include "url/gurl.h" | 27 #include "url/gurl.h" |
27 | 28 |
28 #if defined(OS_WIN) | 29 #if defined(OS_WIN) |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 return GetWWWSubDomainMatch(request_url, dns_names, &www_host); | 113 return GetWWWSubDomainMatch(request_url, dns_names, &www_host); |
113 } | 114 } |
114 | 115 |
115 // The time to use when doing build time operations in browser tests. | 116 // The time to use when doing build time operations in browser tests. |
116 base::LazyInstance<base::Time> g_testing_build_time = LAZY_INSTANCE_INITIALIZER; | 117 base::LazyInstance<base::Time> g_testing_build_time = LAZY_INSTANCE_INITIALIZER; |
117 | 118 |
118 } // namespace | 119 } // namespace |
119 | 120 |
120 void RecordUMAStatistics(bool overridable, | 121 void RecordUMAStatistics(bool overridable, |
121 const base::Time& current_time, | 122 const base::Time& current_time, |
123 const network_time::NetworkTimeTracker* network_time, | |
122 const GURL& request_url, | 124 const GURL& request_url, |
123 int cert_error, | 125 int cert_error, |
124 const net::X509Certificate& cert) { | 126 const net::X509Certificate& cert) { |
125 ssl_errors::ErrorInfo::ErrorType type = | 127 ssl_errors::ErrorInfo::ErrorType type = |
126 ssl_errors::ErrorInfo::NetErrorToErrorType(cert_error); | 128 ssl_errors::ErrorInfo::NetErrorToErrorType(cert_error); |
127 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl_error_type", type, | 129 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl_error_type", type, |
128 ssl_errors::ErrorInfo::END_OF_ENUM); | 130 ssl_errors::ErrorInfo::END_OF_ENUM); |
129 switch (type) { | 131 switch (type) { |
130 case ssl_errors::ErrorInfo::CERT_DATE_INVALID: { | 132 case ssl_errors::ErrorInfo::CERT_DATE_INVALID: { |
131 if (IsUserClockInThePast(base::Time::NowFromSystemTime())) { | 133 if (IsUserClockAhead(base::Time::NowFromSystemTime(), network_time)) { |
132 RecordSSLInterstitialCause(overridable, CLOCK_PAST); | 134 RecordSSLInterstitialCause(overridable, CLOCK_PAST); |
estark
2016/03/08 23:17:36
I think we should preserve the meaning of the exis
mab
2016/03/09 23:35:28
I like the idea of having an enum to describe what
estark
2016/03/10 20:10:08
I had (a) in mind, which is wasteful as you said b
mab
2016/03/11 04:18:41
For background, the calling sequence is like this:
mab
2016/03/11 21:07:15
Oh, I should add: if you buy my argument, I think
estark
2016/03/11 22:00:05
Oh, drat! I totally forgot that this is called onl
mab
2016/03/11 23:12:49
Updated histograms.xml. I've kept the enum, becau
| |
133 } else if (IsUserClockInTheFuture(base::Time::NowFromSystemTime())) { | 135 } else if (IsUserClockBehind(base::Time::NowFromSystemTime(), |
mab
2016/03/09 23:35:28
Why the use of NowFromSystemTime here, BTW, instea
estark
2016/03/10 20:10:08
Hmm... good question. Probably an oversight? I'd s
mab
2016/03/11 04:18:41
Done.
| |
136 network_time)) { | |
134 RecordSSLInterstitialCause(overridable, CLOCK_FUTURE); | 137 RecordSSLInterstitialCause(overridable, CLOCK_FUTURE); |
135 } else if (cert.HasExpired() && | 138 } else if (cert.HasExpired() && |
136 (current_time - cert.valid_expiry()).InDays() < 28) { | 139 (current_time - cert.valid_expiry()).InDays() < 28) { |
137 RecordSSLInterstitialCause(overridable, EXPIRED_RECENTLY); | 140 RecordSSLInterstitialCause(overridable, EXPIRED_RECENTLY); |
138 } | 141 } |
139 break; | 142 break; |
140 } | 143 } |
141 case ssl_errors::ErrorInfo::CERT_COMMON_NAME_INVALID: { | 144 case ssl_errors::ErrorInfo::CERT_COMMON_NAME_INVALID: { |
142 std::string host_name = request_url.host(); | 145 std::string host_name = request_url.host(); |
143 if (IsHostNameKnownTLD(host_name)) { | 146 if (IsHostNameKnownTLD(host_name)) { |
(...skipping 30 matching lines...) Expand all Loading... | |
174 break; | 177 break; |
175 } | 178 } |
176 default: | 179 default: |
177 break; | 180 break; |
178 } | 181 } |
179 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl.connection_type", | 182 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl.connection_type", |
180 net::NetworkChangeNotifier::GetConnectionType(), | 183 net::NetworkChangeNotifier::GetConnectionType(), |
181 net::NetworkChangeNotifier::CONNECTION_LAST); | 184 net::NetworkChangeNotifier::CONNECTION_LAST); |
182 } | 185 } |
183 | 186 |
184 bool IsUserClockInThePast(const base::Time& time_now) { | 187 bool IsUserClockBehind(const base::Time& now_system, |
estark
2016/03/08 23:17:36
Definition order should match declaration order (i
estark
2016/03/08 23:17:36
Could you add a couple unit tests for these functi
mab
2016/03/09 23:35:28
Done. I couldn't figure out how to run error_clas
mab
2016/03/09 23:35:28
Sort of moot if you mean just these two functions,
estark
2016/03/10 20:10:08
Urgh, I guess that means error_classification_unit
estark
2016/03/10 20:10:08
I just meant these two functions, so this is fine.
| |
188 const network_time::NetworkTimeTracker* network_time) { | |
189 base::Time now_network; | |
190 base::TimeDelta uncertainty; | |
191 if (network_time->GetNetworkTime(&now_network, &uncertainty)) { | |
192 return now_system < | |
193 now_network - uncertainty - base::TimeDelta::FromMinutes(5); | |
194 } | |
195 | |
185 base::Time build_time; | 196 base::Time build_time; |
186 if (!g_testing_build_time.Get().is_null()) { | 197 if (!g_testing_build_time.Get().is_null()) { |
187 build_time = g_testing_build_time.Get(); | 198 build_time = g_testing_build_time.Get(); |
188 } else { | 199 } else { |
189 build_time = base::GetBuildTime(); | 200 build_time = base::GetBuildTime(); |
190 } | 201 } |
191 | 202 |
192 if (time_now < build_time - base::TimeDelta::FromDays(2)) | 203 if (now_system < build_time - base::TimeDelta::FromDays(2)) |
193 return true; | 204 return true; |
194 return false; | 205 return false; |
195 } | 206 } |
196 | 207 |
197 bool IsUserClockInTheFuture(const base::Time& time_now) { | 208 bool IsUserClockAhead(const base::Time& now_system, |
209 const network_time::NetworkTimeTracker* network_time) { | |
210 base::Time now_network; | |
211 base::TimeDelta uncertainty; | |
212 if (network_time->GetNetworkTime(&now_network, &uncertainty)) { | |
213 return now_system > | |
214 now_network + uncertainty + base::TimeDelta::FromMinutes(5); | |
215 } | |
216 | |
198 base::Time build_time; | 217 base::Time build_time; |
199 if (!g_testing_build_time.Get().is_null()) { | 218 if (!g_testing_build_time.Get().is_null()) { |
200 build_time = g_testing_build_time.Get(); | 219 build_time = g_testing_build_time.Get(); |
201 } else { | 220 } else { |
202 build_time = base::GetBuildTime(); | 221 build_time = base::GetBuildTime(); |
203 } | 222 } |
204 | 223 |
205 if (time_now > build_time + base::TimeDelta::FromDays(365)) | 224 if (now_system > build_time + base::TimeDelta::FromDays(365)) |
206 return true; | 225 return true; |
207 return false; | 226 return false; |
208 } | 227 } |
209 | 228 |
210 void SetBuildTimeForTesting(const base::Time& testing_time) { | 229 void SetBuildTimeForTesting(const base::Time& testing_time) { |
211 g_testing_build_time.Get() = testing_time; | 230 g_testing_build_time.Get() = testing_time; |
212 } | 231 } |
213 | 232 |
214 bool IsHostNameKnownTLD(const std::string& host_name) { | 233 bool IsHostNameKnownTLD(const std::string& host_name) { |
215 size_t tld_length = net::registry_controlled_domains::GetRegistryLength( | 234 size_t tld_length = net::registry_controlled_domains::GetRegistryLength( |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
412 return std::find(dns_names_domain.begin(), dns_names_domain.end() - 1, | 431 return std::find(dns_names_domain.begin(), dns_names_domain.end() - 1, |
413 host_name_domain) != dns_names_domain.end() - 1; | 432 host_name_domain) != dns_names_domain.end() - 1; |
414 } | 433 } |
415 | 434 |
416 bool IsHostnameNonUniqueOrDotless(const std::string& hostname) { | 435 bool IsHostnameNonUniqueOrDotless(const std::string& hostname) { |
417 return net::IsHostnameNonUnique(hostname) || | 436 return net::IsHostnameNonUnique(hostname) || |
418 hostname.find('.') == std::string::npos; | 437 hostname.find('.') == std::string::npos; |
419 } | 438 } |
420 | 439 |
421 } // namespace ssl_errors | 440 } // namespace ssl_errors |
OLD | NEW |