| 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 "net/cert/cert_verify_proc.h" | 5 #include "net/cert/cert_verify_proc.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
| 8 #include "base/sha1.h" | 8 #include "base/sha1.h" |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
| 11 #include "net/base/net_util.h" | 11 #include "net/base/net_util.h" |
| 12 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | |
| 13 #include "net/cert/cert_status_flags.h" | 12 #include "net/cert/cert_status_flags.h" |
| 14 #include "net/cert/cert_verifier.h" | 13 #include "net/cert/cert_verifier.h" |
| 15 #include "net/cert/cert_verify_result.h" | 14 #include "net/cert/cert_verify_result.h" |
| 16 #include "net/cert/crl_set.h" | 15 #include "net/cert/crl_set.h" |
| 17 #include "net/cert/x509_certificate.h" | 16 #include "net/cert/x509_certificate.h" |
| 18 #include "url/url_canon.h" | |
| 19 | 17 |
| 20 #if defined(USE_NSS) || defined(OS_IOS) | 18 #if defined(USE_NSS) || defined(OS_IOS) |
| 21 #include "net/cert/cert_verify_proc_nss.h" | 19 #include "net/cert/cert_verify_proc_nss.h" |
| 22 #elif defined(USE_OPENSSL) && !defined(OS_ANDROID) | 20 #elif defined(USE_OPENSSL) && !defined(OS_ANDROID) |
| 23 #include "net/cert/cert_verify_proc_openssl.h" | 21 #include "net/cert/cert_verify_proc_openssl.h" |
| 24 #elif defined(OS_ANDROID) | 22 #elif defined(OS_ANDROID) |
| 25 #include "net/cert/cert_verify_proc_android.h" | 23 #include "net/cert/cert_verify_proc_android.h" |
| 26 #elif defined(OS_MACOSX) | 24 #elif defined(OS_MACOSX) |
| 27 #include "net/cert/cert_verify_proc_mac.h" | 25 #include "net/cert/cert_verify_proc_mac.h" |
| 28 #elif defined(OS_WIN) | 26 #elif defined(OS_WIN) |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 // Avoid replacing a more serious error, such as an OS/library failure, | 143 // Avoid replacing a more serious error, such as an OS/library failure, |
| 146 // by ensuring that if verification failed, it failed with a certificate | 144 // by ensuring that if verification failed, it failed with a certificate |
| 147 // error. | 145 // error. |
| 148 if (rv == OK || IsCertificateError(rv)) | 146 if (rv == OK || IsCertificateError(rv)) |
| 149 rv = MapCertStatusToNetError(verify_result->cert_status); | 147 rv = MapCertStatusToNetError(verify_result->cert_status); |
| 150 } | 148 } |
| 151 | 149 |
| 152 // Flag certificates from publicly-trusted CAs that are issued to intranet | 150 // Flag certificates from publicly-trusted CAs that are issued to intranet |
| 153 // hosts. While the CA/Browser Forum Baseline Requirements (v1.1) permit | 151 // hosts. While the CA/Browser Forum Baseline Requirements (v1.1) permit |
| 154 // these to be issued until 1 November 2015, they represent a real risk for | 152 // these to be issued until 1 November 2015, they represent a real risk for |
| 155 // the deployment of gTLDs and are being phased out. | 153 // the deployment of gTLDs and are being phased out ahead of the hard |
| 154 // deadline. |
| 155 // TODO(rsleevi): http://crbug.com/119212 - Also match internal IP address |
| 156 // ranges. |
| 156 if (verify_result->is_issued_by_known_root && IsHostnameNonUnique(hostname)) { | 157 if (verify_result->is_issued_by_known_root && IsHostnameNonUnique(hostname)) { |
| 157 verify_result->cert_status |= CERT_STATUS_NON_UNIQUE_NAME; | 158 verify_result->cert_status |= CERT_STATUS_NON_UNIQUE_NAME; |
| 158 } | 159 } |
| 159 | 160 |
| 160 return rv; | 161 return rv; |
| 161 } | 162 } |
| 162 | 163 |
| 163 // static | 164 // static |
| 164 bool CertVerifyProc::IsBlacklisted(X509Certificate* cert) { | 165 bool CertVerifyProc::IsBlacklisted(X509Certificate* cert) { |
| 165 static const unsigned kComodoSerialBytes = 16; | 166 static const unsigned kComodoSerialBytes = 16; |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 if (j->tag == HASH_VALUE_SHA1 && | 287 if (j->tag == HASH_VALUE_SHA1 && |
| 287 memcmp(j->data(), kHashes[i], base::kSHA1Length) == 0) { | 288 memcmp(j->data(), kHashes[i], base::kSHA1Length) == 0) { |
| 288 return true; | 289 return true; |
| 289 } | 290 } |
| 290 } | 291 } |
| 291 } | 292 } |
| 292 | 293 |
| 293 return false; | 294 return false; |
| 294 } | 295 } |
| 295 | 296 |
| 296 // static | |
| 297 bool CertVerifyProc::IsHostnameNonUnique(const std::string& hostname) { | |
| 298 // CanonicalizeHost requires surrounding brackets to parse an IPv6 address. | |
| 299 const std::string host_or_ip = hostname.find(':') != std::string::npos ? | |
| 300 "[" + hostname + "]" : hostname; | |
| 301 url_canon::CanonHostInfo host_info; | |
| 302 std::string canonical_name = CanonicalizeHost(host_or_ip, &host_info); | |
| 303 | |
| 304 // If canonicalization fails, then the input is truly malformed. However, | |
| 305 // to avoid mis-reporting bad inputs as "non-unique", treat them as unique. | |
| 306 if (canonical_name.empty()) | |
| 307 return false; | |
| 308 | |
| 309 // If |hostname| is an IP address, presume it's unique. | |
| 310 // TODO(rsleevi): In the future, this should also reject IP addresses in | |
| 311 // IANA-reserved ranges, since those are also non-unique among publicly | |
| 312 // trusted CAs. | |
| 313 if (host_info.IsIPAddress()) | |
| 314 return false; | |
| 315 | |
| 316 // Check for a registry controlled portion of |hostname|, ignoring private | |
| 317 // registries, as they already chain to ICANN-administered registries, | |
| 318 // and explicitly ignoring unknown registries. | |
| 319 // | |
| 320 // Note: This means that as new gTLDs are introduced on the Internet, they | |
| 321 // will be treated as non-unique until the registry controlled domain list | |
| 322 // is updated. However, because gTLDs are expected to provide significant | |
| 323 // advance notice to deprecate older versions of this code, this an | |
| 324 // acceptable tradeoff. | |
| 325 return 0 == registry_controlled_domains::GetRegistryLength( | |
| 326 canonical_name, | |
| 327 registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES, | |
| 328 registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES); | |
| 329 } | |
| 330 | |
| 331 } // namespace net | 297 } // namespace net |
| OLD | NEW |