| 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "chrome/browser/ssl/ssl_error_classification.h" | 7 #include "chrome/browser/ssl/ssl_error_classification.h" |
| 8 | 8 |
| 9 #include "base/build_time.h" | 9 #include "base/build_time.h" |
| 10 #include "base/lazy_instance.h" |
| 10 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
| 11 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 14 #include "components/ssl_errors/error_info.h" | 15 #include "components/ssl_errors/error_info.h" |
| 15 #include "net/base/net_util.h" | 16 #include "net/base/net_util.h" |
| 16 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 17 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 17 #include "net/cert/x509_cert_types.h" | 18 #include "net/cert/x509_cert_types.h" |
| 18 #include "net/cert/x509_certificate.h" | 19 #include "net/cert/x509_certificate.h" |
| 19 #include "url/gurl.h" | 20 #include "url/gurl.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 kSecondRow[j+1] = std::min(std::min( | 79 kSecondRow[j+1] = std::min(std::min( |
| 79 kSecondRow[j] + 1, kFirstRow[j + 1] + 1), kFirstRow[j] + cost); | 80 kSecondRow[j] + 1, kFirstRow[j + 1] + 1), kFirstRow[j] + cost); |
| 80 } | 81 } |
| 81 for (size_t j = 0; j < kFirstRow.size(); j++) | 82 for (size_t j = 0; j < kFirstRow.size(); j++) |
| 82 kFirstRow[j] = kSecondRow[j]; | 83 kFirstRow[j] = kSecondRow[j]; |
| 83 } | 84 } |
| 84 return kSecondRow[str2.size()]; | 85 return kSecondRow[str2.size()]; |
| 85 } | 86 } |
| 86 | 87 |
| 87 // The time to use when doing build time operations in browser tests. | 88 // The time to use when doing build time operations in browser tests. |
| 88 base::Time g_testing_build_time; | 89 base::LazyInstance<base::Time> g_testing_build_time = LAZY_INSTANCE_INITIALIZER; |
| 89 | 90 |
| 90 } // namespace | 91 } // namespace |
| 91 | 92 |
| 92 SSLErrorClassification::SSLErrorClassification(const base::Time& current_time, | 93 SSLErrorClassification::SSLErrorClassification(const base::Time& current_time, |
| 93 const GURL& url, | 94 const GURL& url, |
| 94 int cert_error, | 95 int cert_error, |
| 95 const net::X509Certificate& cert) | 96 const net::X509Certificate& cert) |
| 96 : current_time_(current_time), | 97 : current_time_(current_time), |
| 97 request_url_(url), | 98 request_url_(url), |
| 98 cert_error_(cert_error), | 99 cert_error_(cert_error), |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 default: | 156 default: |
| 156 break; | 157 break; |
| 157 } | 158 } |
| 158 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl.connection_type", | 159 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl.connection_type", |
| 159 net::NetworkChangeNotifier::GetConnectionType(), | 160 net::NetworkChangeNotifier::GetConnectionType(), |
| 160 net::NetworkChangeNotifier::CONNECTION_LAST); | 161 net::NetworkChangeNotifier::CONNECTION_LAST); |
| 161 } | 162 } |
| 162 | 163 |
| 163 bool SSLErrorClassification::IsUserClockInThePast(const base::Time& time_now) { | 164 bool SSLErrorClassification::IsUserClockInThePast(const base::Time& time_now) { |
| 164 base::Time build_time; | 165 base::Time build_time; |
| 165 if (!g_testing_build_time.is_null()) { | 166 if (!g_testing_build_time.Get().is_null()) { |
| 166 build_time = g_testing_build_time; | 167 build_time = g_testing_build_time.Get(); |
| 167 } else { | 168 } else { |
| 168 #if defined(DONT_EMBED_BUILD_METADATA) && !defined(OFFICIAL_BUILD) | 169 #if defined(DONT_EMBED_BUILD_METADATA) && !defined(OFFICIAL_BUILD) |
| 169 return false; | 170 return false; |
| 170 #else | 171 #else |
| 171 build_time = base::GetBuildTime(); | 172 build_time = base::GetBuildTime(); |
| 172 #endif | 173 #endif |
| 173 } | 174 } |
| 174 | 175 |
| 175 if (time_now < build_time - base::TimeDelta::FromDays(2)) | 176 if (time_now < build_time - base::TimeDelta::FromDays(2)) |
| 176 return true; | 177 return true; |
| 177 return false; | 178 return false; |
| 178 } | 179 } |
| 179 | 180 |
| 180 bool SSLErrorClassification::IsUserClockInTheFuture( | 181 bool SSLErrorClassification::IsUserClockInTheFuture( |
| 181 const base::Time& time_now) { | 182 const base::Time& time_now) { |
| 182 base::Time build_time; | 183 base::Time build_time; |
| 183 if (!g_testing_build_time.is_null()) { | 184 if (!g_testing_build_time.Get().is_null()) { |
| 184 build_time = g_testing_build_time; | 185 build_time = g_testing_build_time.Get(); |
| 185 } else { | 186 } else { |
| 186 #if defined(DONT_EMBED_BUILD_METADATA) && !defined(OFFICIAL_BUILD) | 187 #if defined(DONT_EMBED_BUILD_METADATA) && !defined(OFFICIAL_BUILD) |
| 187 return false; | 188 return false; |
| 188 #else | 189 #else |
| 189 build_time = base::GetBuildTime(); | 190 build_time = base::GetBuildTime(); |
| 190 #endif | 191 #endif |
| 191 } | 192 } |
| 192 | 193 |
| 193 if (time_now > build_time + base::TimeDelta::FromDays(365)) | 194 if (time_now > build_time + base::TimeDelta::FromDays(365)) |
| 194 return true; | 195 return true; |
| 195 return false; | 196 return false; |
| 196 } | 197 } |
| 197 | 198 |
| 198 // static | 199 // static |
| 199 void SSLErrorClassification::SetBuildTimeForTesting( | 200 void SSLErrorClassification::SetBuildTimeForTesting( |
| 200 const base::Time& testing_time) { | 201 const base::Time& testing_time) { |
| 201 g_testing_build_time = testing_time; | 202 g_testing_build_time.Get() = testing_time; |
| 202 } | 203 } |
| 203 | 204 |
| 204 bool SSLErrorClassification::MaybeWindowsLacksSHA256Support() { | 205 bool SSLErrorClassification::MaybeWindowsLacksSHA256Support() { |
| 205 #if defined(OS_WIN) | 206 #if defined(OS_WIN) |
| 206 return !base::win::MaybeHasSHA256Support(); | 207 return !base::win::MaybeHasSHA256Support(); |
| 207 #else | 208 #else |
| 208 return false; | 209 return false; |
| 209 #endif | 210 #endif |
| 210 } | 211 } |
| 211 | 212 |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 return std::find(dns_names_domain.begin(), dns_names_domain.end() - 1, | 436 return std::find(dns_names_domain.begin(), dns_names_domain.end() - 1, |
| 436 host_name_domain) != dns_names_domain.end() - 1; | 437 host_name_domain) != dns_names_domain.end() - 1; |
| 437 } | 438 } |
| 438 | 439 |
| 439 // static | 440 // static |
| 440 bool SSLErrorClassification::IsHostnameNonUniqueOrDotless( | 441 bool SSLErrorClassification::IsHostnameNonUniqueOrDotless( |
| 441 const std::string& hostname) { | 442 const std::string& hostname) { |
| 442 return net::IsHostnameNonUnique(hostname) || | 443 return net::IsHostnameNonUnique(hostname) || |
| 443 hostname.find('.') == std::string::npos; | 444 hostname.find('.') == std::string::npos; |
| 444 } | 445 } |
| OLD | NEW |