8#include <botan/x509_ca.h>
9#include <botan/x509_key.h>
10#include <botan/pkcs10.h>
11#include <botan/x509_ext.h>
12#include <botan/pubkey.h>
13#include <botan/der_enc.h>
14#include <botan/bigint.h>
23 std::string_view hash_fn,
24 std::string_view padding_method,
32 m_ca_sig_algo = m_signer->algorithm_identifier();
33 m_hash_fn = m_signer->hash_function();
40 std::string_view hash_fn)
42 const auto constraints =
46 if(!constraints.compatible_with(*key))
47 throw Invalid_Argument(
"The requested key constraints are incompatible with the algorithm");
52 std::make_unique<Cert_Extension::Basic_Constraints>(req.
is_CA(), req.
path_limit()),
55 if(!constraints.empty())
57 extensions.
replace(std::make_unique<Cert_Extension::Key_Usage>(constraints),
true);
64 std::make_unique<Cert_Extension::Subject_Alternative_Name>(req.
subject_alt_name()));
67 std::make_unique<Cert_Extension::Extended_Key_Usage>(req.
ex_constraints()));
74 const BigInt& serial_number,
80 return make_cert(*m_signer, rng, serial_number,
82 not_before, not_after,
99 not_before, not_after,
107 const std::vector<uint8_t>& pub_key,
114 const size_t SERIAL_BITS = 128;
115 BigInt serial_no(rng, SERIAL_BITS);
117 return make_cert(signer, rng, serial_no, sig_algo, pub_key,
118 not_before, not_after, issuer_dn, subject_dn, extensions);
128 const std::vector<uint8_t>& pub_key,
135 const size_t X509_CERT_VERSION = 3;
139 signer, rng, sig_algo,
142 .encode(X509_CERT_VERSION-1)
173 uint32_t next_update)
const
176 std::chrono::system_clock::now(),
177 std::chrono::seconds(next_update));
184 const std::vector<CRL_Entry>& new_revoked,
186 uint32_t next_update)
const
189 std::chrono::system_clock::now(),
190 std::chrono::seconds(next_update));
195 std::chrono::system_clock::time_point issue_time,
196 std::chrono::seconds next_update)
const
198 std::vector<CRL_Entry> empty;
199 return make_crl(empty, 1, rng, issue_time, next_update);
203 const std::vector<CRL_Entry>& new_revoked,
205 std::chrono::system_clock::time_point issue_time,
206 std::chrono::seconds next_update)
const
208 std::vector<CRL_Entry> revoked = last_crl.
get_revoked();
210 std::copy(new_revoked.begin(), new_revoked.end(),
211 std::back_inserter(revoked));
213 return make_crl(revoked, last_crl.
crl_number() + 1, rng, issue_time, next_update);
219X509_CRL X509_CA::make_crl(
const std::vector<CRL_Entry>& revoked,
222 std::chrono::system_clock::time_point issue_time,
223 std::chrono::seconds next_update)
const
225 const size_t X509_CRL_VERSION = 2;
227 auto expire_time = issue_time + next_update;
230 extensions.
add(std::make_unique<Cert_Extension::Authority_Key_ID>(m_ca_cert.
subject_key_id()));
231 extensions.
add(std::make_unique<Cert_Extension::CRL_Number>(crl_number));
235 *m_signer, rng, m_ca_sig_algo,
237 .encode(X509_CRL_VERSION-1)
238 .encode(m_ca_sig_algo)
242 .encode_if(!revoked.empty(),
245 .encode_list(revoked)
void replace(std::unique_ptr< Certificate_Extension > extn, bool critical=false)
void add(std::unique_ptr< Certificate_Extension > extn, bool critical=false)
static Key_Constraints ca_constraints()
std::unique_ptr< Public_Key > subject_public_key() const
const X509_DN & subject_dn() const
std::vector< OID > ex_constraints() const
size_t path_limit() const
const std::vector< uint8_t > & raw_public_key() const
Key_Constraints constraints() const
const AlternativeName & subject_alt_name() const
const Extensions & extensions() const
X509_CRL new_crl(RandomNumberGenerator &rng, std::chrono::system_clock::time_point issue_time, std::chrono::seconds next_update) const
static X509_Certificate make_cert(PK_Signer &signer, RandomNumberGenerator &rng, const AlgorithmIdentifier &sig_algo, const std::vector< uint8_t > &pub_key, const X509_Time ¬_before, const X509_Time ¬_after, const X509_DN &issuer_dn, const X509_DN &subject_dn, const Extensions &extensions)
X509_CRL update_crl(const X509_CRL &last_crl, const std::vector< CRL_Entry > &new_entries, RandomNumberGenerator &rng, std::chrono::system_clock::time_point issue_time, std::chrono::seconds next_update) const
const AlgorithmIdentifier algorithm_identifier() const
X509_CA(const X509_Certificate &ca_certificate, const Private_Key &key, std::string_view hash_fn, std::string_view padding_method, RandomNumberGenerator &rng)
const X509_Certificate & ca_certificate() const
static Extensions choose_extensions(const PKCS10_Request &req, const X509_Certificate &ca_certificate, std::string_view hash_fn)
X509_Certificate sign_request(const PKCS10_Request &req, RandomNumberGenerator &rng, const X509_Time ¬_before, const X509_Time ¬_after) const
const std::vector< CRL_Entry > & get_revoked() const
uint32_t crl_number() const
const X509_DN & subject_dn() const
const std::vector< uint8_t > & subject_key_id() const
static std::unique_ptr< PK_Signer > choose_sig_format(const Private_Key &key, RandomNumberGenerator &rng, std::string_view hash_fn, std::string_view padding_algo)
static std::vector< uint8_t > make_signed(PK_Signer &signer, RandomNumberGenerator &rng, const AlgorithmIdentifier &alg_id, const secure_vector< uint8_t > &tbs)