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