Botan 3.11.0
Crypto and TLS for C&
certstor_windows.h
Go to the documentation of this file.
1/*
2* Certificate Store
3* (C) 1999-2019 Jack Lloyd
4* (C) 2019 Patrick Schmidt
5* (C) 2021 René Meusel
6*
7* Botan is released under the Simplified BSD License (see license.txt)
8*/
9
10#ifndef BOTAN_CERT_STORE_SYSTEM_WINDOWS_H_
11#define BOTAN_CERT_STORE_SYSTEM_WINDOWS_H_
12
13#include <botan/certstor.h>
14#include <botan/mutex.h>
15#include <map>
16
17// Use Certificate_Store_System instead
18BOTAN_FUTURE_INTERNAL_HEADER(certstor_windows.h)
19
20namespace Botan {
21/**
22* Certificate Store that is backed by the system trust store on Windows.
23*/
25 public:
27
32
33 /**
34 * @return DNs for all certificates managed by the store
35 */
36 std::vector<X509_DN> all_subjects() const override;
37
38 /**
39 * Find a certificate by Subject DN and (optionally) key identifier
40 * @return the first certificate that matches
41 */
42 std::optional<X509_Certificate> find_cert(const X509_DN& subject_dn,
43 const std::vector<uint8_t>& key_id) const override;
44
45 /**
46 * Find all certificates with a given Subject DN.
47 * Subject DN and even the key identifier might not be unique.
48 */
49 std::vector<X509_Certificate> find_all_certs(const X509_DN& subject_dn,
50 const std::vector<uint8_t>& key_id) const override;
51
52 /**
53 * Find a certificate by searching for one with a matching SHA-1 hash of
54 * public key.
55 * @return a matching certificate or nullptr otherwise
56 */
57 std::optional<X509_Certificate> find_cert_by_pubkey_sha1(const std::vector<uint8_t>& key_hash) const override;
58
59 /**
60 * @throws Not_Implemented as this is not possible in the Windows system cert API
61 */
62 std::optional<X509_Certificate> find_cert_by_raw_subject_dn_sha256(
63 const std::vector<uint8_t>& subject_hash) const override;
64
65 std::optional<X509_Certificate> find_cert_by_issuer_dn_and_serial_number(
66 const X509_DN& issuer_dn, std::span<const uint8_t> serial_number) const override;
67
68 /**
69 * Not Yet Implemented
70 * @return nullptr;
71 */
72 std::optional<X509_CRL> find_crl_for(const X509_Certificate& subject) const override;
73
74 private:
75 /**
76 * Handle certificates that do not adhere to RFC 3280 using a subject key identifier
77 * that is not equal to the SHA-1 of the public key (w/o algorithm identifier)
78 *
79 * This method lazily builds a cache of certificates found in previous queries as well
80 * as negative results for @p key_hash queries that didn't find a certificate.
81 *
82 * See here for further details: https://github.com/randombit/botan/issues/2779
83 */
84 std::optional<X509_Certificate> find_cert_by_pubkey_sha1_via_exhaustive_search(
85 const std::vector<uint8_t>& key_hash) const;
86
87 private:
88 mutable mutex_type m_mutex;
89 mutable std::map<std::vector<uint8_t>, std::optional<X509_Certificate>> m_sha1_pubkey_to_cert;
90};
91
92} // namespace Botan
93
94#endif
#define BOTAN_PUBLIC_API(maj, min)
Definition api.h:21
#define BOTAN_FUTURE_INTERNAL_HEADER(hdr)
Definition api.h:98
Certificate_Store_Windows & operator=(const Certificate_Store_Windows &)=delete
Certificate_Store_Windows(const Certificate_Store_Windows &)=delete
Certificate_Store_Windows & operator=(Certificate_Store_Windows &&)=delete
Certificate_Store_Windows(Certificate_Store_Windows &&)=delete
virtual std::optional< X509_CRL > find_crl_for(const X509_Certificate &subject) const
Definition certstor.cpp:34
virtual std::vector< X509_DN > all_subjects() const =0
virtual std::optional< X509_Certificate > find_cert_by_raw_subject_dn_sha256(const std::vector< uint8_t > &subject_hash) const =0
virtual 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 =0
virtual std::optional< X509_Certificate > find_cert_by_pubkey_sha1(const std::vector< uint8_t > &key_hash) const =0
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
Definition certstor.cpp:22
noop_mutex mutex_type
Definition mutex.h:37