fa0499
# ./pullrev.sh 1870095 1870097
fa0499
http://svn.apache.org/viewvc?view=revision&revision=1870095
fa0499
http://svn.apache.org/viewvc?view=revision&revision=1870097
fa0499
fa0499
--- httpd-2.4.37/modules/ssl/ssl_engine_kernel.c
fa0499
+++ httpd-2.4.37/modules/ssl/ssl_engine_kernel.c
fa0499
@@ -114,6 +114,45 @@
fa0499
     return result;
fa0499
 }
fa0499
 
fa0499
+/* If a renegotiation is required for the location, and the request
fa0499
+ * includes a message body (and the client has not requested a "100
fa0499
+ * Continue" response), then the client will be streaming the request
fa0499
+ * body over the wire already.  In that case, it is not possible to
fa0499
+ * stop and perform a new SSL handshake immediately; once the SSL
fa0499
+ * library moves to the "accept" state, it will reject the SSL packets
fa0499
+ * which the client is sending for the request body.
fa0499
+ *
fa0499
+ * To allow authentication to complete in the hook, the solution used
fa0499
+ * here is to fill a (bounded) buffer with the request body, and then
fa0499
+ * to reinject that request body later.
fa0499
+ *
fa0499
+ * This function is called to fill the renegotiation buffer for the
fa0499
+ * location as required, or fail.  Returns zero on success or HTTP_
fa0499
+ * error code on failure.
fa0499
+ */
fa0499
+static int fill_reneg_buffer(request_rec *r, SSLDirConfigRec *dc)
fa0499
+{
fa0499
+    int rv;
fa0499
+    apr_size_t rsize;
fa0499
+
fa0499
+    /* ### this is HTTP/1.1 specific, special case for protocol? */
fa0499
+    if (r->expecting_100 || !ap_request_has_body(r)) {
fa0499
+        return 0;
fa0499
+    }
fa0499
+
fa0499
+    rsize = dc->nRenegBufferSize == UNSET ? DEFAULT_RENEG_BUFFER_SIZE : dc->nRenegBufferSize;
fa0499
+    if (rsize > 0) {
fa0499
+        /* Fill the I/O buffer with the request body if possible. */
fa0499
+        rv = ssl_io_buffer_fill(r, rsize);
fa0499
+    }
fa0499
+    else {
fa0499
+        /* If the reneg buffer size is set to zero, just fail. */
fa0499
+        rv = HTTP_REQUEST_ENTITY_TOO_LARGE;
fa0499
+    }
fa0499
+
fa0499
+    return rv;
fa0499
+}
fa0499
+
fa0499
 #ifdef HAVE_TLSEXT
fa0499
 static int ap_array_same_str_set(apr_array_header_t *s1, apr_array_header_t *s2)
fa0499
 {
fa0499
@@ -814,41 +853,14 @@
fa0499
         }
fa0499
     }
fa0499
 
fa0499
-    /* If a renegotiation is now required for this location, and the
fa0499
-     * request includes a message body (and the client has not
fa0499
-     * requested a "100 Continue" response), then the client will be
fa0499
-     * streaming the request body over the wire already.  In that
fa0499
-     * case, it is not possible to stop and perform a new SSL
fa0499
-     * handshake immediately; once the SSL library moves to the
fa0499
-     * "accept" state, it will reject the SSL packets which the client
fa0499
-     * is sending for the request body.
fa0499
-     *
fa0499
-     * To allow authentication to complete in this auth hook, the
fa0499
-     * solution used here is to fill a (bounded) buffer with the
fa0499
-     * request body, and then to reinject that request body later.
fa0499
-     */
fa0499
-    if (renegotiate && !renegotiate_quick
fa0499
-        && !r->expecting_100
fa0499
-        && ap_request_has_body(r)) {
fa0499
-        int rv;
fa0499
-        apr_size_t rsize;
fa0499
-
fa0499
-        rsize = dc->nRenegBufferSize == UNSET ? DEFAULT_RENEG_BUFFER_SIZE :
fa0499
-                                                dc->nRenegBufferSize;
fa0499
-        if (rsize > 0) {
fa0499
-            /* Fill the I/O buffer with the request body if possible. */
fa0499
-            rv = ssl_io_buffer_fill(r, rsize);
fa0499
-        }
fa0499
-        else {
fa0499
-            /* If the reneg buffer size is set to zero, just fail. */
fa0499
-            rv = HTTP_REQUEST_ENTITY_TOO_LARGE;
fa0499
-        }
fa0499
-
fa0499
-        if (rv) {
fa0499
+    /* Fill reneg buffer if required. */
fa0499
+    if (renegotiate && !renegotiate_quick) {
fa0499
+        rc = fill_reneg_buffer(r, dc);
fa0499
+        if (rc) {
fa0499
             ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(02257)
fa0499
                           "could not buffer message body to allow "
fa0499
                           "SSL renegotiation to proceed");
fa0499
-            return rv;
fa0499
+            return rc;
fa0499
         }
fa0499
     }
fa0499
 
fa0499
@@ -1132,6 +1144,17 @@
fa0499
             }
fa0499
         }
fa0499
 
fa0499
+        /* Fill reneg buffer if required. */
fa0499
+        if (change_vmode) {
fa0499
+            rc = fill_reneg_buffer(r, dc);
fa0499
+            if (rc) {
fa0499
+                ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(10228)
fa0499
+                              "could not buffer message body to allow "
fa0499
+                              "TLS Post-Handshake Authentication to proceed");
fa0499
+                return rc;
fa0499
+            }
fa0499
+        }
fa0499
+
fa0499
         if (change_vmode) {
fa0499
             char peekbuf[1];
fa0499