| OLD | NEW |
| 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_PARSE_CERTIFICATE_H_ | 5 #ifndef NET_CERT_INTERNAL_PARSE_CERTIFICATE_H_ |
| 6 #define NET_CERT_INTERNAL_PARSE_CERTIFICATE_H_ | 6 #define NET_CERT_INTERNAL_PARSE_CERTIFICATE_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 // Given the uniqueness requirements above, serial numbers can be | 39 // Given the uniqueness requirements above, serial numbers can be |
| 40 // expected to contain long integers. Certificate users MUST be able to | 40 // expected to contain long integers. Certificate users MUST be able to |
| 41 // handle serialNumber values up to 20 octets. Conforming CAs MUST NOT | 41 // handle serialNumber values up to 20 octets. Conforming CAs MUST NOT |
| 42 // use serialNumber values longer than 20 octets. | 42 // use serialNumber values longer than 20 octets. |
| 43 // | 43 // |
| 44 // Note: Non-conforming CAs may issue certificates with serial numbers | 44 // Note: Non-conforming CAs may issue certificates with serial numbers |
| 45 // that are negative or zero. Certificate users SHOULD be prepared to | 45 // that are negative or zero. Certificate users SHOULD be prepared to |
| 46 // gracefully handle such certificates. | 46 // gracefully handle such certificates. |
| 47 NET_EXPORT bool VerifySerialNumber(const der::Input& value) WARN_UNUSED_RESULT; | 47 NET_EXPORT bool VerifySerialNumber(const der::Input& value) WARN_UNUSED_RESULT; |
| 48 | 48 |
| 49 struct NET_EXPORT ParseCertificateOptions { |
| 50 // If set to true, then parsing will skip checks on the certificate's serial |
| 51 // number. The only requirement will be that the serial number is an INTEGER, |
| 52 // however it is not required to be a valid DER-encoding (i.e. minimal |
| 53 // encoding), nor is it required to be constrained to any particular length. |
| 54 bool allow_invalid_serial_numbers = false; |
| 55 }; |
| 56 |
| 49 // Parses a DER-encoded "Certificate" as specified by RFC 5280. Returns true on | 57 // Parses a DER-encoded "Certificate" as specified by RFC 5280. Returns true on |
| 50 // success and sets the results in the |out_*| parameters. | 58 // success and sets the results in the |out_*| parameters. |
| 51 // | 59 // |
| 52 // Note that on success the out parameters alias data from the input | 60 // Note that on success the out parameters alias data from the input |
| 53 // |certificate_tlv|. Hence the output values are only valid as long as | 61 // |certificate_tlv|. Hence the output values are only valid as long as |
| 54 // |certificate_tlv| remains valid. | 62 // |certificate_tlv| remains valid. |
| 55 // | 63 // |
| 56 // On failure the out parameters have an undefined state. Some of them may have | 64 // On failure the out parameters have an undefined state. Some of them may have |
| 57 // been updated during parsing, whereas others may not have been changed. | 65 // been updated during parsing, whereas others may not have been changed. |
| 58 // | 66 // |
| (...skipping 21 matching lines...) Expand all Loading... |
| 80 // signatureValue BIT STRING } | 88 // signatureValue BIT STRING } |
| 81 // | 89 // |
| 82 // Parsing guarantees that this is a valid BIT STRING. | 90 // Parsing guarantees that this is a valid BIT STRING. |
| 83 NET_EXPORT bool ParseCertificate(const der::Input& certificate_tlv, | 91 NET_EXPORT bool ParseCertificate(const der::Input& certificate_tlv, |
| 84 der::Input* out_tbs_certificate_tlv, | 92 der::Input* out_tbs_certificate_tlv, |
| 85 der::Input* out_signature_algorithm_tlv, | 93 der::Input* out_signature_algorithm_tlv, |
| 86 der::BitString* out_signature_value) | 94 der::BitString* out_signature_value) |
| 87 WARN_UNUSED_RESULT; | 95 WARN_UNUSED_RESULT; |
| 88 | 96 |
| 89 // Parses a DER-encoded "TBSCertificate" as specified by RFC 5280. Returns true | 97 // Parses a DER-encoded "TBSCertificate" as specified by RFC 5280. Returns true |
| 90 // on success and sets the results in |out|. | 98 // on success and sets the results in |out|. Certain invalid inputs may |
| 99 // be accepted based on the provided |options|. |
| 91 // | 100 // |
| 92 // Note that on success |out| aliases data from the input |tbs_tlv|. | 101 // Note that on success |out| aliases data from the input |tbs_tlv|. |
| 93 // Hence the fields of the ParsedTbsCertificate are only valid as long as | 102 // Hence the fields of the ParsedTbsCertificate are only valid as long as |
| 94 // |tbs_tlv| remains valid. | 103 // |tbs_tlv| remains valid. |
| 95 // | 104 // |
| 96 // On failure |out| has an undefined state. Some of its fields may have been | 105 // On failure |out| has an undefined state. Some of its fields may have been |
| 97 // updated during parsing, whereas others may not have been changed. | 106 // updated during parsing, whereas others may not have been changed. |
| 98 // | 107 // |
| 99 // Refer to the per-field documentation of ParsedTbsCertificate for details on | 108 // Refer to the per-field documentation of ParsedTbsCertificate for details on |
| 100 // what validity checks parsing performs. | 109 // what validity checks parsing performs. |
| 101 // | 110 // |
| 102 // TBSCertificate ::= SEQUENCE { | 111 // TBSCertificate ::= SEQUENCE { |
| 103 // version [0] EXPLICIT Version DEFAULT v1, | 112 // version [0] EXPLICIT Version DEFAULT v1, |
| 104 // serialNumber CertificateSerialNumber, | 113 // serialNumber CertificateSerialNumber, |
| 105 // signature AlgorithmIdentifier, | 114 // signature AlgorithmIdentifier, |
| 106 // issuer Name, | 115 // issuer Name, |
| 107 // validity Validity, | 116 // validity Validity, |
| 108 // subject Name, | 117 // subject Name, |
| 109 // subjectPublicKeyInfo SubjectPublicKeyInfo, | 118 // subjectPublicKeyInfo SubjectPublicKeyInfo, |
| 110 // issuerUniqueID [1] IMPLICIT UniqueIdentifier OPTIONAL, | 119 // issuerUniqueID [1] IMPLICIT UniqueIdentifier OPTIONAL, |
| 111 // -- If present, version MUST be v2 or v3 | 120 // -- If present, version MUST be v2 or v3 |
| 112 // subjectUniqueID [2] IMPLICIT UniqueIdentifier OPTIONAL, | 121 // subjectUniqueID [2] IMPLICIT UniqueIdentifier OPTIONAL, |
| 113 // -- If present, version MUST be v2 or v3 | 122 // -- If present, version MUST be v2 or v3 |
| 114 // extensions [3] EXPLICIT Extensions OPTIONAL | 123 // extensions [3] EXPLICIT Extensions OPTIONAL |
| 115 // -- If present, version MUST be v3 | 124 // -- If present, version MUST be v3 |
| 116 // } | 125 // } |
| 117 NET_EXPORT bool ParseTbsCertificate(const der::Input& tbs_tlv, | 126 NET_EXPORT bool ParseTbsCertificate(const der::Input& tbs_tlv, |
| 127 const ParseCertificateOptions& options, |
| 118 ParsedTbsCertificate* out) | 128 ParsedTbsCertificate* out) |
| 119 WARN_UNUSED_RESULT; | 129 WARN_UNUSED_RESULT; |
| 120 | 130 |
| 121 // Represents a "Version" from RFC 5280: | 131 // Represents a "Version" from RFC 5280: |
| 122 // Version ::= INTEGER { v1(0), v2(1), v3(2) } | 132 // Version ::= INTEGER { v1(0), v2(1), v3(2) } |
| 123 enum class CertificateVersion { | 133 enum class CertificateVersion { |
| 124 V1, | 134 V1, |
| 125 V2, | 135 V2, |
| 126 V3, | 136 V3, |
| 127 }; | 137 }; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 142 // Parsing guarantees that the version is one of v1, v2, or v3. | 152 // Parsing guarantees that the version is one of v1, v2, or v3. |
| 143 CertificateVersion version = CertificateVersion::V1; | 153 CertificateVersion version = CertificateVersion::V1; |
| 144 | 154 |
| 145 // Corresponds with "serialNumber" from RFC 5280: | 155 // Corresponds with "serialNumber" from RFC 5280: |
| 146 // serialNumber CertificateSerialNumber, | 156 // serialNumber CertificateSerialNumber, |
| 147 // | 157 // |
| 148 // This field specifically contains the content bytes of the INTEGER. So for | 158 // This field specifically contains the content bytes of the INTEGER. So for |
| 149 // instance if the serial number was 1000 then this would contain bytes | 159 // instance if the serial number was 1000 then this would contain bytes |
| 150 // {0x03, 0xE8}. | 160 // {0x03, 0xE8}. |
| 151 // | 161 // |
| 152 // In addition to being a valid DER-encoded INTEGER, parsing guarantees that | 162 // The serial number may or may not be a valid DER-encoded INTEGER: |
| 163 // |
| 164 // If the option |allow_invalid_serial_numbers=true| was used during |
| 165 // parsing, then nothing further can be assumed about these bytes. |
| 166 // |
| 167 // Otherwise if |allow_invalid_serial_numbers=false| then in addition |
| 168 // to being a valid DER-encoded INTEGER, parsing guarantees that |
| 153 // the serial number is at most 20 bytes long. Parsing does NOT guarantee | 169 // the serial number is at most 20 bytes long. Parsing does NOT guarantee |
| 154 // that the integer is positive (might be zero or negative). | 170 // that the integer is positive (might be zero or negative). |
| 155 der::Input serial_number; | 171 der::Input serial_number; |
| 156 | 172 |
| 157 // Corresponds with "signatureAlgorithm" from RFC 5280: | 173 // Corresponds with "signatureAlgorithm" from RFC 5280: |
| 158 // signatureAlgorithm AlgorithmIdentifier, | 174 // signatureAlgorithm AlgorithmIdentifier, |
| 159 // | 175 // |
| 160 // This contains the full (unverified) Tag-Length-Value for a SEQUENCE. No | 176 // This contains the full (unverified) Tag-Length-Value for a SEQUENCE. No |
| 161 // guarantees are made regarding the value of this SEQUENCE. | 177 // guarantees are made regarding the value of this SEQUENCE. |
| 162 // | 178 // |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 // accessLocation types other than uniformResourceIdentifier are silently | 446 // accessLocation types other than uniformResourceIdentifier are silently |
| 431 // ignored. | 447 // ignored. |
| 432 NET_EXPORT bool ParseAuthorityInfoAccess( | 448 NET_EXPORT bool ParseAuthorityInfoAccess( |
| 433 const der::Input& authority_info_access_tlv, | 449 const der::Input& authority_info_access_tlv, |
| 434 std::vector<base::StringPiece>* out_ca_issuers_uris, | 450 std::vector<base::StringPiece>* out_ca_issuers_uris, |
| 435 std::vector<base::StringPiece>* out_ocsp_uris) WARN_UNUSED_RESULT; | 451 std::vector<base::StringPiece>* out_ocsp_uris) WARN_UNUSED_RESULT; |
| 436 | 452 |
| 437 } // namespace net | 453 } // namespace net |
| 438 | 454 |
| 439 #endif // NET_CERT_INTERNAL_PARSE_CERTIFICATE_H_ | 455 #endif // NET_CERT_INTERNAL_PARSE_CERTIFICATE_H_ |
| OLD | NEW |