Botan: Botan::X509_CA Class Reference

Botan 1.10.16

Public Member Functions | Static Public Member Functions | List of all members
Botan::X509_CA Class Reference

`#include <x509_ca.h>`

## Public Member Functions
X509_Certificate | ca_certificate () const
X509_CRL | new_crl (RandomNumberGenerator &rng, u32bit next_update=0) const
X509_Certificate | sign_request (const PKCS10_Request &req, RandomNumberGenerator &rng, const X509_Time &not_before, const X509_Time &not_after)
X509_CRL | update_crl (const X509_CRL &last_crl, const std::vector< CRL_Entry > &new_entries, RandomNumberGenerator &rng, u32bit next_update=0) const
| X509_CA (const X509_Certificate &ca_certificate, const Private_Key &key, const std::string &hash_fn)
| ~X509_CA ()

## Static Public Member Functions
static X509_Certificate | make_cert (PK_Signer *signer, RandomNumberGenerator &rng, const AlgorithmIdentifier &sig_algo, const MemoryRegion< byte > &pub_key, const X509_Time &not_before, const X509_Time &not_after, const X509_DN &issuer_dn, const X509_DN &subject_dn, const Extensions &extensions)

## Detailed Description

This class represents X.509 Certificate Authorities (CAs).

Definition at line 23 of file x509_ca.h.

## Constructor & Destructor Documentation

## ◆ X509_CA()

Botan::X509_CA::X509_CA | ( | const X509_Certificate & | ca_certificate,
|  | const Private_Key & | key,
|  | const std::string & | hash_fn
| ) |  |

Create a new CA object.

Parameters

  ca_certificate | the certificate of the CA
  key | the private key of the CA
  hash_fn | name of a hash function to use for signing

Definition at line 28 of file x509_ca.cpp.

References Botan::choose_sig_format(), and Botan::X509_Certificate::is_CA_cert().

30 : cert(c)
31 {
32 if(!cert.is_CA_cert())
33 throw Invalid_Argument("X509_CA: This certificate is not for a CA");
34
35 signer = choose_sig_format(key, hash_fn, ca_sig_algo);
36 }
Botan::Invalid_Argument
std::invalid_argument Invalid_Argument
Definition: exceptn.h:20
Botan::X509_Certificate::is_CA_cert
bool is_CA_cert() const
Definition: x509cert.cpp:205
Botan::choose_sig_format
PK_Signer * choose_sig_format(const Private_Key &key, const std::string &hash_fn, AlgorithmIdentifier &sig_algo)
Definition: x509_ca.cpp:218

## ◆ ~X509_CA()

Botan::X509_CA::~X509_CA | ( |  | ) |

Definition at line 41 of file x509_ca.cpp.

42 {
43 delete signer;
44 }

## Member Function Documentation

## ◆ ca_certificate()

X509_Certificate Botan::X509_CA::ca_certificate | ( |  | ) | const

Get the certificate of this CA.

Returns
  CA certificate

Definition at line 210 of file x509_ca.cpp.

211 {
212 return cert;
213 }

## ◆ make_cert()

X509_Certificate Botan::X509_CA::make_cert | ( | PK_Signer * | signer,
|  | RandomNumberGenerator & | rng,
|  | const AlgorithmIdentifier & | sig_algo,
|  | const MemoryRegion< byte > & | pub_key,
|  | const X509_Time & | not_before,
|  | const X509_Time & | not_after,
|  | const X509_DN & | issuer_dn,
|  | const X509_DN & | subject_dn,
|  | const Extensions & | extensions
| ) |  |
| static

Interface for creating new certificates

Parameters

  signer | a signing object
  rng | a random number generator
  sig_algo | the signature algorithm identifier
  pub_key | the serialized public key
  not_before | the start time of the certificate
  not_after | the end time of the certificate
  issuer_dn | the DN of the issuer
  subject_dn | the DN of the subject
  extensions | an optional list of certificate extensions

Returns
  newly minted certificate

Definition at line 90 of file x509_ca.cpp.

99 {
100 const size_t X509_CERT_VERSION = 3;
101 const size_t SERIAL_BITS = 128;
102
103 BigInt serial_no(rng, SERIAL_BITS);
104
105 DataSource_Memory source(X509_Object::make_signed(signer, rng, sig_algo,
106 DER_Encoder().start_cons(SEQUENCE)
107 .start_explicit(0)
108 .encode(X509_CERT_VERSION-1)
109 .end_explicit()
110
111 .encode(serial_no)
112
113 .encode(sig_algo)
114 .encode(issuer_dn)
115
116 .start_cons(SEQUENCE)
117 .encode(not_before)
118 .encode(not_after)
119 .end_cons()
120
121 .encode(subject_dn)
122 .raw_bytes(pub_key)
123
124 .start_explicit(3)
125 .start_cons(SEQUENCE)
126 .encode(extensions)
127 .end_cons()
128 .end_explicit()
129 .end_cons()
130 .get_contents()
131 ));
132
133 return X509_Certificate(source);
134 }
Botan::SEQUENCE
Definition: asn1_int.h:35
Botan::X509_Object::make_signed
static MemoryVector< byte > make_signed(class PK_Signer *signer, RandomNumberGenerator &rng, const AlgorithmIdentifier &alg_id, const MemoryRegion< byte > &tbs)
Definition: x509_obj.cpp:204
Botan::PEM_Code::encode
std::string encode(const byte der[], size_t length, const std::string &label, size_t width)
Definition: pem.cpp:19

