Botan 2.19.3
Crypto and TLS for C&
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/parsing.h>
10#include <chrono>
11
12namespace Botan {
13
14/*
15* Set when the certificate should become valid
16*/
17void X509_Cert_Options::not_before(const std::string& time_string)
18 {
20 }
21
22/*
23* Set when the certificate should expire
24*/
25void X509_Cert_Options::not_after(const std::string& time_string)
26 {
28 }
29
30/*
31* Set key constraint information
32*/
37
38/*
39* Set key constraint information
40*/
42 {
43 ex_constraints.push_back(oid);
44 }
45
46/*
47* Set key constraint information
48*/
49void X509_Cert_Options::add_ex_constraint(const std::string& oid_str)
50 {
51 ex_constraints.push_back(OID::from_string(oid_str));
52 }
53
54/*
55* Mark this certificate for CA usage
56*/
57void X509_Cert_Options::CA_key(size_t limit)
58 {
59 is_CA = true;
60 path_limit = limit;
61 }
62
63void X509_Cert_Options::set_padding_scheme(const std::string& scheme)
64 {
65 padding_scheme = scheme;
66 }
67
68/*
69* Initialize the certificate options
70*/
71X509_Cert_Options::X509_Cert_Options(const std::string& initial_opts,
72 uint32_t expiration_time)
73 {
74 is_CA = false;
75 path_limit = 0;
77 // use default for chosen algorithm
78 padding_scheme = "";
79
80 auto now = std::chrono::system_clock::now();
81
82 start = X509_Time(now);
83 end = X509_Time(now + std::chrono::seconds(expiration_time));
84
85 if(initial_opts.empty())
86 return;
87
88 std::vector<std::string> parsed = split_on(initial_opts, '/');
89
90 if(parsed.size() > 4)
91 throw Invalid_Argument("X.509 cert options: Too many names: "
92 + initial_opts);
93
94 if(parsed.size() >= 1) common_name = parsed[0];
95 if(parsed.size() >= 2) country = parsed[1];
96 if(parsed.size() >= 3) organization = parsed[2];
97 if(parsed.size() == 4) org_unit = parsed[3];
98 }
99
100}
static OID from_string(const std::string &str)
Definition asn1_oid.cpp:62
std::string common_name
Definition x509self.h:29
std::vector< OID > ex_constraints
Definition x509self.h:130
Key_Constraints constraints
Definition x509self.h:125
X509_Cert_Options(const std::string &opts="", uint32_t expire_time=365 *24 *60 *60)
Definition x509opt.cpp:71
void add_constraints(Key_Constraints constr)
Definition x509opt.cpp:33
std::string organization
Definition x509self.h:39
void set_padding_scheme(const std::string &scheme)
Definition x509opt.cpp:63
void add_ex_constraint(const OID &oid)
Definition x509opt.cpp:41
void CA_key(size_t limit=1)
Definition x509opt.cpp:57
void not_after(const std::string &time)
Definition x509opt.cpp:25
std::string padding_scheme
Definition x509self.h:120
void not_before(const std::string &time)
Definition x509opt.cpp:17
ASN1_Time X509_Time
Definition asn1_obj.h:386
std::vector< std::string > split_on(const std::string &str, char delim)
Definition parsing.cpp:148
@ UTC_OR_GENERALIZED_TIME
Definition asn1_obj.h:56
Key_Constraints
Definition pkix_enums.h:106
@ NO_CONSTRAINTS
Definition pkix_enums.h:107