mirror of
https://github.com/drwetter/testssl.sh.git
synced 2026-09-14 13:48:16 +02:00
Fix connect and other problems
The previous commit held the socket open in the perl 1..30 loop which prevented later on testssl.sh to scan. Also the subtets is gone . It removes and addiotional message which was confusing.
This commit is contained in:
+17
-20
@@ -30,7 +30,7 @@ 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"
|
$OPENSSL req -x509 -newkey rsa:2048 -keyout "$KEY" -out "$CERT" -days 42 -nodes -subj "/CN=localhost" 2>&1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Start OpenSSL server
|
# Start OpenSSL server
|
||||||
@@ -39,25 +39,22 @@ echo "Starting server on port $PORT..."
|
|||||||
$OPENSSL s_server -accept "$PORT" -cert "$CERT" -key "$KEY" -tls1_3
|
$OPENSSL s_server -accept "$PORT" -cert "$CERT" -key "$KEY" -tls1_3
|
||||||
HEREDOC
|
HEREDOC
|
||||||
|
|
||||||
# Write and execute the script
|
|
||||||
subtest 'TLS 1.3 Only Server Setup', sub {
|
|
||||||
plan skip_all => "File::Temp not available" unless eval { require File::Temp; 1 };
|
|
||||||
|
|
||||||
# Write the script to the temp directory
|
# Write the script to the temp directory
|
||||||
open(my $fh, '>', $server_script) or die "Cannot write script: $!";
|
open(my $fh, '>', $server_script) or die "Cannot write script: $!";
|
||||||
print $fh $shell_code;
|
print $fh $shell_code;
|
||||||
close($fh);
|
close($fh);
|
||||||
|
|
||||||
chmod 0755, $server_script;
|
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
|
# Exec the script in a child process
|
||||||
exec($server_script);
|
exec($server_script);
|
||||||
exit 0; # Should not reach here
|
exit 0; # Should not reach here
|
||||||
}
|
}
|
||||||
elsif ($pid > 0) {
|
elsif ($pid > 0) {
|
||||||
# Parent process: Wait for server to be ready
|
# Parent process: Wait for server to be ready
|
||||||
|
|
||||||
# Wait for the server to be listening on the port
|
# Wait for the server to be listening on the port
|
||||||
@@ -74,6 +71,7 @@ subtest 'TLS 1.3 Only Server Setup', sub {
|
|||||||
|
|
||||||
if ($socket) {
|
if ($socket) {
|
||||||
$ready = 1;
|
$ready = 1;
|
||||||
|
close($socket);
|
||||||
last;
|
last;
|
||||||
}
|
}
|
||||||
sleep 1;
|
sleep 1;
|
||||||
@@ -82,8 +80,8 @@ subtest 'TLS 1.3 Only Server Setup', sub {
|
|||||||
ok($ready, "Server is listening on port $port");
|
ok($ready, "Server is listening on port $port");
|
||||||
|
|
||||||
if ($ready) {
|
if ($ready) {
|
||||||
# Run testssl.sh
|
# Run testssl.sh, capture both stdout and stderr.
|
||||||
# capture both stdout and stderr
|
# We're using the OpenSSL version testssl.sh picks up
|
||||||
my $testssl_output = `./testssl.sh --protocols localhost:$port 2>&1`;
|
my $testssl_output = `./testssl.sh --protocols localhost:$port 2>&1`;
|
||||||
|
|
||||||
# Check if TLS 1.3 is found
|
# Check if TLS 1.3 is found
|
||||||
@@ -100,11 +98,10 @@ subtest 'TLS 1.3 Only Server Setup', sub {
|
|||||||
# Cleanup: Kill the server process
|
# Cleanup: Kill the server process
|
||||||
kill 9, $pid;
|
kill 9, $pid;
|
||||||
waitpid($pid, 0);
|
waitpid($pid, 0);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
die "Fork failed: $!";
|
die "Fork failed: $!";
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
done_testing();
|
done_testing();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user