Botan 3.10.0
Crypto and TLS for C&
certstor_flatfile.h
Go to the documentation of this file.
1/*
2* Certificate Store
3* (C) 1999-2019 Jack Lloyd
4* (C) 2019 Patrick Schmidt
5*
6* Botan is released under the Simplified BSD License (see license.txt)
7*/
8
9#ifndef BOTAN_CERT_STORE_FLATFILE_H_
10#define BOTAN_CERT_STORE_FLATFILE_H_
11
12#include <botan/certstor.h>
13#include <botan/pkix_types.h>
14
15#include <map>
16#include <memory>
17#include <vector>
18
19namespace Botan {
20/**
21* Certificate Store that is backed by a file of PEMs of trusted CAs.
22*/
24 public:
25 /**
26 * Construct a new Certificate_Store given a file path to a file including
27 * PEMs of trusted self-signed CAs.
28 *
29 * @param file the name of the file to read certificates from
30 * @param ignore_non_ca if true, certs that are not self-signed CA certs will
31 * be ignored. Otherwise (if false), an exception will be thrown instead.
32 */
33 BOTAN_FUTURE_EXPLICIT Flatfile_Certificate_Store(std::string_view file, bool ignore_non_ca = false);
34
39 ~Flatfile_Certificate_Store() override = default;
40
41 /**
42 * @return DNs for all certificates managed by the store
43 */
44 std::vector<X509_DN> all_subjects() const override;
45
46 /**
47 * Find all certificates with a given Subject DN.
48 * Subject DN and even the key identifier might not be unique.
49 */
50 std::vector<X509_Certificate> find_all_certs(const X509_DN& subject_dn,
51 const std::vector<uint8_t>& key_id) const override;
52
53 /**
54 * Find a certificate by searching for one with a matching SHA-1 hash of
55 * public key.
56 * @return a matching certificate or nullptr otherwise
57 */
58 std::optional<X509_Certificate> find_cert_by_pubkey_sha1(const std::vector<uint8_t>& key_hash) const override;
59
60 std::optional<X509_Certificate> find_cert_by_raw_subject_dn_sha256(
61 const std::vector<uint8_t>& subject_hash) const override;
62
63 std::optional<X509_Certificate> find_cert_by_issuer_dn_and_serial_number(
64 const X509_DN& issuer_dn, std::span<const uint8_t> serial_number) const override;
65
66 /**
67 * Fetching CRLs is not supported by this certificate store. This will
68 * always return an empty list.
69 */
70 std::optional<X509_CRL> find_crl_for(const X509_Certificate& subject) const override;
71
72 private:
73 std::vector<X509_DN> m_all_subjects;
74 std::map<X509_DN, std::vector<X509_Certificate>> m_dn_to_cert;
75 std::map<std::vector<uint8_t>, std::optional<X509_Certificate>> m_pubkey_sha1_to_cert;
76 std::map<std::vector<uint8_t>, std::optional<X509_Certificate>> m_subject_dn_sha256_to_cert;
77 std::map<X509_DN, std::vector<X509_Certificate>> m_issuer_dn_to_cert;
78};
79} // namespace Botan
80
81#endif
#define BOTAN_PUBLIC_API(maj, min)
Definition api.h:21
#define BOTAN_FUTURE_EXPLICIT
Definition api.h:52
std::optional< X509_CRL > find_crl_for(const X509_Certificate &subject) const override
Flatfile_Certificate_Store & operator=(const Flatfile_Certificate_Store &)=default
std::vector< X509_DN > all_subjects() const override
std::optional< X509_Certificate > find_cert_by_raw_subject_dn_sha256(const std::vector< uint8_t > &subject_hash) const override
Flatfile_Certificate_Store(const Flatfile_Certificate_Store &)=default
std::vector< X509_Certificate > find_all_certs(const X509_DN &subject_dn, const std::vector< uint8_t > &key_id) const override
~Flatfile_Certificate_Store() override=default
std::optional< X509_Certificate > find_cert_by_pubkey_sha1(const std::vector< uint8_t > &key_hash) const override
Flatfile_Certificate_Store(Flatfile_Certificate_Store &&)=default
Flatfile_Certificate_Store & operator=(Flatfile_Certificate_Store &&)=default
std::optional< X509_Certificate > find_cert_by_issuer_dn_and_serial_number(const X509_DN &issuer_dn, std::span< const uint8_t > serial_number) const override
BOTAN_FUTURE_EXPLICIT Flatfile_Certificate_Store(std::string_view file, bool ignore_non_ca=false)