OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef NET_CERT_INTERNAL_PARSE_CERTIFICATE_H_ | |
6 #define NET_CERT_INTERNAL_PARSE_CERTIFICATE_H_ | |
7 | |
8 #include "base/basictypes.h" | |
9 #include "base/compiler_specific.h" | |
10 #include "net/base/net_export.h" | |
11 #include "net/der/input.h" | |
12 #include "net/der/parse_values.h" | |
13 | |
14 namespace net { | |
15 | |
16 struct ParsedCertificate; | |
17 struct ParsedTbsCertificate; | |
18 | |
19 // Parses a DER-encoded "Certificate" as specified by RFC 5280. Returns true on | |
20 // success and sets the results in |out|. | |
21 // | |
22 // Refer to the per-field documention of the ParsedCertificate structure for | |
23 // details on what validity checks parsing performs. | |
24 // | |
25 // Certificate ::= SEQUENCE { | |
26 // tbsCertificate TBSCertificate, | |
27 // signatureAlgorithm AlgorithmIdentifier, | |
28 // signatureValue BIT STRING } | |
29 NET_EXPORT bool ParseCertificate(const der::Input& certificate_tlv, | |
30 ParsedCertificate* out) WARN_UNUSED_RESULT; | |
31 | |
32 // Parses a DER-encoded "TBSCertificate" as specified by RFC 5280. Returns true | |
33 // on success and sets the results in |out|. | |
34 // | |
35 // Refer to the per-field documentation of ParsedTbsCertificate for details on | |
36 // what validity checks parsing performs. | |
37 // | |
38 // TBSCertificate ::= SEQUENCE { | |
39 // version [0] EXPLICIT Version DEFAULT v1, | |
40 // serialNumber CertificateSerialNumber, | |
41 // signature AlgorithmIdentifier, | |
42 // issuer Name, | |
43 // validity Validity, | |
44 // subject Name, | |
45 // subjectPublicKeyInfo SubjectPublicKeyInfo, | |
46 // issuerUniqueID [1] IMPLICIT UniqueIdentifier OPTIONAL, | |
47 // -- If present, version MUST be v2 or v3 | |
48 // subjectUniqueID [2] IMPLICIT UniqueIdentifier OPTIONAL, | |
49 // -- If present, version MUST be v2 or v3 | |
50 // extensions [3] EXPLICIT Extensions OPTIONAL | |
51 // -- If present, version MUST be v3 | |
52 // } | |
53 NET_EXPORT bool ParseTbsCertificate(const der::Input& tbs_tlv, | |
54 ParsedTbsCertificate* out) | |
55 WARN_UNUSED_RESULT; | |
56 | |
57 // Represents a "Version" from RFC 5280: | |
58 // Version ::= INTEGER { v1(0), v2(1), v3(2) } | |
59 enum class CertificateVersion { | |
60 V1, | |
61 V2, | |
62 V3, | |
63 }; | |
64 | |
65 // ParsedCertificate contains pointers to the main fields of a DER-encoded RFC | |
66 // 5280 "Certificate". | |
67 // | |
68 // ParsedCertificate is expected to be filled by ParseCertificate(), so | |
69 // subsequent field descriptions are in terms of what ParseCertificate() sets. | |
70 struct NET_EXPORT ParsedCertificate { | |
davidben
2015/08/11 20:31:56
I don't know if you want ot share code or not both
eroman
2015/08/11 21:13:34
That sounds reasonable, let me give it a try (alth
eroman
2015/08/12 00:37:10
I split up the tests for separate Certificate and
davidben
2015/08/12 16:20:59
Mostly as an example of something which treats thi
| |
71 // Corresponds with "tbsCertificate" from RFC 5280: | |
72 // tbsCertificate TBSCertificate, | |
73 // | |
74 // This contains the full (unverified) Tag-Length-Value. No guarantees are | |
75 // made on the tag or value (might not be a sequence for instance). | |
davidben
2015/08/11 20:31:57
If you want to at least check the SEQUENCE, Boring
eroman
2015/08/11 21:13:33
Is your suggestion here to use BoringSSL's CBS_get
davidben
2015/08/12 16:20:59
I just meant that (a) is an option. What you have
eroman
2015/08/13 00:31:46
Done -- I am now enforcing that all those TLVs mus
| |
76 // | |
77 // This can be further parsed using ParseTbsCertificate(). | |
78 der::Input tbs_certificate_tlv; | |
79 | |
80 // Corresponds with "signatureAlgorithm" from RFC 5280: | |
81 // signatureAlgorithm AlgorithmIdentifier, | |
82 // | |
83 // This contains the full (unverified) Tag-Length-Value. No guarantees are | |
84 // made on the tag or value (might not be a sequence for instance). | |
85 // | |
86 // This can be further parsed using SignatureValue::CreateFromDer(). | |
87 der::Input signature_algorithm_tlv; | |
88 | |
89 // Corresponds with "signatureValue" from RFC 5280: | |
90 // signatureValue BIT STRING } | |
91 // | |
92 // Parsing guarantees that this is a valid BIT STRING. | |
93 der::BitString signature_value; | |
94 }; | |
95 | |
96 // ParsedTbsCertificate contains pointers to the main fields of a DER-encoded | |
97 // RFC 5280 "TBSCertificate". | |
98 // | |
99 // ParsedTbsCertificate is expected to be filled by ParseTbsCertificate(), so | |
100 // subsequent field descriptions are in terms of what ParseTbsCertificate() | |
101 // sets. | |
102 struct NET_EXPORT ParsedTbsCertificate { | |
103 ParsedTbsCertificate(); | |
104 ~ParsedTbsCertificate(); | |
105 | |
106 // Corresponds with "version" from RFC 5280: | |
107 // version [0] EXPLICIT Version DEFAULT v1, | |
108 // | |
109 // Parsing guarantees that the version is one of v1, v2, or v3. | |
110 CertificateVersion version; | |
111 | |
112 // Corresponds with "serialNumber" from RFC 5280: | |
113 // serialNumber CertificateSerialNumber, | |
114 // | |
115 // This field specifically contains the content bytes of the INTEGER. So for | |
116 // instance if the serial number was 1000 then this would contain bytes | |
117 // {0x03, 0xE8}. | |
118 // | |
119 // In addition to being a valid DER-encoded INTEGER, parsing guarantees that | |
120 // the serial number is at most 20 bytes long. Parsing does NOT guarantee | |
121 // that the integer is positive (might be zero or negative). | |
122 der::Input serial_number; | |
123 | |
124 // Corresponds with "signatureAlgorithm" from RFC 5280: | |
125 // signatureAlgorithm AlgorithmIdentifier, | |
126 // | |
127 // This contains the full (unverified) Tag-Length-Value. No guarantees are | |
128 // made on the tag or value (might not be a sequence for instance). | |
129 // | |
130 // This can be further parsed using SignatureValue::CreateFromDer(). | |
131 der::Input signature_algorithm_tlv; | |
132 | |
133 // Corresponds with "issuer" from RFC 5280: | |
134 // issuer Name, | |
135 // | |
136 // This contains the full (unverified) Tag-Length-Value. No guarantees are | |
137 // made on the tag or value. | |
138 der::Input issuer_tlv; | |
139 | |
140 // Corresponds with "validity" from RFC 5280: | |
141 // validity Validity, | |
142 // | |
143 // This contains the full (unverified) Tag-Length-Value. No guarantees are | |
144 // made on the tag or value. | |
145 der::Input validity_tlv; | |
146 | |
147 // Corresponds with "subject" from RFC 5280: | |
148 // subject Name, | |
149 // | |
150 // This contains the full (unverified) Tag-Length-Value. No guarantees are | |
151 // made on the tag or value. | |
152 der::Input subject_tlv; | |
153 | |
154 // Corresponds with "subjectPublicKeyInfo" from RFC 5280: | |
155 // subjectPublicKeyInfo SubjectPublicKeyInfo, | |
156 // | |
157 // This contains the full (unverified) Tag-Length-Value. No guarantees are | |
158 // made on the tag or value. | |
159 der::Input spki_tlv; | |
160 | |
161 // Corresponds with "issuerUniqueID" from RFC 5280: | |
162 // issuerUniqueID [1] IMPLICIT UniqueIdentifier OPTIONAL, | |
163 // -- If present, version MUST be v2 or v3 | |
164 // | |
165 // Parsing guarantees that if issuer_unique_id is present it is a valid BIT | |
166 // STRING, and that the version is either v2 or v3 | |
167 bool has_issuer_unique_id; | |
168 der::BitString issuer_unique_id; | |
169 | |
170 // Corresponds with "subjectUniqueID" from RFC 5280: | |
171 // subjectUniqueID [2] IMPLICIT UniqueIdentifier OPTIONAL, | |
172 // -- If present, version MUST be v2 or v3 | |
173 // | |
174 // Parsing guarantees that if subject_unique_id is present it is a valid BIT | |
175 // STRING, and that the version is either v2 or v3 | |
176 bool has_subject_unique_id; | |
177 der::BitString subject_unique_id; | |
178 | |
179 // Corresponds with "extensions" from RFC 5280: | |
180 // extensions [3] EXPLICIT Extensions OPTIONAL | |
181 // -- If present, version MUST be v3 | |
182 // | |
183 // This contains the full (unverified) Tag-Length-Value. No guarantees are | |
184 // made on the tag or value. | |
davidben
2015/08/11 20:31:57
This includes the TLV for Extensions, but not the
eroman
2015/08/12 00:37:10
Done.
| |
185 // | |
186 // Parsing guarantees that if extensions is present the version is v3. | |
187 bool has_extensions; | |
188 der::Input extensions_tlv; | |
189 }; | |
190 | |
191 } // namespace net | |
192 | |
193 #endif // NET_CERT_INTERNAL_PARSE_CERTIFICATE_H_ | |
OLD | NEW |