Botan 3.4.0
Crypto and TLS for C&
certstor_sql.h
Go to the documentation of this file.
1/*
2* Certificate Store in SQL
3* (C) 2016 Kai Michaelis, Rohde & Schwarz Cybersecurity
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#ifndef BOTAN_CERT_STORE_SQL_H_
9#define BOTAN_CERT_STORE_SQL_H_
10
11#include <botan/certstor.h>
12#include <botan/database.h>
13#include <botan/x509_crl.h>
14#include <botan/x509cert.h>
15
16namespace Botan {
17
18class Private_Key;
19class RandomNumberGenerator;
20
21/**
22 * Certificate and private key store backed by an SQL database.
23 */
25 public:
26 /**
27 * Create/open a certificate store.
28 * @param db underlying database storage
29 * @param passwd password to encrypt private keys in the database
30 * @param rng used for encrypting keys
31 * @param table_prefix optional prefix for db table names
32 */
33 explicit Certificate_Store_In_SQL(std::shared_ptr<SQL_Database> db,
34 std::string_view passwd,
36 std::string_view table_prefix = "");
37
38 /**
39 * Returns the first certificate with matching subject DN and optional key ID.
40 */
41 std::optional<X509_Certificate> find_cert(const X509_DN& subject_dn,
42 const std::vector<uint8_t>& key_id) const override;
43
44 /*
45 * Find all certificates with a given Subject DN.
46 * Subject DN and even the key identifier might not be unique.
47 */
48 std::vector<X509_Certificate> find_all_certs(const X509_DN& subject_dn,
49 const std::vector<uint8_t>& key_id) const override;
50
51 std::optional<X509_Certificate> find_cert_by_pubkey_sha1(const std::vector<uint8_t>& key_hash) const override;
52
53 std::optional<X509_Certificate> find_cert_by_raw_subject_dn_sha256(
54 const std::vector<uint8_t>& subject_hash) const override;
55
56 /**
57 * Returns all subject DNs known to the store instance.
58 */
59 std::vector<X509_DN> all_subjects() const override;
60
61 /**
62 * Inserts "cert" into the store, returns false if the certificate is
63 * already known and true if insertion was successful.
64 */
65 bool insert_cert(const X509_Certificate& cert);
66
67 /**
68 * Removes "cert" from the store. Returns false if the certificate could not
69 * be found and true if removal was successful.
70 */
71 bool remove_cert(const X509_Certificate& cert);
72
73 /// Returns the private key for "cert" or an empty shared_ptr if none was found.
74 std::shared_ptr<const Private_Key> find_key(const X509_Certificate&) const;
75
76 /// Returns all certificates for private key "key".
77 std::vector<X509_Certificate> find_certs_for_key(const Private_Key& key) const;
78
79 /**
80 * Inserts "key" for "cert" into the store, returns false if the key is
81 * already known and true if insertion was successful.
82 */
83 bool insert_key(const X509_Certificate& cert, const Private_Key& key);
84
85 /// Removes "key" from the store.
86 void remove_key(const Private_Key& key);
87
88 /// Marks "cert" as revoked starting from "time".
89 void revoke_cert(const X509_Certificate&, CRL_Code, const X509_Time& time = X509_Time());
90
91 /// Reverses the revokation for "cert".
92 void affirm_cert(const X509_Certificate&);
93
94 /**
95 * Generates Certificate Revocation Lists for all certificates marked as revoked.
96 * A CRL is returned for each unique issuer DN.
97 */
98 std::vector<X509_CRL> generate_crls() const;
99
100 /**
101 * Generates a CRL for all certificates issued by the given issuer.
102 */
103 std::optional<X509_CRL> find_crl_for(const X509_Certificate& issuer) const override;
104
105 private:
107 std::shared_ptr<SQL_Database> m_database;
108 std::string m_prefix;
109 std::string m_password;
110};
111
112} // namespace Botan
113#endif
#define BOTAN_PUBLIC_API(maj, min)
Definition compiler.h:31