• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2015 The Chromium Authors
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 BSSL_PKI_PARSE_CERTIFICATE_H_
6 #define BSSL_PKI_PARSE_CERTIFICATE_H_
7 
8 #include "fillins/openssl_util.h"
9 #include <stdint.h>
10 
11 #include <map>
12 #include <memory>
13 #include <vector>
14 
15 
16 #include "general_names.h"
17 #include "input.h"
18 #include "parse_values.h"
19 #include <optional>
20 
21 namespace bssl {
22 
23 namespace der {
24 class Parser;
25 }
26 
27 class CertErrors;
28 struct ParsedTbsCertificate;
29 
30 // Returns true if the given serial number (CertificateSerialNumber in RFC 5280)
31 // is valid:
32 //
33 //    CertificateSerialNumber  ::=  INTEGER
34 //
35 // The input to this function is the (unverified) value octets of the INTEGER.
36 // This function will verify that:
37 //
38 //   * The octets are a valid DER-encoding of an INTEGER (for instance, minimal
39 //     encoding length).
40 //
41 //   * No more than 20 octets are used.
42 //
43 // Note that it DOES NOT reject non-positive values (zero or negative).
44 //
45 // For reference, here is what RFC 5280 section 4.1.2.2 says:
46 //
47 //     Given the uniqueness requirements above, serial numbers can be
48 //     expected to contain long integers.  Certificate users MUST be able to
49 //     handle serialNumber values up to 20 octets.  Conforming CAs MUST NOT
50 //     use serialNumber values longer than 20 octets.
51 //
52 //     Note: Non-conforming CAs may issue certificates with serial numbers
53 //     that are negative or zero.  Certificate users SHOULD be prepared to
54 //     gracefully handle such certificates.
55 //
56 // |errors| must be a non-null destination for any errors/warnings. If
57 // |warnings_only| is set to true, then what would ordinarily be errors are
58 // instead added as warnings.
59 [[nodiscard]] OPENSSL_EXPORT bool VerifySerialNumber(const der::Input& value,
60                                                  bool warnings_only,
61                                                  CertErrors* errors);
62 
63 // Consumes a "Time" value (as defined by RFC 5280) from |parser|. On success
64 // writes the result to |*out| and returns true. On failure no guarantees are
65 // made about the state of |parser|.
66 //
67 // From RFC 5280:
68 //
69 //     Time ::= CHOICE {
70 //          utcTime        UTCTime,
71 //          generalTime    GeneralizedTime }
72 [[nodiscard]] OPENSSL_EXPORT bool ReadUTCOrGeneralizedTime(
73     der::Parser* parser,
74     der::GeneralizedTime* out);
75 
76 // Parses a DER-encoded "Validity" as specified by RFC 5280. Returns true on
77 // success and sets the results in |not_before| and |not_after|:
78 //
79 //       Validity ::= SEQUENCE {
80 //            notBefore      Time,
81 //            notAfter       Time }
82 //
83 // Note that upon success it is NOT guaranteed that |*not_before <= *not_after|.
84 [[nodiscard]] OPENSSL_EXPORT bool ParseValidity(const der::Input& validity_tlv,
85                                             der::GeneralizedTime* not_before,
86                                             der::GeneralizedTime* not_after);
87 
88 struct OPENSSL_EXPORT ParseCertificateOptions {
89   // If set to true, then parsing will skip checks on the certificate's serial
90   // number. The only requirement will be that the serial number is an INTEGER,
91   // however it is not required to be a valid DER-encoding (i.e. minimal
92   // encoding), nor is it required to be constrained to any particular length.
93   bool allow_invalid_serial_numbers = false;
94 };
95 
96 // Parses a DER-encoded "Certificate" as specified by RFC 5280. Returns true on
97 // success and sets the results in the |out_*| parameters. On both the failure
98 // and success case, if |out_errors| was non-null it may contain extra error
99 // information.
100 //
101 // Note that on success the out parameters alias data from the input
102 // |certificate_tlv|.  Hence the output values are only valid as long as
103 // |certificate_tlv| remains valid.
104 //
105 // On failure the out parameters have an undefined state, except for
106 // out_errors. Some of them may have been updated during parsing, whereas
107 // others may not have been changed.
108 //
109 // The out parameters represent each field of the Certificate SEQUENCE:
110 //       Certificate  ::=  SEQUENCE  {
111 //
112 // The |out_tbs_certificate_tlv| parameter corresponds with "tbsCertificate"
113 // from RFC 5280:
114 //         tbsCertificate       TBSCertificate,
115 //
116 // This contains the full (unverified) Tag-Length-Value for a SEQUENCE. No
117 // guarantees are made regarding the value of this SEQUENCE.
118 // This can be further parsed using ParseTbsCertificate().
119 //
120 // The |out_signature_algorithm_tlv| parameter corresponds with
121 // "signatureAlgorithm" from RFC 5280:
122 //         signatureAlgorithm   AlgorithmIdentifier,
123 //
124 // This contains the full (unverified) Tag-Length-Value for a SEQUENCE. No
125 // guarantees are made regarding the value of this SEQUENCE.
126 // This can be further parsed using SignatureValue::Create().
127 //
128 // The |out_signature_value| parameter corresponds with "signatureValue" from
129 // RFC 5280:
130 //         signatureValue       BIT STRING  }
131 //
132 // Parsing guarantees that this is a valid BIT STRING.
133 [[nodiscard]] OPENSSL_EXPORT bool ParseCertificate(
134     const der::Input& certificate_tlv,
135     der::Input* out_tbs_certificate_tlv,
136     der::Input* out_signature_algorithm_tlv,
137     der::BitString* out_signature_value,
138     CertErrors* out_errors);
139 
140 // Parses a DER-encoded "TBSCertificate" as specified by RFC 5280. Returns true
141 // on success and sets the results in |out|. Certain invalid inputs may
142 // be accepted based on the provided |options|.
143 //
144 // If |errors| was non-null then any warnings/errors that occur during parsing
145 // are added to it.
146 //
147 // Note that on success |out| aliases data from the input |tbs_tlv|.
148 // Hence the fields of the ParsedTbsCertificate are only valid as long as
149 // |tbs_tlv| remains valid.
150 //
151 // On failure |out| has an undefined state. Some of its fields may have been
152 // updated during parsing, whereas others may not have been changed.
153 //
154 // Refer to the per-field documentation of ParsedTbsCertificate for details on
155 // what validity checks parsing performs.
156 //
157 //       TBSCertificate  ::=  SEQUENCE  {
158 //            version         [0]  EXPLICIT Version DEFAULT v1,
159 //            serialNumber         CertificateSerialNumber,
160 //            signature            AlgorithmIdentifier,
161 //            issuer               Name,
162 //            validity             Validity,
163 //            subject              Name,
164 //            subjectPublicKeyInfo SubjectPublicKeyInfo,
165 //            issuerUniqueID  [1]  IMPLICIT UniqueIdentifier OPTIONAL,
166 //                                 -- If present, version MUST be v2 or v3
167 //            subjectUniqueID [2]  IMPLICIT UniqueIdentifier OPTIONAL,
168 //                                 -- If present, version MUST be v2 or v3
169 //            extensions      [3]  EXPLICIT Extensions OPTIONAL
170 //                                 -- If present, version MUST be v3
171 //            }
172 [[nodiscard]] OPENSSL_EXPORT bool ParseTbsCertificate(
173     const der::Input& tbs_tlv,
174     const ParseCertificateOptions& options,
175     ParsedTbsCertificate* out,
176     CertErrors* errors);
177 
178 // Represents a "Version" from RFC 5280:
179 //         Version  ::=  INTEGER  {  v1(0), v2(1), v3(2)  }
180 enum class CertificateVersion {
181   V1,
182   V2,
183   V3,
184 };
185 
186 // ParsedTbsCertificate contains pointers to the main fields of a DER-encoded
187 // RFC 5280 "TBSCertificate".
188 //
189 // ParsedTbsCertificate is expected to be filled by ParseTbsCertificate(), so
190 // subsequent field descriptions are in terms of what ParseTbsCertificate()
191 // sets.
192 struct OPENSSL_EXPORT ParsedTbsCertificate {
193   ParsedTbsCertificate();
194   ParsedTbsCertificate(ParsedTbsCertificate&& other);
195   ParsedTbsCertificate& operator=(ParsedTbsCertificate&& other) = default;
196   ~ParsedTbsCertificate();
197 
198   // Corresponds with "version" from RFC 5280:
199   //         version         [0]  EXPLICIT Version DEFAULT v1,
200   //
201   // Parsing guarantees that the version is one of v1, v2, or v3.
202   CertificateVersion version = CertificateVersion::V1;
203 
204   // Corresponds with "serialNumber" from RFC 5280:
205   //         serialNumber         CertificateSerialNumber,
206   //
207   // This field specifically contains the content bytes of the INTEGER. So for
208   // instance if the serial number was 1000 then this would contain bytes
209   // {0x03, 0xE8}.
210   //
211   // The serial number may or may not be a valid DER-encoded INTEGER:
212   //
213   // If the option |allow_invalid_serial_numbers=true| was used during
214   // parsing, then nothing further can be assumed about these bytes.
215   //
216   // Otherwise if |allow_invalid_serial_numbers=false| then in addition
217   // to being a valid DER-encoded INTEGER, parsing guarantees that
218   // the serial number is at most 20 bytes long. Parsing does NOT guarantee
219   // that the integer is positive (might be zero or negative).
220   der::Input serial_number;
221 
222   // Corresponds with "signatureAlgorithm" from RFC 5280:
223   //         signatureAlgorithm   AlgorithmIdentifier,
224   //
225   // This contains the full (unverified) Tag-Length-Value for a SEQUENCE. No
226   // guarantees are made regarding the value of this SEQUENCE.
227   //
228   // This can be further parsed using SignatureValue::Create().
229   der::Input signature_algorithm_tlv;
230 
231   // Corresponds with "issuer" from RFC 5280:
232   //         issuer               Name,
233   //
234   // This contains the full (unverified) Tag-Length-Value for a SEQUENCE. No
235   // guarantees are made regarding the value of this SEQUENCE.
236   der::Input issuer_tlv;
237 
238   // Corresponds with "validity" from RFC 5280:
239   //         validity             Validity,
240   //
241   // Where Validity is defined as:
242   //
243   //   Validity ::= SEQUENCE {
244   //        notBefore      Time,
245   //        notAfter       Time }
246   //
247   // Parsing guarantees that notBefore (validity_not_before) and notAfter
248   // (validity_not_after) are valid DER-encoded dates, however it DOES NOT
249   // gurantee anything about their values. For instance notAfter could be
250   // before notBefore, or the dates could indicate an expired certificate.
251   // Consumers are responsible for testing expiration.
252   der::GeneralizedTime validity_not_before;
253   der::GeneralizedTime validity_not_after;
254 
255   // Corresponds with "subject" from RFC 5280:
256   //         subject              Name,
257   //
258   // This contains the full (unverified) Tag-Length-Value for a SEQUENCE. No
259   // guarantees are made regarding the value of this SEQUENCE.
260   der::Input subject_tlv;
261 
262   // Corresponds with "subjectPublicKeyInfo" from RFC 5280:
263   //         subjectPublicKeyInfo SubjectPublicKeyInfo,
264   //
265   // This contains the full (unverified) Tag-Length-Value for a SEQUENCE. No
266   // guarantees are made regarding the value of this SEQUENCE.
267   der::Input spki_tlv;
268 
269   // Corresponds with "issuerUniqueID" from RFC 5280:
270   //         issuerUniqueID  [1]  IMPLICIT UniqueIdentifier OPTIONAL,
271   //                              -- If present, version MUST be v2 or v3
272   //
273   // Parsing guarantees that if issuer_unique_id is present it is a valid BIT
274   // STRING, and that the version is either v2 or v3
275   std::optional<der::BitString> issuer_unique_id;
276 
277   // Corresponds with "subjectUniqueID" from RFC 5280:
278   //         subjectUniqueID [2]  IMPLICIT UniqueIdentifier OPTIONAL,
279   //                              -- If present, version MUST be v2 or v3
280   //
281   // Parsing guarantees that if subject_unique_id is present it is a valid BIT
282   // STRING, and that the version is either v2 or v3
283   std::optional<der::BitString> subject_unique_id;
284 
285   // Corresponds with "extensions" from RFC 5280:
286   //         extensions      [3]  EXPLICIT Extensions OPTIONAL
287   //                              -- If present, version MUST be v3
288   //
289   //
290   // This contains the full (unverified) Tag-Length-Value for a SEQUENCE. No
291   // guarantees are made regarding the value of this SEQUENCE. (Note that the
292   // EXPLICIT outer tag is stripped.)
293   //
294   // Parsing guarantees that if extensions is present the version is v3.
295   std::optional<der::Input> extensions_tlv;
296 };
297 
298 // ParsedExtension represents a parsed "Extension" from RFC 5280. It contains
299 // der:Inputs which are not owned so the associated data must be kept alive.
300 //
301 //    Extension  ::=  SEQUENCE  {
302 //            extnID      OBJECT IDENTIFIER,
303 //            critical    BOOLEAN DEFAULT FALSE,
304 //            extnValue   OCTET STRING
305 //                        -- contains the DER encoding of an ASN.1 value
306 //                        -- corresponding to the extension type identified
307 //                        -- by extnID
308 //            }
309 struct OPENSSL_EXPORT ParsedExtension {
310   der::Input oid;
311   // |value| will contain the contents of the OCTET STRING. For instance for
312   // basicConstraints it will be the TLV for a SEQUENCE.
313   der::Input value;
314   bool critical = false;
315 };
316 
317 // Parses a DER-encoded "Extension" as specified by RFC 5280. Returns true on
318 // success and sets the results in |out|.
319 //
320 // Note that on success |out| aliases data from the input |extension_tlv|.
321 // Hence the fields of the ParsedExtension are only valid as long as
322 // |extension_tlv| remains valid.
323 //
324 // On failure |out| has an undefined state. Some of its fields may have been
325 // updated during parsing, whereas others may not have been changed.
326 [[nodiscard]] OPENSSL_EXPORT bool ParseExtension(const der::Input& extension_tlv,
327                                              ParsedExtension* out);
328 
329 // From RFC 5280:
330 //
331 //     id-ce-subjectKeyIdentifier OBJECT IDENTIFIER ::=  { id-ce 14 }
332 //
333 // In dotted notation: 2.5.29.14
334 inline constexpr uint8_t kSubjectKeyIdentifierOid[] = {0x55, 0x1d, 0x0e};
335 
336 // From RFC 5280:
337 //
338 //     id-ce-keyUsage OBJECT IDENTIFIER ::=  { id-ce 15 }
339 //
340 // In dotted notation: 2.5.29.15
341 inline constexpr uint8_t kKeyUsageOid[] = {0x55, 0x1d, 0x0f};
342 
343 // From RFC 5280:
344 //
345 //     id-ce-subjectAltName OBJECT IDENTIFIER ::=  { id-ce 17 }
346 //
347 // In dotted notation: 2.5.29.17
348 inline constexpr uint8_t kSubjectAltNameOid[] = {0x55, 0x1d, 0x11};
349 
350 // From RFC 5280:
351 //
352 //     id-ce-basicConstraints OBJECT IDENTIFIER ::=  { id-ce 19 }
353 //
354 // In dotted notation: 2.5.29.19
355 inline constexpr uint8_t kBasicConstraintsOid[] = {0x55, 0x1d, 0x13};
356 
357 // From RFC 5280:
358 //
359 //     id-ce-nameConstraints OBJECT IDENTIFIER ::=  { id-ce 30 }
360 //
361 // In dotted notation: 2.5.29.30
362 inline constexpr uint8_t kNameConstraintsOid[] = {0x55, 0x1d, 0x1e};
363 
364 // From RFC 5280:
365 //
366 //     id-ce-certificatePolicies OBJECT IDENTIFIER ::=  { id-ce 32 }
367 //
368 // In dotted notation: 2.5.29.32
369 inline constexpr uint8_t kCertificatePoliciesOid[] = {0x55, 0x1d, 0x20};
370 
371 // From RFC 5280:
372 //
373 //     id-ce-authorityKeyIdentifier OBJECT IDENTIFIER ::=  { id-ce 35 }
374 //
375 // In dotted notation: 2.5.29.35
376 inline constexpr uint8_t kAuthorityKeyIdentifierOid[] = {0x55, 0x1d, 0x23};
377 
378 // From RFC 5280:
379 //
380 //     id-ce-policyConstraints OBJECT IDENTIFIER ::=  { id-ce 36 }
381 //
382 // In dotted notation: 2.5.29.36
383 inline constexpr uint8_t kPolicyConstraintsOid[] = {0x55, 0x1d, 0x24};
384 
385 // From RFC 5280:
386 //
387 //     id-ce-extKeyUsage OBJECT IDENTIFIER ::= { id-ce 37 }
388 //
389 // In dotted notation: 2.5.29.37
390 inline constexpr uint8_t kExtKeyUsageOid[] = {0x55, 0x1d, 0x25};
391 
392 // From RFC 5280:
393 //
394 //     id-pe-authorityInfoAccess OBJECT IDENTIFIER ::= { id-pe 1 }
395 //
396 // In dotted notation: 1.3.6.1.5.5.7.1.1
397 inline constexpr uint8_t kAuthorityInfoAccessOid[] = {0x2B, 0x06, 0x01, 0x05,
398                                                       0x05, 0x07, 0x01, 0x01};
399 
400 // From RFC 5280:
401 //
402 //     id-ad-caIssuers OBJECT IDENTIFIER ::= { id-ad 2 }
403 //
404 // In dotted notation: 1.3.6.1.5.5.7.48.2
405 inline constexpr uint8_t kAdCaIssuersOid[] = {0x2B, 0x06, 0x01, 0x05,
406                                               0x05, 0x07, 0x30, 0x02};
407 
408 // From RFC 5280:
409 //
410 //     id-ad-ocsp OBJECT IDENTIFIER ::= { id-ad 1 }
411 //
412 // In dotted notation: 1.3.6.1.5.5.7.48.1
413 inline constexpr uint8_t kAdOcspOid[] = {0x2B, 0x06, 0x01, 0x05,
414                                          0x05, 0x07, 0x30, 0x01};
415 
416 // From RFC 5280:
417 //
418 //     id-ce-cRLDistributionPoints OBJECT IDENTIFIER ::=  { id-ce 31 }
419 //
420 // In dotted notation: 2.5.29.31
421 inline constexpr uint8_t kCrlDistributionPointsOid[] = {0x55, 0x1d, 0x1f};
422 
423 // From
424 // https://learn.microsoft.com/en-us/windows/win32/seccertenroll/supported-extensions#msapplicationpolicies
425 //
426 // OID: XCN_OID_APPLICATION_CERT_POLICIES (1.3.6.1.4.1.311.21.10)
427 inline constexpr uint8_t kMSApplicationPoliciesOid[] = {
428     0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x15, 0x0a};
429 
430 // Parses the Extensions sequence as defined by RFC 5280. Extensions are added
431 // to the map |extensions| keyed by the OID. Parsing guarantees that each OID
432 // is unique. Note that certificate verification must consume each extension
433 // marked as critical.
434 //
435 // Returns true on success and fills |extensions|. The output will reference
436 // bytes in |extensions_tlv|, so that data must be kept alive.
437 // On failure |extensions| may be partially written to and should not be used.
438 [[nodiscard]] OPENSSL_EXPORT bool ParseExtensions(
439     const der::Input& extensions_tlv,
440     std::map<der::Input, ParsedExtension>* extensions);
441 
442 // Removes the extension with OID |oid| from |unconsumed_extensions| and fills
443 // |extension| with the matching extension value. If there was no extension
444 // matching |oid| then returns |false|.
445 [[nodiscard]] OPENSSL_EXPORT bool ConsumeExtension(
446     const der::Input& oid,
447     std::map<der::Input, ParsedExtension>* unconsumed_extensions,
448     ParsedExtension* extension);
449 
450 struct ParsedBasicConstraints {
451   bool is_ca = false;
452   bool has_path_len = false;
453   uint8_t path_len = 0;
454 };
455 
456 // Parses the BasicConstraints extension as defined by RFC 5280:
457 //
458 //    BasicConstraints ::= SEQUENCE {
459 //         cA                      BOOLEAN DEFAULT FALSE,
460 //         pathLenConstraint       INTEGER (0..MAX) OPTIONAL }
461 //
462 // The maximum allowed value of pathLenConstraints will be whatever can fit
463 // into a uint8_t.
464 [[nodiscard]] OPENSSL_EXPORT bool ParseBasicConstraints(
465     const der::Input& basic_constraints_tlv,
466     ParsedBasicConstraints* out);
467 
468 // KeyUsageBit contains the index for a particular key usage. The index is
469 // measured from the most significant bit of a bit string.
470 //
471 // From RFC 5280 section 4.2.1.3:
472 //
473 //     KeyUsage ::= BIT STRING {
474 //          digitalSignature        (0),
475 //          nonRepudiation          (1), -- recent editions of X.509 have
476 //                               -- renamed this bit to contentCommitment
477 //          keyEncipherment         (2),
478 //          dataEncipherment        (3),
479 //          keyAgreement            (4),
480 //          keyCertSign             (5),
481 //          cRLSign                 (6),
482 //          encipherOnly            (7),
483 //          decipherOnly            (8) }
484 enum KeyUsageBit {
485   KEY_USAGE_BIT_DIGITAL_SIGNATURE = 0,
486   KEY_USAGE_BIT_NON_REPUDIATION = 1,
487   KEY_USAGE_BIT_KEY_ENCIPHERMENT = 2,
488   KEY_USAGE_BIT_DATA_ENCIPHERMENT = 3,
489   KEY_USAGE_BIT_KEY_AGREEMENT = 4,
490   KEY_USAGE_BIT_KEY_CERT_SIGN = 5,
491   KEY_USAGE_BIT_CRL_SIGN = 6,
492   KEY_USAGE_BIT_ENCIPHER_ONLY = 7,
493   KEY_USAGE_BIT_DECIPHER_ONLY = 8,
494 };
495 
496 // Parses the KeyUsage extension as defined by RFC 5280. Returns true on
497 // success, and |key_usage| will alias data in |key_usage_tlv|. On failure
498 // returns false, and |key_usage| may have been modified.
499 //
500 // In addition to validating that key_usage_tlv is a BIT STRING, this does
501 // additional KeyUsage specific validations such as requiring at least 1 bit to
502 // be set.
503 //
504 // To test if a particular key usage is set, call, e.g.:
505 //     key_usage->AssertsBit(KEY_USAGE_BIT_DIGITAL_SIGNATURE);
506 [[nodiscard]] OPENSSL_EXPORT bool ParseKeyUsage(const der::Input& key_usage_tlv,
507                                             der::BitString* key_usage);
508 
509 struct AuthorityInfoAccessDescription {
510   // The accessMethod DER OID value.
511   der::Input access_method_oid;
512   // The accessLocation DER TLV.
513   der::Input access_location;
514 };
515 // Parses the Authority Information Access extension defined by RFC 5280.
516 // Returns true on success, and |out_access_descriptions| will alias data
517 // in |authority_info_access_tlv|.On failure returns false, and
518 // out_access_descriptions may have been partially filled.
519 //
520 // No validation is performed on the contents of the
521 // AuthorityInfoAccessDescription fields.
522 [[nodiscard]] OPENSSL_EXPORT bool ParseAuthorityInfoAccess(
523     const der::Input& authority_info_access_tlv,
524     std::vector<AuthorityInfoAccessDescription>* out_access_descriptions);
525 
526 // Parses the Authority Information Access extension defined by RFC 5280,
527 // extracting the caIssuers URIs and OCSP URIs.
528 //
529 // Returns true on success, and |out_ca_issuers_uris| and |out_ocsp_uris| will
530 // alias data in |authority_info_access_tlv|. On failure returns false, and
531 // |out_ca_issuers_uris| and |out_ocsp_uris| may have been partially filled.
532 //
533 // |out_ca_issuers_uris| is filled with the accessLocations of type
534 // uniformResourceIdentifier for the accessMethod id-ad-caIssuers.
535 // |out_ocsp_uris| is filled with the accessLocations of type
536 // uniformResourceIdentifier for the accessMethod id-ad-ocsp.
537 //
538 // The values in |out_ca_issuers_uris| and |out_ocsp_uris| are checked to be
539 // IA5String (ASCII strings), but no other validation is performed on them.
540 //
541 // accessMethods other than id-ad-caIssuers and id-ad-ocsp are silently ignored.
542 // accessLocation types other than uniformResourceIdentifier are silently
543 // ignored.
544 [[nodiscard]] OPENSSL_EXPORT bool ParseAuthorityInfoAccessURIs(
545     const der::Input& authority_info_access_tlv,
546     std::vector<std::string_view>* out_ca_issuers_uris,
547     std::vector<std::string_view>* out_ocsp_uris);
548 
549 // ParsedDistributionPoint represents a parsed DistributionPoint from RFC 5280.
550 //
551 //   DistributionPoint ::= SEQUENCE {
552 //    distributionPoint       [0]     DistributionPointName OPTIONAL,
553 //    reasons                 [1]     ReasonFlags OPTIONAL,
554 //    cRLIssuer               [2]     GeneralNames OPTIONAL }
555 struct OPENSSL_EXPORT ParsedDistributionPoint {
556   ParsedDistributionPoint();
557   ParsedDistributionPoint(ParsedDistributionPoint&& other);
558   ~ParsedDistributionPoint();
559 
560   // The parsed fullName, if distributionPoint was present and was a fullName.
561   std::unique_ptr<GeneralNames> distribution_point_fullname;
562 
563   // If present, the DER encoded value of the nameRelativeToCRLIssuer field.
564   // This should be a RelativeDistinguishedName, but the parser does not
565   // validate it.
566   std::optional<der::Input> distribution_point_name_relative_to_crl_issuer;
567 
568   // If present, the DER encoded value of the reasons field. This should be a
569   // ReasonFlags bitString, but the parser does not validate it.
570   std::optional<der::Input> reasons;
571 
572   // If present, the DER encoded value of the cRLIssuer field. This should be a
573   // GeneralNames, but the parser does not validate it.
574   std::optional<der::Input> crl_issuer;
575 };
576 
577 // Parses the value of a CRL Distribution Points extension (sequence of
578 // DistributionPoint). Return true on success, and fills |distribution_points|
579 // with values that reference data in |distribution_points_tlv|.
580 [[nodiscard]] OPENSSL_EXPORT bool ParseCrlDistributionPoints(
581     const der::Input& distribution_points_tlv,
582     std::vector<ParsedDistributionPoint>* distribution_points);
583 
584 // Represents the AuthorityKeyIdentifier extension defined by RFC 5280 section
585 // 4.2.1.1.
586 //
587 //    AuthorityKeyIdentifier ::= SEQUENCE {
588 //       keyIdentifier             [0] KeyIdentifier           OPTIONAL,
589 //       authorityCertIssuer       [1] GeneralNames            OPTIONAL,
590 //       authorityCertSerialNumber [2] CertificateSerialNumber OPTIONAL  }
591 //
592 //    KeyIdentifier ::= OCTET STRING
593 struct OPENSSL_EXPORT ParsedAuthorityKeyIdentifier {
594   ParsedAuthorityKeyIdentifier();
595   ~ParsedAuthorityKeyIdentifier();
596   ParsedAuthorityKeyIdentifier(ParsedAuthorityKeyIdentifier&& other);
597   ParsedAuthorityKeyIdentifier& operator=(ParsedAuthorityKeyIdentifier&& other);
598 
599   // The keyIdentifier, which is an OCTET STRING.
600   std::optional<der::Input> key_identifier;
601 
602   // The authorityCertIssuer, which should be a GeneralNames, but this is not
603   // enforced by ParseAuthorityKeyIdentifier.
604   std::optional<der::Input> authority_cert_issuer;
605 
606   // The DER authorityCertSerialNumber, which should be a
607   // CertificateSerialNumber (an INTEGER) but this is not enforced by
608   // ParseAuthorityKeyIdentifier.
609   std::optional<der::Input> authority_cert_serial_number;
610 };
611 
612 // Parses the value of an authorityKeyIdentifier extension. Returns true on
613 // success and fills |authority_key_identifier| with values that reference data
614 // in |extension_value|. On failure the state of |authority_key_identifier| is
615 // not guaranteed.
616 [[nodiscard]] OPENSSL_EXPORT bool ParseAuthorityKeyIdentifier(
617     const der::Input& extension_value,
618     ParsedAuthorityKeyIdentifier* authority_key_identifier);
619 
620 // Parses the value of a subjectKeyIdentifier extension. Returns true on
621 // success and |subject_key_identifier| references data in |extension_value|.
622 // On failure the state of |subject_key_identifier| is not guaranteed.
623 [[nodiscard]] OPENSSL_EXPORT bool ParseSubjectKeyIdentifier(
624     const der::Input& extension_value,
625     der::Input* subject_key_identifier);
626 
627 }  // namespace net
628 
629 #endif  // BSSL_PKI_PARSE_CERTIFICATE_H_
630