• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "path_builder.h"
6 
7 #include "cert_issuer_source_static.h"
8 #include "simple_path_builder_delegate.h"
9 #include "trust_store_in_memory.h"
10 #include "verify_certificate_chain_typed_unittest.h"
11 
12 namespace bssl {
13 
14 namespace {
15 
16 class PathBuilderTestDelegate {
17  public:
Verify(const VerifyCertChainTest & test,const std::string & test_file_path)18   static void Verify(const VerifyCertChainTest& test,
19                      const std::string& test_file_path) {
20     SimplePathBuilderDelegate path_builder_delegate(1024, test.digest_policy);
21     ASSERT_FALSE(test.chain.empty());
22 
23     TrustStoreInMemory trust_store;
24     trust_store.AddCertificate(test.chain.back(), test.last_cert_trust);
25 
26     CertIssuerSourceStatic intermediate_cert_issuer_source;
27     for (size_t i = 1; i < test.chain.size(); ++i)
28       intermediate_cert_issuer_source.AddCert(test.chain[i]);
29 
30     // First cert in the |chain| is the target.
31     CertPathBuilder path_builder(
32         test.chain.front(), &trust_store, &path_builder_delegate, test.time,
33         test.key_purpose, test.initial_explicit_policy,
34         test.user_initial_policy_set, test.initial_policy_mapping_inhibit,
35         test.initial_any_policy_inhibit);
36     path_builder.AddCertIssuerSource(&intermediate_cert_issuer_source);
37 
38     CertPathBuilder::Result result = path_builder.Run();
39     EXPECT_EQ(!test.HasHighSeverityErrors(), result.HasValidPath());
40     if (result.HasValidPath()) {
41       VerifyUserConstrainedPolicySet(
42           test.expected_user_constrained_policy_set,
43           result.GetBestValidPath()->user_constrained_policy_set,
44           test_file_path);
45     }
46   }
47 };
48 
49 }  // namespace
50 
51 INSTANTIATE_TYPED_TEST_SUITE_P(PathBuilder,
52                                VerifyCertificateChainSingleRootTest,
53                                PathBuilderTestDelegate);
54 
55 }  // namespace net
56