19#ifndef OPENSSL_COMPAT_H
20#define OPENSSL_COMPAT_H
23#error compat/openssl.h depends on USE_OPENSSL
28#if HAVE_OPENSSL_ASN1_H
29#include <openssl/asn1.h>
32#include <openssl/bio.h>
35#include <openssl/dh.h>
38#include <openssl/evp.h>
40#if HAVE_OPENSSL_LHASH_H
41#include <openssl/lhash.h>
44#include <openssl/ssl.h>
46#if HAVE_OPENSSL_X509_H
47#include <openssl/x509.h>
52#if !HAVE_LIBCRYPTO_ASN1_STRING_GET0_DATA
53 inline const unsigned char *
60#if !HAVE_LIBCRYPTO_BIO_GET_DATA
80#if !HAVE_LIBCRYPTO_BIO_GET_INIT
88#if !HAVE_LIBCRYPTO_DH_UP_REF
89#if defined(CRYPTO_LOCK_DH)
93 if (t && (CRYPTO_add(&t->references, 1, CRYPTO_LOCK_DH) > 1))
98#error missing both OpenSSL API features DH_up_ref (v1.1) and CRYPTO_LOCK_DH (v1.0)
102#if !HAVE_LIBCRYPTO_EVP_PKEY_GET0_RSA
106 if (pkey->type != EVP_PKEY_RSA)
108 return pkey->pkey.rsa;
112#if !HAVE_LIBCRYPTO_EVP_PKEY_UP_REF
113#if defined(CRYPTO_LOCK_EVP_PKEY)
115 EVP_PKEY_up_ref(EVP_PKEY *t)
117 if (t && (CRYPTO_add(&t->references, 1, CRYPTO_LOCK_EVP_PKEY)) > 1)
123#error missing both OpenSSL API features EVP_PKEY_up_ref (v1.1) and CRYPTO_LOCK_EVP_PKEY (v1.0)
127#if !HAVE_LIBCRYPTO_OPENSSL_LH_STRHASH
128#define OPENSSL_LH_delete lh_delete
129#define OPENSSL_LH_strhash lh_strhash
132#if !defined OPENSSL_VERSION
133#define OPENSSL_VERSION SSLEAY_VERSION
134#define OpenSSL_version SSLeay_version
137#if !HAVE_LIBSSL_SSL_CIPHER_FIND
138 inline const SSL_CIPHER *
141 return ssl->method->get_cipher_by_char(ptr);
145#if !HAVE_LIBSSL_SSL_SESSION_GET_ID
146 inline const unsigned char *
150 *len = s->session_id_length;
151 return s->session_id;
155#if !HAVE_LIBSSL_SSL_GET_CLIENT_RANDOM
159 if (!ssl || !ssl->s3)
162 const auto &source = ssl->s3->client_random;
164 const auto sourceSize =
sizeof(source);
168 const auto sourceStart =
reinterpret_cast<const char *
>(source);
169 const auto outSize =
std::min(sourceSize, outSizeMax);
171 memmove(outStart, sourceStart, outSize);
176#if !HAVE_LIBSSL_SSL_SESSION_GET_MASTER_KEY
180 if (!session || session->master_key_length <= 0)
183 const auto sourceSize =
static_cast<size_t>(session->master_key_length);
187 const auto sourceStart =
reinterpret_cast<const char *
>(session->master_key);
188 const auto outSize =
std::min(sourceSize, outSizeMax);
190 memmove(outStart, sourceStart, outSize);
195#if !HAVE_OPENSSL_TLS_CLIENT_METHOD
196#define TLS_client_method SSLv23_client_method
199#if !HAVE_OPENSSL_TLS_SERVER_METHOD
200#define TLS_server_method SSLv23_server_method
203#if !HAVE_LIBCRYPTO_X509_CRL_UP_REF
204#if defined(CRYPTO_LOCK_X509_CRL)
206 X509_CRL_up_ref(X509_CRL *t)
208 if (t && (CRYPTO_add(&t->references, 1, CRYPTO_LOCK_X509_CRL) > 1))
213#error missing both OpenSSL API features X509_up_ref (v1.1) and CRYPTO_LOCK_X509 (v1.0)
217#if !HAVE_LIBCRYPTO_X509_GET0_SIGNATURE
222 *psig = x->signature;
228#if !HAVE_LIBCRYPTO_X509_STORE_CTX_GET0_CERT
236#if !HAVE_LIBCRYPTO_X509_STORE_CTX_GET0_UNTRUSTED
238 X509_STORE_CTX_get0_untrusted(X509_STORE_CTX *ctx)
240 return ctx->untrusted;
246#define X509_STORE_CTX_set0_untrusted X509_STORE_CTX_set_chain
247#define X509_getm_notAfter X509_get_notAfter
248#define X509_getm_notBefore X509_get_notBefore
249#define X509_set1_notAfter X509_set_notAfter
250#define X509_set1_notBefore X509_set_notBefore
253#if !HAVE_LIBCRYPTO_X509_UP_REF
254#if defined(CRYPTO_LOCK_X509)
258 if (t && (CRYPTO_add(&t->references, 1, CRYPTO_LOCK_X509)) > 1)
263#error missing both OpenSSL API features X509_up_ref (v1.1) and CRYPTO_LOCK_X509 (v1.0)
267#if !HAVE_LIBCRYPTO_X509_CHAIN_UP_REF
269 X509_chain_up_ref(
STACK_OF(X509) *chain)
271 if (
STACK_OF(X509) *newChain = sk_X509_dup(chain)) {
274 for (i = 0; !
error && i < sk_X509_num(newChain); i++) {
275 X509 *cert = sk_X509_value(newChain, i);
276 if (!X509_up_ref(cert))
282 for (
int k = 0; k < i; k++)
283 X509_free(sk_X509_value(newChain, k));
284 sk_X509_free(newChain);
290#if !HAVE_LIBCRYPTO_X509_VERIFY_PARAM_GET_DEPTH
298#if !HAVE_SSL_GET0_PARAM
299 inline X509_VERIFY_PARAM *
310#if HAVE_LIBSSL_OPENSSL_INIT_SSL
315 SSL_load_error_strings();
316 SSLeay_add_ssl_algorithms();
void error(char *format,...)
A const & min(A const &lhs, A const &rhs)
const SSL_CIPHER * SSL_CIPHER_find(SSL *ssl, const unsigned char *ptr)
int X509_VERIFY_PARAM_get_depth(const X509_VERIFY_PARAM *param)
void * BIO_get_data(BIO *table)
void SQUID_OPENSSL_init_ssl(void)
X509_VERIFY_PARAM * SSL_get0_param(SSL *ssl)
const unsigned char * SSL_SESSION_get_id(const SSL_SESSION *s, unsigned int *len)
void BIO_set_init(BIO *table, int init)
size_t SSL_get_client_random(const SSL *ssl, unsigned char *outStart, size_t outSizeMax)
void X509_get0_signature(ASN1_BIT_STRING **psig, X509_ALGOR **palg, const X509 *x)
STACK_OF(X509) *X509_STORE_CTX_get0_untrusted(X509_STORE_CTX *ctx)
X509 * X509_STORE_CTX_get0_cert(X509_STORE_CTX *ctx)
const unsigned char * ASN1_STRING_get0_data(const ASN1_STRING *x)
void BIO_set_data(BIO *table, void *data)
RSA * EVP_PKEY_get0_RSA(EVP_PKEY *pkey)
int BIO_get_init(BIO *table)
size_t SSL_SESSION_get_master_key(const SSL_SESSION *session, unsigned char *outStart, size_t outSizeMax)