blob: a5aeef7355754cef1eccac2b0536f2a8e8337b5b [file] [log] [blame]
Bob Beckbc97b7a2023-04-18 08:35:15 -06001// 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
12namespace bssl {
13
14namespace {
15
16class PathBuilderTestDelegate {
17 public:
Bob Beck5c7a2a02023-11-20 17:28:21 -070018 static void Verify(const VerifyCertChainTest &test,
19 const std::string &test_file_path) {
Bob Beckbc97b7a2023-04-18 08:35:15 -060020 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;
Bob Beck6beabf32023-11-21 09:43:52 -070027 for (size_t i = 1; i < test.chain.size(); ++i) {
Bob Beckbc97b7a2023-04-18 08:35:15 -060028 intermediate_cert_issuer_source.AddCert(test.chain[i]);
Bob Beck6beabf32023-11-21 09:43:52 -070029 }
Bob Beckbc97b7a2023-04-18 08:35:15 -060030
31 // First cert in the |chain| is the target.
32 CertPathBuilder path_builder(
33 test.chain.front(), &trust_store, &path_builder_delegate, test.time,
34 test.key_purpose, test.initial_explicit_policy,
35 test.user_initial_policy_set, test.initial_policy_mapping_inhibit,
36 test.initial_any_policy_inhibit);
37 path_builder.AddCertIssuerSource(&intermediate_cert_issuer_source);
38
39 CertPathBuilder::Result result = path_builder.Run();
40 EXPECT_EQ(!test.HasHighSeverityErrors(), result.HasValidPath());
41 if (result.HasValidPath()) {
42 VerifyUserConstrainedPolicySet(
43 test.expected_user_constrained_policy_set,
44 result.GetBestValidPath()->user_constrained_policy_set,
45 test_file_path);
46 }
47 }
48};
49
50} // namespace
51
52INSTANTIATE_TYPED_TEST_SUITE_P(PathBuilder,
53 VerifyCertificateChainSingleRootTest,
54 PathBuilderTestDelegate);
55
Bob Beck5c7a2a02023-11-20 17:28:21 -070056} // namespace bssl