| 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> |
| 11 | 11 |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "net/base/net_export.h" | 13 #include "net/base/net_export.h" |
| 14 #include "net/der/input.h" | 14 #include "net/der/input.h" |
| 15 #include "net/der/parse_values.h" | 15 #include "net/der/parse_values.h" |
| 16 | 16 |
| 17 namespace net { | 17 namespace net { |
| 18 | 18 |
| 19 struct ParsedCertificate; | |
| 20 struct ParsedTbsCertificate; | 19 struct ParsedTbsCertificate; |
| 21 | 20 |
| 22 // Returns true if the given serial number (CertificateSerialNumber in RFC 5280) | 21 // Returns true if the given serial number (CertificateSerialNumber in RFC 5280) |
| 23 // is valid: | 22 // is valid: |
| 24 // | 23 // |
| 25 // CertificateSerialNumber ::= INTEGER | 24 // CertificateSerialNumber ::= INTEGER |
| 26 // | 25 // |
| 27 // The input to this function is the (unverified) value octets of the INTEGER. | 26 // The input to this function is the (unverified) value octets of the INTEGER. |
| 28 // This function will verify that: | 27 // This function will verify that: |
| 29 // | 28 // |
| (...skipping 10 matching lines...) Expand all Loading... |
| 40 // expected to contain long integers. Certificate users MUST be able to | 39 // expected to contain long integers. Certificate users MUST be able to |
| 41 // handle serialNumber values up to 20 octets. Conforming CAs MUST NOT | 40 // handle serialNumber values up to 20 octets. Conforming CAs MUST NOT |
| 42 // use serialNumber values longer than 20 octets. | 41 // use serialNumber values longer than 20 octets. |
| 43 // | 42 // |
| 44 // Note: Non-conforming CAs may issue certificates with serial numbers | 43 // Note: Non-conforming CAs may issue certificates with serial numbers |
| 45 // that are negative or zero. Certificate users SHOULD be prepared to | 44 // that are negative or zero. Certificate users SHOULD be prepared to |
| 46 // gracefully handle such certificates. | 45 // gracefully handle such certificates. |
| 47 NET_EXPORT bool VerifySerialNumber(const der::Input& value) WARN_UNUSED_RESULT; | 46 NET_EXPORT bool VerifySerialNumber(const der::Input& value) WARN_UNUSED_RESULT; |
| 48 | 47 |
| 49 // Parses a DER-encoded "Certificate" as specified by RFC 5280. Returns true on | 48 // Parses a DER-encoded "Certificate" as specified by RFC 5280. Returns true on |
| 50 // success and sets the results in |out|. | 49 // success and sets the results in the |out_*| parameters. |
| 51 // | 50 // |
| 52 // Note that on success |out| aliases data from the input |certificate_tlv|. | 51 // Note that on success the out parameters alias data from the input |
| 53 // Hence the fields of the ParsedCertificate are only valid as long as | 52 // |certificate_tlv|. Hence the output values are only valid as long as |
| 54 // |certificate_tlv| remains valid. | 53 // |certificate_tlv| remains valid. |
| 55 // | 54 // |
| 56 // On failure |out| has an undefined state. Some of its fields may have been | 55 // On failure the out parameters have an undefined state. Some of them may have |
| 57 // updated during parsing, whereas others may not have been changed. | 56 // been updated during parsing, whereas others may not have been changed. |
| 58 // | 57 // |
| 59 // Refer to the per-field documention of the ParsedCertificate structure for | 58 // The out parameters represent each field of the Certificate SEQUENCE: |
| 60 // details on what validity checks parsing performs. | 59 // Certificate ::= SEQUENCE { |
| 61 // | 60 // |
| 62 // Certificate ::= SEQUENCE { | 61 // The |out_tbs_certificate_tlv| parameter corresponds with "tbsCertificate" |
| 63 // tbsCertificate TBSCertificate, | 62 // from RFC 5280: |
| 64 // signatureAlgorithm AlgorithmIdentifier, | 63 // tbsCertificate TBSCertificate, |
| 65 // signatureValue BIT STRING } | 64 // |
| 65 // This contains the full (unverified) Tag-Length-Value for a SEQUENCE. No |
| 66 // guarantees are made regarding the value of this SEQUENCE. |
| 67 // This can be further parsed using ParseTbsCertificate(). |
| 68 // |
| 69 // The |out_signature_algorithm_tlv| parameter corresponds with |
| 70 // "signatureAlgorithm" from RFC 5280: |
| 71 // signatureAlgorithm AlgorithmIdentifier, |
| 72 // |
| 73 // This contains the full (unverified) Tag-Length-Value for a SEQUENCE. No |
| 74 // guarantees are made regarding the value of this SEQUENCE. |
| 75 // This can be further parsed using SignatureValue::CreateFromDer(). |
| 76 // |
| 77 // The |out_signature_value| parameter corresponds with "signatureValue" from |
| 78 // RFC 5280: |
| 79 // signatureValue BIT STRING } |
| 80 // |
| 81 // Parsing guarantees that this is a valid BIT STRING. |
| 66 NET_EXPORT bool ParseCertificate(const der::Input& certificate_tlv, | 82 NET_EXPORT bool ParseCertificate(const der::Input& certificate_tlv, |
| 67 ParsedCertificate* out) WARN_UNUSED_RESULT; | 83 der::Input* out_tbs_certificate_tlv, |
| 84 der::Input* out_signature_algorithm_tlv, |
| 85 der::BitString* out_signature_value) |
| 86 WARN_UNUSED_RESULT; |
| 68 | 87 |
| 69 // Parses a DER-encoded "TBSCertificate" as specified by RFC 5280. Returns true | 88 // Parses a DER-encoded "TBSCertificate" as specified by RFC 5280. Returns true |
| 70 // on success and sets the results in |out|. | 89 // on success and sets the results in |out|. |
| 71 // | 90 // |
| 72 // Note that on success |out| aliases data from the input |tbs_tlv|. | 91 // Note that on success |out| aliases data from the input |tbs_tlv|. |
| 73 // Hence the fields of the ParsedTbsCertificate are only valid as long as | 92 // Hence the fields of the ParsedTbsCertificate are only valid as long as |
| 74 // |tbs_tlv| remains valid. | 93 // |tbs_tlv| remains valid. |
| 75 // | 94 // |
| 76 // On failure |out| has an undefined state. Some of its fields may have been | 95 // On failure |out| has an undefined state. Some of its fields may have been |
| 77 // updated during parsing, whereas others may not have been changed. | 96 // updated during parsing, whereas others may not have been changed. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 99 WARN_UNUSED_RESULT; | 118 WARN_UNUSED_RESULT; |
| 100 | 119 |
| 101 // Represents a "Version" from RFC 5280: | 120 // Represents a "Version" from RFC 5280: |
| 102 // Version ::= INTEGER { v1(0), v2(1), v3(2) } | 121 // Version ::= INTEGER { v1(0), v2(1), v3(2) } |
| 103 enum class CertificateVersion { | 122 enum class CertificateVersion { |
| 104 V1, | 123 V1, |
| 105 V2, | 124 V2, |
| 106 V3, | 125 V3, |
| 107 }; | 126 }; |
| 108 | 127 |
| 109 // ParsedCertificate contains pointers to the main fields of a DER-encoded RFC | |
| 110 // 5280 "Certificate". | |
| 111 // | |
| 112 // ParsedCertificate is expected to be filled by ParseCertificate(), so | |
| 113 // subsequent field descriptions are in terms of what ParseCertificate() sets. | |
| 114 struct NET_EXPORT ParsedCertificate { | |
| 115 ParsedCertificate(); | |
| 116 ~ParsedCertificate(); | |
| 117 | |
| 118 // Corresponds with "tbsCertificate" from RFC 5280: | |
| 119 // tbsCertificate TBSCertificate, | |
| 120 // | |
| 121 // This contains the full (unverified) Tag-Length-Value for a SEQUENCE. No | |
| 122 // guarantees are made regarding the value of this SEQUENCE. | |
| 123 // | |
| 124 // This can be further parsed using ParseTbsCertificate(). | |
| 125 der::Input tbs_certificate_tlv; | |
| 126 | |
| 127 // Corresponds with "signatureAlgorithm" from RFC 5280: | |
| 128 // signatureAlgorithm AlgorithmIdentifier, | |
| 129 // | |
| 130 // This contains the full (unverified) Tag-Length-Value for a SEQUENCE. No | |
| 131 // guarantees are made regarding the value of this SEQUENCE. | |
| 132 // | |
| 133 // This can be further parsed using SignatureValue::CreateFromDer(). | |
| 134 der::Input signature_algorithm_tlv; | |
| 135 | |
| 136 // Corresponds with "signatureValue" from RFC 5280: | |
| 137 // signatureValue BIT STRING } | |
| 138 // | |
| 139 // Parsing guarantees that this is a valid BIT STRING. | |
| 140 der::BitString signature_value; | |
| 141 }; | |
| 142 | |
| 143 // ParsedTbsCertificate contains pointers to the main fields of a DER-encoded | 128 // ParsedTbsCertificate contains pointers to the main fields of a DER-encoded |
| 144 // RFC 5280 "TBSCertificate". | 129 // RFC 5280 "TBSCertificate". |
| 145 // | 130 // |
| 146 // ParsedTbsCertificate is expected to be filled by ParseTbsCertificate(), so | 131 // ParsedTbsCertificate is expected to be filled by ParseTbsCertificate(), so |
| 147 // subsequent field descriptions are in terms of what ParseTbsCertificate() | 132 // subsequent field descriptions are in terms of what ParseTbsCertificate() |
| 148 // sets. | 133 // sets. |
| 149 struct NET_EXPORT ParsedTbsCertificate { | 134 struct NET_EXPORT ParsedTbsCertificate { |
| 150 ParsedTbsCertificate(); | 135 ParsedTbsCertificate(); |
| 151 ~ParsedTbsCertificate(); | 136 ~ParsedTbsCertificate(); |
| 152 | 137 |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 // be set. | 379 // be set. |
| 395 // | 380 // |
| 396 // To test if a particular key usage is set, call, e.g.: | 381 // To test if a particular key usage is set, call, e.g.: |
| 397 // key_usage->AssertsBit(KEY_USAGE_BIT_DIGITAL_SIGNATURE); | 382 // key_usage->AssertsBit(KEY_USAGE_BIT_DIGITAL_SIGNATURE); |
| 398 NET_EXPORT bool ParseKeyUsage(const der::Input& key_usage_tlv, | 383 NET_EXPORT bool ParseKeyUsage(const der::Input& key_usage_tlv, |
| 399 der::BitString* key_usage) WARN_UNUSED_RESULT; | 384 der::BitString* key_usage) WARN_UNUSED_RESULT; |
| 400 | 385 |
| 401 } // namespace net | 386 } // namespace net |
| 402 | 387 |
| 403 #endif // NET_CERT_INTERNAL_PARSE_CERTIFICATE_H_ | 388 #endif // NET_CERT_INTERNAL_PARSE_CERTIFICATE_H_ |
| OLD | NEW |