9#ifndef SQUID_SRC_SSL_GADGETS_H
10#define SQUID_SRC_SSL_GADGETS_H
24#if HAVE_OPENSSL_ASN1_H
25#include <openssl/asn1.h>
28#include <openssl/pem.h>
30#if HAVE_OPENSSL_TXT_DB_H
31#include <openssl/txt_db.h>
33#if HAVE_OPENSSL_X509V3_H
34#include <openssl/x509v3.h>
45#if !defined(SQUID_SSL_SIGN_HASH_IF_NONE)
46#define SQUID_SSL_SIGN_HASH_IF_NONE "sha256"
55typedef std::unique_ptr<BIGNUM, HardFun<void, BIGNUM*, &BN_free>>
BIGNUM_Pointer;
57typedef std::unique_ptr<BIO, HardFun<void, BIO*, &BIO_vfree>>
BIO_Pointer;
59typedef std::unique_ptr<ASN1_INTEGER, HardFun<void, ASN1_INTEGER*, &ASN1_INTEGER_free>>
ASN1_INT_Pointer;
63typedef std::unique_ptr<TXT_DB, HardFun<void, TXT_DB*, &TXT_DB_free>>
TXT_DB_Pointer;
65typedef std::unique_ptr<X509_NAME, HardFun<void, X509_NAME*, &X509_NAME_free>>
X509_NAME_Pointer;
67using EVP_PKEY_CTX_Pointer = std::unique_ptr<EVP_PKEY_CTX, HardFun<void, EVP_PKEY_CTX*, &EVP_PKEY_CTX_free>>;
69typedef std::unique_ptr<X509_REQ, HardFun<void, X509_REQ*, &X509_REQ_free>>
X509_REQ_Pointer;
76typedef std::unique_ptr<GENERAL_NAME, HardFun<void, GENERAL_NAME*, &GENERAL_NAME_free>>
GENERAL_NAME_Pointer;
80typedef std::unique_ptr<X509_STORE_CTX, HardFun<void, X509_STORE_CTX *, &X509_STORE_CTX_free>>
X509_STORE_CTX_Pointer;
84using UniqueCString = std::unique_ptr<char, HardFun<void, char *, &OPENSSL_free_for_c_strings> >;
121void ReadPrivateKeyFromFile(
char const * keyFilename, Security::PrivateKeyPointer &pkey, pem_password_cb *passwd_callback);
Security::PrivateKeyPointer signWithPkey
The key of the signing certificate.
Security::CertPointer signWithX509
Certificate to sign the generated request.
bool setCommonName
Replace the CN field of the mimicking subject with the given.
CertificateProperties(CertificateProperties &)
bool setValidAfter
Do not mimic "Not Valid After" field.
CertSignAlgorithm signAlgorithm
The signing algorithm to use.
CertificateProperties & operator=(CertificateProperties const &)
bool setValidBefore
Do not mimic "Not Valid Before" field.
Security::CertPointer mimicCert
Certificate to mimic.
const EVP_MD * signHash
The signing hash to use.
std::string commonName
A CN to use for the generated certificate.
const char * getOrganization(X509 *x509)
const char * CommonHostName(X509 *x509)
bool CertificatesCmp(const Security::CertPointer &cert1, const Security::CertPointer &cert2)
void ReadPrivateKeyFromFile(char const *keyFilename, Security::PrivateKeyPointer &pkey, pem_password_cb *passwd_callback)
bool ReadPrivateKey(BIO_Pointer &bio, Security::PrivateKeyPointer &pkey, pem_password_cb *passwd_callback)
bool OpenCertsFileForWriting(BIO_Pointer &bio, const char *filename)
bool WritePrivateKey(BIO_Pointer &bio, const Security::PrivateKeyPointer &pkey)
CertSignAlgorithm certSignAlgorithmId(const char *sg)
const char * sslCertAdaptAlgoritm(int alg)
bool appendCertToMemory(Security::CertPointer const &cert, std::string &bufferToWrite)
bool sslDateIsInTheFuture(char const *date)
bool OpenCertsFileForReading(BIO_Pointer &bio, const char *filename)
std::string & OnDiskCertificateDbKey(const CertificateProperties &)
bool generateSslCertificate(Security::CertPointer &cert, Security::PrivateKeyPointer &pkey, CertificateProperties const &properties)
bool writeCertAndPrivateKeyToMemory(Security::CertPointer const &cert, Security::PrivateKeyPointer const &pkey, std::string &bufferToWrite)
bool readCertAndPrivateKeyFromMemory(Security::CertPointer &cert, Security::PrivateKeyPointer &pkey, char const *bufferToRead)
bool certificateMatchesProperties(X509 *peer_cert, CertificateProperties const &properties)
bool WriteX509Certificate(BIO_Pointer &bio, const Security::CertPointer &cert)
const char * CertAdaptAlgorithmStr[]
const char * certSignAlgorithm(int sg)
const char * CertSignAlgorithmStr[]
std::unique_ptr< EVP_PKEY_CTX, HardFun< void, EVP_PKEY_CTX *, &EVP_PKEY_CTX_free > > EVP_PKEY_CTX_Pointer
std::optional< AnyP::Host > ParseAsSimpleDomainNameOrIp(const SBuf &)
std::unique_ptr< GENERAL_NAME, HardFun< void, GENERAL_NAME *, &GENERAL_NAME_free > > GENERAL_NAME_Pointer
std::unique_ptr< BIO, HardFun< void, BIO *, &BIO_vfree > > BIO_Pointer
std::unique_ptr< BIGNUM, HardFun< void, BIGNUM *, &BN_free > > BIGNUM_Pointer
std::unique_ptr< TXT_DB, HardFun< void, TXT_DB *, &TXT_DB_free > > TXT_DB_Pointer
std::unique_ptr< X509_STORE_CTX, HardFun< void, X509_STORE_CTX *, &X509_STORE_CTX_free > > X509_STORE_CTX_Pointer
void OPENSSL_free_for_c_strings(char *const string)
std::unique_ptr< ASN1_OCTET_STRING, HardFun< void, ASN1_OCTET_STRING *, &ASN1_OCTET_STRING_free > > ASN1_OCTET_STRING_Pointer
std::ostream & ReportAndForgetErrors(std::ostream &)
std::optional< AnyP::Host > ParseCommonNameAt(X509_NAME &, int)
interprets X.509 Subject or Issuer name entry (at the given position) as CN
Security::CertPointer ReadOptionalCertificate(const BIO_Pointer &)
const ASN1_BIT_STRING * X509_get_signature(const Security::CertPointer &)
UniqueCString OneLineSummary(X509_NAME &)
a RAII wrapper for the memory-allocating flavor of X509_NAME_oneline()
Security::CertPointer ReadCertificate(const BIO_Pointer &)
std::unique_ptr< X509_REQ, HardFun< void, X509_REQ *, &X509_REQ_free > > X509_REQ_Pointer
std::unique_ptr< STACK_OF(GENERAL_NAME), sk_GENERAL_NAME_free_wrapper > GENERAL_NAME_STACK_Pointer
BIO_Pointer ReadOnlyBioTiedTo(const char *)
SBuf AsnToSBuf(const ASN1_STRING &)
converts ASN1_STRING to SBuf
std::unique_ptr< X509_NAME, HardFun< void, X509_NAME *, &X509_NAME_free > > X509_NAME_Pointer
std::unique_ptr< ASN1_INTEGER, HardFun< void, ASN1_INTEGER *, &ASN1_INTEGER_free > > ASN1_INT_Pointer
std::unique_ptr< X509_EXTENSION, HardFun< void, X509_EXTENSION *, &X509_EXTENSION_free > > X509_EXTENSION_Pointer
std::unique_ptr< char, HardFun< void, char *, &OPENSSL_free_for_c_strings > > UniqueCString
std::unique_ptr< STACK_OF(X509), sk_X509_free_wrapper > X509_STACK_Pointer
void ForgetErrors()
Clear any errors accumulated by OpenSSL in its global storage.
std::unique_ptr< AUTHORITY_KEYID, HardFun< void, AUTHORITY_KEYID *, &AUTHORITY_KEYID_free > > AUTHORITY_KEYID_Pointer
STACK_OF(X509) *X509_STORE_CTX_get0_untrusted(X509_STORE_CTX *ctx)
#define sk_dtor_wrapper(sk_object, argument_type, freefunction)