Botan 3.6.1
Crypto and TLS for C&
x509_ca.h
Go to the documentation of this file.
1/*
2* X.509 Certificate Authority
3* (C) 1999-2008 Jack Lloyd
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#ifndef BOTAN_X509_CA_H_
9#define BOTAN_X509_CA_H_
10
11#include <botan/x509_crl.h>
12#include <botan/x509cert.h>
13#include <chrono>
14#include <map>
15
16namespace Botan {
17
18class RandomNumberGenerator;
19class BigInt;
20class Private_Key;
21class PKCS10_Request;
22class PK_Signer;
23
24/**
25* An interface capable of creating new X.509 certificates
26*/
28 public:
29 /**
30 * Return the algorithm identifier used to identify signatures that
31 * this CA will create.
32 */
33 const AlgorithmIdentifier& algorithm_identifier() const { return m_ca_sig_algo; }
34
35 /**
36 * Return the CA's certificate
37 */
38 const X509_Certificate& ca_certificate() const { return m_ca_cert; }
39
40 /**
41 * Return the hash function the CA is using to sign with
42 */
43 const std::string& hash_function() const { return m_hash_fn; }
44
45 /**
46 * Return the signature object this CA uses to sign with
47 */
48 PK_Signer& signature_op() { return *m_signer; }
49
50 /**
51 * Sign a PKCS#10 Request.
52 * @param req the request to sign
53 * @param rng the rng to use
54 * @param not_before the starting time for the certificate
55 * @param not_after the expiration time for the certificate
56 * @return resulting certificate
57 */
58 X509_Certificate sign_request(const PKCS10_Request& req,
60 const X509_Time& not_before,
61 const X509_Time& not_after) const;
62
63 /**
64 * Sign a PKCS#10 Request.
65 * @param req the request to sign
66 * @param rng the rng to use
67 * @param serial_number the serial number the cert will be assigned.
68 * @param not_before the starting time for the certificate
69 * @param not_after the expiration time for the certificate
70 * @return resulting certificate
71 */
72 X509_Certificate sign_request(const PKCS10_Request& req,
74 const BigInt& serial_number,
75 const X509_Time& not_before,
76 const X509_Time& not_after) const;
77
78 /**
79 * Create a new and empty CRL for this CA.
80 * @param rng the random number generator to use
81 * @param issue_time the issue time (typically system_clock::now)
82 * @param next_update the time interval after issue_data within which
83 * a new CRL will be produced.
84 * @return new CRL
85 */
87 std::chrono::system_clock::time_point issue_time,
88 std::chrono::seconds next_update) const;
89
90 /**
91 * Create a new CRL by with additional entries.
92 * @param last_crl the last CRL of this CA to add the new entries to
93 * @param new_entries contains the new CRL entries to be added to the CRL
94 * @param rng the random number generator to use
95 * @param issue_time the issue time (typically system_clock::now)
96 * @param next_update the time interval after issue_data within which
97 * a new CRL will be produced.
98 */
99 X509_CRL update_crl(const X509_CRL& last_crl,
100 const std::vector<CRL_Entry>& new_entries,
102 std::chrono::system_clock::time_point issue_time,
103 std::chrono::seconds next_update) const;
104
105 /**
106 * Create a new and empty CRL for this CA.
107 * @param rng the random number generator to use
108 * @param next_update the time to set in next update in seconds
109 * as the offset from the current time
110 * @return new CRL
111 */
112 X509_CRL new_crl(RandomNumberGenerator& rng, uint32_t next_update = 604800) const;
113
114 /**
115 * Create a new CRL by with additional entries.
116 * @param last_crl the last CRL of this CA to add the new entries to
117 * @param new_entries contains the new CRL entries to be added to the CRL
118 * @param rng the random number generator to use
119 * @param next_update the time to set in next update in seconds
120 * as the offset from the current time
121 */
122 X509_CRL update_crl(const X509_CRL& last_crl,
123 const std::vector<CRL_Entry>& new_entries,
125 uint32_t next_update = 604800) const;
126
127 /**
128 * Return the set of extensions that will be used for a certificate.
129 *
130 * This is a helper method that is used internally. It is also exposed
131 * so you can call it directly and then modify the extensions before
132 * creating a certificate using X509_CA::make_cert.
133 */
134 static Extensions choose_extensions(const PKCS10_Request& req,
135 const X509_Certificate& ca_certificate,
136 std::string_view hash_fn);
137
138 /**
139 * Interface for creating new certificates
140 * @param signer a signing object
141 * @param rng a random number generator
142 * @param sig_algo the signature algorithm identifier
143 * @param pub_key the serialized public key
144 * @param not_before the start time of the certificate
145 * @param not_after the end time of the certificate
146 * @param issuer_dn the DN of the issuer
147 * @param subject_dn the DN of the subject
148 * @param extensions an optional list of certificate extensions
149 * @returns newly minted certificate
150 */
151 static X509_Certificate make_cert(PK_Signer& signer,
153 const AlgorithmIdentifier& sig_algo,
154 const std::vector<uint8_t>& pub_key,
155 const X509_Time& not_before,
156 const X509_Time& not_after,
157 const X509_DN& issuer_dn,
158 const X509_DN& subject_dn,
159 const Extensions& extensions);
160
161 /**
162 * Interface for creating new certificates
163 * @param signer a signing object
164 * @param rng a random number generator
165 * @param serial_number the serial number the cert will be assigned
166 * @param sig_algo the signature algorithm identifier
167 * @param pub_key the serialized public key
168 * @param not_before the start time of the certificate
169 * @param not_after the end time of the certificate
170 * @param issuer_dn the DN of the issuer
171 * @param subject_dn the DN of the subject
172 * @param extensions an optional list of certificate extensions
173 * @returns newly minted certificate
174 */
175 static X509_Certificate make_cert(PK_Signer& signer,
177 const BigInt& serial_number,
178 const AlgorithmIdentifier& sig_algo,
179 const std::vector<uint8_t>& pub_key,
180 const X509_Time& not_before,
181 const X509_Time& not_after,
182 const X509_DN& issuer_dn,
183 const X509_DN& subject_dn,
184 const Extensions& extensions);
185
186 /**
187 * Create a new CA object with custom padding option
188 *
189 * This is mostly useful for creating RSA-PSS certificates
190 *
191 * @param ca_certificate the certificate of the CA
192 * @param key the private key of the CA
193 * @param hash_fn name of a hash function to use for signing
194 * @param padding_method name of the signature padding method to use
195 * @param rng the random generator to use
196 */
197 X509_CA(const X509_Certificate& ca_certificate,
198 const Private_Key& key,
199 std::string_view hash_fn,
200 std::string_view padding_method,
202
203 /**
204 * Create a new CA object.
205 * @param ca_certificate the certificate of the CA
206 * @param key the private key of the CA
207 * @param hash_fn name of a hash function to use for signing
208 * @param rng the random generator to use
209 */
210 X509_CA(const X509_Certificate& ca_certificate,
211 const Private_Key& key,
212 std::string_view hash_fn,
214 X509_CA(ca_certificate, key, hash_fn, "", rng) {}
215
216 /**
217 * Create a new CA object.
218 * @param ca_certificate the certificate of the CA
219 * @param key the private key of the CA
220 * @param opts additional options, e.g. padding, as key value pairs
221 * @param hash_fn name of a hash function to use for signing
222 * @param rng the random generator to use
223 */
224 BOTAN_DEPRECATED("Use version taking padding as an explicit arg")
225
226 X509_CA(const X509_Certificate& ca_certificate,
227 const Private_Key& key,
228 const std::map<std::string, std::string>& opts,
229 std::string_view hash_fn,
231 X509_CA(ca_certificate, key, hash_fn, opts.at("padding"), rng) {}
232
233 X509_CA(const X509_CA&) = delete;
234 X509_CA& operator=(const X509_CA&) = delete;
235
236 X509_CA(X509_CA&&) = default;
237 X509_CA& operator=(X509_CA&&) = default;
238
240
241 private:
242 X509_CRL make_crl(const std::vector<CRL_Entry>& entries,
243 uint32_t crl_number,
245 std::chrono::system_clock::time_point issue_time,
246 std::chrono::seconds next_update) const;
247
248 AlgorithmIdentifier m_ca_sig_algo;
249 X509_Certificate m_ca_cert;
250 std::string m_hash_fn;
251 std::unique_ptr<PK_Signer> m_signer;
252};
253
254} // namespace Botan
255
256#endif
X509_CA(const X509_Certificate &ca_certificate, const Private_Key &key, std::string_view hash_fn, RandomNumberGenerator &rng)
Definition x509_ca.h:210
X509_CA & operator=(X509_CA &&)=default
PK_Signer & signature_op()
Definition x509_ca.h:48
X509_CA & operator=(const X509_CA &)=delete
const AlgorithmIdentifier & algorithm_identifier() const
Definition x509_ca.h:33
X509_CA(const X509_CA &)=delete
const X509_Certificate & ca_certificate() const
Definition x509_ca.h:38
X509_CA(X509_CA &&)=default
const std::string & hash_function() const
Definition x509_ca.h:43
int(* final)(unsigned char *, CTX *)
#define BOTAN_PUBLIC_API(maj, min)
Definition compiler.h:31
#define BOTAN_DEPRECATED(msg)
Definition compiler.h:125