fix error (server stopped)

... , exec server with log and started testssl differently
This commit is contained in:
Dirk
2026-09-04 00:49:33 +02:00
parent 6c735af807
commit 75c35bdbc7
Regular → Executable
+18 -7
View File
@@ -30,13 +30,13 @@ OPENSSL=/usr/bin/openssl
# Generate self-signed cert and key if they don't exist # Generate self-signed cert and key if they don't exist
if [ ! -f "$CERT" ] || [ ! -f "$KEY" ]; then if [ ! -f "$CERT" ] || [ ! -f "$KEY" ]; then
echo "Generating self-signed certificate and key..." echo "Generating self-signed certificate and key..."
$OPENSSL req -x509 -newkey rsa:2048 -keyout "$KEY" -out "$CERT" -days 42 -nodes -subj "/CN=localhost" 2>&1 $OPENSSL req -x509 -newkey rsa:2048 -keyout "$KEY" -out "$CERT" -days 42 -nodes -subj "/CN=localhost" >/dev/null 2>&1
fi fi
# Start OpenSSL server # Start OpenSSL server
echo "Starting server on port $PORT..." echo "Starting server on port $PORT..."
# $OPENSSL s_server -accept "$PORT" -cert "$CERT" -key "$KEY" -tls1_3 -ciphersuites "$CIPHER_SUITE" # $OPENSSL s_server -accept "$PORT" -cert "$CERT" -key "$KEY" -tls1_3 -ciphersuites "$CIPHER_SUITE" -naccept 4242
$OPENSSL s_server -accept "$PORT" -cert "$CERT" -key "$KEY" -tls1_3 $OPENSSL s_server -accept "$PORT" -cert "$CERT" -key "$KEY" -tls1_3 -naccept 4242
HEREDOC HEREDOC
@@ -50,9 +50,11 @@ chmod 0755, $server_script;
# Start the server in the background using fork/exec # Start the server in the background using fork/exec
my $pid = fork(); my $pid = fork();
if ($pid == 0) { if ($pid == 0) {
# Exec the script in a child process chdir($temp_dir) or exit 1;
open(STDOUT, '>', "$temp_dir/server.log") or exit 1;
open(STDERR, '>&', STDOUT) or exit 1;
exec($server_script); exec($server_script);
exit 0; # Should not reach here exit 1;
} }
elsif ($pid > 0) { elsif ($pid > 0) {
# Parent process: Wait for server to be ready # Parent process: Wait for server to be ready
@@ -90,10 +92,19 @@ elsif ($pid > 0) {
# Check if TLS 1.2 is NOT found # Check if TLS 1.2 is NOT found
unlike($testssl_output, qr/OFFERED\s+TLS 1\.2/, "TLS 1.2 is NOT offered"); unlike($testssl_output, qr/OFFERED\s+TLS 1\.2/, "TLS 1.2 is NOT offered");
diag("Test output:\n$testssl_output"); # diag("Test output:\n$testssl_output");
} else { } else {
diag("Server failed to start"); my $log = '';
if (open my $lfh, '<', "$temp_dir/server.log") {
local $/; # slurp mode
$log = <$lfh> // '';
close $lfh;
} }
diag("Server failed to start. Log:\n$log");
}
# Cleanup: Kill the server process # Cleanup: Kill the server process
kill 9, $pid; kill 9, $pid;