Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

x509opt.cpp
Go to the documentation of this file.
1 /*
2 * X.509 Certificate Options
3 * (C) 1999-2007 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7
8 #include <botan/x509self.h>
9 #include <botan/oids.h>
10 #include <botan/parsing.h>
11 #include <chrono>
12
13 namespace Botan {
14
15 /*
16 * Set when the certificate should become valid
17 */
18 void X509_Cert_Options::not_before(const std::string& time_string)
19 {
20 start = X509_Time(time_string, ASN1_Tag::UTC_OR_GENERALIZED_TIME);
21 }
22
23 /*
24 * Set when the certificate should expire
25 */
26 void X509_Cert_Options::not_after(const std::string& time_string)
27 {
28 end = X509_Time(time_string, ASN1_Tag::UTC_OR_GENERALIZED_TIME);
29 }
30
31 /*
32 * Set key constraint information
33 */
34 void X509_Cert_Options::add_constraints(Key_Constraints usage)
35 {
36 constraints = usage;
37 }
38
39 /*
40 * Set key constraint information
41 */
42 void X509_Cert_Options::add_ex_constraint(const OID& oid)
43 {
44 ex_constraints.push_back(oid);
45 }
46
47 /*
48 * Set key constraint information
49 */
50 void X509_Cert_Options::add_ex_constraint(const std::string& oid_str)
51 {
52 ex_constraints.push_back(OIDS::lookup(oid_str));
53 }
54
55 /*
56 * Mark this certificate for CA usage
57 */
58 void X509_Cert_Options::CA_key(size_t limit)
59 {
60 is_CA = true;
61 path_limit = limit;
62 }
63
64 /*
65 * Initialize the certificate options
66 */
67 X509_Cert_Options::X509_Cert_Options(const std::string& initial_opts,
68 uint32_t expiration_time)
69 {
70 is_CA = false;
71 path_limit = 0;
72 constraints = NO_CONSTRAINTS;
73
74 auto now = std::chrono::system_clock::now();
75
76 start = X509_Time(now);
77 end = X509_Time(now + std::chrono::seconds(expiration_time));
78
79 if(initial_opts.empty())
80 return;
81
82 std::vector<std::string> parsed = split_on(initial_opts, '/');
83
84 if(parsed.size() > 4)
85 throw Invalid_Argument("X.509 cert options: Too many names: "
86 + initial_opts);
87
88 if(parsed.size() >= 1) common_name = parsed[0];
89 if(parsed.size() >= 2) country = parsed[1];
90 if(parsed.size() >= 3) organization = parsed[2];
91 if(parsed.size() == 4) org_unit = parsed[3];
92 }
93
94 }
Botan::Invalid_Argument
Definition: exceptn.h:34
Botan::X509_Cert_Options::add_constraints
void add_constraints(Key_Constraints constr)
Definition: x509opt.cpp:34
Botan::X509_Cert_Options::org_unit
std::string org_unit
Definition: x509self.h:42
Botan::UTC_OR_GENERALIZED_TIME
Definition: asn1_obj.h:52
Botan::X509_Cert_Options::country
std::string country
Definition: x509self.h:32
Botan::X509_Cert_Options::not_before
void not_before(const std::string &time)
Definition: x509opt.cpp:18
Botan::split_on
std::vector< std::string > split_on(const std::string &str, char delim)
Definition: parsing.cpp:138
Botan::X509_Cert_Options::not_after
void not_after(const std::string &time)
Definition: x509opt.cpp:26
Botan::X509_Cert_Options::add_ex_constraint
void add_ex_constraint(const OID &oid)
Definition: x509opt.cpp:42
Botan::X509_Cert_Options::path_limit
size_t path_limit
Definition: x509self.h:106
Botan::X509_Cert_Options::CA_key
void CA_key(size_t limit=1)
Definition: x509opt.cpp:58
Botan::X509_Cert_Options::common_name
std::string common_name
Definition: x509self.h:27
Botan::NO_CONSTRAINTS
Definition: key_constraint.h:22
Botan::OIDS::lookup
std::string lookup(const OID &oid)
Definition: oids.cpp:18
Botan::X509_Cert_Options::is_CA
bool is_CA
Definition: x509self.h:101
Botan::X509_Cert_Options::constraints
Key_Constraints constraints
Definition: x509self.h:111
Botan
Definition: alg_id.cpp:13
Botan::X509_Cert_Options::X509_Cert_Options
X509_Cert_Options(const std::string &opts="", uint32_t expire_time=365 *24 *60 *60)
Definition: x509opt.cpp:67
Botan::X509_Cert_Options::end
X509_Time end
Definition: x509self.h:96
Botan::X509_Cert_Options::start
X509_Time start
Definition: x509self.h:92
Botan::OID
Definition: asn1_oid.h:20
Botan::Key_Constraints
Key_Constraints
Definition: key_constraint.h:21
Botan::X509_Cert_Options::ex_constraints
std::vector< OID > ex_constraints
Definition: x509self.h:116
Botan::X509_Time
Definition: asn1_time.h:19
Botan::X509_Cert_Options::organization
std::string organization
Definition: x509self.h:37