| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #include "net/cert/internal/verify_certificate_chain.h" | 5 #include "net/cert/internal/verify_certificate_chain.h" |
| 6 | 6 |
| 7 #include "net/cert/internal/parsed_certificate.h" | 7 #include "net/cert/internal/parsed_certificate.h" |
| 8 #include "net/cert/internal/signature_policy.h" | 8 #include "net/cert/internal/signature_policy.h" |
| 9 #include "net/cert/internal/trust_store.h" | 9 #include "net/cert/internal/trust_store.h" |
| 10 #include "net/der/input.h" | 10 #include "net/der/input.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 | 41 |
| 42 #include "net/cert/internal/nist_pkits_unittest.h" | 42 #include "net/cert/internal/nist_pkits_unittest.h" |
| 43 | 43 |
| 44 namespace net { | 44 namespace net { |
| 45 | 45 |
| 46 namespace { | 46 namespace { |
| 47 | 47 |
| 48 class VerifyCertificateChainPkitsTestDelegate { | 48 class VerifyCertificateChainPkitsTestDelegate { |
| 49 public: | 49 public: |
| 50 static bool Verify(std::vector<std::string> cert_ders, | 50 static bool Verify(std::vector<std::string> cert_ders, |
| 51 std::vector<std::string> crl_ders) { | 51 std::vector<std::string> crl_ders, |
| 52 const PkitsTestSettings& settings) { |
| 52 if (cert_ders.empty()) { | 53 if (cert_ders.empty()) { |
| 53 ADD_FAILURE() << "cert_ders is empty"; | 54 ADD_FAILURE() << "cert_ders is empty"; |
| 54 return false; | 55 return false; |
| 55 } | 56 } |
| 56 | 57 |
| 57 // PKITS lists chains from trust anchor to target, VerifyCertificateChain | 58 // PKITS lists chains from trust anchor to target, whereas |
| 58 // takes them starting with the target and not including the trust anchor. | 59 // VerifyCertificateChain takes them starting with the target and ending |
| 60 // with the trust anchor. |
| 59 std::vector<scoped_refptr<net::ParsedCertificate>> input_chain; | 61 std::vector<scoped_refptr<net::ParsedCertificate>> input_chain; |
| 60 CertErrors parsing_errors; | 62 CertErrors parsing_errors; |
| 61 for (auto i = cert_ders.rbegin(); i != cert_ders.rend(); ++i) { | 63 for (auto i = cert_ders.rbegin(); i != cert_ders.rend(); ++i) { |
| 62 if (!net::ParsedCertificate::CreateAndAddToVector( | 64 if (!net::ParsedCertificate::CreateAndAddToVector( |
| 63 bssl::UniquePtr<CRYPTO_BUFFER>( | 65 bssl::UniquePtr<CRYPTO_BUFFER>( |
| 64 CRYPTO_BUFFER_new(reinterpret_cast<const uint8_t*>(i->data()), | 66 CRYPTO_BUFFER_new(reinterpret_cast<const uint8_t*>(i->data()), |
| 65 i->size(), nullptr)), | 67 i->size(), nullptr)), |
| 66 {}, &input_chain, &parsing_errors)) { | 68 {}, &input_chain, &parsing_errors)) { |
| 67 ADD_FAILURE() << "Cert failed to parse:\n" | 69 ADD_FAILURE() << "Cert failed to parse:\n" |
| 68 << parsing_errors.ToDebugString(); | 70 << parsing_errors.ToDebugString(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 90 class PkitsTest01SignatureVerificationCustom | 92 class PkitsTest01SignatureVerificationCustom |
| 91 : public PkitsTest<VerifyCertificateChainPkitsTestDelegate> {}; | 93 : public PkitsTest<VerifyCertificateChainPkitsTestDelegate> {}; |
| 92 | 94 |
| 93 // Modified version of 4.1.4 Valid DSA Signatures Test4 | 95 // Modified version of 4.1.4 Valid DSA Signatures Test4 |
| 94 TEST_F(PkitsTest01SignatureVerificationCustom, | 96 TEST_F(PkitsTest01SignatureVerificationCustom, |
| 95 Section1ValidDSASignaturesTest4Custom) { | 97 Section1ValidDSASignaturesTest4Custom) { |
| 96 const char* const certs[] = {"TrustAnchorRootCertificate", "DSACACert", | 98 const char* const certs[] = {"TrustAnchorRootCertificate", "DSACACert", |
| 97 "ValidDSASignaturesTest4EE"}; | 99 "ValidDSASignaturesTest4EE"}; |
| 98 const char* const crls[] = {"TrustAnchorRootCRL", "DSACACRL"}; | 100 const char* const crls[] = {"TrustAnchorRootCRL", "DSACACRL"}; |
| 99 // DSA signatures are intentionally unsupported. | 101 // DSA signatures are intentionally unsupported. |
| 100 ASSERT_FALSE(this->Verify(certs, crls)); | 102 ASSERT_FALSE(this->Verify(certs, crls, {})); |
| 101 } | 103 } |
| 102 | 104 |
| 103 // Modified version of 4.1.5 Valid DSA Parameter Inheritance Test5 | 105 // Modified version of 4.1.5 Valid DSA Parameter Inheritance Test5 |
| 104 TEST_F(PkitsTest01SignatureVerificationCustom, | 106 TEST_F(PkitsTest01SignatureVerificationCustom, |
| 105 Section1ValidDSAParameterInheritanceTest5Custom) { | 107 Section1ValidDSAParameterInheritanceTest5Custom) { |
| 106 const char* const certs[] = {"TrustAnchorRootCertificate", "DSACACert", | 108 const char* const certs[] = {"TrustAnchorRootCertificate", "DSACACert", |
| 107 "DSAParametersInheritedCACert", | 109 "DSAParametersInheritedCACert", |
| 108 "ValidDSAParameterInheritanceTest5EE"}; | 110 "ValidDSAParameterInheritanceTest5EE"}; |
| 109 const char* const crls[] = {"TrustAnchorRootCRL", "DSACACRL", | 111 const char* const crls[] = {"TrustAnchorRootCRL", "DSACACRL", |
| 110 "DSAParametersInheritedCACRL"}; | 112 "DSAParametersInheritedCACRL"}; |
| 111 // DSA signatures are intentionally unsupported. | 113 // DSA signatures are intentionally unsupported. |
| 112 ASSERT_FALSE(this->Verify(certs, crls)); | 114 ASSERT_FALSE(this->Verify(certs, crls, {})); |
| 113 } | 115 } |
| 114 | 116 |
| 115 class PkitsTest13SignatureVerificationCustom | 117 class PkitsTest13SignatureVerificationCustom |
| 116 : public PkitsTest<VerifyCertificateChainPkitsTestDelegate> {}; | 118 : public PkitsTest<VerifyCertificateChainPkitsTestDelegate> {}; |
| 117 | 119 |
| 118 // Modified version of 4.13.21 Valid RFC822 nameConstraints Test21 | 120 // Modified version of 4.13.21 Valid RFC822 nameConstraints Test21 |
| 119 TEST_F(PkitsTest13SignatureVerificationCustom, | 121 TEST_F(PkitsTest13SignatureVerificationCustom, |
| 120 Section13ValidRFC822nameConstraintsTest21Custom) { | 122 Section13ValidRFC822nameConstraintsTest21Custom) { |
| 121 const char* const certs[] = {"TrustAnchorRootCertificate", | 123 const char* const certs[] = {"TrustAnchorRootCertificate", |
| 122 "nameConstraintsRFC822CA1Cert", | 124 "nameConstraintsRFC822CA1Cert", |
| 123 "ValidRFC822nameConstraintsTest21EE"}; | 125 "ValidRFC822nameConstraintsTest21EE"}; |
| 124 const char* const crls[] = {"TrustAnchorRootCRL", | 126 const char* const crls[] = {"TrustAnchorRootCRL", |
| 125 "nameConstraintsRFC822CA1CRL"}; | 127 "nameConstraintsRFC822CA1CRL"}; |
| 126 // Name constraints on rfc822Names are not supported. | 128 // Name constraints on rfc822Names are not supported. |
| 127 ASSERT_FALSE(this->Verify(certs, crls)); | 129 ASSERT_FALSE(this->Verify(certs, crls, {})); |
| 128 } | 130 } |
| 129 | 131 |
| 130 // Modified version of 4.13.23 Valid RFC822 nameConstraints Test23 | 132 // Modified version of 4.13.23 Valid RFC822 nameConstraints Test23 |
| 131 TEST_F(PkitsTest13SignatureVerificationCustom, | 133 TEST_F(PkitsTest13SignatureVerificationCustom, |
| 132 Section13ValidRFC822nameConstraintsTest23Custom) { | 134 Section13ValidRFC822nameConstraintsTest23Custom) { |
| 133 const char* const certs[] = {"TrustAnchorRootCertificate", | 135 const char* const certs[] = {"TrustAnchorRootCertificate", |
| 134 "nameConstraintsRFC822CA2Cert", | 136 "nameConstraintsRFC822CA2Cert", |
| 135 "ValidRFC822nameConstraintsTest23EE"}; | 137 "ValidRFC822nameConstraintsTest23EE"}; |
| 136 const char* const crls[] = {"TrustAnchorRootCRL", | 138 const char* const crls[] = {"TrustAnchorRootCRL", |
| 137 "nameConstraintsRFC822CA2CRL"}; | 139 "nameConstraintsRFC822CA2CRL"}; |
| 138 // Name constraints on rfc822Names are not supported. | 140 // Name constraints on rfc822Names are not supported. |
| 139 ASSERT_FALSE(this->Verify(certs, crls)); | 141 ASSERT_FALSE(this->Verify(certs, crls, {})); |
| 140 } | 142 } |
| 141 | 143 |
| 142 // Modified version of 4.13.25 Valid RFC822 nameConstraints Test25 | 144 // Modified version of 4.13.25 Valid RFC822 nameConstraints Test25 |
| 143 TEST_F(PkitsTest13SignatureVerificationCustom, | 145 TEST_F(PkitsTest13SignatureVerificationCustom, |
| 144 Section13ValidRFC822nameConstraintsTest25Custom) { | 146 Section13ValidRFC822nameConstraintsTest25Custom) { |
| 145 const char* const certs[] = {"TrustAnchorRootCertificate", | 147 const char* const certs[] = {"TrustAnchorRootCertificate", |
| 146 "nameConstraintsRFC822CA3Cert", | 148 "nameConstraintsRFC822CA3Cert", |
| 147 "ValidRFC822nameConstraintsTest25EE"}; | 149 "ValidRFC822nameConstraintsTest25EE"}; |
| 148 const char* const crls[] = {"TrustAnchorRootCRL", | 150 const char* const crls[] = {"TrustAnchorRootCRL", |
| 149 "nameConstraintsRFC822CA3CRL"}; | 151 "nameConstraintsRFC822CA3CRL"}; |
| 150 // Name constraints on rfc822Names are not supported. | 152 // Name constraints on rfc822Names are not supported. |
| 151 ASSERT_FALSE(this->Verify(certs, crls)); | 153 ASSERT_FALSE(this->Verify(certs, crls, {})); |
| 152 } | 154 } |
| 153 | 155 |
| 154 // Modified version of 4.13.27 Valid DN and RFC822 nameConstraints Test27 | 156 // Modified version of 4.13.27 Valid DN and RFC822 nameConstraints Test27 |
| 155 TEST_F(PkitsTest13SignatureVerificationCustom, | 157 TEST_F(PkitsTest13SignatureVerificationCustom, |
| 156 Section13ValidDNandRFC822nameConstraintsTest27Custom) { | 158 Section13ValidDNandRFC822nameConstraintsTest27Custom) { |
| 157 const char* const certs[] = {"TrustAnchorRootCertificate", | 159 const char* const certs[] = {"TrustAnchorRootCertificate", |
| 158 "nameConstraintsDN1CACert", | 160 "nameConstraintsDN1CACert", |
| 159 "nameConstraintsDN1subCA3Cert", | 161 "nameConstraintsDN1subCA3Cert", |
| 160 "ValidDNandRFC822nameConstraintsTest27EE"}; | 162 "ValidDNandRFC822nameConstraintsTest27EE"}; |
| 161 const char* const crls[] = {"TrustAnchorRootCRL", "nameConstraintsDN1CACRL", | 163 const char* const crls[] = {"TrustAnchorRootCRL", "nameConstraintsDN1CACRL", |
| 162 "nameConstraintsDN1subCA3CRL"}; | 164 "nameConstraintsDN1subCA3CRL"}; |
| 163 // Name constraints on rfc822Names are not supported. | 165 // Name constraints on rfc822Names are not supported. |
| 164 ASSERT_FALSE(this->Verify(certs, crls)); | 166 ASSERT_FALSE(this->Verify(certs, crls, {})); |
| 165 } | 167 } |
| 166 | 168 |
| 167 // Modified version of 4.13.34 Valid URI nameConstraints Test34 | 169 // Modified version of 4.13.34 Valid URI nameConstraints Test34 |
| 168 TEST_F(PkitsTest13SignatureVerificationCustom, | 170 TEST_F(PkitsTest13SignatureVerificationCustom, |
| 169 Section13ValidURInameConstraintsTest34Custom) { | 171 Section13ValidURInameConstraintsTest34Custom) { |
| 170 const char* const certs[] = {"TrustAnchorRootCertificate", | 172 const char* const certs[] = {"TrustAnchorRootCertificate", |
| 171 "nameConstraintsURI1CACert", | 173 "nameConstraintsURI1CACert", |
| 172 "ValidURInameConstraintsTest34EE"}; | 174 "ValidURInameConstraintsTest34EE"}; |
| 173 const char* const crls[] = {"TrustAnchorRootCRL", "nameConstraintsURI1CACRL"}; | 175 const char* const crls[] = {"TrustAnchorRootCRL", "nameConstraintsURI1CACRL"}; |
| 174 // Name constraints on uniformResourceIdentifiers are not supported. | 176 // Name constraints on uniformResourceIdentifiers are not supported. |
| 175 ASSERT_FALSE(this->Verify(certs, crls)); | 177 ASSERT_FALSE(this->Verify(certs, crls, {})); |
| 176 } | 178 } |
| 177 | 179 |
| 178 // Modified version of 4.13.36 Valid URI nameConstraints Test36 | 180 // Modified version of 4.13.36 Valid URI nameConstraints Test36 |
| 179 TEST_F(PkitsTest13SignatureVerificationCustom, | 181 TEST_F(PkitsTest13SignatureVerificationCustom, |
| 180 Section13ValidURInameConstraintsTest36Custom) { | 182 Section13ValidURInameConstraintsTest36Custom) { |
| 181 const char* const certs[] = {"TrustAnchorRootCertificate", | 183 const char* const certs[] = {"TrustAnchorRootCertificate", |
| 182 "nameConstraintsURI2CACert", | 184 "nameConstraintsURI2CACert", |
| 183 "ValidURInameConstraintsTest36EE"}; | 185 "ValidURInameConstraintsTest36EE"}; |
| 184 const char* const crls[] = {"TrustAnchorRootCRL", "nameConstraintsURI2CACRL"}; | 186 const char* const crls[] = {"TrustAnchorRootCRL", "nameConstraintsURI2CACRL"}; |
| 185 // Name constraints on uniformResourceIdentifiers are not supported. | 187 // Name constraints on uniformResourceIdentifiers are not supported. |
| 186 ASSERT_FALSE(this->Verify(certs, crls)); | 188 ASSERT_FALSE(this->Verify(certs, crls, {})); |
| 187 } | 189 } |
| 188 | 190 |
| 189 INSTANTIATE_TYPED_TEST_CASE_P(VerifyCertificateChain, | 191 INSTANTIATE_TYPED_TEST_CASE_P(VerifyCertificateChain, |
| 190 PkitsTest01SignatureVerification, | 192 PkitsTest01SignatureVerification, |
| 191 VerifyCertificateChainPkitsTestDelegate); | 193 VerifyCertificateChainPkitsTestDelegate); |
| 192 INSTANTIATE_TYPED_TEST_CASE_P(VerifyCertificateChain, | 194 INSTANTIATE_TYPED_TEST_CASE_P(VerifyCertificateChain, |
| 193 PkitsTest02ValidityPeriods, | 195 PkitsTest02ValidityPeriods, |
| 194 VerifyCertificateChainPkitsTestDelegate); | 196 VerifyCertificateChainPkitsTestDelegate); |
| 195 INSTANTIATE_TYPED_TEST_CASE_P(VerifyCertificateChain, | 197 INSTANTIATE_TYPED_TEST_CASE_P(VerifyCertificateChain, |
| 196 PkitsTest03VerifyingNameChaining, | 198 PkitsTest03VerifyingNameChaining, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 210 | 212 |
| 211 // TODO(mattm): CRL support: PkitsTest04BasicCertificateRevocationTests, | 213 // TODO(mattm): CRL support: PkitsTest04BasicCertificateRevocationTests, |
| 212 // PkitsTest05VerifyingPathswithSelfIssuedCertificates, | 214 // PkitsTest05VerifyingPathswithSelfIssuedCertificates, |
| 213 // PkitsTest14DistributionPoints, PkitsTest15DeltaCRLs | 215 // PkitsTest14DistributionPoints, PkitsTest15DeltaCRLs |
| 214 | 216 |
| 215 // TODO(mattm): Certificate Policies support: PkitsTest08CertificatePolicies, | 217 // TODO(mattm): Certificate Policies support: PkitsTest08CertificatePolicies, |
| 216 // PkitsTest09RequireExplicitPolicy PkitsTest10PolicyMappings, | 218 // PkitsTest09RequireExplicitPolicy PkitsTest10PolicyMappings, |
| 217 // PkitsTest11InhibitPolicyMapping, PkitsTest12InhibitAnyPolicy | 219 // PkitsTest11InhibitPolicyMapping, PkitsTest12InhibitAnyPolicy |
| 218 | 220 |
| 219 } // namespace net | 221 } // namespace net |
| OLD | NEW |