cleanup: Remove OpenSSL and consequently https support. Run behind a reverse proxy if you need https.
Some checks failed
Build Tilde Friends / Build-All (push) Has been cancelled

This commit is contained in:
2025-10-15 20:02:59 -04:00
parent 26de1f7daa
commit b2b4ffeeae
17 changed files with 22 additions and 956 deletions

View File

@@ -2,7 +2,6 @@
#include "log.h"
#include "mem.h"
#include "tls.h"
#include "trace.h"
#include "util.js.h"
@@ -26,7 +25,6 @@ int s_http_instance_count;
typedef struct _tf_http_connection_t
{
tf_http_t* http;
tf_tls_session_t* tls;
uv_tcp_t tcp;
uv_shutdown_t shutdown;
uv_timer_t timeout;
@@ -78,7 +76,6 @@ typedef struct _tf_http_handler_t
typedef struct _tf_http_listener_t
{
tf_http_t* http;
tf_tls_context_t* tls;
uv_tcp_t tcp;
tf_http_cleanup_t* cleanup;
void* user_data;
@@ -109,7 +106,6 @@ typedef struct _tf_http_t
static const char* _http_connection_get_header(const tf_http_connection_t* connection, const char* name);
static void _http_connection_destroy(tf_http_connection_t* connection, const char* reason);
static void _http_timer_reset(tf_http_connection_t* connection);
static void _http_tls_update(tf_http_connection_t* connection);
static void _http_builtin_404_handler(tf_http_request_t* request);
tf_http_t* tf_http_create(uv_loop_t* loop)
@@ -260,11 +256,6 @@ static void _http_connection_destroy(tf_http_connection_t* connection, const cha
{
uv_close((uv_handle_t*)&connection->timeout, _http_connection_on_close);
}
if (connection->tls)
{
tf_tls_session_destroy(connection->tls);
connection->tls = NULL;
}
if (connection->ref_count == 0 && !connection->tcp.data && !connection->shutdown.data && !connection->timeout.data)
{
@@ -446,7 +437,6 @@ static void _http_add_body_bytes(tf_http_connection_t* connection, const void* d
*request = (tf_http_request_t) {
.http = connection->http,
.connection = connection,
.is_tls = connection->tls != NULL,
.method = connection->method,
.path = connection->path,
.query = connection->query,
@@ -587,21 +577,7 @@ static void _http_on_read(uv_stream_t* stream, ssize_t read_size, const uv_buf_t
_http_timer_reset(connection);
if (read_size > 0)
{
if (connection->tls)
{
if (tf_tls_session_write_encrypted(connection->tls, buffer->base, read_size) < 0)
{
_http_connection_destroy(connection, "tf_tls_session_write_encrypted");
}
else
{
_http_tls_update(connection);
}
}
else
{
_http_on_read_plain(connection, buffer->base, read_size);
}
_http_on_read_plain(connection, buffer->base, read_size);
}
else if (read_size < 0)
{
@@ -643,17 +619,6 @@ static void _http_on_connection(uv_stream_t* stream, int status)
tf_http_connection_t* connection = tf_malloc(sizeof(tf_http_connection_t));
*connection = (tf_http_connection_t) { .http = http, .tcp = { .data = connection }, .is_receiving_headers = true };
if (listener->tls)
{
connection->tls = tf_tls_context_create_session(listener->tls);
if (!connection->tls)
{
_http_connection_destroy(connection, "tf_tls_context_create_session");
return;
}
tf_tls_session_start_accept(connection->tls);
connection->is_handshaking = true;
}
int r = uv_tcp_init(connection->http->loop, &connection->tcp);
if (r)
{
@@ -694,21 +659,15 @@ static void _http_on_connection(uv_stream_t* stream, int status)
return;
}
if (connection->tls)
{
_http_tls_update(connection);
}
http->connections = tf_resize_vec(http->connections, sizeof(tf_http_connection_t*) * (http->connections_count + 1));
http->connections[http->connections_count++] = connection;
}
int tf_http_listen(tf_http_t* http, int port, bool local_only, tf_tls_context_t* tls, tf_http_cleanup_t* cleanup, void* user_data)
int tf_http_listen(tf_http_t* http, int port, bool local_only, tf_http_cleanup_t* cleanup, void* user_data)
{
tf_http_listener_t* listener = tf_malloc(sizeof(tf_http_listener_t));
*listener = (tf_http_listener_t) {
.http = http,
.tls = tls,
.tcp = { .data = listener },
.cleanup = cleanup,
.user_data = user_data,
@@ -948,71 +907,10 @@ static void _http_write_internal(tf_http_connection_t* connection, const void* d
}
}
static void _http_tls_update(tf_http_connection_t* connection)
{
bool again = true;
while (again)
{
again = false;
if (connection->is_handshaking && connection->tls)
{
switch (tf_tls_session_handshake(connection->tls))
{
case k_tls_handshake_done:
connection->is_handshaking = false;
break;
case k_tls_handshake_more:
break;
case k_tls_handshake_failed:
_http_connection_destroy(connection, "tf_tls_session_handshake");
return;
}
}
/* Maybe we became disconnected and cleaned up our TLS session. */
if (connection->tls)
{
char buffer[8192];
int r = tf_tls_session_read_encrypted(connection->tls, buffer, sizeof(buffer));
if (r > 0)
{
_http_write_internal(connection, buffer, r);
again = true;
}
}
if (connection->tls)
{
char buffer[8192];
int r = tf_tls_session_read_plain(connection->tls, buffer, sizeof(buffer));
if (r > 0)
{
_http_on_read_plain(connection, buffer, r);
again = true;
}
}
}
}
static void _http_write(tf_http_connection_t* connection, const void* data, size_t size)
{
_http_timer_reset(connection);
if (connection->tls)
{
int r = tf_tls_session_write_plain(connection->tls, data, size);
if (r < (ssize_t)size)
{
char buffer[8192];
tf_tls_session_get_error(connection->tls, buffer, sizeof(buffer));
tf_printf("tf_tls_session_write_plain: %s\n", buffer);
}
_http_tls_update(connection);
}
else
{
_http_write_internal(connection, data, size);
}
_http_write_internal(connection, data, size);
}
void tf_http_request_websocket_send(tf_http_request_t* request, int op_code, const void* data, size_t size)