Skip to content

Commit 602b253

Browse files
ammarioclaude
andcommitted
Add TLS debugging and certificate generation improvements
- Added comprehensive TLS environment debug script for CI - Added explicit serial number and validity dates to generated certificates to avoid potential OpenSSL 3.0.x compatibility issues - Added logging for certificate generation The Linux CI failures appear to be environment-specific since the same code passes on macOS CI. The error 'OpenSSL/3.0.13: error:06880006:asn1 encoding routines::EVP lib' suggests OpenSSL 3.0.x may have issues with certain ECDSA certificate configurations. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 751a542 commit 602b253

2 files changed

Lines changed: 94 additions & 0 deletions

File tree

scripts/debug_tls_handshake.sh

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/bin/bash
2+
# Debug script to test TLS handshake with httpjail proxy
3+
4+
echo "=== TLS Handshake Debug ==="
5+
echo ""
6+
7+
# Find httpjail binary
8+
HTTPJAIL=""
9+
for bin in target/debug/httpjail target/release/httpjail; do
10+
if [ -f "$bin" ]; then
11+
HTTPJAIL="$bin"
12+
echo "Using httpjail: $HTTPJAIL"
13+
break
14+
fi
15+
done
16+
17+
if [ -z "$HTTPJAIL" ]; then
18+
echo "Error: httpjail binary not found"
19+
exit 1
20+
fi
21+
22+
# Find CA cert
23+
CA_CERT=""
24+
for dir in /home/runner/.config/httpjail /root/.config/httpjail $HOME/.config/httpjail; do
25+
if [ -f "$dir/ca-cert.pem" ]; then
26+
CA_CERT="$dir/ca-cert.pem"
27+
echo "Using CA cert: $CA_CERT"
28+
break
29+
fi
30+
done
31+
32+
if [ -z "$CA_CERT" ]; then
33+
echo "Warning: No CA cert found, will generate one"
34+
fi
35+
36+
echo ""
37+
echo "1. Starting httpjail in background (weak mode for testing)..."
38+
# Start httpjail in weak mode to test proxy directly
39+
$HTTPJAIL -r "allow: .*" --weak -- sleep 30 &
40+
HTTPJAIL_PID=$!
41+
sleep 2
42+
43+
# Get proxy ports from environment
44+
HTTP_PROXY_PORT=$(ps aux | grep -E "httpjail.*--weak" | grep -v grep | sed -n 's/.*HTTP_PROXY=.*:\([0-9]*\).*/\1/p' | head -1)
45+
HTTPS_PROXY_PORT=$(ps aux | grep -E "httpjail.*--weak" | grep -v grep | sed -n 's/.*HTTPS_PROXY=.*:\([0-9]*\).*/\1/p' | head -1)
46+
47+
if [ -z "$HTTP_PROXY_PORT" ]; then
48+
HTTP_PROXY_PORT=3128
49+
fi
50+
if [ -z "$HTTPS_PROXY_PORT" ]; then
51+
HTTPS_PROXY_PORT=3129
52+
fi
53+
54+
echo "Proxy ports: HTTP=$HTTP_PROXY_PORT, HTTPS=$HTTPS_PROXY_PORT"
55+
echo ""
56+
57+
echo "2. Testing direct HTTPS connection to proxy..."
58+
# Use openssl s_client to test the TLS handshake directly
59+
echo "CONNECT example.com:443 HTTP/1.1" | openssl s_client -connect 127.0.0.1:$HTTPS_PROXY_PORT -servername example.com -CAfile "$CA_CERT" -showcerts 2>&1 | head -50
60+
61+
echo ""
62+
echo "3. Testing with curl through proxy..."
63+
if [ -n "$CA_CERT" ]; then
64+
curl -v --proxy https://127.0.0.1:$HTTPS_PROXY_PORT --cacert "$CA_CERT" -I https://example.com 2>&1 | head -30
65+
else
66+
curl -v --proxy https://127.0.0.1:$HTTPS_PROXY_PORT -I https://example.com 2>&1 | head -30
67+
fi
68+
69+
echo ""
70+
echo "4. Extracting certificate details from proxy..."
71+
# Connect and get the certificate the proxy is sending
72+
echo | openssl s_client -connect 127.0.0.1:$HTTPS_PROXY_PORT -servername example.com 2>/dev/null | openssl x509 -text -noout 2>&1 | grep -E "Subject:|Issuer:|Signature Algorithm:|Public Key Algorithm:|Not Before:|Not After:" | head -20
73+
74+
# Kill httpjail
75+
kill $HTTPJAIL_PID 2>/dev/null
76+
wait $HTTPJAIL_PID 2>/dev/null
77+
78+
echo ""
79+
echo "=== End TLS Handshake Debug ==="

src/tls.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ impl CertificateManager {
178178

179179
// Generate new certificate
180180
debug!("Generating certificate for {}", hostname);
181+
info!(
182+
"Certificate generation: hostname={}, key_type=ECDSA-P256",
183+
hostname
184+
);
181185

182186
let mut params = CertificateParams::new(vec![hostname.to_string()])
183187
.context("Failed to create certificate params")?;
@@ -195,6 +199,17 @@ impl CertificateManager {
195199

196200
params.extended_key_usages = vec![rcgen::ExtendedKeyUsagePurpose::ServerAuth];
197201

202+
// Set serial number explicitly to avoid potential issues with OpenSSL 3.0.x
203+
params.serial_number = Some(rcgen::SerialNumber::from(vec![1, 2, 3, 4]));
204+
205+
// Set validity period - 1 year from now
206+
use chrono::{Datelike, Utc};
207+
let now = Utc::now();
208+
let not_before = rcgen::date_time_ymd(now.year(), now.month() as u8, now.day() as u8);
209+
let not_after = rcgen::date_time_ymd(now.year() + 1, now.month() as u8, now.day() as u8);
210+
params.not_before = not_before;
211+
params.not_after = not_after;
212+
198213
// Sign certificate with CA using the shared key pair
199214
let cert = params.signed_by(&self.server_key_pair, &self.ca_cert, &self.ca_key_pair)?;
200215
let cert_der = cert.der().clone();

0 commit comments

Comments
 (0)