9#include <botan/certstor.h>
11#include <botan/data_src.h>
12#include <botan/hash.h>
13#include <botan/pkix_types.h>
14#include <botan/internal/filesystem.h>
21 const std::vector<uint8_t>& key_id)
const {
37 for(
const auto& c : m_certs) {
43 m_certs.push_back(cert);
47 std::vector<X509_DN> subjects;
48 subjects.reserve(m_certs.size());
49 for(
const auto& cert : m_certs) {
50 subjects.push_back(cert.subject_dn());
56 const std::vector<uint8_t>& key_id)
const {
57 for(
const auto& cert : m_certs) {
60 const std::vector<uint8_t>& skid = cert.subject_key_id();
62 if(!skid.empty() && skid != key_id) {
67 if(cert.subject_dn() == subject_dn) {
76 const std::vector<uint8_t>& key_id)
const {
77 std::vector<X509_Certificate> matches;
79 for(
const auto& cert : m_certs) {
81 const std::vector<uint8_t>& skid = cert.subject_key_id();
83 if(!skid.empty() && skid != key_id) {
88 if(cert.subject_dn() == subject_dn) {
89 matches.push_back(cert);
97 const std::vector<uint8_t>& key_hash)
const {
98 if(key_hash.size() != 20) {
99 throw Invalid_Argument(
"Certificate_Store_In_Memory::find_cert_by_pubkey_sha1 invalid hash");
104 for(
const auto& cert : m_certs) {
105 hash->update(cert.subject_public_key_bitstring());
106 if(key_hash == hash->final_stdvec()) {
115 const std::vector<uint8_t>& subject_hash)
const {
116 if(subject_hash.size() != 32) {
117 throw Invalid_Argument(
"Certificate_Store_In_Memory::find_cert_by_raw_subject_dn_sha256 invalid hash");
122 for(
const auto& cert : m_certs) {
123 hash->update(cert.raw_subject_dn());
124 if(subject_hash == hash->final_stdvec()) {
135 for(
auto& c : m_crls) {
137 if(c.issuer_dn() == crl_issuer) {
146 m_crls.push_back(crl);
152 for(
const auto& c : m_crls) {
154 if(!key_id.empty()) {
155 const std::vector<uint8_t>& akid = c.authority_key_id();
157 if(!akid.empty() && akid != key_id) {
162 if(c.issuer_dn() == subject.
issuer_dn()) {
174#if defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
182 if(maybe_certs.empty()) {
183 maybe_certs.push_back(std::string(dir));
186 for(
auto&& cert_file : maybe_certs) {
188 DataSource_Stream src(cert_file,
true);
189 while(!src.end_of_data()) {
191 X509_Certificate cert(src);
192 m_certs.push_back(cert);
193 }
catch(std::exception&) {
198 }
catch(std::exception&) {}
std::vector< X509_Certificate > find_all_certs(const X509_DN &subject_dn, const std::vector< uint8_t > &key_id) const override
std::optional< X509_Certificate > find_cert_by_pubkey_sha1(const std::vector< uint8_t > &key_hash) const override
std::optional< X509_Certificate > find_cert(const X509_DN &subject_dn, const std::vector< uint8_t > &key_id) const override
Certificate_Store_In_Memory()=default
void add_crl(const X509_CRL &crl)
std::optional< X509_Certificate > find_cert_by_raw_subject_dn_sha256(const std::vector< uint8_t > &subject_hash) const override
std::optional< X509_CRL > find_crl_for(const X509_Certificate &subject) const override
void add_certificate(const X509_Certificate &cert)
std::vector< X509_DN > all_subjects() const override
virtual std::optional< X509_CRL > find_crl_for(const X509_Certificate &subject) const
virtual ~Certificate_Store()
virtual std::vector< X509_Certificate > find_all_certs(const X509_DN &subject_dn, const std::vector< uint8_t > &key_id) const =0
virtual std::optional< X509_Certificate > find_cert(const X509_DN &subject_dn, const std::vector< uint8_t > &key_id) const
static std::unique_ptr< HashFunction > create(std::string_view algo_spec, std::string_view provider="")
const X509_Time & this_update() const
const X509_DN & issuer_dn() const
const std::vector< uint8_t > & authority_key_id() const
const X509_DN & issuer_dn() const
std::vector< std::string > get_files_recursive(std::string_view dir)