906948
diff --git a/modules/ssl/ssl_engine_init.c b/modules/ssl/ssl_engine_init.c
906948
index 211ebff..c8cb1af 100644
906948
--- a/modules/ssl/ssl_engine_init.c
906948
+++ b/modules/ssl/ssl_engine_init.c
906948
@@ -871,6 +871,13 @@ static apr_status_t ssl_init_ctx_protocol(server_rec *s,
906948
         SSL_CTX_set_keylog_callback(ctx, modssl_callback_keylog);
906948
     }
906948
 #endif
906948
+
906948
+#ifdef SSL_OP_NO_RENEGOTIATION
906948
+    /* For server-side SSL_CTX, disable renegotiation by default.. */
906948
+    if (!mctx->pkp) {
906948
+        SSL_CTX_set_options(ctx, SSL_OP_NO_RENEGOTIATION);
906948
+    }
906948
+#endif
906948
     
906948
     return APR_SUCCESS;
906948
 }
906948
@@ -892,6 +899,14 @@ static void ssl_init_ctx_session_cache(server_rec *s,
906948
     }
906948
 }
906948
 
906948
+#ifdef SSL_OP_NO_RENEGOTIATION
906948
+/* OpenSSL-level renegotiation protection. */
906948
+#define MODSSL_BLOCKS_RENEG (0)
906948
+#else
906948
+/* mod_ssl-level renegotiation protection. */
906948
+#define MODSSL_BLOCKS_RENEG (1)
906948
+#endif
906948
+
906948
 static void ssl_init_ctx_callbacks(server_rec *s,
906948
                                    apr_pool_t *p,
906948
                                    apr_pool_t *ptemp,
906948
@@ -905,7 +920,13 @@ static void ssl_init_ctx_callbacks(server_rec *s,
906948
     SSL_CTX_set_tmp_dh_callback(ctx,  ssl_callback_TmpDH);
906948
 #endif
906948
 
906948
-    SSL_CTX_set_info_callback(ctx, ssl_callback_Info);
906948
+    /* The info callback is used for debug-level tracing.  For OpenSSL
906948
+     * versions where SSL_OP_NO_RENEGOTIATION is not available, the
906948
+     * callback is also used to prevent use of client-initiated
906948
+     * renegotiation.  Enable it in either case. */
906948
+    if (APLOGdebug(s) || MODSSL_BLOCKS_RENEG) {
906948
+        SSL_CTX_set_info_callback(ctx, ssl_callback_Info);
906948
+    }
906948
 
906948
 #ifdef HAVE_TLS_ALPN
906948
     SSL_CTX_set_alpn_select_cb(ctx, ssl_callback_alpn_select, NULL);
906948
diff --git a/modules/ssl/ssl_engine_io.c b/modules/ssl/ssl_engine_io.c
906948
index 79b9a70..3a0c22a 100644
906948
--- a/modules/ssl/ssl_engine_io.c
906948
+++ b/modules/ssl/ssl_engine_io.c
906948
@@ -209,11 +209,13 @@ static int bio_filter_out_write(BIO *bio, const char *in, int inl)
906948
 
906948
     BIO_clear_retry_flags(bio);
906948
 
906948
+#ifndef SSL_OP_NO_RENEGOTIATION
906948
     /* Abort early if the client has initiated a renegotiation. */
906948
     if (outctx->filter_ctx->config->reneg_state == RENEG_ABORT) {
906948
         outctx->rc = APR_ECONNABORTED;
906948
         return -1;
906948
     }
906948
+#endif
906948
 
906948
     ap_log_cerror(APLOG_MARK, APLOG_TRACE6, 0, outctx->c,
906948
                   "bio_filter_out_write: %i bytes", inl);
906948
@@ -474,11 +476,13 @@ static int bio_filter_in_read(BIO *bio, char *in, int inlen)
906948
 
906948
     BIO_clear_retry_flags(bio);
906948
 
906948
+#ifndef SSL_OP_NO_RENEGOTIATION
906948
     /* Abort early if the client has initiated a renegotiation. */
906948
     if (inctx->filter_ctx->config->reneg_state == RENEG_ABORT) {
906948
         inctx->rc = APR_ECONNABORTED;
906948
         return -1;
906948
     }
906948
+#endif
906948
 
906948
     if (!inctx->bb) {
906948
         inctx->rc = APR_EOF;
906948
diff --git a/modules/ssl/ssl_engine_kernel.c b/modules/ssl/ssl_engine_kernel.c
906948
index 591f6ae..8416864 100644
906948
--- a/modules/ssl/ssl_engine_kernel.c
906948
+++ b/modules/ssl/ssl_engine_kernel.c
906948
@@ -992,7 +992,7 @@ static int ssl_hook_Access_classic(request_rec *r, SSLSrvConfigRec *sc, SSLDirCo
906948
 
906948
             /* Toggle the renegotiation state to allow the new
906948
              * handshake to proceed. */
906948
-            sslconn->reneg_state = RENEG_ALLOW;
906948
+            modssl_set_reneg_state(sslconn, RENEG_ALLOW);
906948
 
906948
             SSL_renegotiate(ssl);
906948
             SSL_do_handshake(ssl);
906948
@@ -1019,7 +1019,7 @@ static int ssl_hook_Access_classic(request_rec *r, SSLSrvConfigRec *sc, SSLDirCo
906948
              */
906948
             SSL_peek(ssl, peekbuf, 0);
906948
 
906948
-            sslconn->reneg_state = RENEG_REJECT;
906948
+            modssl_set_reneg_state(sslconn, RENEG_REJECT);
906948
 
906948
             if (!SSL_is_init_finished(ssl)) {
906948
                 ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(02261)
906948
@@ -1078,7 +1078,7 @@ static int ssl_hook_Access_modern(request_rec *r, SSLSrvConfigRec *sc, SSLDirCon
906948
         (sc->server->auth.verify_mode != SSL_CVERIFY_UNSET)) {
906948
         int vmode_inplace, vmode_needed;
906948
         int change_vmode = FALSE;
906948
-        int old_state, n, rc;
906948
+        int n, rc;
906948
 
906948
         vmode_inplace = SSL_get_verify_mode(ssl);
906948
         vmode_needed = SSL_VERIFY_NONE;
906948
@@ -1180,8 +1180,6 @@ static int ssl_hook_Access_modern(request_rec *r, SSLSrvConfigRec *sc, SSLDirCon
906948
                 return HTTP_FORBIDDEN;
906948
             }
906948
             
906948
-            old_state = sslconn->reneg_state;
906948
-            sslconn->reneg_state = RENEG_ALLOW;
906948
             modssl_set_app_data2(ssl, r);
906948
 
906948
             SSL_do_handshake(ssl);
906948
@@ -1191,7 +1189,6 @@ static int ssl_hook_Access_modern(request_rec *r, SSLSrvConfigRec *sc, SSLDirCon
906948
              */
906948
             SSL_peek(ssl, peekbuf, 0);
906948
 
906948
-            sslconn->reneg_state = old_state;
906948
             modssl_set_app_data2(ssl, NULL);
906948
 
906948
             /*
906948
@@ -2263,8 +2260,8 @@ static void log_tracing_state(const SSL *ssl, conn_rec *c,
906948
 /*
906948
  * This callback function is executed while OpenSSL processes the SSL
906948
  * handshake and does SSL record layer stuff.  It's used to trap
906948
- * client-initiated renegotiations, and for dumping everything to the
906948
- * log.
906948
+ * client-initiated renegotiations (where SSL_OP_NO_RENEGOTIATION is
906948
+ * not available), and for dumping everything to the log.
906948
  */
906948
 void ssl_callback_Info(const SSL *ssl, int where, int rc)
906948
 {
906948
@@ -2276,14 +2273,12 @@ void ssl_callback_Info(const SSL *ssl, int where, int rc)
906948
         return;
906948
     }
906948
 
906948
-    /* With TLS 1.3 this callback may be called multiple times on the first
906948
-     * negotiation, so the below logic to detect renegotiations can't work.
906948
-     * Fortunately renegotiations are forbidden starting with TLS 1.3, and
906948
-     * this is enforced by OpenSSL so there's nothing to be done here.
906948
-     */
906948
-#if SSL_HAVE_PROTOCOL_TLSV1_3
906948
-    if (SSL_version(ssl) < TLS1_3_VERSION)
906948
-#endif
906948
+#ifndef SSL_OP_NO_RENEGOTIATION
906948
+    /* With OpenSSL < 1.1.1 (implying TLS v1.2 or earlier), this
906948
+     * callback is used to block client-initiated renegotiation.  With
906948
+     * TLSv1.3 it is unnecessary since renegotiation is forbidden at
906948
+     * protocol level.  Otherwise (TLSv1.2 with OpenSSL >=1.1.1),
906948
+     * SSL_OP_NO_RENEGOTIATION is used to block renegotiation. */
906948
     {
906948
         SSLConnRec *sslconn;
906948
 
906948
@@ -2308,6 +2303,7 @@ void ssl_callback_Info(const SSL *ssl, int where, int rc)
906948
             sslconn->reneg_state = RENEG_REJECT;
906948
         }
906948
     }
906948
+#endif
906948
 
906948
     s = mySrvFromConn(c);
906948
     if (s && APLOGdebug(s)) {
906948
diff --git a/modules/ssl/ssl_private.h b/modules/ssl/ssl_private.h
906948
index a329d99..7666c31 100644
906948
--- a/modules/ssl/ssl_private.h
906948
+++ b/modules/ssl/ssl_private.h
906948
@@ -512,6 +512,16 @@ typedef struct {
906948
     apr_time_t     source_mtime;
906948
 } ssl_asn1_t;
906948
 
906948
+typedef enum {
906948
+    RENEG_INIT = 0, /* Before initial handshake */
906948
+    RENEG_REJECT,   /* After initial handshake; any client-initiated
906948
+                     * renegotiation should be rejected */
906948
+    RENEG_ALLOW,    /* A server-initiated renegotiation is taking
906948
+                     * place (as dictated by configuration) */
906948
+    RENEG_ABORT     /* Renegotiation initiated by client, abort the
906948
+                     * connection */
906948
+} modssl_reneg_state;
906948
+
906948
 /**
906948
  * Define the mod_ssl per-module configuration structure
906948
  * (i.e. the global configuration for each httpd process)
906948
@@ -543,18 +553,13 @@ typedef struct {
906948
         NON_SSL_SET_ERROR_MSG  /* Need to set the error message */
906948
     } non_ssl_request;
906948
 
906948
-    /* Track the handshake/renegotiation state for the connection so
906948
-     * that all client-initiated renegotiations can be rejected, as a
906948
-     * partial fix for CVE-2009-3555. */
906948
-    enum {
906948
-        RENEG_INIT = 0, /* Before initial handshake */
906948
-        RENEG_REJECT,   /* After initial handshake; any client-initiated
906948
-                         * renegotiation should be rejected */
906948
-        RENEG_ALLOW,    /* A server-initiated renegotiation is taking
906948
-                         * place (as dictated by configuration) */
906948
-        RENEG_ABORT     /* Renegotiation initiated by client, abort the
906948
-                         * connection */
906948
-    } reneg_state;
906948
+#ifndef SSL_OP_NO_RENEGOTIATION
906948
+    /* For OpenSSL < 1.1.1, track the handshake/renegotiation state
906948
+     * for the connection to block client-initiated renegotiations.
906948
+     * For OpenSSL >=1.1.1, the SSL_OP_NO_RENEGOTIATION flag is used in
906948
+     * the SSL * options state with equivalent effect. */
906948
+    modssl_reneg_state reneg_state;
906948
+#endif
906948
 
906948
     server_rec *server;
906948
     SSLDirConfigRec *dc;
906948
@@ -1158,6 +1163,9 @@ int ssl_is_challenge(conn_rec *c, const char *servername,
906948
  * the configured ENGINE. */
906948
 int modssl_is_engine_id(const char *name);
906948
 
906948
+/* Set the renegotation state for connection. */
906948
+void modssl_set_reneg_state(SSLConnRec *sslconn, modssl_reneg_state state);
906948
+
906948
 #endif /* SSL_PRIVATE_H */
906948
 /** @} */
906948
 
906948
diff --git a/modules/ssl/ssl_util_ssl.c b/modules/ssl/ssl_util_ssl.c
906948
index 38079a9..dafb833 100644
906948
--- a/modules/ssl/ssl_util_ssl.c
906948
+++ b/modules/ssl/ssl_util_ssl.c
906948
@@ -589,3 +589,19 @@ cleanup:
906948
     }
906948
     return rv;
906948
 }
906948
+
906948
+void modssl_set_reneg_state(SSLConnRec *sslconn, modssl_reneg_state state)
906948
+{
906948
+#ifdef SSL_OP_NO_RENEGOTIATION
906948
+    switch (state) {
906948
+    case RENEG_ALLOW:
906948
+        SSL_clear_options(sslconn->ssl, SSL_OP_NO_RENEGOTIATION);
906948
+        break;
906948
+    default:
906948
+        SSL_set_options(sslconn->ssl, SSL_OP_NO_RENEGOTIATION);
906948
+        break;
906948
+    }
906948
+#else
906948
+    sslconn->reneg_state = state;
906948
+#endif
906948
+}