Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Side by Side Diff: net/cert/known_roots_win.cc

Issue 2833623002: Extract IsKnownRoot() functionality for testing if a certificate is a (Closed)
Patch Set: checkpoint Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« net/cert/known_roots_nss.h ('K') | « net/cert/known_roots_win.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
OLDNEW
« net/cert/known_roots_nss.h ('K') | « net/cert/known_roots_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698