Add support for Websockets with https inspection enabled
authorFabian Keil <fk@fabiankeil.de>
Sat, 3 Oct 2020 11:53:17 +0000 (13:53 +0200)
committerFabian Keil <fk@fabiankeil.de>
Fri, 9 Oct 2020 07:40:39 +0000 (09:40 +0200)
Set the CT_TABOO flag in case of status code 101 and
continue shuffling data around until one of the sockets
gets closed.

jcc.c
parsers.c

diff --git a/jcc.c b/jcc.c
index bb57ded..dbc5e11 100644 (file)
--- a/jcc.c
+++ b/jcc.c
@@ -2841,6 +2841,37 @@ static void handle_established_connection(struct client_state *csp)
 #ifdef FEATURE_HTTPS_INSPECTION
          if (client_use_ssl(csp))
          {
+            if (csp->http->status == 101)
+            {
+               len = ssl_recv_data(&(csp->ssl_client_attr),
+                  (unsigned char *)csp->receive_buffer,
+                  (size_t)max_bytes_to_read);
+               if (len == -1)
+               {
+                  log_error(LOG_LEVEL_ERROR, "Failed to receive data "
+                     "on client socket %d for an upgraded connection",
+                     csp->cfd);
+                  break;
+               }
+               if (len == 0)
+               {
+                  log_error(LOG_LEVEL_CONNECT, "Done receiving data "
+                     "on client socket %d for an upgraded connection",
+                     csp->cfd);
+                  break;
+               }
+               byte_count += (unsigned long long)len;
+               len = ssl_send_data(&(csp->ssl_server_attr),
+                  (unsigned char *)csp->receive_buffer, (size_t)len);
+               if (len == -1)
+               {
+                  log_error(LOG_LEVEL_ERROR, "Failed to send data "
+                     "on server socket %d for an upgraded connection",
+                     csp->server_connection.sfd);
+                  break;
+               }
+               continue;
+            }
             log_error(LOG_LEVEL_CONNECT, "Breaking with TLS/SSL.");
             break;
          }
index 06f1ae8..3f704de 100644 (file)
--- a/parsers.c
+++ b/parsers.c
@@ -4067,7 +4067,8 @@ static jb_err server_http(struct client_state *csp, char **header)
       return JB_ERR_PARSE;
    }
 
-   if (csp->http->status == 206)
+   if (csp->http->status == 101 ||
+       csp->http->status == 206)
    {
       csp->content_type = CT_TABOO;
    }