Botan 3.10.0
Crypto and TLS for C&
pkix_enums.h
Go to the documentation of this file.
1/*
2* (C) 2013,2023 Jack Lloyd
3*
4* Botan is released under the Simplified BSD License (see license.txt)
5*/
6
7#ifndef BOTAN_X509_PKIX_ENUMS_H_
8#define BOTAN_X509_PKIX_ENUMS_H_
9
10#include <botan/types.h>
11#include <string>
12
13namespace Botan {
14
15class Public_Key;
16
17/**
18* Certificate validation status code
19*/
20enum class Certificate_Status_Code : uint16_t {
21 // TODO(Botan4) renumber this, e.g. Validation Errors -> IP_ADDR_BLOCKS_ERROR
22 // TODO(Botan4) rename variants to CamelCase
23 OK = 0,
24 VERIFIED = 0,
25
26 // Revocation status
30 OCSP_NO_HTTP = 4,
31
32 // Warnings
35 DN_TOO_LONG = 501,
40
41 // Errors
42 FIRST_ERROR_STATUS = 1000,
43
45 UNTRUSTED_HASH = 1001,
46 NO_REVOCATION_DATA = 1002,
47 NO_MATCHING_CRLDP = 1003,
49
50 // Time problems
51 CERT_NOT_YET_VALID = 2000,
52 CERT_HAS_EXPIRED = 2001,
53 OCSP_NOT_YET_VALID = 2002,
54 OCSP_HAS_EXPIRED = 2003,
55 CRL_NOT_YET_VALID = 2004,
56 CRL_HAS_EXPIRED = 2005,
57 OCSP_IS_TOO_OLD = 2006,
58
59 // Chain generation problems
62 CERT_CHAIN_LOOP = 3002,
65
66 // Validation errors
67 POLICY_ERROR = 4000,
68 INVALID_USAGE = 4001,
73 AS_BLOCKS_ERROR = 4012,
74
75 // Revocation errors
78 OCSP_BAD_STATUS = 4007,
79
80 // Other problems
81 CERT_NAME_NOMATCH = 4008,
88 EXT_IN_V1_V2_CERT = 4505,
91
92 // Hard failures
93 CERT_IS_REVOKED = 5000,
94 CRL_BAD_SIGNATURE = 5001,
95 SIGNATURE_ERROR = 5002,
99};
100
101/**
102* Convert a status code to a human readable diagnostic message
103* @param code the certificate status
104* @return string literal constant, or nullptr if code unknown
105*/
107
108/**
109* X.509v3 Key Constraints.
110* If updating update copy in ffi.h
111*/
113 public:
114 enum Bits : uint16_t /* NOLINT(*-use-enum-class) */ {
115 None = 0,
116 DigitalSignature = 1 << 15,
117 NonRepudiation = 1 << 14,
118 KeyEncipherment = 1 << 13,
119 DataEncipherment = 1 << 12,
120 KeyAgreement = 1 << 11,
121 KeyCertSign = 1 << 10,
122 CrlSign = 1 << 9,
123 EncipherOnly = 1 << 8,
124 DecipherOnly = 1 << 7,
125
126 // Deprecated SHOUTING_CASE names for Key_Constraints
127 // will be removed in a future major release
129 DIGITAL_SIGNATURE BOTAN_DEPRECATED("Use DigitalSignature") = DigitalSignature,
130 NON_REPUDIATION BOTAN_DEPRECATED("Use NonRepudiation") = NonRepudiation,
131 KEY_ENCIPHERMENT BOTAN_DEPRECATED("Use KeyEncipherment") = KeyEncipherment,
132 DATA_ENCIPHERMENT BOTAN_DEPRECATED("Use DataEncipherment") = DataEncipherment,
134 KEY_CERT_SIGN BOTAN_DEPRECATED("Use KeyCertSign") = KeyCertSign,
135 CRL_SIGN BOTAN_DEPRECATED("Use CrlSign") = CrlSign,
136 ENCIPHER_ONLY BOTAN_DEPRECATED("Use EncipherOnly") = EncipherOnly,
137 DECIPHER_ONLY BOTAN_DEPRECATED("Use DecipherOnly") = DecipherOnly,
138 };
139
140 Key_Constraints(const Key_Constraints& other) = default;
142 Key_Constraints& operator=(const Key_Constraints& other) = default;
144 ~Key_Constraints() = default;
145
146 // NOLINTNEXTLINE(*-explicit-conversions)
147 Key_Constraints(Key_Constraints::Bits bits) : m_value(bits) {}
148
149 explicit Key_Constraints(uint32_t bits) : m_value(bits) {}
150
151 Key_Constraints() : m_value(0) {}
152
153 /**
154 * Return typical constraints for a CA certificate.
155 *
156 * The reasons for KeyCertSign and CrlSign should be obvious
157 *
158 * CAB baseline requirements are that DigitalSignature should be set
159 * if the certificate is used to sign OCSP responses.
160 */
165
166 bool operator==(const Key_Constraints&) const = default;
167
168 void operator|=(Key_Constraints::Bits other) { m_value |= other; }
169
170 // Return true if all bits in mask are set
171 bool includes(Key_Constraints::Bits other) const { return (m_value & other) == other; }
172
173 bool includes(Key_Constraints other) const { return (m_value & other.m_value) == other.m_value; }
174
175 // Return true if any of the bits provided are set
176 bool includes_any(auto&&... bits) const { return (m_value & (bits | ...)) > 0; }
177
178 bool empty() const { return m_value == 0; }
179
180 uint32_t value() const { return m_value; }
181
182 std::string to_string() const;
183
184 /**
185 * Check that key constraints are permitted for a specific public key.
186 * @param key the public key on which the constraints shall be enforced on
187 * @return false if the constraints are not permitted for this key
188 */
189 bool compatible_with(const Public_Key& key) const;
190
191 private:
192 uint32_t m_value;
193};
194
195/**
196* X.509v2 CRL Reason Code.
197*/
198enum class CRL_Code : uint8_t {
199 Unspecified = 0,
200 KeyCompromise = 1,
201 CaCompromise = 2,
203 Superseded = 4,
205 CertificateHold = 6,
206 RemoveFromCrl = 8,
208 AaCompromise = 10,
209};
210
211} // namespace Botan
212
213#endif
#define BOTAN_PUBLIC_API(maj, min)
Definition api.h:21
#define BOTAN_DEPRECATED(msg)
Definition api.h:73
static Key_Constraints ca_constraints()
Definition pkix_enums.h:161
bool includes(Key_Constraints other) const
Definition pkix_enums.h:173
void operator|=(Key_Constraints::Bits other)
Definition pkix_enums.h:168
bool operator==(const Key_Constraints &) const =default
Key_Constraints(uint32_t bits)
Definition pkix_enums.h:149
Key_Constraints(Key_Constraints &&other)=default
bool includes(Key_Constraints::Bits other) const
Definition pkix_enums.h:171
uint32_t value() const
Definition pkix_enums.h:180
Key_Constraints(const Key_Constraints &other)=default
bool includes_any(auto &&... bits) const
Definition pkix_enums.h:176
Key_Constraints & operator=(Key_Constraints &&other)=default
Key_Constraints & operator=(const Key_Constraints &other)=default
Key_Constraints(Key_Constraints::Bits bits)
Definition pkix_enums.h:147
int(* final)(unsigned char *, CTX *)
@ KEY_ENCIPHERMENT
Definition ffi.h:2191
@ NO_CONSTRAINTS
Definition ffi.h:2188
@ CRL_SIGN
Definition ffi.h:2195
@ DIGITAL_SIGNATURE
Definition ffi.h:2189
@ KEY_AGREEMENT
Definition ffi.h:2193
@ DATA_ENCIPHERMENT
Definition ffi.h:2192
@ KEY_CERT_SIGN
Definition ffi.h:2194
@ ENCIPHER_ONLY
Definition ffi.h:2196
@ NON_REPUDIATION
Definition ffi.h:2190
@ DECIPHER_ONLY
Definition ffi.h:2197
Certificate_Status_Code
Definition pkix_enums.h:20
std::string to_string(ErrorType type)
Convert an ErrorType to string.
Definition exceptn.cpp:13