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

Side by Side Diff: net/cert/internal/verify_certificate_chain.h

Issue 2903283002: Add policies support to VerifyCertificateChain(). (Closed)
Patch Set: Created 3 years, 7 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
OLDNEW
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 #ifndef NET_CERT_INTERNAL_VERIFY_CERTIFICATE_CHAIN_H_ 5 #ifndef NET_CERT_INTERNAL_VERIFY_CERTIFICATE_CHAIN_H_
6 #define NET_CERT_INTERNAL_VERIFY_CERTIFICATE_CHAIN_H_ 6 #define NET_CERT_INTERNAL_VERIFY_CERTIFICATE_CHAIN_H_
7 7
8 #include <vector> 8 #include <set>
9 9
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "net/base/net_export.h" 12 #include "net/base/net_export.h"
13 #include "net/cert/internal/cert_errors.h" 13 #include "net/cert/internal/cert_errors.h"
14 #include "net/cert/internal/parsed_certificate.h" 14 #include "net/cert/internal/parsed_certificate.h"
15 #include "net/der/input.h" 15 #include "net/der/input.h"
16 16
17 namespace net { 17 namespace net {
18 18
19 namespace der { 19 namespace der {
20 struct GeneralizedTime; 20 struct GeneralizedTime;
21 } 21 }
22 22
23 class SignaturePolicy; 23 class SignaturePolicy;
24 struct CertificateTrust; 24 struct CertificateTrust;
25 25
26 // The key purpose (extended key usage) to check for during verification. 26 // The key purpose (extended key usage) to check for during verification.
27 enum class KeyPurpose { 27 enum class KeyPurpose {
28 ANY_EKU, 28 ANY_EKU,
29 SERVER_AUTH, 29 SERVER_AUTH,
30 CLIENT_AUTH, 30 CLIENT_AUTH,
31 }; 31 };
32 32
33 // VerifyCertificateChain() verifies an ordered certificate path in accordance 33 // VerifyCertificateChain() verifies an ordered certificate path in accordance
34 // with RFC 5280 (with some modifications [1]). 34 // with RFC 5280's "Certification Path Validation" algorithm (section 6).
35 // 35 //
36 // [1] Deviations from RFC 5280: 36 // -----------------------------------------
37 // Deviations from RFC 5280
38 // -----------------------------------------
37 // 39 //
38 // * If Extended Key Usage appears on intermediates it is treated as a 40 // * If Extended Key Usage appears on intermediates, it is treated as
39 // restriction on subordinate certificates. 41 // a restriction on subordinate certificates.
40 // 42 //
41 // The caller is responsible for additionally checking: 43 // -----------------------------------------
44 // Additional responsibilities of the caller
45 // -----------------------------------------
46 //
47 // After successful path verification, the caller is responsible for
48 // subsequently checking:
42 // 49 //
43 // * The end-entity's KeyUsage before using its SPKI. 50 // * The end-entity's KeyUsage before using its SPKI.
44 // * The end-entity's name/subjectAltName (note that name constraints from 51 // * The end-entity's name/subjectAltName. Name constraints from intermediates
45 // intermediates will have already been applied, so just need to check 52 // will have already been applied, so it is sufficient to check the
46 // the end-entity for a match). 53 // end-entity for a match.
47 // * Policies
48 //
49 // WARNING: This implementation is in progress, and is currently incomplete.
50 // Consult an OWNER before using it.
51 //
52 // TODO(eroman): Take a CertPath instead of ParsedCertificateList +
53 // TrustAnchor.
54 // 54 //
55 // --------- 55 // ---------
56 // Inputs 56 // Inputs
57 // --------- 57 // ---------
58 // 58 //
59 // cert_chain: 59 // certs:
60 // A non-empty chain of N DER-encoded certificates, listed in the 60 // A non-empty chain of DER-encoded certificates, listed in the
61 // "forward" direction. The first certificate is the target certificate to 61 // "forward" direction. The first certificate is the target
62 // verify, and the last certificate has trustedness given by 62 // certificate to verify, and the last certificate has trustedness
63 // |last_cert_trust|. 63 // given by |last_cert_trust| (generally a trust anchor).
64 // 64 //
65 // * cert_chain[0] is the target certificate to verify. 65 // * certs[0] is the target certificate to verify.
66 // * cert_chain[i+1] holds the certificate that issued cert_chain[i]. 66 // * certs[i+1] holds the certificate that issued cert_chain[i].
67 // * cert_chain[N-1] the root certificate 67 // * certs[N-1] the root certificate
68 //
69 // Note that THIS IS NOT identical in meaning to the same named
70 // "certs" input defined in RFC 5280 section 6.1.1.a. The differences
71 // are:
72 //
73 // * The order of certificates is reversed
74 // * In RFC 5280 "certs" DOES NOT include the trust anchor
68 // 75 //
69 // last_cert_trust: 76 // last_cert_trust:
70 // Trustedness of certs.back(). The trustedness of certs.back() MUST BE 77 // Trustedness of |certs.back()|. The trustedness of |certs.back()|
71 // decided by the caller -- this function takes it purely as an input. 78 // MUST BE decided by the caller -- this function takes it purely as
72 // Moreover, the CertificateTrust can be used to specify trust anchor 79 // an input. Moreover, the CertificateTrust can be used to specify
73 // constraints [1] 80 // trust anchor constraints.
81 //
82 // This combined with |certs.back()| (the root certificate) fills a
83 // similar role to "trust anchor information" defined in RFC 5280
84 // section 6.1.1.d.
74 // 85 //
75 // signature_policy: 86 // signature_policy:
76 // The policy to use when verifying signatures (what hash algorithms are 87 // The policy to use when verifying signatures (what hash algorithms are
77 // allowed, what length keys, what named curves, etc). 88 // allowed, what length keys, what named curves, etc).
78 // 89 //
79 // time: 90 // time:
80 // The UTC time to use for expiration checks. 91 // The UTC time to use for expiration checks. This is equivalent to
92 // the input from RFC 5280 section 6.1.1:
81 // 93 //
82 // key_purpose: 94 // (b) the current date/time.
95 //
96 // required_key_purpose:
83 // The key purpose that the target certificate needs to be valid for. 97 // The key purpose that the target certificate needs to be valid for.
84 // 98 //
99 // user_initial_policy_set:
100 // This is equivalent to the same named input in RFC 5280 section
101 // 6.1.1:
102 //
103 // (c) user-initial-policy-set: A set of certificate policy
104 // identifiers naming the policies that are acceptable to the
105 // certificate user. The user-initial-policy-set contains the
106 // special value any-policy if the user is not concerned about
107 // certificate policy.
108 //
109 // initial_policy_mapping_inhibit:
110 // This is equivalent to the same named input in RFC 5280 section
111 // 6.1.1:
112 //
113 // (e) initial-policy-mapping-inhibit, which indicates if policy
114 // mapping is allowed in the certification path.
115 //
116 // initial_explicit_policy:
117 // This is equivalent to the same named input in RFC 5280 section
118 // 6.1.1:
119 //
120 // (f) initial-explicit-policy, which indicates if the path must be
121 // valid for at least one of the certificate policies in the
122 // user-initial-policy-set.
123 //
124 // initial_any_policy_inhibit:
125 // This is equivalent to the same named input in RFC 5280 section
126 // 6.1.1:
127 //
128 // (g) initial-any-policy-inhibit, which indicates whether the
129 // anyPolicy OID should be processed if it is included in a
130 // certificate.
131 //
85 // --------- 132 // ---------
86 // Outputs 133 // Outputs
87 // --------- 134 // ---------
88 // errors: 135 // errors:
89 // Must be non-null. The set of errors/warnings encountered while 136 // Must be non-null. The set of errors/warnings encountered while
90 // validating the path are appended to this structure. If verification 137 // validating the path are appended to this structure. If verification
91 // failed, then there is guaranteed to be at least 1 high severity error 138 // failed, then there is guaranteed to be at least 1 high severity error
92 // written to |errors|. 139 // written to |errors|.
93 // 140 //
94 // [1] Conceptually VerifyCertificateChain() sets RFC 5937's 141 // -------------------------
95 // "enforceTrustAnchorConstraints" to true. And one specifies whether to 142 // Trust Anchor constraints
96 // interpret a root certificate as having trust anchor constraints through the 143 // -------------------------
97 // |last_cert_trust| parameter. The constraints are just a subset of the 144 //
98 // extensions present in the certificate: 145 // Conceptually, VerifyCertificateChain() sets RFC 5937's
146 // "enforceTrustAnchorConstraints" to true.
147 //
148 // One specifies trust anchor constraints using the |last_cert_trust|
149 // parameter in conjunction with extensions appearing in |certs.back()|.
150 //
151 // The trust anchor |certs.back()| is always passed as a certificate to
152 // this function, however the manner in which that certificate is
153 // interpreted depends on |last_cert_trust|:
154 //
155 // TRUSTED_ANCHOR:
156 //
157 // No properties from the root certificate, other than its Subject and
158 // SPKI, are checked during verification. This is the usual
159 // interpretation for a "trust anchor".
160 //
161 // TRUSTED_ANCHOR_WITH_CONSTRAINTS:
162 //
163 // Only a subset of extensions and properties from the certificate are checked:
99 // 164 //
100 // * Signature: No 165 // * Signature: No
101 // * Validity (expiration): No 166 // * Validity (expiration): No
102 // * Key usage: No 167 // * Key usage: No
103 // * Extended key usage: Yes (not part of RFC 5937) 168 // * Extended key usage: Yes (not part of RFC 5937)
104 // * Basic constraints: Yes, but only the pathlen (CA=false is accepted) 169 // * Basic constraints: Yes, but only the pathlen (CA=false is accepted)
105 // * Name constraints: Yes 170 // * Name constraints: Yes
106 // * Certificate policies: Not currently, TODO(crbug.com/634453) 171 // * Certificate policies: Not currently, TODO(crbug.com/634453)
172 // * Policy Mappings: No
mattm 2017/05/25 23:21:49 yes?
eroman 2017/05/26 18:49:59 The "No" is because it is not specified in rfc 593
107 // * inhibitAnyPolicy: Not currently, TODO(crbug.com/634453) 173 // * inhibitAnyPolicy: Not currently, TODO(crbug.com/634453)
108 // * PolicyConstraints: Not currently, TODO(crbug.com/634452) 174 // * PolicyConstraints: Not currently, TODO(crbug.com/634452)
109 // 175 //
110 // The presence of any other unrecognized extension marked as critical fails 176 // The presence of any other unrecognized extension marked as critical fails
111 // validation. 177 // validation.
112 NET_EXPORT void VerifyCertificateChain(const ParsedCertificateList& certs, 178 NET_EXPORT void VerifyCertificateChain(
113 const CertificateTrust& last_cert_trust, 179 const ParsedCertificateList& certs,
114 const SignaturePolicy* signature_policy, 180 const CertificateTrust& last_cert_trust,
115 const der::GeneralizedTime& time, 181 const SignaturePolicy* signature_policy,
116 KeyPurpose required_key_purpose, 182 const der::GeneralizedTime& time,
117 CertPathErrors* errors); 183 KeyPurpose required_key_purpose,
184 bool initial_explicit_policy,
185 const std::set<der::Input>& user_initial_policy_set,
186 bool initial_policy_mapping_inhibit,
187 bool initial_any_policy_inhibit,
mattm 2017/05/25 23:21:49 maybe use enums instead of passing a bunch of bool
eroman 2017/05/26 18:49:59 sgtm
188 CertPathErrors* errors);
mattm 2017/05/25 23:21:49 Add a todo for outputting the final valid_policy_t
eroman 2017/05/26 18:49:59 Good idea. I will go ahead and add "user-constrai
118 189
119 // TODO(crbug.com/634443): Move exported errors to a central location? 190 // TODO(crbug.com/634443): Move exported errors to a central location?
120 extern CertErrorId kValidityFailedNotAfter; 191 extern CertErrorId kValidityFailedNotAfter;
121 extern CertErrorId kValidityFailedNotBefore; 192 extern CertErrorId kValidityFailedNotBefore;
122 NET_EXPORT extern CertErrorId kCertIsDistrusted; 193 NET_EXPORT extern CertErrorId kCertIsDistrusted;
123 194
124 } // namespace net 195 } // namespace net
125 196
126 #endif // NET_CERT_INTERNAL_VERIFY_CERTIFICATE_CHAIN_H_ 197 #endif // NET_CERT_INTERNAL_VERIFY_CERTIFICATE_CHAIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698