| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "net/cert/known_roots_win.h" |
| 6 |
| 7 #include "base/metrics/histogram_macros.h" |
| 8 #include "crypto/sha2.h" |
| 9 #include "net/cert/x509_certificate.h" |
| 10 #include "net/cert/x509_certificate_known_roots_win.h" |
| 11 |
| 12 namespace net { |
| 13 |
| 14 bool IsKnownRoot(PCCERT_CONTEXT cert) { |
| 15 SHA256HashValue hash = X509Certificate::CalculateFingerprint256(cert); |
| 16 bool is_builtin = |
| 17 IsSHA256HashInSortedArray(hash, &kKnownRootCertSHA256Hashes[0][0], |
| 18 sizeof(kKnownRootCertSHA256Hashes)); |
| 19 |
| 20 // Test to see if the use of a built-in set of known roots on Windows can be |
| 21 // replaced with using AuthRoot's SHA-256 property. On any system other than |
| 22 // a fresh RTM with no AuthRoot updates, this property should always exist for |
| 23 // roots delivered via AuthRoot.stl, but should not exist on any manually or |
| 24 // administratively deployed roots. |
| 25 BYTE hash_prop[32] = {0}; |
| 26 DWORD size = sizeof(hash_prop); |
| 27 bool found_property = |
| 28 CertGetCertificateContextProperty( |
| 29 cert, CERT_AUTH_ROOT_SHA256_HASH_PROP_ID, &hash_prop, &size) && |
| 30 size == sizeof(hash_prop); |
| 31 |
| 32 enum BuiltinStatus { |
| 33 BUILT_IN_PROPERTY_NOT_FOUND_BUILTIN_NOT_SET = 0, |
| 34 BUILT_IN_PROPERTY_NOT_FOUND_BUILTIN_SET = 1, |
| 35 BUILT_IN_PROPERTY_FOUND_BUILTIN_NOT_SET = 2, |
| 36 BUILT_IN_PROPERTY_FOUND_BUILTIN_SET = 3, |
| 37 BUILT_IN_MAX_VALUE, |
| 38 } status; |
| 39 if (!found_property && !is_builtin) { |
| 40 status = BUILT_IN_PROPERTY_NOT_FOUND_BUILTIN_NOT_SET; |
| 41 } else if (!found_property && is_builtin) { |
| 42 status = BUILT_IN_PROPERTY_NOT_FOUND_BUILTIN_SET; |
| 43 } else if (found_property && !is_builtin) { |
| 44 status = BUILT_IN_PROPERTY_FOUND_BUILTIN_NOT_SET; |
| 45 } else if (found_property && is_builtin) { |
| 46 status = BUILT_IN_PROPERTY_FOUND_BUILTIN_SET; |
| 47 } else { |
| 48 status = BUILT_IN_MAX_VALUE; |
| 49 } |
| 50 UMA_HISTOGRAM_ENUMERATION("Net.SSL_AuthRootConsistency", status, |
| 51 BUILT_IN_MAX_VALUE); |
| 52 |
| 53 return is_builtin; |
| 54 } |
| 55 |
| 56 } // namespace net |
| OLD | NEW |