8#ifndef BOTAN_X509_EXTENSIONS_H_
9#define BOTAN_X509_EXTENSIONS_H_
11#include <botan/pkix_types.h>
16class X509_Certificate;
18namespace Cert_Extension {
20static const size_t NO_CERT_PATH_LIMIT = 0xFFFFFFF0;
27 std::unique_ptr<Certificate_Extension>
copy()
const override {
28 return std::make_unique<Basic_Constraints>(m_is_ca, m_path_limit);
35 size_t get_path_limit()
const;
39 OID oid_of()
const override {
return static_oid(); }
42 std::string oid_name()
const override {
return "X509v3.BasicConstraints"; }
44 std::vector<uint8_t> encode_inner()
const override;
45 void decode_inner(
const std::vector<uint8_t>&)
override;
56 std::unique_ptr<Certificate_Extension>
copy()
const override {
57 return std::make_unique<Key_Usage>(m_constraints);
68 OID oid_of()
const override {
return static_oid(); }
71 std::string oid_name()
const override {
return "X509v3.KeyUsage"; }
73 bool should_encode()
const override {
return !m_constraints.empty(); }
75 std::vector<uint8_t> encode_inner()
const override;
76 void decode_inner(
const std::vector<uint8_t>&)
override;
78 Key_Constraints m_constraints;
90 Subject_Key_ID(
const std::vector<uint8_t>& public_key, std::string_view hash_fn);
92 std::unique_ptr<Certificate_Extension>
copy()
const override {
93 return std::make_unique<Subject_Key_ID>(m_key_id);
96 const std::vector<uint8_t>&
get_key_id()
const {
return m_key_id; }
103 std::string oid_name()
const override {
return "X509v3.SubjectKeyIdentifier"; }
105 bool should_encode()
const override {
return (!m_key_id.empty()); }
107 std::vector<uint8_t> encode_inner()
const override;
108 void decode_inner(
const std::vector<uint8_t>&)
override;
110 std::vector<uint8_t> m_key_id;
118 std::unique_ptr<Certificate_Extension>
copy()
const override {
119 return std::make_unique<Authority_Key_ID>(m_key_id);
126 const std::vector<uint8_t>&
get_key_id()
const {
return m_key_id; }
133 std::string oid_name()
const override {
return "X509v3.AuthorityKeyIdentifier"; }
135 bool should_encode()
const override {
return (!m_key_id.empty()); }
137 std::vector<uint8_t> encode_inner()
const override;
138 void decode_inner(
const std::vector<uint8_t>&)
override;
140 std::vector<uint8_t> m_key_id;
154 std::unique_ptr<Certificate_Extension>
copy()
const override {
155 return std::make_unique<Subject_Alternative_Name>(get_alt_name());
161 std::string oid_name()
const override {
return "X509v3.SubjectAlternativeName"; }
163 bool should_encode()
const override {
return m_alt_name.has_items(); }
165 std::vector<uint8_t> encode_inner()
const override;
166 void decode_inner(
const std::vector<uint8_t>&)
override;
168 AlternativeName m_alt_name;
182 std::unique_ptr<Certificate_Extension>
copy()
const override {
183 return std::make_unique<Issuer_Alternative_Name>(get_alt_name());
189 std::string oid_name()
const override {
return "X509v3.IssuerAlternativeName"; }
191 bool should_encode()
const override {
return m_alt_name.has_items(); }
193 std::vector<uint8_t> encode_inner()
const override;
194 void decode_inner(
const std::vector<uint8_t>&)
override;
196 AlternativeName m_alt_name;
204 std::unique_ptr<Certificate_Extension>
copy()
const override {
205 return std::make_unique<Extended_Key_Usage>(m_oids);
219 std::string oid_name()
const override {
return "X509v3.ExtendedKeyUsage"; }
221 bool should_encode()
const override {
return (!m_oids.empty()); }
223 std::vector<uint8_t> encode_inner()
const override;
224 void decode_inner(
const std::vector<uint8_t>&)
override;
226 std::vector<OID> m_oids;
234 std::unique_ptr<Certificate_Extension>
copy()
const override {
235 return std::make_unique<Name_Constraints>(m_name_constraints);
244 const std::vector<X509_Certificate>& cert_path,
245 std::vector<std::set<Certificate_Status_Code>>& cert_status,
246 size_t pos)
override;
255 std::string oid_name()
const override {
return "X509v3.NameConstraints"; }
257 bool should_encode()
const override {
return true; }
259 std::vector<uint8_t> encode_inner()
const override;
260 void decode_inner(
const std::vector<uint8_t>&)
override;
262 NameConstraints m_name_constraints;
270 std::unique_ptr<Certificate_Extension>
copy()
const override {
271 return std::make_unique<Certificate_Policies>(m_oids);
286 const std::vector<X509_Certificate>& cert_path,
287 std::vector<std::set<Certificate_Status_Code>>& cert_status,
288 size_t pos)
override;
291 std::string oid_name()
const override {
return "X509v3.CertificatePolicies"; }
293 bool should_encode()
const override {
return (!m_oids.empty()); }
295 std::vector<uint8_t> encode_inner()
const override;
296 void decode_inner(
const std::vector<uint8_t>&)
override;
298 std::vector<OID> m_oids;
306 std::unique_ptr<Certificate_Extension>
copy()
const override {
307 return std::make_unique<Authority_Information_Access>(m_ocsp_responder, m_ca_issuers);
313 const std::vector<std::string>& ca_issuers = std::vector<std::string>()) :
314 m_ocsp_responder(ocsp), m_ca_issuers(ca_issuers) {}
322 const std::vector<std::string>&
ca_issuers()
const {
return m_ca_issuers; }
325 std::string oid_name()
const override {
return "PKIX.AuthorityInformationAccess"; }
327 bool should_encode()
const override {
return (!m_ocsp_responder.empty() || !m_ca_issuers.empty()); }
329 std::vector<uint8_t> encode_inner()
const override;
330 void decode_inner(
const std::vector<uint8_t>&)
override;
332 std::string m_ocsp_responder;
333 std::vector<std::string> m_ca_issuers;
341 std::unique_ptr<Certificate_Extension> copy()
const override;
347 size_t get_crl_number()
const;
354 std::string oid_name()
const override {
return "X509v3.CRLNumber"; }
356 bool should_encode()
const override {
return m_has_value; }
358 std::vector<uint8_t> encode_inner()
const override;
359 void decode_inner(
const std::vector<uint8_t>&)
override;
370 std::unique_ptr<Certificate_Extension>
copy()
const override {
371 return std::make_unique<CRL_ReasonCode>(m_reason);
383 std::string oid_name()
const override {
return "X509v3.ReasonCode"; }
385 bool should_encode()
const override {
return (m_reason != CRL_Code::Unspecified); }
387 std::vector<uint8_t> encode_inner()
const override;
388 void decode_inner(
const std::vector<uint8_t>&)
override;
412 std::unique_ptr<Certificate_Extension>
copy()
const override {
413 return std::make_unique<CRL_Distribution_Points>(m_distribution_points);
429 std::string oid_name()
const override {
return "X509v3.CRLDistributionPoints"; }
431 bool should_encode()
const override {
return !m_distribution_points.empty(); }
433 std::vector<uint8_t> encode_inner()
const override;
434 void decode_inner(
const std::vector<uint8_t>&)
override;
436 std::vector<Distribution_Point> m_distribution_points;
437 std::vector<std::string> m_crl_distribution_urls;
449 m_distribution_point(distribution_point) {}
451 std::unique_ptr<Certificate_Extension>
copy()
const override {
452 return std::make_unique<CRL_Issuing_Distribution_Point>(m_distribution_point);
462 std::string oid_name()
const override {
return "X509v3.CRLIssuingDistributionPoint"; }
464 bool should_encode()
const override {
return true; }
466 std::vector<uint8_t> encode_inner()
const override;
467 void decode_inner(
const std::vector<uint8_t>&)
override;
469 CRL_Distribution_Points::Distribution_Point m_distribution_point;
487 std::unique_ptr<Certificate_Extension>
copy()
const override {
return std::make_unique<OCSP_NoCheck>(); }
494 std::string oid_name()
const override {
return "PKIX.OCSP.NoCheck"; }
496 bool should_encode()
const override {
return true; }
498 std::vector<uint8_t> encode_inner()
const override {
return {}; }
500 void decode_inner(
const std::vector<uint8_t>&)
override;
515 enum Type { ServiceProviderCode = 0, TelephoneNumberRange = 1, TelephoneNumber = 2 };
526 void decode_from(
class BER_Decoder& from)
override;
532 return std::get<ASN1_String>(m_data).value();
537 return std::get<RangeContainer>(m_data);
542 return std::get<ASN1_String>(m_data).value();
547 DataContainer m_data;
552 std::unique_ptr<Certificate_Extension>
copy()
const override {
return std::make_unique<TNAuthList>(*
this); }
558 const std::vector<Entry>&
entries()
const {
return m_tn_entries; }
561 std::string oid_name()
const override {
return "PKIX.TNAuthList"; }
563 bool should_encode()
const override {
return true; }
565 std::vector<uint8_t> encode_inner()
const override;
566 void decode_inner(
const std::vector<uint8_t>&)
override;
568 std::vector<Entry> m_tn_entries;
579 std::unique_ptr<Certificate_Extension>
copy()
const override {
580 return std::make_unique<Unknown_Extension>(m_oid, m_critical);
602 const std::vector<X509_Certificate>&,
603 std::vector<std::set<Certificate_Status_Code>>& cert_status,
604 size_t pos)
override {
606 cert_status.at(pos).insert(Certificate_Status_Code::UNKNOWN_CRITICAL_EXTENSION);
611 std::string oid_name()
const override {
return ""; }
613 bool should_encode()
const override {
return true; }
615 std::vector<uint8_t> encode_inner()
const override;
616 void decode_inner(
const std::vector<uint8_t>&)
override;
620 std::vector<uint8_t> m_bytes;
#define BOTAN_STATE_CHECK(expr)
Authority_Key_ID(const std::vector< uint8_t > &k)
OID oid_of() const override
Authority_Key_ID()=default
std::unique_ptr< Certificate_Extension > copy() const override
const std::vector< uint8_t > & get_key_id() const
OID oid_of() const override
std::unique_ptr< Certificate_Extension > copy() const override
Basic_Constraints(bool ca=false, size_t limit=0)
Distribution_Point(const AlternativeName &name=AlternativeName())
const AlternativeName & point() const
CRL_Distribution_Points(const std::vector< Distribution_Point > &points)
CRL_Distribution_Points()=default
OID oid_of() const override
std::unique_ptr< Certificate_Extension > copy() const override
const std::vector< std::string > & crl_distribution_urls() const
const std::vector< Distribution_Point > & distribution_points() const
const AlternativeName & get_point() const
OID oid_of() const override
std::unique_ptr< Certificate_Extension > copy() const override
CRL_Issuing_Distribution_Point(const CRL_Distribution_Points::Distribution_Point &distribution_point)
CRL_Issuing_Distribution_Point()=default
OID oid_of() const override
std::unique_ptr< Certificate_Extension > copy() const override
CRL_Code get_reason() const
CRL_ReasonCode(CRL_Code r=CRL_Code::Unspecified)
OID oid_of() const override
Certificate_Policies()=default
const std::vector< OID > & get_policy_oids() const
std::unique_ptr< Certificate_Extension > copy() const override
Certificate_Policies(const std::vector< OID > &o)
OID oid_of() const override
OID oid_of() const override
const std::vector< OID > & object_identifiers() const
std::unique_ptr< Certificate_Extension > copy() const override
Extended_Key_Usage()=default
Extended_Key_Usage(const std::vector< OID > &o)
std::unique_ptr< Certificate_Extension > copy() const override
const AlternativeName & get_alt_name() const
Issuer_Alternative_Name(const AlternativeName &name=AlternativeName())
OID oid_of() const override
std::unique_ptr< Certificate_Extension > copy() const override
OID oid_of() const override
Key_Usage(Key_Constraints c)
Key_Constraints get_constraints() const
Name_Constraints(const NameConstraints &nc)
OID oid_of() const override
const NameConstraints & get_name_constraints() const
std::unique_ptr< Certificate_Extension > copy() const override
Name_Constraints()=default
std::unique_ptr< Certificate_Extension > copy() const override
OID oid_of() const override
const AlternativeName & get_alt_name() const
OID oid_of() const override
Subject_Alternative_Name(const AlternativeName &name=AlternativeName())
std::unique_ptr< Certificate_Extension > copy() const override
OID oid_of() const override
Subject_Key_ID(const std::vector< uint8_t > &k)
std::unique_ptr< Certificate_Extension > copy() const override
const std::vector< uint8_t > & get_key_id() const
const std::string & service_provider_code() const
const std::string & telephone_number() const
const RangeContainer & telephone_number_range() const
std::vector< TelephoneNumberRangeData > RangeContainer
std::variant< ASN1_String, RangeContainer > DataContainer
std::unique_ptr< Certificate_Extension > copy() const override
OID oid_of() const override
const std::vector< Entry > & entries() const
void validate(const X509_Certificate &, const X509_Certificate &, const std::vector< X509_Certificate > &, std::vector< std::set< Certificate_Status_Code > > &cert_status, size_t pos) override
OID oid_of() const override
std::unique_ptr< Certificate_Extension > copy() const override
Unknown_Extension(const OID &oid, bool critical)
const std::vector< uint8_t > & extension_contents() const
bool is_critical_extension() const
int(* final)(unsigned char *, CTX *)
#define BOTAN_PUBLIC_API(maj, min)