Botan 1.10.17
Botan::X509_Cert_Options Class Reference

#include <x509self.h>

Public Member Functions

void add_constraints (Key_Constraints constr)
void add_ex_constraint (const OID &oid)
void add_ex_constraint (const std::string &name)
void CA_key (size_t limit=1)
void not_after (const std::string &time)
void not_before (const std::string &time)
void sanity_check () const
 X509_Cert_Options (const std::string &opts="", u32bit expire_time=365 *24 *60 *60)

Public Attributes

std::string challenge
std::string common_name
Key_Constraints constraints
std::string country
std::string dns
std::string email
X509_Time end
std::vector< OIDex_constraints
std::string ip
bool is_CA
std::string locality
std::string org_unit
std::string organization
size_t path_limit
std::string serial_number
X509_Time start
std::string state
std::string uri
std::string xmpp

Detailed Description

Options for X.509 certificates.

Definition at line 20 of file x509self.h.

Constructor & Destructor Documentation

◆ X509_Cert_Options()

Botan::X509_Cert_Options::X509_Cert_Options ( const std::string & opts = "",
u32bit expire_time = 365 * 24 * 60 * 60 )

Construct a new options object

Parameters
optsdefine the common name of this object. An example for this parameter would be "common_name/country/organization/organizational_unit".
expire_timethe expiration time (from the current clock in seconds)

Definition at line 80 of file x509opt.cpp.

82 {
83 is_CA = false;
84 path_limit = 0;
86
87 const u64bit now = system_time();
88
89 start = X509_Time(now);
90 end = X509_Time(now + expiration_time_in_seconds);
91
92 if(initial_opts == "")
93 return;
94
95 std::vector<std::string> parsed = split_on(initial_opts, '/');
96
97 if(parsed.size() > 4)
98 throw Invalid_Argument("X.509 cert options: Too many names: "
99 + initial_opts);
100
101 if(parsed.size() >= 1) common_name = parsed[0];
102 if(parsed.size() >= 2) country = parsed[1];
103 if(parsed.size() >= 3) organization = parsed[2];
104 if(parsed.size() == 4) org_unit = parsed[3];
105 }
std::string common_name
Definition x509self.h:26
Key_Constraints constraints
Definition x509self.h:110
std::string organization
Definition x509self.h:36
X509_Time(u64bit)
Definition asn1_tm.cpp:28
unsigned long long u64bit
Definition types.h:49
u64bit system_time()
Definition time.cpp:73
std::invalid_argument Invalid_Argument
Definition exceptn.h:20
std::vector< std::string > split_on(const std::string &str, char delim)
Definition parsing.cpp:152
@ NO_CONSTRAINTS

References common_name, constraints, country, end, is_CA, Botan::NO_CONSTRAINTS, org_unit, organization, path_limit, Botan::split_on(), start, Botan::system_time(), and Botan::X509_Time::X509_Time().

Member Function Documentation

◆ add_constraints()

void Botan::X509_Cert_Options::add_constraints ( Key_Constraints constr)

Add the key constraints of the KeyUsage extension.

Parameters
constrthe constraints to set

Definition at line 34 of file x509opt.cpp.

35 {
36 constraints = usage;
37 }

References constraints.

◆ add_ex_constraint() [1/2]

void Botan::X509_Cert_Options::add_ex_constraint ( const OID & oid)

Add constraints to the ExtendedKeyUsage extension.

Parameters
oidthe oid to add

Definition at line 42 of file x509opt.cpp.

43 {
44 ex_constraints.push_back(oid);
45 }
std::vector< OID > ex_constraints
Definition x509self.h:115

References ex_constraints.

◆ add_ex_constraint() [2/2]

void Botan::X509_Cert_Options::add_ex_constraint ( const std::string & name)

Add constraints to the ExtendedKeyUsage extension.

Parameters
namethe name to look up the oid to add

Definition at line 50 of file x509opt.cpp.

51 {
52 ex_constraints.push_back(OIDS::lookup(oid_str));
53 }
std::string lookup(const OID &oid)
Definition oids.cpp:31

References ex_constraints, and Botan::OIDS::lookup().

◆ CA_key()

void Botan::X509_Cert_Options::CA_key ( size_t limit = 1)

Mark the certificate as a CA certificate and set the path limit.

Parameters
limitthe path limit to be set in the BasicConstraints extension.

Definition at line 58 of file x509opt.cpp.

59 {
60 is_CA = true;
61 path_limit = limit;
62 }

References is_CA, and path_limit.

◆ not_after()

void Botan::X509_Cert_Options::not_after ( const std::string & time)

Set the notAfter of the certificate.

Parameters
timethe notAfter value of the certificate

Definition at line 26 of file x509opt.cpp.

27 {
28 end = X509_Time(time_string);
29 }

