Botan 3.13.0
Crypto and TLS for C&
x509_crl.h
Go to the documentation of this file.
1/*
2* X.509 CRL
3* (C) 1999-2007 Jack Lloyd
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#ifndef BOTAN_X509_CRL_H_
9#define BOTAN_X509_CRL_H_
10
11#include <botan/asn1_obj.h>
12#include <botan/pkix_enums.h>
13#include <botan/uri.h>
14#include <botan/x509_obj.h>
15#include <memory>
16#include <vector>
17
18namespace Botan {
19
20class Extensions;
21class BigInt;
23class X509_DN;
24
25class CRL_Entry_Data;
26class CRL_Data;
28
29/**
30* This class represents CRL entries
31*/
32class BOTAN_PUBLIC_API(2, 0) CRL_Entry final : public ASN1_Object {
33 public:
34 void encode_into(DER_Encoder& to) const override;
35 void decode_from(BER_Decoder& from) override;
36
37 /**
38 * Get the serial number of the certificate associated with this entry.
39 *
40 * Note this is the absolute value; the (rare, non-conforming) negative
41 * serial numbers are indistinguishable from their positive counterpart.
42 * Prefer serial() which preserves the sign.
43 *
44 * @return certificate's serial number
45 */
46 BOTAN_DEPRECATED("Prefer CRL_Entry::serial") const std::vector<uint8_t>& serial_number() const;
47
48 /**
49 * Get the serial number of the certificate associated with this entry
50 */
51 const X509_Serial_Number& serial() const;
52
53 /**
54 * Get the revocation date of the certificate associated with this entry
55 * @return certificate's revocation date
56 */
57 const X509_Time& expire_time() const;
58
59 /**
60 * Get the entries reason code
61 * @return reason code
62 */
63 CRL_Code reason_code() const;
64
65 /**
66 * Get the extensions on this CRL entry
67 */
68 const Extensions& extensions() const;
69
70 /**
71 * Create uninitialized CRL_Entry object
72 */
73 CRL_Entry() = default;
74
75 /**
76 * Construct an CRL entry.
77 * @param cert the certificate to revoke
78 * @param reason the reason code to set in the entry
79 */
81
82 private:
83 friend class X509_CRL;
84
85 const CRL_Entry_Data& data() const;
86
87 std::shared_ptr<const CRL_Entry_Data> m_data;
88};
89
90/**
91* Test two CRL entries for equality in all fields.
92*/
93BOTAN_PUBLIC_API(2, 0) bool operator==(const CRL_Entry& lhs, const CRL_Entry& rhs);
94
95/**
96* Test two CRL entries for inequality in at least one field.
97*/
98BOTAN_PUBLIC_API(2, 0) bool operator!=(const CRL_Entry& lhs, const CRL_Entry& rhs);
99
100/**
101* This class represents X.509 Certificate Revocation Lists (CRLs).
102*/
103class BOTAN_PUBLIC_API(2, 0) X509_CRL final : public X509_Object {
104 public:
105 /**
106 * Check if this particular certificate is listed in the CRL
107 */
108 bool is_revoked(const X509_Certificate& cert) const;
109
110 /**
111 * Get the entries of this CRL in the form of a vector.
112 * @return vector containing the entries of this CRL.
113 */
114 const std::vector<CRL_Entry>& get_revoked() const;
115
116 /**
117 * Get the X509 version of this CRL object
118 * @return X509 version
119 */
120 uint32_t x509_version() const;
121
122 /**
123 * Get the issuer DN of this CRL.
124 * @return CRLs issuer DN
125 */
126 const X509_DN& issuer_dn() const;
127
128 /**
129 * @return extension data for this CRL
130 */
131 const Extensions& extensions() const;
132
133 /**
134 * Return true if either the CRL extensions or any CRL entry extensions
135 * contained a critical extension which we did not recognize.
136 */
138
139 /**
140 * Get the AuthorityKeyIdentifier of this CRL.
141 * @return this CRLs AuthorityKeyIdentifier
142 */
143 const std::vector<uint8_t>& authority_key_id() const;
144
145 /**
146 * Get the CRL number of this CRL.
147 * @return CRL number (or nullopt if not set in the extensions)
148 */
149 const std::optional<BigInt>& crl_number_bigint() const;
150
151 /**
152 * Get the CRL number of this CRL.
153 * @return CRL number (or zero if not set in the extensions)
154 */
155 BOTAN_DEPRECATED("Use crl_number_bigint") uint32_t crl_number() const;
156
157 /**
158 * Get the CRL's thisUpdate value.
159 * @return CRLs thisUpdate
160 */
161 const X509_Time& this_update() const;
162
163 /**
164 * Get the CRL's nextUpdate value.
165 *
166 * Technically nextUpdate is optional in the X.509 spec and may be omitted,
167 * despite RFC 5280 requiring it. If the nextUpdate field is not set, this
168 * will return a time object with time_is_set() returning false.
169 *
170 * TODO(Botan4) return a `const std::optional<X509_Time>&` instead
171 *
172 * @return CRLs nextUpdate
173 */
174 const X509_Time& next_update() const;
175
176 /**
177 * Get the CRL's issuing distribution point
178 */
179 BOTAN_DEPRECATED("Use issuing_distribution_point_uris") std::string crl_issuing_distribution_point() const;
180
181 /**
182 * Get the CRL's issuing distribution points
183 *
184 * See https://www.rfc-editor.org/rfc/rfc5280#section-5.2.5
185 */
186 BOTAN_DEPRECATED("Use issuing_distribution_point_uris")
187 std::vector<std::string> issuing_distribution_points() const;
188
189 /**
190 * Get the CRL's issuing distribution points
191 *
192 * See https://www.rfc-editor.org/rfc/rfc5280#section-5.2.5
193 */
194 const std::vector<URI>& issuing_distribution_point_uris() const;
195
196 /**
197 * Check whether this CRL's scope covers the given certificate per the
198 * RFC 5280 6.3.3 (b)(1) and (b)(2)(i) name-matching rules.
199 *
200 * When the certificate has a CRLDP extension (4.2.1.13), iterates each
201 * DistributionPoint and verifies:
202 * - (b)(1): if the DP includes cRLIssuer, this CRL's issuer must
203 * appear in that field and this CRL must carry an IDP with
204 * indirectCRL = TRUE; otherwise this CRL's issuer must match the
205 * certificate's issuer.
206 * - (b)(2)(i): if this CRL's IDP names a distributionPoint, that
207 * name must overlap with the DP's distributionPoint (fullName
208 * GeneralNames) or, if the DP omits distributionPoint, with
209 * the DP's cRLIssuer entries.
210 *
211 * The trailing paragraph of 6.3.3 supplies an implicit DP: this CRL
212 * is also usable if its issuer matches the certificate's issuer and,
213 * if its IDP names a distributionPoint, that name overlaps with the
214 * certificate's issuer DN or any entry in the certificate's
215 * issuerAltName extension. This implicit DP applies both when the
216 * certificate has no CRLDP and, as a fallback, when it has a CRLDP
217 * but no DistributionPoint matches: a same-issuer complete CRL not
218 * named in any DP is still usable.
219 *
220 * Returns false if none of the above match. Returns true on a name
221 * match. Reason coverage is a separate question; this predicate
222 * intentionally does not consult the DP's reasons field or the IDP's
223 * onlySomeReasons.
224 */
226
227 /**
228 * Create an uninitialized CRL object. Any attempts to access
229 * this object will throw an exception.
230 */
231 X509_CRL() = default;
232
233 /**
234 * Construct a CRL from a data source.
235 * @param source the data source providing the DER or PEM encoded CRL.
236 */
238
239#if defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
240 /**
241 * Construct a CRL from a file containing the DER or PEM encoded CRL.
242 * @param filename the name of the CRL file
243 */
244 BOTAN_FUTURE_EXPLICIT X509_CRL(std::string_view filename);
245#endif
246
247 /**
248 * Construct a CRL from a binary vector
249 * @param vec the binary (DER) representation of the CRL
250 */
251 BOTAN_FUTURE_EXPLICIT X509_CRL(const std::vector<uint8_t>& vec);
252
253 /**
254 * Construct a CRL
255 * @param issuer issuer of this CRL
256 * @param thisUpdate valid from
257 * @param nextUpdate valid until
258 * @param revoked entries to be included in the CRL
259 */
260 X509_CRL(const X509_DN& issuer,
261 const X509_Time& thisUpdate,
262 const X509_Time& nextUpdate,
263 const std::vector<CRL_Entry>& revoked);
264
265 private:
266 std::string PEM_label() const override;
267
268 std::vector<std::string> alternate_PEM_labels() const override;
269
270 void force_decode() override;
271
272 const CRL_Data& data() const;
273
274 std::shared_ptr<const CRL_Data> m_data;
275};
276
277} // namespace Botan
278
279#endif
#define BOTAN_PUBLIC_API(maj, min)
Definition api.h:21
#define BOTAN_DEPRECATED(msg)
Definition api.h:73
#define BOTAN_FUTURE_EXPLICIT
Definition api.h:52
ASN1_Object()=default
Definition x509_crl.h:32
friend class X509_CRL
Definition x509_crl.h:83
CRL_Code reason_code() const
Definition crl_ent.cpp:149
void encode_into(DER_Encoder &to) const override
Definition crl_ent.cpp:76
const X509_Serial_Number & serial() const
Definition crl_ent.cpp:141
const X509_Time & expire_time() const
Definition crl_ent.cpp:145
CRL_Entry()=default
const std::vector< uint8_t > & serial_number() const
Definition crl_ent.cpp:137
void decode_from(BER_Decoder &from) override
Definition crl_ent.cpp:89
const Extensions & extensions() const
Definition crl_ent.cpp:153
const std::vector< CRL_Entry > & get_revoked() const
Definition x509_crl.cpp:260
const std::vector< uint8_t > & authority_key_id() const
Definition x509_crl.cpp:282
const X509_Time & this_update() const
Definition x509_crl.cpp:311
std::vector< std::string > issuing_distribution_points() const
Definition x509_crl.cpp:335
X509_CRL()=default
const Extensions & extensions() const
Definition x509_crl.cpp:253
uint32_t crl_number() const
Definition x509_crl.cpp:293
const std::vector< URI > & issuing_distribution_point_uris() const
Definition x509_crl.cpp:344
const X509_Time & next_update() const
Definition x509_crl.cpp:318
const X509_DN & issuer_dn() const
Definition x509_crl.cpp:275
bool has_unknown_critical_extension() const
Definition x509_crl.cpp:268
bool has_matching_distribution_point(const X509_Certificate &cert) const
Definition x509_crl.cpp:515
bool is_revoked(const X509_Certificate &cert) const
Definition x509_crl.cpp:96
std::string crl_issuing_distribution_point() const
Definition x509_crl.cpp:325
uint32_t x509_version() const
Definition x509_crl.cpp:264
const std::optional< BigInt > & crl_number_bigint() const
Definition x509_crl.cpp:289
X509_Object()=default
ASN1_Time X509_Time
Definition asn1_obj.h:27