aee92c2
aee92c2
https://github.com/apache/httpd/pull/258
aee92c2
aee92c2
diff --git a/modules/ssl/ssl_engine_init.c b/modules/ssl/ssl_engine_init.c
aee92c2
index 4da24eddcc..5d199cddaf 100644
aee92c2
--- a/modules/ssl/ssl_engine_init.c
aee92c2
+++ b/modules/ssl/ssl_engine_init.c
aee92c2
@@ -91,7 +91,6 @@ static int DH_set0_pqg(DH *dh, BIGNUM *p, BIGNUM *q, BIGNUM *g)
aee92c2
 
aee92c2
     return 1;
aee92c2
 }
aee92c2
-#endif
aee92c2
 
aee92c2
 /*
aee92c2
  * Grab well-defined DH parameters from OpenSSL, see the BN_get_rfc*
aee92c2
@@ -171,6 +170,7 @@ DH *modssl_get_dh_params(unsigned keylen)
aee92c2
         
aee92c2
     return NULL; /* impossible to reach. */
aee92c2
 }
aee92c2
+#endif
aee92c2
 
aee92c2
 static void ssl_add_version_components(apr_pool_t *ptemp, apr_pool_t *pconf,
aee92c2
                                        server_rec *s)
aee92c2
@@ -440,8 +440,9 @@ apr_status_t ssl_init_Module(apr_pool_t *p, apr_pool_t *plog,
aee92c2
 
aee92c2
     modssl_init_app_data2_idx(); /* for modssl_get_app_data2() at request time */
aee92c2
 
aee92c2
+#if MODSSL_USE_OPENSSL_PRE_1_1_API
aee92c2
     init_dh_params();
aee92c2
-#if !MODSSL_USE_OPENSSL_PRE_1_1_API
aee92c2
+#else
aee92c2
     init_bio_methods();
aee92c2
 #endif
aee92c2
 
aee92c2
@@ -834,7 +835,11 @@ static void ssl_init_ctx_callbacks(server_rec *s,
aee92c2
 {
aee92c2
     SSL_CTX *ctx = mctx->ssl_ctx;
aee92c2
 
aee92c2
+#if MODSSL_USE_OPENSSL_PRE_1_1_API
aee92c2
     SSL_CTX_set_tmp_dh_callback(ctx,  ssl_callback_TmpDH);
aee92c2
+#else
aee92c2
+    SSL_CTX_set_dh_auto(ctx, 1);
aee92c2
+#endif
aee92c2
 
aee92c2
     SSL_CTX_set_info_callback(ctx, ssl_callback_Info);
aee92c2
 
aee92c2
@@ -843,6 +848,23 @@ static void ssl_init_ctx_callbacks(server_rec *s,
aee92c2
 #endif
aee92c2
 }
aee92c2
 
aee92c2
+static APR_INLINE
aee92c2
+int modssl_CTX_load_verify_locations(SSL_CTX *ctx,
aee92c2
+                                     const char *file,
aee92c2
+                                     const char *path)
aee92c2
+{
aee92c2
+#if OPENSSL_VERSION_NUMBER < 0x30000000L
aee92c2
+    if (!SSL_CTX_load_verify_locations(ctx, file, path))
aee92c2
+        return 0;
aee92c2
+#else
aee92c2
+    if (file && !SSL_CTX_load_verify_file(ctx, file))
aee92c2
+        return 0;
aee92c2
+    if (path && !SSL_CTX_load_verify_dir(ctx, path))
aee92c2
+        return 0;
aee92c2
+#endif
aee92c2
+    return 1;
aee92c2
+}
aee92c2
+
aee92c2
 static apr_status_t ssl_init_ctx_verify(server_rec *s,
aee92c2
                                         apr_pool_t *p,
aee92c2
                                         apr_pool_t *ptemp,
aee92c2
@@ -883,10 +905,8 @@ static apr_status_t ssl_init_ctx_verify(server_rec *s,
aee92c2
         ap_log_error(APLOG_MARK, APLOG_TRACE1, 0, s,
aee92c2
                      "Configuring client authentication");
aee92c2
 
aee92c2
-        if (!SSL_CTX_load_verify_locations(ctx,
aee92c2
-                                           mctx->auth.ca_cert_file,
aee92c2
-                                           mctx->auth.ca_cert_path))
aee92c2
-        {
aee92c2
+        if (!modssl_CTX_load_verify_locations(ctx, mctx->auth.ca_cert_file,
aee92c2
+                                                   mctx->auth.ca_cert_path)) {
aee92c2
             ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(01895)
aee92c2
                     "Unable to configure verify locations "
aee92c2
                     "for client authentication");
aee92c2
@@ -971,6 +991,23 @@ static apr_status_t ssl_init_ctx_cipher_suite(server_rec *s,
aee92c2
     return APR_SUCCESS;
aee92c2
 }
aee92c2
 
aee92c2
+static APR_INLINE
aee92c2
+int modssl_X509_STORE_load_locations(X509_STORE *store,
aee92c2
+                                     const char *file,
aee92c2
+                                     const char *path)
aee92c2
+{
aee92c2
+#if OPENSSL_VERSION_NUMBER < 0x30000000L
aee92c2
+    if (!X509_STORE_load_locations(store, file, path))
aee92c2
+        return 0;
aee92c2
+#else
aee92c2
+    if (file && !X509_STORE_load_file(store, file))
aee92c2
+        return 0;
aee92c2
+    if (path && !X509_STORE_load_path(store, path))
aee92c2
+        return 0;
aee92c2
+#endif
aee92c2
+    return 1;
aee92c2
+}
aee92c2
+
aee92c2
 static apr_status_t ssl_init_ctx_crl(server_rec *s,
aee92c2
                                      apr_pool_t *p,
aee92c2
                                      apr_pool_t *ptemp,
aee92c2
@@ -1009,8 +1046,8 @@ static apr_status_t ssl_init_ctx_crl(server_rec *s,
aee92c2
     ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(01900)
aee92c2
                  "Configuring certificate revocation facility");
aee92c2
 
aee92c2
-    if (!store || !X509_STORE_load_locations(store, mctx->crl_file,
aee92c2
-                                             mctx->crl_path)) {
aee92c2
+    if (!store || !modssl_X509_STORE_load_locations(store, mctx->crl_file,
aee92c2
+                                                           mctx->crl_path)) {
aee92c2
         ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(01901)
aee92c2
                      "Host %s: unable to configure X.509 CRL storage "
aee92c2
                      "for certificate revocation", mctx->sc->vhost_id);
aee92c2
@@ -1239,6 +1276,31 @@ static int ssl_no_passwd_prompt_cb(char *buf, int size, int rwflag,
aee92c2
    return 0;
aee92c2
 }
aee92c2
 
aee92c2
+static APR_INLINE int modssl_DH_bits(DH *dh)
aee92c2
+{
aee92c2
+#if OPENSSL_VERSION_NUMBER < 0x30000000L
aee92c2
+    return DH_bits(dh);
aee92c2
+#else
aee92c2
+    return BN_num_bits(DH_get0_p(dh));
aee92c2
+#endif
aee92c2
+}
aee92c2
+
aee92c2
+/* SSL_CTX_use_PrivateKey_file() can fail either because the private
aee92c2
+ * key was encrypted, or due to a mismatch between an already-loaded
aee92c2
+ * cert and the key - a common misconfiguration - from calling
aee92c2
+ * X509_check_private_key().  This macro is passed the last error code
aee92c2
+ * off the OpenSSL stack and evaluates to true only for the first
aee92c2
+ * case.  With OpenSSL < 3 the second case is identifiable by the
aee92c2
+ * function code, but function codes are not used from 3.0. */
aee92c2
+#if OPENSSL_VERSION_NUMBER < 0x30000000L
aee92c2
+#define CHECK_PRIVKEY_ERROR(ec) (ERR_GET_FUNC(ec) != X509_F_X509_CHECK_PRIVATE_KEY)
aee92c2
+#else
aee92c2
+#define CHECK_PRIVKEY_ERROR(ec) (ERR_GET_LIB != ERR_LIB_X509            \
aee92c2
+                                 || (ERR_GET_REASON(ec) != X509_R_KEY_TYPE_MISMATCH \
aee92c2
+                                     && ERR_GET_REASON(ec) != X509_R_KEY_VALUES_MISMATCH \
aee92c2
+                                     && ERR_GET_REASON(ec) != X509_R_UNKNOWN_KEY_TYPE))
aee92c2
+#endif
aee92c2
+
aee92c2
 static apr_status_t ssl_init_server_certs(server_rec *s,
aee92c2
                                           apr_pool_t *p,
aee92c2
                                           apr_pool_t *ptemp,
aee92c2
@@ -1249,7 +1311,7 @@ static apr_status_t ssl_init_server_certs(server_rec *s,
aee92c2
     const char *vhost_id = mctx->sc->vhost_id, *key_id, *certfile, *keyfile;
aee92c2
     int i;
aee92c2
     X509 *cert;
aee92c2
-    DH *dhparams;
aee92c2
+    DH *dh;
aee92c2
 #ifdef HAVE_ECC
aee92c2
     EC_GROUP *ecparams = NULL;
aee92c2
     int nid;
aee92c2
@@ -1344,8 +1406,7 @@ static apr_status_t ssl_init_server_certs(server_rec *s,
aee92c2
         }
aee92c2
         else if ((SSL_CTX_use_PrivateKey_file(mctx->ssl_ctx, keyfile,
aee92c2
                                               SSL_FILETYPE_PEM) < 1)
aee92c2
-                 && (ERR_GET_FUNC(ERR_peek_last_error())
aee92c2
-                     != X509_F_X509_CHECK_PRIVATE_KEY)) {
aee92c2
+                 && CHECK_PRIVKEY_ERROR(ERR_peek_last_error())) {
aee92c2
             ssl_asn1_t *asn1;
aee92c2
             const unsigned char *ptr;
aee92c2
 
aee92c2
@@ -1434,12 +1495,12 @@ static apr_status_t ssl_init_server_certs(server_rec *s,
aee92c2
      */
aee92c2
     certfile = APR_ARRAY_IDX(mctx->pks->cert_files, 0, const char *);
aee92c2
     if (certfile && !modssl_is_engine_id(certfile)
aee92c2
-        && (dhparams = ssl_dh_GetParamFromFile(certfile))) {
aee92c2
-        SSL_CTX_set_tmp_dh(mctx->ssl_ctx, dhparams);
aee92c2
+        && (dh = ssl_dh_GetParamFromFile(certfile))) {
aee92c2
+        SSL_CTX_set_tmp_dh(mctx->ssl_ctx, dh);
aee92c2
         ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(02540)
aee92c2
                      "Custom DH parameters (%d bits) for %s loaded from %s",
aee92c2
-                     DH_bits(dhparams), vhost_id, certfile);
aee92c2
-        DH_free(dhparams);
aee92c2
+                     modssl_DH_bits(dh), vhost_id, certfile);
aee92c2
+        DH_free(dh);
aee92c2
     }
aee92c2
 
aee92c2
 #ifdef HAVE_ECC
aee92c2
@@ -1490,6 +1551,7 @@ static apr_status_t ssl_init_ticket_key(server_rec *s,
aee92c2
     char buf[TLSEXT_TICKET_KEY_LEN];
aee92c2
     char *path;
aee92c2
     modssl_ticket_key_t *ticket_key = mctx->ticket_key;
aee92c2
+    int res;
aee92c2
 
aee92c2
     if (!ticket_key->file_path) {
aee92c2
         return APR_SUCCESS;
aee92c2
@@ -1517,11 +1579,22 @@ static apr_status_t ssl_init_ticket_key(server_rec *s,
aee92c2
     }
aee92c2
 
aee92c2
     memcpy(ticket_key->key_name, buf, 16);
aee92c2
-    memcpy(ticket_key->hmac_secret, buf + 16, 16);
aee92c2
     memcpy(ticket_key->aes_key, buf + 32, 16);
aee92c2
-
aee92c2
-    if (!SSL_CTX_set_tlsext_ticket_key_cb(mctx->ssl_ctx,
aee92c2
-                                          ssl_callback_SessionTicket)) {
aee92c2
+#if OPENSSL_VERSION_NUMBER < 0x30000000L
aee92c2
+    memcpy(ticket_key->hmac_secret, buf + 16, 16);
aee92c2
+    res = SSL_CTX_set_tlsext_ticket_key_cb(mctx->ssl_ctx,
aee92c2
+                                           ssl_callback_SessionTicket);
aee92c2
+#else
aee92c2
+    ticket_key->mac_params[0] =
aee92c2
+        OSSL_PARAM_construct_octet_string(OSSL_MAC_PARAM_KEY, buf + 16, 16);
aee92c2
+    ticket_key->mac_params[1] =
aee92c2
+        OSSL_PARAM_construct_utf8_string(OSSL_MAC_PARAM_DIGEST, "sha256", 0);
aee92c2
+    ticket_key->mac_params[2] =
aee92c2
+        OSSL_PARAM_construct_end();
aee92c2
+    res = SSL_CTX_set_tlsext_ticket_key_evp_cb(mctx->ssl_ctx,
aee92c2
+                                               ssl_callback_SessionTicket);
aee92c2
+#endif
aee92c2
+    if (!res) {
aee92c2
         ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(01913)
aee92c2
                      "Unable to initialize TLS session ticket key callback "
aee92c2
                      "(incompatible OpenSSL version?)");
aee92c2
@@ -1652,7 +1725,7 @@ static apr_status_t ssl_init_proxy_certs(server_rec *s,
aee92c2
         return ssl_die(s);
aee92c2
     }
aee92c2
 
aee92c2
-    X509_STORE_load_locations(store, pkp->ca_cert_file, NULL);
aee92c2
+    modssl_X509_STORE_load_locations(store, pkp->ca_cert_file, NULL);
aee92c2
 
aee92c2
     for (n = 0; n < ncerts; n++) {
aee92c2
         int i;
aee92c2
@@ -2249,10 +2322,11 @@ apr_status_t ssl_init_ModuleKill(void *data)
aee92c2
 
aee92c2
     }
aee92c2
 
aee92c2
-#if !MODSSL_USE_OPENSSL_PRE_1_1_API
aee92c2
+#if MODSSL_USE_OPENSSL_PRE_1_1_API
aee92c2
+    free_dh_params();
aee92c2
+#else
aee92c2
     free_bio_methods();
aee92c2
 #endif
aee92c2
-    free_dh_params();
aee92c2
 
aee92c2
     return APR_SUCCESS;
aee92c2
 }
aee92c2
diff --git a/modules/ssl/ssl_engine_io.c b/modules/ssl/ssl_engine_io.c
aee92c2
index cabf753790..3db7077f1e 100644
aee92c2
--- a/modules/ssl/ssl_engine_io.c
aee92c2
+++ b/modules/ssl/ssl_engine_io.c
aee92c2
@@ -194,6 +194,10 @@ static int bio_filter_destroy(BIO *bio)
aee92c2
 static int bio_filter_out_read(BIO *bio, char *out, int outl)
aee92c2
 {
aee92c2
     /* this is never called */
aee92c2
+    bio_filter_out_ctx_t *outctx = (bio_filter_out_ctx_t *)BIO_get_data(bio);
aee92c2
+    ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, outctx->c,
aee92c2
+                  "BUG: %s() should not be called", "bio_filter_out_read");
aee92c2
+    AP_DEBUG_ASSERT(0);
aee92c2
     return -1;
aee92c2
 }
aee92c2
 
aee92c2
@@ -293,12 +297,20 @@ static long bio_filter_out_ctrl(BIO *bio, int cmd, long num, void *ptr)
aee92c2
 static int bio_filter_out_gets(BIO *bio, char *buf, int size)
aee92c2
 {
aee92c2
     /* this is never called */
aee92c2
+    bio_filter_out_ctx_t *outctx = (bio_filter_out_ctx_t *)BIO_get_data(bio);
aee92c2
+    ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, outctx->c,
aee92c2
+                  "BUG: %s() should not be called", "bio_filter_out_gets");
aee92c2
+    AP_DEBUG_ASSERT(0);
aee92c2
     return -1;
aee92c2
 }
aee92c2
 
aee92c2
 static int bio_filter_out_puts(BIO *bio, const char *str)
aee92c2
 {
aee92c2
     /* this is never called */
aee92c2
+    bio_filter_out_ctx_t *outctx = (bio_filter_out_ctx_t *)BIO_get_data(bio);
aee92c2
+    ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, outctx->c,
aee92c2
+                  "BUG: %s() should not be called", "bio_filter_out_puts");
aee92c2
+    AP_DEBUG_ASSERT(0);
aee92c2
     return -1;
aee92c2
 }
aee92c2
 
aee92c2
@@ -533,22 +545,47 @@ static int bio_filter_in_read(BIO *bio, char *in, int inlen)
aee92c2
 
aee92c2
 static int bio_filter_in_write(BIO *bio, const char *in, int inl)
aee92c2
 {
aee92c2
+    bio_filter_in_ctx_t *inctx = (bio_filter_in_ctx_t *)BIO_get_data(bio);
aee92c2
+    ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, inctx->f->c,
aee92c2
+                  "BUG: %s() should not be called", "bio_filter_in_write");
aee92c2
+    AP_DEBUG_ASSERT(0);
aee92c2
     return -1;
aee92c2
 }
aee92c2
 
aee92c2
 static int bio_filter_in_puts(BIO *bio, const char *str)
aee92c2
 {
aee92c2
+    bio_filter_in_ctx_t *inctx = (bio_filter_in_ctx_t *)BIO_get_data(bio);
aee92c2
+    ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, inctx->f->c,
aee92c2
+                  "BUG: %s() should not be called", "bio_filter_in_puts");
aee92c2
+    AP_DEBUG_ASSERT(0);
aee92c2
     return -1;
aee92c2
 }
aee92c2
 
aee92c2
 static int bio_filter_in_gets(BIO *bio, char *buf, int size)
aee92c2
 {
aee92c2
+    bio_filter_in_ctx_t *inctx = (bio_filter_in_ctx_t *)BIO_get_data(bio);
aee92c2
+    ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, inctx->f->c,
aee92c2
+                  "BUG: %s() should not be called", "bio_filter_in_gets");
aee92c2
+    AP_DEBUG_ASSERT(0);
aee92c2
     return -1;
aee92c2
 }
aee92c2
 
aee92c2
 static long bio_filter_in_ctrl(BIO *bio, int cmd, long num, void *ptr)
aee92c2
 {
aee92c2
-    return -1;
aee92c2
+    bio_filter_in_ctx_t *inctx = (bio_filter_in_ctx_t *)BIO_get_data(bio);
aee92c2
+    switch (cmd) {
aee92c2
+#ifdef BIO_CTRL_EOF
aee92c2
+    case BIO_CTRL_EOF:
aee92c2
+        return inctx->rc == APR_EOF;
aee92c2
+#endif
aee92c2
+    default:
aee92c2
+        break;
aee92c2
+    }
aee92c2
+    ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, inctx->f->c,
aee92c2
+                  "BUG: bio_filter_in_ctrl() should not be called with cmd=%i",
aee92c2
+                  cmd);
aee92c2
+    AP_DEBUG_ASSERT(0);
aee92c2
+    return 0;
aee92c2
 }
aee92c2
 
aee92c2
 #if MODSSL_USE_OPENSSL_PRE_1_1_API
aee92c2
@@ -573,7 +610,7 @@ static BIO_METHOD bio_filter_in_method = {
aee92c2
     bio_filter_in_read,
aee92c2
     bio_filter_in_puts,         /* puts is never called */
aee92c2
     bio_filter_in_gets,         /* gets is never called */
aee92c2
-    bio_filter_in_ctrl,         /* ctrl is never called */
aee92c2
+    bio_filter_in_ctrl,         /* ctrl is called for EOF check */
aee92c2
     bio_filter_create,
aee92c2
     bio_filter_destroy,
aee92c2
     NULL
aee92c2
diff --git a/modules/ssl/ssl_engine_kernel.c b/modules/ssl/ssl_engine_kernel.c
aee92c2
index b99dcf19d4..aced92d2d0 100644
aee92c2
--- a/modules/ssl/ssl_engine_kernel.c
aee92c2
+++ b/modules/ssl/ssl_engine_kernel.c
aee92c2
@@ -1685,6 +1685,7 @@ const authz_provider ssl_authz_provider_verify_client =
aee92c2
 **  _________________________________________________________________
aee92c2
 */
aee92c2
 
aee92c2
+#if MODSSL_USE_OPENSSL_PRE_1_1_API
aee92c2
 /*
aee92c2
  * Hand out standard DH parameters, based on the authentication strength
aee92c2
  */
aee92c2
@@ -1730,6 +1731,7 @@ DH *ssl_callback_TmpDH(SSL *ssl, int export, int keylen)
aee92c2
 
aee92c2
     return modssl_get_dh_params(keylen);
aee92c2
 }
aee92c2
+#endif
aee92c2
 
aee92c2
 /*
aee92c2
  * This OpenSSL callback function is called when OpenSSL
aee92c2
@@ -2614,7 +2616,11 @@ int ssl_callback_SessionTicket(SSL *ssl,
aee92c2
                                unsigned char *keyname,
aee92c2
                                unsigned char *iv,
aee92c2
                                EVP_CIPHER_CTX *cipher_ctx,
aee92c2
-                               HMAC_CTX *hctx,
aee92c2
+#if OPENSSL_VERSION_NUMBER < 0x30000000L
aee92c2
+                               HMAC_CTX *hmac_ctx,
aee92c2
+#else
aee92c2
+                               EVP_MAC_CTX *mac_ctx,
aee92c2
+#endif
aee92c2
                                int mode)
aee92c2
 {
aee92c2
     conn_rec *c = (conn_rec *)SSL_get_app_data(ssl);
aee92c2
@@ -2641,7 +2647,13 @@ int ssl_callback_SessionTicket(SSL *ssl,
aee92c2
         }
aee92c2
         EVP_EncryptInit_ex(cipher_ctx, EVP_aes_128_cbc(), NULL,
aee92c2
                            ticket_key->aes_key, iv);
aee92c2
-        HMAC_Init_ex(hctx, ticket_key->hmac_secret, 16, tlsext_tick_md(), NULL);
aee92c2
+
aee92c2
+#if OPENSSL_VERSION_NUMBER < 0x30000000L
aee92c2
+        HMAC_Init_ex(hmac_ctx, ticket_key->hmac_secret, 16,
aee92c2
+                     tlsext_tick_md(), NULL);
aee92c2
+#else
aee92c2
+        EVP_MAC_CTX_set_params(mac_ctx, ticket_key->mac_params);
aee92c2
+#endif
aee92c2
 
aee92c2
         ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, c, APLOGNO(02289)
aee92c2
                       "TLS session ticket key for %s successfully set, "
aee92c2
@@ -2662,7 +2674,13 @@ int ssl_callback_SessionTicket(SSL *ssl,
aee92c2
 
aee92c2
         EVP_DecryptInit_ex(cipher_ctx, EVP_aes_128_cbc(), NULL,
aee92c2
                            ticket_key->aes_key, iv);
aee92c2
-        HMAC_Init_ex(hctx, ticket_key->hmac_secret, 16, tlsext_tick_md(), NULL);
aee92c2
+
aee92c2
+#if OPENSSL_VERSION_NUMBER < 0x30000000L
aee92c2
+        HMAC_Init_ex(hmac_ctx, ticket_key->hmac_secret, 16,
aee92c2
+                     tlsext_tick_md(), NULL);
aee92c2
+#else
aee92c2
+        EVP_MAC_CTX_set_params(mac_ctx, ticket_key->mac_params);
aee92c2
+#endif
aee92c2
 
aee92c2
         ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, c, APLOGNO(02290)
aee92c2
                       "TLS session ticket key for %s successfully set, "
aee92c2
diff --git a/modules/ssl/ssl_engine_log.c b/modules/ssl/ssl_engine_log.c
aee92c2
index 7dbbbdb55e..3b3ceacf0a 100644
aee92c2
--- a/modules/ssl/ssl_engine_log.c
aee92c2
+++ b/modules/ssl/ssl_engine_log.c
aee92c2
@@ -78,6 +78,16 @@ apr_status_t ssl_die(server_rec *s)
aee92c2
     return APR_EGENERAL;
aee92c2
 }
aee92c2
 
aee92c2
+static APR_INLINE
aee92c2
+unsigned long modssl_ERR_peek_error_data(const char **data, int *flags)
aee92c2
+{
aee92c2
+#if OPENSSL_VERSION_NUMBER < 0x30000000L
aee92c2
+    return ERR_peek_error_line_data(NULL, NULL, data, flags);
aee92c2
+#else
aee92c2
+    return ERR_peek_error_data(data, flags);
aee92c2
+#endif
aee92c2
+}
aee92c2
+
aee92c2
 /*
aee92c2
  * Prints the SSL library error information.
aee92c2
  */
aee92c2
@@ -87,7 +97,7 @@ void ssl_log_ssl_error(const char *file, int line, int level, server_rec *s)
aee92c2
     const char *data;
aee92c2
     int flags;
aee92c2
 
aee92c2
-    while ((e = ERR_peek_error_line_data(NULL, NULL, &data, &flags))) {
aee92c2
+    while ((e = modssl_ERR_peek_error_data(&data, &flags))) {
aee92c2
         const char *annotation;
aee92c2
         char err[256];
aee92c2
 
aee92c2
diff --git a/modules/ssl/ssl_private.h b/modules/ssl/ssl_private.h
aee92c2
index a6fc7513a2..b091c58c94 100644
aee92c2
--- a/modules/ssl/ssl_private.h
aee92c2
+++ b/modules/ssl/ssl_private.h
aee92c2
@@ -89,6 +89,9 @@
aee92c2
 /* must be defined before including ssl.h */
aee92c2
 #define OPENSSL_NO_SSL_INTERN
aee92c2
 #endif
aee92c2
+#if OPENSSL_VERSION_NUMBER >= 0x30000000
aee92c2
+#include <openssl/core_names.h>
aee92c2
+#endif
aee92c2
 #include <openssl/ssl.h>
aee92c2
 #include <openssl/err.h>
aee92c2
 #include <openssl/x509.h>
aee92c2
@@ -134,13 +137,12 @@
aee92c2
         SSL_CTX_ctrl(ctx, SSL_CTRL_SET_MIN_PROTO_VERSION, version, NULL)
aee92c2
 #define SSL_CTX_set_max_proto_version(ctx, version) \
aee92c2
         SSL_CTX_ctrl(ctx, SSL_CTRL_SET_MAX_PROTO_VERSION, version, NULL)
aee92c2
-#elif LIBRESSL_VERSION_NUMBER < 0x2070000f
aee92c2
+#endif /* LIBRESSL_VERSION_NUMBER < 0x2060000f */
aee92c2
 /* LibreSSL before 2.7 declares OPENSSL_VERSION_NUMBER == 2.0 but does not
aee92c2
  * include most changes from OpenSSL >= 1.1 (new functions, macros, 
aee92c2
  * deprecations, ...), so we have to work around this...
aee92c2
  */
aee92c2
-#define MODSSL_USE_OPENSSL_PRE_1_1_API (1)
aee92c2
-#endif /* LIBRESSL_VERSION_NUMBER < 0x2060000f */
aee92c2
+#define MODSSL_USE_OPENSSL_PRE_1_1_API (LIBRESSL_VERSION_NUMBER < 0x2070000f)
aee92c2
 #else /* defined(LIBRESSL_VERSION_NUMBER) */
aee92c2
 #define MODSSL_USE_OPENSSL_PRE_1_1_API (OPENSSL_VERSION_NUMBER < 0x10100000L)
aee92c2
 #endif
aee92c2
@@ -674,7 +676,11 @@ typedef struct {
aee92c2
 typedef struct {
aee92c2
     const char *file_path;
aee92c2
     unsigned char key_name[16];
aee92c2
+#if OPENSSL_VERSION_NUMBER < 0x30000000L
aee92c2
     unsigned char hmac_secret[16];
aee92c2
+#else
aee92c2
+    OSSL_PARAM mac_params[3];
aee92c2
+#endif
aee92c2
     unsigned char aes_key[16];
aee92c2
 } modssl_ticket_key_t;
aee92c2
 #endif
aee92c2
@@ -938,8 +944,16 @@ int          ssl_callback_ServerNameIndication(SSL *, int *, modssl_ctx_t *);
aee92c2
 int          ssl_callback_ClientHello(SSL *, int *, void *);
aee92c2
 #endif
aee92c2
 #ifdef HAVE_TLS_SESSION_TICKETS
aee92c2
-int         ssl_callback_SessionTicket(SSL *, unsigned char *, unsigned char *,
aee92c2
-                                       EVP_CIPHER_CTX *, HMAC_CTX *, int);
aee92c2
+int ssl_callback_SessionTicket(SSL *ssl,
aee92c2
+                               unsigned char *keyname,
aee92c2
+                               unsigned char *iv,
aee92c2
+                               EVP_CIPHER_CTX *cipher_ctx,
aee92c2
+#if OPENSSL_VERSION_NUMBER < 0x30000000L
aee92c2
+                               HMAC_CTX *hmac_ctx,
aee92c2
+#else
aee92c2
+                               EVP_MAC_CTX *mac_ctx,
aee92c2
+#endif
aee92c2
+                               int mode);
aee92c2
 #endif
aee92c2
 
aee92c2
 #ifdef HAVE_TLS_ALPN
aee92c2
@@ -1112,10 +1126,12 @@ void ssl_init_ocsp_certificates(server_rec *s, modssl_ctx_t *mctx);
aee92c2
 
aee92c2
 #endif
aee92c2
 
aee92c2
+#if MODSSL_USE_OPENSSL_PRE_1_1_API
aee92c2
 /* Retrieve DH parameters for given key length.  Return value should
aee92c2
  * be treated as unmutable, since it is stored in process-global
aee92c2
  * memory. */
aee92c2
 DH *modssl_get_dh_params(unsigned keylen);
aee92c2
+#endif
aee92c2
 
aee92c2
 /* Returns non-zero if the request was made over SSL/TLS.  If sslconn
aee92c2
  * is non-NULL and the request is using SSL/TLS, sets *sslconn to the