References end, and Botan::X509_Time::X509_Time().

◆ not_before()

void Botan::X509_Cert_Options::not_before ( const std::string & time)

Set the notBefore of the certificate.

Parameters
timethe notBefore value of the certificate

Definition at line 18 of file x509opt.cpp.

19 {
20 start = X509_Time(time_string);
21 }

References start, and Botan::X509_Time::X509_Time().

◆ sanity_check()

void Botan::X509_Cert_Options::sanity_check ( ) const

Check the options set in this object for validity.

Definition at line 67 of file x509opt.cpp.

68 {
69 if(common_name == "" || country == "")
70 throw Encoding_Error("X.509 certificate: name and country MUST be set");
71 if(country.size() != 2)
72 throw Encoding_Error("Invalid ISO country code: " + country);
73 if(start >= end)
74 throw Encoding_Error("X509_Cert_Options: invalid time constraints");
75 }
Encoding_Error(const std::string &name)
Definition exceptn.h:131

References common_name, country, Botan::Encoding_Error::Encoding_Error(), end, and start.

Referenced by Botan::X509::create_cert_req(), and Botan::X509::create_self_signed_cert().

Member Data Documentation

◆ challenge

std::string Botan::X509_Cert_Options::challenge

the subject challenge password

Definition at line 86 of file x509self.h.

Referenced by Botan::X509::create_cert_req().

◆ common_name

std::string Botan::X509_Cert_Options::common_name

the subject common name

Definition at line 26 of file x509self.h.

Referenced by sanity_check(), and X509_Cert_Options().

◆ constraints

Key_Constraints Botan::X509_Cert_Options::constraints

The key constraints for the subject public key

Definition at line 110 of file x509self.h.

Referenced by add_constraints(), Botan::X509::create_cert_req(), Botan::X509::create_self_signed_cert(), and X509_Cert_Options().

◆ country

std::string Botan::X509_Cert_Options::country

the subject counry

Definition at line 31 of file x509self.h.

Referenced by sanity_check(), and X509_Cert_Options().

◆ dns

std::string Botan::X509_Cert_Options::dns

the subject DNS

Definition at line 76 of file x509self.h.

◆ email

std::string Botan::X509_Cert_Options::email

the subject email adress

Definition at line 61 of file x509self.h.

◆ end

X509_Time Botan::X509_Cert_Options::end

the subject notAfter

Definition at line 95 of file x509self.h.

Referenced by Botan::X509::create_self_signed_cert(), not_after(), sanity_check(), and X509_Cert_Options().

◆ ex_constraints

std::vector<OID> Botan::X509_Cert_Options::ex_constraints

The key extended constraints for the subject public key

Definition at line 115 of file x509self.h.

Referenced by add_ex_constraint(), add_ex_constraint(), Botan::X509::create_cert_req(), and Botan::X509::create_self_signed_cert().

◆ ip

std::string Botan::X509_Cert_Options::ip

the subject IPv4 address

Definition at line 71 of file x509self.h.

◆ is_CA

bool Botan::X509_Cert_Options::is_CA

Indicates whether the certificate request

Definition at line 100 of file x509self.h.

Referenced by CA_key(), Botan::X509::create_cert_req(), Botan::X509::create_self_signed_cert(), and X509_Cert_Options().

◆ locality

std::string Botan::X509_Cert_Options::locality

the subject locality

Definition at line 46 of file x509self.h.

◆ org_unit

std::string Botan::X509_Cert_Options::org_unit

the subject organizational unit

Definition at line 41 of file x509self.h.

Referenced by X509_Cert_Options().

◆ organization

std::string Botan::X509_Cert_Options::organization

the subject organization

Definition at line 36 of file x509self.h.

Referenced by X509_Cert_Options().

◆ path_limit

size_t Botan::X509_Cert_Options::path_limit

Indicates the BasicConstraints path limit

Definition at line 105 of file x509self.h.

Referenced by CA_key(), Botan::X509::create_cert_req(), Botan::X509::create_self_signed_cert(), and X509_Cert_Options().

◆ serial_number

std::string Botan::X509_Cert_Options::serial_number

the subject serial number

Definition at line 56 of file x509self.h.

◆ start

X509_Time Botan::X509_Cert_Options::start

the subject notBefore

Definition at line 91 of file x509self.h.

Referenced by Botan::X509::create_self_signed_cert(), not_before(), sanity_check(), and X509_Cert_Options().

◆ state

std::string Botan::X509_Cert_Options::state

the subject state

Definition at line 51 of file x509self.h.

◆ uri

std::string Botan::X509_Cert_Options::uri

the subject URI

Definition at line 66 of file x509self.h.

◆ xmpp

std::string Botan::X509_Cert_Options::xmpp

the subject XMPP

Definition at line 81 of file x509self.h.


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