31#ifndef ASYNC_SSL_X509_EXTENSIONS_INCLUDED
32#define ASYNC_SSL_X509_EXTENSIONS_INCLUDED
41#include <openssl/x509v3.h>
127 m_exts = sk_X509_EXTENSION_new_null();
145 m_exts = other.m_exts;
146 other.m_exts =
nullptr;
156 for (
int i=0; i<X509v3_get_ext_count(other.m_exts); ++i)
158 const auto ext = X509v3_get_ext(other.m_exts, i);
159 X509v3_add_ext(&m_exts, ext, -1);
173 if (m_exts !=
nullptr)
175 sk_X509_EXTENSION_pop_free(m_exts, X509_EXTENSION_free);
189 return addExt(NID_basic_constraints, bc);
203 return addExt(NID_key_usage, ku);
215 return addExt(NID_ext_key_usage, eku);
227 return addExt(NID_subject_alt_name, san);
236 int ext_idx = X509v3_get_ext_by_NID(m_exts, NID_subject_alt_name, -1);
241 auto ext = X509v3_get_ext(m_exts, ext_idx);
251 const X509_EXTENSION* other_ext = san;
252#if OPENSSL_VERSION_MAJOR >= 3
253 auto ext = X509_EXTENSION_dup(other_ext);
255 auto ext = X509_EXTENSION_dup(
const_cast<X509_EXTENSION*
>(other_ext));
257 return (sk_X509_EXTENSION_push(m_exts, ext) > 0);
263 operator const STACK_OF(X509_EXTENSION)*()
const {
return m_exts; }
266 STACK_OF(X509_EXTENSION)* m_exts =
nullptr;
268 bool addExt(
int nid,
const std::string& value)
270 auto ex = X509V3_EXT_conf_nid(NULL, NULL, nid, value.c_str());
275 sk_X509_EXTENSION_push(m_exts, ex);
279 X509_EXTENSION* cloneExtension(
int nid)
const
281 int ext_idx = X509v3_get_ext_by_NID(m_exts, nid, -1);
286 auto ext = X509v3_get_ext(m_exts, ext_idx);
287 return X509_EXTENSION_dup(ext);
Platform independent representation of an IP address.
A class representing the X.509 Subject Alternative Name extension.
A class representing X.509 extensions.
~SslX509Extensions(void)
Destructor.
bool addExtKeyUsage(const std::string &eku)
Add extended key usage.
SslX509ExtSubjectAltName subjectAltName(void) const
Get the subject alternative names extension.
bool addSubjectAltNames(const std::string &san)
Add subject alternative names.
SslX509Extensions(SslX509Extensions &&other)
Move Constructor.
bool addExtension(const SslX509ExtSubjectAltName &san)
Add a subject alternative names object.
SslX509Extensions(void)
Default constructor.
bool addBasicConstraints(const std::string &bc)
Add basic constraints extension.
bool addKeyUsage(const std::string &ku)
Add key usage.
SslX509Extensions(STACK_OF(X509_EXTENSION) *exts)
Constructor.
SslX509Extensions & operator=(const SslX509Extensions &)=delete
Disallow copy assignment.
SslX509Extensions(const SslX509Extensions &other)
Copy constructor.
Namespace for the asynchronous programming classes.