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;
*********************************************************************/
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;
{
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;
+ }
}
}
"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;
}
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. */
}
#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;
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.
{
send_crunch_response(csp, rsp);
}
+ close_client_and_server_ssl_connections(csp);
return;
}
}
* 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);