Botan 3.0.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>
12namespace Botan {
13
14class Public_Key;
15
16/**
17* Certificate validation status code
18*/
20 OK = 0,
21 VERIFIED = 0,
22
23 // Revocation status
27 OCSP_NO_HTTP = 4,
28
29 // Warnings
32 DN_TOO_LONG = 501,
35
36 // Errors
37 FIRST_ERROR_STATUS = 1000,
38
40 UNTRUSTED_HASH = 1001,
41 NO_REVOCATION_DATA = 1002,
42 NO_MATCHING_CRLDP = 1003,
44
45 // Time problems
46 CERT_NOT_YET_VALID = 2000,
47 CERT_HAS_EXPIRED = 2001,
48 OCSP_NOT_YET_VALID = 2002,
49 OCSP_HAS_EXPIRED = 2003,
50 CRL_NOT_YET_VALID = 2004,
51 CRL_HAS_EXPIRED = 2005,
52 OCSP_IS_TOO_OLD = 2006,
53
54 // Chain generation problems
57 CERT_CHAIN_LOOP = 3002,
60
61 // Validation errors
62 POLICY_ERROR = 4000,
63 INVALID_USAGE = 4001,
67
68 // Revocation errors
71 OCSP_BAD_STATUS = 4007,
72
73 // Other problems
74 CERT_NAME_NOMATCH = 4008,
81 EXT_IN_V1_V2_CERT = 4505,
84
85 // Hard failures
86 CERT_IS_REVOKED = 5000,
87 CRL_BAD_SIGNATURE = 5001,
88 SIGNATURE_ERROR = 5002,
92};
93
94/**
95* Convert a status code to a human readable diagnostic message
96* @param code the certifcate status
97* @return string literal constant, or nullptr if code unknown
98*/
100
101/**
102* X.509v3 Key Constraints.
103* If updating update copy in ffi.h
104*/
106 {
107 public:
108 enum Bits : uint32_t {
109 None = 0,
110 DigitalSignature = 1 << 15,
111 NonRepudiation = 1 << 14,
112 KeyEncipherment = 1 << 13,
113 DataEncipherment = 1 << 12,
114 KeyAgreement = 1 << 11,
115 KeyCertSign = 1 << 10,
116 CrlSign = 1 << 9,
117 EncipherOnly = 1 << 8,
118 DecipherOnly = 1 << 7,
119
120 // Deprecated SHOUTING_CASE names for Key_Constraints
121 // will be removed in a future major release
122 NO_CONSTRAINTS BOTAN_DEPRECATED("Use None") = None,
123 DIGITAL_SIGNATURE BOTAN_DEPRECATED("Use DigitalSignature") = DigitalSignature,
124 NON_REPUDIATION BOTAN_DEPRECATED("Use NonRepudiation") = NonRepudiation,
125 KEY_ENCIPHERMENT BOTAN_DEPRECATED("Use KeyEncipherment") = KeyEncipherment,
126 DATA_ENCIPHERMENT BOTAN_DEPRECATED("Use DataEncipherment") = DataEncipherment,
127 KEY_AGREEMENT BOTAN_DEPRECATED("Use KeyAgreement") = KeyAgreement,
128 KEY_CERT_SIGN BOTAN_DEPRECATED("Use KeyCertSign") = KeyCertSign,
129 CRL_SIGN BOTAN_DEPRECATED("Use CrlSign") = CrlSign,
130 ENCIPHER_ONLY BOTAN_DEPRECATED("Use EncipherOnly") = EncipherOnly,
131 DECIPHER_ONLY BOTAN_DEPRECATED("Use DecipherOnly") = DecipherOnly,
132 };
133
134 Key_Constraints(const Key_Constraints& other) = default;
136 Key_Constraints& operator=(const Key_Constraints& other) = default;
138
139 Key_Constraints(Key_Constraints::Bits bits) : m_value(bits) {}
140
141 explicit Key_Constraints(uint32_t bits) : m_value(bits) {}
142
143 Key_Constraints() : m_value(0) {}
144
145 /**
146 * Return typical constraints for a CA certificate, namely
147 * KeyCertSign and CrlSign
148 */
150 {
152 }
153
154 bool operator==(const Key_Constraints&) const = default;
155
157 {
158 m_value |= other;
159 }
160
161 // Return true if all bits in mask are set
162 bool includes(Key_Constraints::Bits other) const { return (m_value & other) == other; }
163 bool includes(Key_Constraints other) const { return (m_value & other.m_value) == other.m_value; }
164
165 // Return true if any of the bits provided are set
166 bool includes_any(auto&& ...bits) const
167 {
168 return (m_value & (bits | ...)) > 0;
169 }
170
171 bool empty() const { return m_value == 0; }
172
173 uint32_t value() const { return m_value; }
174
175 std::string to_string() const;
176
177 /**
178 * Check that key constraints are permitted for a specific public key.
179 * @param key the public key on which the constraints shall be enforced on
180 * @return false if the constraints are not permitted for this key
181 */
182 bool compatible_with(const Public_Key& key) const;
183 private:
184 uint32_t m_value;
185 };
186
187/**
188* X.509v2 CRL Reason Code.
189*/
190enum class CRL_Code : uint32_t {
191 Unspecified = 0,
192 KeyCompromise = 1,
193 CaCompromise = 2,
195 Superseded = 4,
197 CertificateHold = 6,
198 RemoveFromCrl = 8,
200 AaCompromise = 10,
201};
202
203}
204
205#endif
static Key_Constraints ca_constraints()
Definition: pkix_enums.h:149
bool empty() const
Definition: pkix_enums.h:171
bool includes(Key_Constraints other) const
Definition: pkix_enums.h:163
bool includes_any(auto &&...bits) const
Definition: pkix_enums.h:166
void operator|=(Key_Constraints::Bits other)
Definition: pkix_enums.h:156
bool operator==(const Key_Constraints &) const =default
Key_Constraints(uint32_t bits)
Definition: pkix_enums.h:141
Key_Constraints(Key_Constraints &&other)=default
bool includes(Key_Constraints::Bits other) const
Definition: pkix_enums.h:162
uint32_t value() const
Definition: pkix_enums.h:173
Key_Constraints(const Key_Constraints &other)=default
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:139
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
@ KEY_ENCIPHERMENT
Definition: ffi.h:1820
@ NO_CONSTRAINTS
Definition: ffi.h:1817
@ CRL_SIGN
Definition: ffi.h:1824
@ DIGITAL_SIGNATURE
Definition: ffi.h:1818
@ KEY_AGREEMENT
Definition: ffi.h:1822
@ DATA_ENCIPHERMENT
Definition: ffi.h:1821
@ KEY_CERT_SIGN
Definition: ffi.h:1823
@ ENCIPHER_ONLY
Definition: ffi.h:1825
@ NON_REPUDIATION
Definition: ffi.h:1819
@ DECIPHER_ONLY
Definition: ffi.h:1826
Definition: alg_id.cpp:12
std::string to_string(ErrorType type)
Convert an ErrorType to string.
Definition: exceptn.cpp:12
Certificate_Status_Code
Definition: pkix_enums.h:19