| 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 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "net/base/net_export.h" | 14 #include "net/base/net_export.h" |
| 15 #include "net/der/input.h" | 15 #include "net/der/input.h" |
| 16 #include "net/der/parse_values.h" | 16 #include "net/der/parse_values.h" |
| 17 | 17 |
| 18 namespace net { | 18 namespace net { |
| 19 | 19 |
| 20 class CertErrors; |
| 20 struct ParsedTbsCertificate; | 21 struct ParsedTbsCertificate; |
| 21 | 22 |
| 22 // Returns true if the given serial number (CertificateSerialNumber in RFC 5280) | 23 // Returns true if the given serial number (CertificateSerialNumber in RFC 5280) |
| 23 // is valid: | 24 // is valid: |
| 24 // | 25 // |
| 25 // CertificateSerialNumber ::= INTEGER | 26 // CertificateSerialNumber ::= INTEGER |
| 26 // | 27 // |
| 27 // The input to this function is the (unverified) value octets of the INTEGER. | 28 // The input to this function is the (unverified) value octets of the INTEGER. |
| 28 // This function will verify that: | 29 // This function will verify that: |
| 29 // | 30 // |
| (...skipping 18 matching lines...) Expand all Loading... |
| 48 | 49 |
| 49 struct NET_EXPORT ParseCertificateOptions { | 50 struct NET_EXPORT ParseCertificateOptions { |
| 50 // If set to true, then parsing will skip checks on the certificate's serial | 51 // 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 // 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 // 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 // encoding), nor is it required to be constrained to any particular length. |
| 54 bool allow_invalid_serial_numbers = false; | 55 bool allow_invalid_serial_numbers = false; |
| 55 }; | 56 }; |
| 56 | 57 |
| 57 // Parses a DER-encoded "Certificate" as specified by RFC 5280. Returns true on | 58 // Parses a DER-encoded "Certificate" as specified by RFC 5280. Returns true on |
| 58 // success and sets the results in the |out_*| parameters. | 59 // success and sets the results in the |out_*| parameters. On both the failure |
| 60 // and success case, if |out_errors| was non-null it may contain extra error |
| 61 // information. |
| 59 // | 62 // |
| 60 // Note that on success the out parameters alias data from the input | 63 // Note that on success the out parameters alias data from the input |
| 61 // |certificate_tlv|. Hence the output values are only valid as long as | 64 // |certificate_tlv|. Hence the output values are only valid as long as |
| 62 // |certificate_tlv| remains valid. | 65 // |certificate_tlv| remains valid. |
| 63 // | 66 // |
| 64 // On failure the out parameters have an undefined state. Some of them may have | 67 // On failure the out parameters have an undefined state, except for |
| 65 // been updated during parsing, whereas others may not have been changed. | 68 // out_errors. Some of them may have been updated during parsing, whereas |
| 69 // others may not have been changed. |
| 66 // | 70 // |
| 67 // The out parameters represent each field of the Certificate SEQUENCE: | 71 // The out parameters represent each field of the Certificate SEQUENCE: |
| 68 // Certificate ::= SEQUENCE { | 72 // Certificate ::= SEQUENCE { |
| 69 // | 73 // |
| 70 // The |out_tbs_certificate_tlv| parameter corresponds with "tbsCertificate" | 74 // The |out_tbs_certificate_tlv| parameter corresponds with "tbsCertificate" |
| 71 // from RFC 5280: | 75 // from RFC 5280: |
| 72 // tbsCertificate TBSCertificate, | 76 // tbsCertificate TBSCertificate, |
| 73 // | 77 // |
| 74 // This contains the full (unverified) Tag-Length-Value for a SEQUENCE. No | 78 // This contains the full (unverified) Tag-Length-Value for a SEQUENCE. No |
| 75 // guarantees are made regarding the value of this SEQUENCE. | 79 // guarantees are made regarding the value of this SEQUENCE. |
| 76 // This can be further parsed using ParseTbsCertificate(). | 80 // This can be further parsed using ParseTbsCertificate(). |
| 77 // | 81 // |
| 78 // The |out_signature_algorithm_tlv| parameter corresponds with | 82 // The |out_signature_algorithm_tlv| parameter corresponds with |
| 79 // "signatureAlgorithm" from RFC 5280: | 83 // "signatureAlgorithm" from RFC 5280: |
| 80 // signatureAlgorithm AlgorithmIdentifier, | 84 // signatureAlgorithm AlgorithmIdentifier, |
| 81 // | 85 // |
| 82 // This contains the full (unverified) Tag-Length-Value for a SEQUENCE. No | 86 // This contains the full (unverified) Tag-Length-Value for a SEQUENCE. No |
| 83 // guarantees are made regarding the value of this SEQUENCE. | 87 // guarantees are made regarding the value of this SEQUENCE. |
| 84 // This can be further parsed using SignatureValue::CreateFromDer(). | 88 // This can be further parsed using SignatureValue::CreateFromDer(). |
| 85 // | 89 // |
| 86 // The |out_signature_value| parameter corresponds with "signatureValue" from | 90 // The |out_signature_value| parameter corresponds with "signatureValue" from |
| 87 // RFC 5280: | 91 // RFC 5280: |
| 88 // signatureValue BIT STRING } | 92 // signatureValue BIT STRING } |
| 89 // | 93 // |
| 90 // Parsing guarantees that this is a valid BIT STRING. | 94 // Parsing guarantees that this is a valid BIT STRING. |
| 91 NET_EXPORT bool ParseCertificate(const der::Input& certificate_tlv, | 95 NET_EXPORT bool ParseCertificate(const der::Input& certificate_tlv, |
| 92 der::Input* out_tbs_certificate_tlv, | 96 der::Input* out_tbs_certificate_tlv, |
| 93 der::Input* out_signature_algorithm_tlv, | 97 der::Input* out_signature_algorithm_tlv, |
| 94 der::BitString* out_signature_value) | 98 der::BitString* out_signature_value, |
| 95 WARN_UNUSED_RESULT; | 99 CertErrors* out_errors) WARN_UNUSED_RESULT; |
| 96 | 100 |
| 97 // Parses a DER-encoded "TBSCertificate" as specified by RFC 5280. Returns true | 101 // Parses a DER-encoded "TBSCertificate" as specified by RFC 5280. Returns true |
| 98 // on success and sets the results in |out|. Certain invalid inputs may | 102 // on success and sets the results in |out|. Certain invalid inputs may |
| 99 // be accepted based on the provided |options|. | 103 // be accepted based on the provided |options|. |
| 100 // | 104 // |
| 101 // Note that on success |out| aliases data from the input |tbs_tlv|. | 105 // Note that on success |out| aliases data from the input |tbs_tlv|. |
| 102 // Hence the fields of the ParsedTbsCertificate are only valid as long as | 106 // Hence the fields of the ParsedTbsCertificate are only valid as long as |
| 103 // |tbs_tlv| remains valid. | 107 // |tbs_tlv| remains valid. |
| 104 // | 108 // |
| 105 // On failure |out| has an undefined state. Some of its fields may have been | 109 // On failure |out| has an undefined state. Some of its fields may have been |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 // accessLocation types other than uniformResourceIdentifier are silently | 450 // accessLocation types other than uniformResourceIdentifier are silently |
| 447 // ignored. | 451 // ignored. |
| 448 NET_EXPORT bool ParseAuthorityInfoAccess( | 452 NET_EXPORT bool ParseAuthorityInfoAccess( |
| 449 const der::Input& authority_info_access_tlv, | 453 const der::Input& authority_info_access_tlv, |
| 450 std::vector<base::StringPiece>* out_ca_issuers_uris, | 454 std::vector<base::StringPiece>* out_ca_issuers_uris, |
| 451 std::vector<base::StringPiece>* out_ocsp_uris) WARN_UNUSED_RESULT; | 455 std::vector<base::StringPiece>* out_ocsp_uris) WARN_UNUSED_RESULT; |
| 452 | 456 |
| 453 } // namespace net | 457 } // namespace net |
| 454 | 458 |
| 455 #endif // NET_CERT_INTERNAL_PARSE_CERTIFICATE_H_ | 459 #endif // NET_CERT_INTERNAL_PARSE_CERTIFICATE_H_ |
| OLD | NEW |