From: Fabian Keil Date: Mon, 24 Feb 2020 12:12:39 +0000 (+0100) Subject: Add receive_and_send_encrypted_post_data() X-Git-Tag: v_3_0_29~491 X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=commitdiff_plain;h=15e6416d9fee24c73f17413a937dd1fb58240b94 Add receive_and_send_encrypted_post_data() ... to deal with POST data that isn't read together with the request headers. Sponsored by: Robert Klemme --- diff --git a/jcc.c b/jcc.c index 703feb94..e18132d4 100644 --- a/jcc.c +++ b/jcc.c @@ -2015,6 +2015,59 @@ static int send_http_request(struct client_state *csp) #ifdef FEATURE_HTTPS_FILTERING +/********************************************************************* + * + * Function : receive_and_send_encrypted_post_data + * + * Description : Reads remaining POST data from the client and sends + * it to the server. + * + * Parameters : + * 1 : csp = Current client state (buffers, headers, etc...) + * + * Returns : 0 on success, anything else is an error. + * + *********************************************************************/ +static jb_err receive_and_send_encrypted_post_data(struct client_state *csp) +{ + unsigned char buf[BUFFER_SIZE]; + int len; + + while (is_ssl_pending(&(csp->mbedtls_client_attr.ssl))) + { + len = ssl_recv_data(&(csp->mbedtls_client_attr.ssl), buf, sizeof(buf)); + if (len == -1) + { + return 1; + } + if (len == 0) + { + /* XXX: Does this actually happen? */ + break; + } + log_error(LOG_LEVEL_HEADER, "Forwarding %d bytes of encrypted POST data", + len); + len = ssl_send_data(&(csp->mbedtls_server_attr.ssl), buf, (size_t)len); + if (len == -1) + { + return 1; + } + if (csp->expected_client_content_length != 0) + { + if (csp->expected_client_content_length >= len) + { + csp->expected_client_content_length -= (unsigned)len; + } + } + } + + log_error(LOG_LEVEL_HEADER, "Done forwarding encrypted POST data"); + + return 0; + +} + + /********************************************************************* * * Function : send_https_request @@ -2085,6 +2138,10 @@ static int send_https_request(struct client_state *csp) "Flushed %d bytes of request body while expecting %llu", flushed, csp->expected_client_content_length); csp->expected_client_content_length -= (unsigned)flushed; + if (receive_and_send_encrypted_post_data(csp)) + { + return 1; + } } } else