Add debug logging to web proxy for troubleshooting connection issues

parent c1447922
......@@ -450,10 +450,13 @@ static int handle_proxy_request(int client_fd, wssshd_state_t *state, const wsss
bool use_ssl = false;
if (strcmp(service_type, "https") == 0) {
use_ssl = true;
printf("[WEB-PROXY] Service type 'https', using SSL\n");
} else if (strcmp(service_type, "web") == 0) {
use_ssl = true; // Try HTTPS first for 'web'
printf("[WEB-PROXY] Service type 'web', trying SSL first\n");
} else {
printf("[WEB-PROXY] Service type '%s', using plain TCP\n", service_type);
}
// 'http' leaves use_ssl = false
// Find or create wsssht process
wsssht_process_t *proc = find_or_create_wsssht_process(hostname, service_type, client->client_id, config->domain);
......@@ -476,20 +479,26 @@ static int handle_proxy_request(int client_fd, wssshd_state_t *state, const wsss
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
addr.sin_port = htons(proc->port);
printf("[WEB-PROXY] Connecting to wsssht on localhost:%d\n", proc->port);
if (connect(tunnel_fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
perror("[WEB-PROXY] Failed to connect to wsssht");
close(tunnel_fd);
send_http_error(client_fd, 502, "Bad Gateway");
return -1;
}
printf("[WEB-PROXY] Connected to wsssht\n");
// SSL setup if needed
SSL_CTX *ssl_ctx = NULL;
SSL *tunnel_ssl = NULL;
if (use_ssl) {
printf("[WEB-PROXY] Setting up SSL connection\n");
ssl_ctx = create_ssl_context();
if (!ssl_ctx) {
printf("[WEB-PROXY] Failed to create SSL context\n");
if (strcmp(service_type, "web") == 0) {
use_ssl = false; // Fallback to HTTP
printf("[WEB-PROXY] Falling back to plain TCP\n");
} else {
close(tunnel_fd);
send_http_error(client_fd, 502, "Bad Gateway");
......@@ -498,14 +507,18 @@ static int handle_proxy_request(int client_fd, wssshd_state_t *state, const wsss
} else {
tunnel_ssl = create_ssl_connection(ssl_ctx, tunnel_fd, 0);
if (!tunnel_ssl) {
printf("[WEB-PROXY] SSL connection failed\n");
SSL_CTX_free(ssl_ctx);
if (strcmp(service_type, "web") == 0) {
use_ssl = false; // Fallback to HTTP
printf("[WEB-PROXY] Falling back to plain TCP\n");
} else {
close(tunnel_fd);
send_http_error(client_fd, 502, "Bad Gateway");
return -1;
}
} else {
printf("[WEB-PROXY] SSL connection established\n");
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment