Botan 3.9.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 auto now = std::chrono::system_clock::now();
67
68 start = X509_Time(now);
69 end = X509_Time(now + std::chrono::seconds(expiration_time));
70
71 if(initial_opts.empty()) {
72 return;
73 }
74
75 std::vector<std::string> parsed = split_on(initial_opts, '/');
76
77 if(parsed.size() > 4) {
78 throw Invalid_Argument("X.509 cert options: Too many names");
79 }
80
81 if(!parsed.empty()) {
82 common_name = parsed[0];
83 }
84 if(parsed.size() >= 2) {
85 country = parsed[1];
86 }
87 if(parsed.size() >= 3) {
88 organization = parsed[2];
89 }
90 if(parsed.size() == 4) {
91 org_unit = parsed[3];
92 }
93}
94
95} // namespace Botan
static OID from_string(std::string_view str)
Definition asn1_oid.cpp:86
std::string common_name
Definition x509self.h:28
std::vector< OID > ex_constraints
Definition x509self.h:132
Key_Constraints constraints
Definition x509self.h:127
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
BOTAN_FUTURE_EXPLICIT 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:122
ASN1_Time X509_Time
Definition asn1_obj.h:424
std::vector< std::string > split_on(std::string_view str, char delim)
Definition parsing.cpp:111