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