X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=blobdiff_plain;f=jcc.c;h=10a2d74a0eaecc6b4c24f5b20cc64f76be9f45fc;hp=3129bab450eb1f6d69e3ce17aeb18bb63bc95e8d;hb=c87840b811c2c2a72c5b67e90e974f74681237c6;hpb=bce0c44ff68888e53be6e0f986cb46c39ce8e3a5 diff --git a/jcc.c b/jcc.c index 3129bab4..10a2d74a 100644 --- a/jcc.c +++ b/jcc.c @@ -193,8 +193,10 @@ privoxy_mutex_t log_mutex; privoxy_mutex_t log_init_mutex; privoxy_mutex_t connection_reuse_mutex; +#ifdef FEATURE_HTTPS_INSPECTION privoxy_mutex_t certificate_mutex; privoxy_mutex_t rng_mutex; +#endif #ifdef FEATURE_EXTERNAL_FILTERS privoxy_mutex_t external_filter_mutex; @@ -2026,12 +2028,23 @@ static int send_http_request(struct client_state *csp) *********************************************************************/ static jb_err receive_and_send_encrypted_post_data(struct client_state *csp) { - unsigned char buf[BUFFER_SIZE]; - int len; + int content_length_known = csp->expected_client_content_length != 0; while (is_ssl_pending(&(csp->mbedtls_client_attr.ssl))) { - len = ssl_recv_data(&(csp->mbedtls_client_attr.ssl), buf, sizeof(buf)); + unsigned char buf[BUFFER_SIZE]; + int len; + int max_bytes_to_read = sizeof(buf); + + if (content_length_known && csp->expected_client_content_length < sizeof(buf)) + { + max_bytes_to_read = (int)csp->expected_client_content_length; + } + log_error(LOG_LEVEL_CONNECT, + "Waiting for up to %d bytes of POST data from the client.", + max_bytes_to_read); + len = ssl_recv_data(&(csp->mbedtls_client_attr.ssl), buf, + (unsigned)max_bytes_to_read); if (len == -1) { return 1; @@ -2054,6 +2067,11 @@ static jb_err receive_and_send_encrypted_post_data(struct client_state *csp) { csp->expected_client_content_length -= (unsigned)len; } + if (csp->expected_client_content_length == 0) + { + log_error(LOG_LEVEL_HEADER, "Forwarded the last %d bytes", len); + break; + } } } @@ -2105,7 +2123,6 @@ static int send_https_request(struct client_state *csp) "Failed sending encrypted request headers to: %s: %E", csp->http->hostport); mark_server_socket_tainted(csp); - close_client_and_server_ssl_connections(csp); return 1; } @@ -2392,13 +2409,6 @@ static void handle_established_connection(struct client_state *csp) int use_ssl_tunnel = 0; csp->dont_verify_certificate = 0; - /* - * Preset flags informing if SSL connections with server or client - * are opened or closed - */ - csp->ssl_with_server_is_opened = 0; - csp->ssl_with_client_is_opened = 0; - if (csp->http->ssl && !(csp->action->flags & ACTION_HTTPS_INSPECTION)) { /* Pass encrypted content without filtering. */ @@ -2510,27 +2520,6 @@ static void handle_established_connection(struct client_state *csp) } #endif /* FEATURE_CONNECTION_KEEP_ALIVE */ -#ifdef FEATURE_HTTPS_INSPECTION - /* - * Test if some data from client or destination server are pending - * on TLS/SSL. We must work with them preferably. TLS/SSL data can - * be pending because of maximal fragment size. - */ - int read_ssl_server = 0; - int read_ssl_client = 0; - - if (client_use_ssl(csp)) - { - read_ssl_client = is_ssl_pending(&(csp->mbedtls_client_attr.ssl)) != 0; - } - - if (server_use_ssl(csp)) - { - read_ssl_server = is_ssl_pending(&(csp->mbedtls_server_attr.ssl)) != 0; - } - - if (!read_ssl_server && !read_ssl_client) -#endif { #ifdef HAVE_POLL poll_fds[0].fd = csp->cfd; @@ -2588,36 +2577,7 @@ static void handle_established_connection(struct client_state *csp) return; } } -#ifdef FEATURE_HTTPS_INSPECTION - else - { - /* set FD if some data are pending on TLS/SSL connections */ -#ifndef HAVE_POLL - FD_ZERO(&rfds); -#endif - if (read_ssl_client) - { -#ifdef HAVE_POLL - poll_fds[0].fd = csp->cfd; - poll_fds[0].events = POLLIN; -#else - FD_SET(csp->cfd, &rfds); -#endif - n++; - } - if (read_ssl_server) - { -#ifdef HAVE_POLL - poll_fds[1].fd = csp->server_connection.sfd; - poll_fds[1].events = POLLIN; -#else - FD_SET(csp->server_connection.sfd, &rfds); -#endif - n++; - } - } -#endif /* * This is the body of the browser's request, * just read and write it. @@ -3964,6 +3924,7 @@ static void chat(struct client_state *csp) { send_crunch_response(csp, rsp); } + close_client_and_server_ssl_connections(csp); return; } } @@ -4586,8 +4547,10 @@ static void initialize_mutexes(void) * Prepare global mutex semaphores */ +#ifdef FEATURE_HTTPS_INSPECTION privoxy_mutex_init(&certificate_mutex); privoxy_mutex_init(&rng_mutex); +#endif privoxy_mutex_init(&log_mutex); privoxy_mutex_init(&log_init_mutex);