mirror of
https://github.com/drwetter/testssl.sh.git
synced 2026-09-14 13:48:16 +02:00
Another try
- remove -naccept as it was futile - fix identation - kill the server when run locally (perl's PID was wrong) - quiet key generation This works on both Linux and Mac locally (except some debug stuff unser MacOS)
This commit is contained in:
+16
-23
@@ -60,13 +60,13 @@ fi
|
||||
# Generate self-signed cert and key if they don't exist
|
||||
if [ ! -f "$CERT" ] || [ ! -f "$KEY" ]; then
|
||||
echo "Generating self-signed certificate and key..."
|
||||
$OPENSSL req -x509 -newkey rsa:2048 -keyout "$KEY" -out "$CERT" -days 42 -nodes -subj "/CN=localhost" -addext "subjectAltName=DNS:localhost,IP:127.0.0.1" >/dev/null
|
||||
$OPENSSL req -quiet -x509 -newkey rsa:2048 -keyout "$KEY" -out "$CERT" -days 42 -nodes -subj "/CN=localhost" -addext "subjectAltName=DNS:localhost,IP:127.0.0.1" >/dev/null
|
||||
fi
|
||||
|
||||
# Start OpenSSL server
|
||||
echo "Starting server on port $PORT..."
|
||||
# $OPENSSL s_server -accept "$IP:$PORT" -cert "$CERT" -key "$KEY" -tls1_3 -ciphersuites "$CIPHER_SUITE" -naccept 4242
|
||||
$OPENSSL s_server -accept "$IP:$PORT" -cert "$CERT" -key "$KEY" -tls1_3 -naccept 4242
|
||||
# $OPENSSL s_server -accept "$IP:$PORT" -cert "$CERT" -key "$KEY" -tls1_3 -ciphersuites "$CIPHER_SUITE"
|
||||
$OPENSSL s_server -accept "$IP:$PORT" -cert "$CERT" -key "$KEY" -tls1_3
|
||||
|
||||
HEREDOC
|
||||
|
||||
@@ -108,14 +108,11 @@ elsif ($pid > 0) {
|
||||
close($socket);
|
||||
last;
|
||||
}
|
||||
sleep 1;
|
||||
sleep (1);
|
||||
}
|
||||
|
||||
ok($ready, "Server is listening on $listenip:$port");
|
||||
|
||||
if ($ready) {
|
||||
sleep(2);
|
||||
|
||||
# ---- DEBUG stuff, taken right before testssl runs ----
|
||||
my $reaped = waitpid($pid, WNOHANG); # 0 => still running
|
||||
my $state = ($reaped == 0) ? 'ALIVE' : "DEAD (waitpid=$reaped)";
|
||||
@@ -124,16 +121,18 @@ elsif ($pid > 0) {
|
||||
my $listening = port_listening($listenip, $port);
|
||||
diag("DEBUG pre-testssl: $listenip:$port LISTEN=" . ($listening // 'n/a'));
|
||||
|
||||
if ( $os eq "linux" ){
|
||||
diag("DEBUG netns: " . (`readlink /proc/self/ns/net 2>&1`));
|
||||
diag("DEBUG cgroup: " . (`cat /proc/self/cgroup 2>&1`));
|
||||
diag("DEBUG ss: " . (`ss -ltnp 2>&1 | grep ":$port " || echo "(no listener)"`));
|
||||
}
|
||||
if ( $os eq "linux" ){
|
||||
diag("DEBUG netns: " . (`readlink /proc/self/ns/net 2>&1`));
|
||||
diag("DEBUG cgroup: " . (`cat /proc/self/cgroup 2>&1`));
|
||||
diag("DEBUG ss: " . (`ss -ltnp 2>&1 | grep ":$port " || echo "(no listener)"`));
|
||||
}
|
||||
|
||||
diag("DEBUG direct bash connect: " .
|
||||
diag("DEBUG direct bash connect: " .
|
||||
(`timeout 2 bash -c "echo > /dev/tcp/$listenip/$port" 2>&1 && echo OK || echo REFUSED`));
|
||||
|
||||
|
||||
sleep (2);
|
||||
|
||||
my $log_pre = '';
|
||||
if (open my $lfh, '<', "$temp_dir/server.log") {
|
||||
local $/;
|
||||
@@ -155,18 +154,12 @@ diag("DEBUG direct bash connect: " .
|
||||
close $lfh;
|
||||
}
|
||||
diag("Server Log:\n$log");
|
||||
}
|
||||
|
||||
# Cleanup: Kill the server process
|
||||
kill 9, $pid;
|
||||
waitpid($pid, 0);
|
||||
}
|
||||
else {
|
||||
die "Fork failed: $!";
|
||||
}
|
||||
|
||||
|
||||
|
||||
# Cleanup: Kill the server process. When run locally this is needed
|
||||
my $openssl_pid = `lsof -i -Pn | grep \$USER | grep openssl | awk '{ print \$2 }'`;
|
||||
kill 9, $openssl_pid;
|
||||
waitpid($openssl_pid, 0);
|
||||
|
||||
done_testing();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user