Botan 3.9.0
Crypto and TLS for C&
pkcs10.h
Go to the documentation of this file.
1/*
2* PKCS #10
3* (C) 1999-2007 Jack Lloyd
4* (C) 2016 René Korthaus, Rohde & Schwarz Cybersecurity
5*
6* Botan is released under the Simplified BSD License (see license.txt)
7*/
8
9#ifndef BOTAN_PKCS10_H_
10#define BOTAN_PKCS10_H_
11
12#include <botan/pkix_enums.h>
13#include <botan/x509_obj.h>
14#include <vector>
15
16namespace Botan {
17
18struct PKCS10_Data;
19
20class Private_Key;
21class Extensions;
22class X509_DN;
23class AlternativeName;
24
25/**
26* PKCS #10 Certificate Request.
27*/
28class BOTAN_PUBLIC_API(2, 0) PKCS10_Request final : public X509_Object {
29 public:
30 /**
31 * Get the subject public key.
32 * @return subject public key
33 */
34 std::unique_ptr<Public_Key> subject_public_key() const;
35
36 /**
37 * Get the raw DER encoded public key.
38 * @return raw DER encoded public key
39 */
40 const std::vector<uint8_t>& raw_public_key() const;
41
42 /**
43 * Get the subject DN.
44 * @return subject DN
45 */
46 const X509_DN& subject_dn() const;
47
48 /**
49 * Get the subject alternative name.
50 * @return subject alternative name.
51 */
52 const AlternativeName& subject_alt_name() const;
53
54 /**
55 * Get the key constraints for the key associated with this
56 * PKCS#10 object.
57 * @return key constraints
58 */
60
61 /**
62 * Get the extendend key constraints (if any).
63 * @return extended key constraints
64 */
65 std::vector<OID> ex_constraints() const;
66
67 /**
68 * Find out whether this is a CA request.
69 * @result true if it is a CA request, false otherwise.
70 */
71 bool is_CA() const;
72
73 /**
74 * Return the constraint on the path length defined in the BasicConstraints extension.
75 *
76 * Note this returns 0 if the extension is not set
77 *
78 * @return path limit
79 */
80 BOTAN_DEPRECATED("Use path_length_constraint") size_t path_limit() const {
81 return path_length_constraint().value_or(0);
82 }
83
84 /**
85 * Return the constraint on the path length defined in the BasicConstraints extension.
86 *
87 * @return path limit (or nullopt if not set)
88 */
89 std::optional<size_t> path_length_constraint() const;
90
91 /**
92 * Get the challenge password for this request
93 * @return challenge password for this request
94 */
95 std::string challenge_password() const;
96
97 /**
98 * Get the X509v3 extensions.
99 * @return X509v3 extensions
100 */
101 const Extensions& extensions() const;
102
103 /**
104 * Create a PKCS#10 Request from a data source.
105 * @param source the data source providing the DER encoded request
106 */
107 explicit PKCS10_Request(DataSource& source);
108
109#if defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
110 /**
111 * Create a PKCS#10 Request from a file.
112 * @param filename the name of the file containing the DER or PEM
113 * encoded request file
114 */
115 explicit PKCS10_Request(std::string_view filename);
116#endif
117
118 /**
119 * Create a PKCS#10 Request from binary data.
120 * @param vec a std::vector containing the DER value
121 */
122 explicit PKCS10_Request(const std::vector<uint8_t>& vec);
123
124 /**
125 * Create a new PKCS10 certificate request
126 * @param key the key that will be included in the certificate request
127 * @param subject_dn the DN to be placed in the request
128 * @param extensions extensions to include in the request
129 * @param hash_fn the hash function to use to create the signature
130 * @param rng a random number generator
131 * @param padding_scheme if set specifies the padding scheme, otherwise an
132 * algorithm-specific default is used.
133 * @param challenge a challenge string to be included in the PKCS10 request,
134 * sometimes used for revocation purposes.
135 */
136 static PKCS10_Request create(const Private_Key& key,
137 const X509_DN& subject_dn,
138 const Extensions& extensions,
139 std::string_view hash_fn,
141 std::string_view padding_scheme = "",
142 std::string_view challenge = "");
143
144 private:
145 std::string PEM_label() const override;
146
147 std::vector<std::string> alternate_PEM_labels() const override;
148
149 void force_decode() override;
150
151 const PKCS10_Data& data() const;
152
153 std::shared_ptr<PKCS10_Data> m_data;
154};
155
156} // namespace Botan
157
158#endif
#define BOTAN_PUBLIC_API(maj, min)
Definition api.h:21
#define BOTAN_DEPRECATED(msg)
Definition api.h:73
PKCS10_Request(DataSource &source)
Definition pkcs10.cpp:36
std::unique_ptr< Public_Key > subject_public_key() const
Definition pkcs10.cpp:203
const X509_DN & subject_dn() const
Definition pkcs10.cpp:189
std::vector< OID > ex_constraints() const
Definition pkcs10.cpp:236
size_t path_limit() const
Definition pkcs10.h:80
const std::vector< uint8_t > & raw_public_key() const
Definition pkcs10.cpp:196
Key_Constraints constraints() const
Definition pkcs10.cpp:225
bool is_CA() const
Definition pkcs10.cpp:247
const AlternativeName & subject_alt_name() const
Definition pkcs10.cpp:211
std::optional< size_t > path_length_constraint() const
Definition pkcs10.cpp:258
X509_Object()=default