## ◆ new_crl()

X509_CRL Botan::X509_CA::new_crl | ( | RandomNumberGenerator & | rng,
|  | u32bit | next_update = `0`
| ) |  | const

Create a new and empty CRL for this CA.

Parameters

  rng | the random number generator to use
  next_update | the time to set in next update in seconds as the offset from the current time

Returns
  new CRL

Definition at line 139 of file x509_ca.cpp.

141 {
142 std::vector<CRL_Entry> empty;
143 return make_crl(empty, 1, next_update, rng);
144 }

## ◆ sign_request()

X509_Certificate Botan::X509_CA::sign_request | ( | const PKCS10_Request & | req,
|  | RandomNumberGenerator & | rng,
|  | const X509_Time & | not_before,
|  | const X509_Time & | not_after
| ) |  |

Sign a PKCS#10 Request.

Parameters

  req | the request to sign
  rng | the rng to use
  not_before | the starting time for the certificate
  not_after | the expiration time for the certificate

Returns
  resulting certificate

Definition at line 49 of file x509_ca.cpp.

53 {
54 Key_Constraints constraints;
55 if(req.is_CA())
56 constraints = Key_Constraints(KEY_CERT_SIGN | CRL_SIGN);
57 else
58 {
59 std::auto_ptr<Public_Key> key(req.subject_public_key());
60 constraints = X509::find_constraints(*key, req.constraints());
61 }
62
63 Extensions extensions;
64
65 extensions.add(
66 new Cert_Extension::Basic_Constraints(req.is_CA(), req.path_limit()),
67 true);
68
69 extensions.add(new Cert_Extension::Key_Usage(constraints), true);
70
71 extensions.add(new Cert_Extension::Authority_Key_ID(cert.subject_key_id()));
72 extensions.add(new Cert_Extension::Subject_Key_ID(req.raw_public_key()));
73
74 extensions.add(
75 new Cert_Extension::Subject_Alternative_Name(req.subject_alt_name()));
76
77 extensions.add(
78 new Cert_Extension::Extended_Key_Usage(req.ex_constraints()));
79
80 return make_cert(signer, rng, ca_sig_algo,
81 req.raw_public_key(),
82 not_before, not_after,
83 cert.subject_dn(), req.subject_dn(),
84 extensions);
85 }
Botan::X509_Certificate::subject_dn
X509_DN subject_dn() const
Definition: x509cert.cpp:282
Botan::X509_Certificate::subject_key_id
MemoryVector< byte > subject_key_id() const
Definition: x509cert.cpp:258
Botan::X509_CA::make_cert
static X509_Certificate make_cert(PK_Signer *signer, RandomNumberGenerator &rng, const AlgorithmIdentifier &sig_algo, const MemoryRegion< byte > &pub_key, const X509_Time &not_before, const X509_Time &not_after, const X509_DN &issuer_dn, const X509_DN &subject_dn, const Extensions &extensions)
Definition: x509_ca.cpp:90
Botan::CRL_SIGN
Definition: pubkey_enums.h:26
Botan::X509::find_constraints
Key_Constraints find_constraints(const Public_Key &pub_key, Key_Constraints limits)
Definition: x509_key.cpp:113
Botan::Key_Constraints
Key_Constraints
Definition: pubkey_enums.h:18
Botan::KEY_CERT_SIGN
Definition: pubkey_enums.h:25

## ◆ update_crl()

X509_CRL Botan::X509_CA::update_crl | ( | const X509_CRL & | last_crl,
|  | const std::vector< CRL_Entry > & | new_entries,
|  | RandomNumberGenerator & | rng,
|  | u32bit | next_update = `0`
| ) |  | const

Create a new CRL by with additional entries.

Parameters

  last_crl | the last CRL of this CA to add the new entries to
  new_entries | contains the new CRL entries to be added to the CRL
  rng | the random number generator to use
  next_update | the time to set in next update in seconds as the offset from the current time

Definition at line 149 of file x509_ca.cpp.

153 {
154 std::vector<CRL_Entry> revoked = crl.get_revoked();
155
156 std::copy(new_revoked.begin(), new_revoked.end(),
157 std::back_inserter(revoked));
158
159 return make_crl(revoked, crl.crl_number() + 1, next_update, rng);
160 }

The documentation for this class was generated from the following files:

- src/cert/x509ca/x509_ca.h
- src/cert/x509ca/x509_ca.cpp