| 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_VERIFY_CERTIFICATE_CHAIN_H_ | 5 #ifndef NET_CERT_INTERNAL_VERIFY_CERTIFICATE_CHAIN_H_ |
| 6 #define NET_CERT_INTERNAL_VERIFY_CERTIFICATE_CHAIN_H_ | 6 #define NET_CERT_INTERNAL_VERIFY_CERTIFICATE_CHAIN_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "net/base/net_export.h" | 12 #include "net/base/net_export.h" |
| 13 #include "net/cert/internal/cert_errors.h" | 13 #include "net/cert/internal/cert_errors.h" |
| 14 #include "net/cert/internal/parsed_certificate.h" | 14 #include "net/cert/internal/parsed_certificate.h" |
| 15 #include "net/der/input.h" | 15 #include "net/der/input.h" |
| 16 | 16 |
| 17 namespace net { | 17 namespace net { |
| 18 | 18 |
| 19 namespace der { | 19 namespace der { |
| 20 struct GeneralizedTime; | 20 struct GeneralizedTime; |
| 21 } | 21 } |
| 22 | 22 |
| 23 class SignaturePolicy; | 23 class SignaturePolicy; |
| 24 class TrustAnchor; | 24 struct CertificateTrust; |
| 25 | 25 |
| 26 // The key purpose (extended key usage) to check for during verification. | 26 // The key purpose (extended key usage) to check for during verification. |
| 27 enum class KeyPurpose { | 27 enum class KeyPurpose { |
| 28 ANY_EKU, | 28 ANY_EKU, |
| 29 SERVER_AUTH, | 29 SERVER_AUTH, |
| 30 CLIENT_AUTH, | 30 CLIENT_AUTH, |
| 31 }; | 31 }; |
| 32 | 32 |
| 33 // VerifyCertificateChain() verifies an ordered certificate path in accordance | 33 // VerifyCertificateChain() verifies an ordered certificate path in accordance |
| 34 // with RFC 5280 (with some modifications [1]). | 34 // with RFC 5280 (with some modifications [1]). |
| (...skipping 16 matching lines...) Expand all Loading... |
| 51 // | 51 // |
| 52 // TODO(eroman): Take a CertPath instead of ParsedCertificateList + | 52 // TODO(eroman): Take a CertPath instead of ParsedCertificateList + |
| 53 // TrustAnchor. | 53 // TrustAnchor. |
| 54 // | 54 // |
| 55 // --------- | 55 // --------- |
| 56 // Inputs | 56 // Inputs |
| 57 // --------- | 57 // --------- |
| 58 // | 58 // |
| 59 // cert_chain: | 59 // cert_chain: |
| 60 // A non-empty chain of N DER-encoded certificates, listed in the | 60 // A non-empty chain of N DER-encoded certificates, listed in the |
| 61 // "forward" direction. | 61 // "forward" direction. The first certificate is the target certificate to |
| 62 // verify, and the last certificate has trustedness given by |
| 63 // |last_cert_trust|. |
| 62 // | 64 // |
| 63 // * cert_chain[0] is the target certificate to verify. | 65 // * cert_chain[0] is the target certificate to verify. |
| 64 // * cert_chain[i+1] holds the certificate that issued cert_chain[i]. | 66 // * cert_chain[i+1] holds the certificate that issued cert_chain[i]. |
| 65 // * cert_chain[N-1] must be issued by the trust anchor. | 67 // * cert_chain[N-1] the root certificate |
| 66 // | 68 // |
| 67 // trust_anchor: | 69 // last_cert_trust: |
| 68 // Contains the trust anchor (root) used to verify the chain. Must be | 70 // Trustedness of certs.back(). The trustedness of certs.back() MUST BE |
| 69 // non-null. | 71 // decided by the caller -- this function takes it purely as an input. |
| 72 // Moreover, the CertificateTrust can be used to specify trust anchor |
| 73 // constraints [1] |
| 70 // | 74 // |
| 71 // signature_policy: | 75 // signature_policy: |
| 72 // The policy to use when verifying signatures (what hash algorithms are | 76 // The policy to use when verifying signatures (what hash algorithms are |
| 73 // allowed, what length keys, what named curves, etc). | 77 // allowed, what length keys, what named curves, etc). |
| 74 // | 78 // |
| 75 // time: | 79 // time: |
| 76 // The UTC time to use for expiration checks. | 80 // The UTC time to use for expiration checks. |
| 77 // | 81 // |
| 78 // key_purpose: | 82 // key_purpose: |
| 79 // The key purpose that the target certificate needs to be valid for. | 83 // The key purpose that the target certificate needs to be valid for. |
| 80 // | 84 // |
| 81 // --------- | 85 // --------- |
| 82 // Outputs | 86 // Outputs |
| 83 // --------- | 87 // --------- |
| 84 // | |
| 85 // Returns true if the target certificate can be verified. | |
| 86 // TODO(eroman): This return value is redundant with the |errors| parameter. | |
| 87 // | |
| 88 // errors: | 88 // errors: |
| 89 // Must be non-null. The set of errors/warnings encountered while | 89 // Must be non-null. The set of errors/warnings encountered while |
| 90 // validating the path are appended to this structure. If verification | 90 // validating the path are appended to this structure. If verification |
| 91 // failed, then there is guaranteed to be at least 1 error written to | 91 // failed, then there is guaranteed to be at least 1 high severity error |
| 92 // |errors|. | 92 // written to |errors|. |
| 93 NET_EXPORT bool VerifyCertificateChain(const ParsedCertificateList& certs, | 93 // |
| 94 const TrustAnchor* trust_anchor, | 94 // [1] Conceptually VerifyCertificateChain() sets RFC 5937's |
| 95 // "enforceTrustAnchorConstraints" to true. And one specifies whether to |
| 96 // interpret a root certificate as having trust anchor constraints through the |
| 97 // |last_cert_trust| parameter. The constraints are just a subset of the |
| 98 // extensions present in the certificate: |
| 99 // |
| 100 // * Signature: No |
| 101 // * Validity (expiration): No |
| 102 // * Key usage: No |
| 103 // * Extended key usage: Yes (not part of RFC 5937) |
| 104 // * Basic constraints: Yes, but only the pathlen (CA=false is accepted) |
| 105 // * Name constraints: Yes |
| 106 // * Certificate policies: Not currently, TODO(crbug.com/634453) |
| 107 // * inhibitAnyPolicy: Not currently, TODO(crbug.com/634453) |
| 108 // * PolicyConstraints: Not currently, TODO(crbug.com/634452) |
| 109 // |
| 110 // The presence of any other unrecognized extension marked as critical fails |
| 111 // validation. |
| 112 NET_EXPORT void VerifyCertificateChain(const ParsedCertificateList& certs, |
| 113 const CertificateTrust& last_cert_trust, |
| 95 const SignaturePolicy* signature_policy, | 114 const SignaturePolicy* signature_policy, |
| 96 const der::GeneralizedTime& time, | 115 const der::GeneralizedTime& time, |
| 97 KeyPurpose required_key_purpose, | 116 KeyPurpose required_key_purpose, |
| 98 CertPathErrors* errors); | 117 CertPathErrors* errors); |
| 99 | 118 |
| 100 // TODO(crbug.com/634443): Move exported errors to a central location? | 119 // TODO(crbug.com/634443): Move exported errors to a central location? |
| 101 extern CertErrorId kValidityFailedNotAfter; | 120 extern CertErrorId kValidityFailedNotAfter; |
| 102 extern CertErrorId kValidityFailedNotBefore; | 121 extern CertErrorId kValidityFailedNotBefore; |
| 103 | 122 |
| 104 } // namespace net | 123 } // namespace net |
| 105 | 124 |
| 106 #endif // NET_CERT_INTERNAL_VERIFY_CERTIFICATE_CHAIN_H_ | 125 #endif // NET_CERT_INTERNAL_VERIFY_CERTIFICATE_CHAIN_H_ |
| OLD | NEW |