mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2026-08-29 17:29:53 +02:00
The negative tests accepted any non-zero client status, and the openssl.test capability and protocol probes read only a command's output. A run killed by timeout(1) therefore looked like the certificate rejection, auth failure or missing feature each site was testing for, and the script still reported success with the coverage silently dropped. Check for the timeout statuses (124, and 137 for the SIGKILL used here) before interpreting a result: - trusted_peer.test: the three wrong-CA / wrong-peer rejection cases - tls13.test: cipher mismatch, mutual auth, and the version downgrade cases - psk.test: the no-peer-cert rejection case - openssl.test: the seven wolfSSL/OpenSSL certificate capability probes and the SSLv3, TLS 1.0 and TLS 1.1 connection probes
213 lines
5.9 KiB
Bash
Executable File
213 lines
5.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# psk.test
|
|
# copyright wolfSSL 2016
|
|
|
|
# timeout(1) is GNU coreutils and absent on macOS; where it's missing, run the
|
|
# command unbounded (the flaky hang this guards against is Linux-only CI).
|
|
# A prefix variable rather than a shell function: backgrounding a function
|
|
# makes $! the forked subshell, so a later "kill $server_pid" would stop the
|
|
# wrapper and orphan the server it was meant to kill.
|
|
if command -v timeout >/dev/null 2>&1; then
|
|
TIMEOUT_KILL_2M="timeout -s KILL 2m"
|
|
else
|
|
TIMEOUT_KILL_2M=""
|
|
fi
|
|
|
|
# timeout(1) exits 124, or 128+signal when it must signal the child (137 for
|
|
# the SIGKILL used here). Skip branches below turn a non-zero status into
|
|
# "feature not compiled in" and exit 0, so a hang must be told apart from a
|
|
# genuine failure or it lands in CI as a silent pass.
|
|
timed_out() { [ "$1" -eq 124 ] || [ "$1" -eq 137 ]; }
|
|
|
|
# if we can, isolate the network namespace to eliminate port collisions.
|
|
if [[ -n "$NETWORK_UNSHARE_HELPER" ]]; then
|
|
if [[ -z "$NETWORK_UNSHARE_HELPER_CALLED" ]]; then
|
|
export NETWORK_UNSHARE_HELPER_CALLED=yes
|
|
exec "$NETWORK_UNSHARE_HELPER" "$0" "$@" || exit $?
|
|
fi
|
|
elif [ "${AM_BWRAPPED-}" != "yes" ]; then
|
|
bwrap_path="$(command -v bwrap)"
|
|
if [ -n "$bwrap_path" ]; then
|
|
export AM_BWRAPPED=yes
|
|
exec "$bwrap_path" --unshare-net --dev-bind / / "$0" "$@"
|
|
fi
|
|
unset AM_BWRAPPED
|
|
fi
|
|
|
|
# getting unique port is modeled after resume.test script
|
|
# need a unique port since may run the same time as testsuite
|
|
# use server port zero hack to get one
|
|
port=0
|
|
no_pid=-1
|
|
server_pid=$no_pid
|
|
counter=0
|
|
# let's use absolute path to a local dir (make distcheck may be in sub dir)
|
|
# also let's add some randomness by adding pid in case multiple 'make check's
|
|
# per source tree
|
|
ready_file=`pwd`/wolfssl_psk_ready$$
|
|
|
|
echo "ready file \"$ready_file\""
|
|
|
|
create_port() {
|
|
counter=0
|
|
while [ ! -s "$ready_file" -a "$counter" -lt 20 ]; do
|
|
echo -e "waiting for ready file..."
|
|
sleep 0.1
|
|
counter=$((counter+ 1))
|
|
done
|
|
|
|
if test -e "$ready_file"; then
|
|
echo -e "found ready file, starting client..."
|
|
|
|
# sleep for an additional 0.1 to mitigate race on write/read of $ready_file:
|
|
sleep 0.1
|
|
|
|
# get created port 0 ephemeral port
|
|
port=`cat "$ready_file"`
|
|
else
|
|
echo -e "NO ready file ending test..."
|
|
do_cleanup
|
|
fi
|
|
}
|
|
|
|
remove_ready_file() {
|
|
if test -e "$ready_file"; then
|
|
echo -e "removing existing ready file"
|
|
rm "$ready_file"
|
|
fi
|
|
}
|
|
|
|
do_cleanup() {
|
|
echo "in cleanup"
|
|
|
|
if [ $server_pid != $no_pid ] && kill -0 $server_pid 2>&-
|
|
then
|
|
# sleep to give sanitizers time to dump backtraces.
|
|
sleep 1
|
|
echo "killing server"
|
|
kill -9 $server_pid
|
|
fi
|
|
remove_ready_file
|
|
}
|
|
|
|
do_trap() {
|
|
echo "got trap"
|
|
do_cleanup
|
|
exit 1
|
|
}
|
|
|
|
trap do_trap INT TERM
|
|
|
|
[ ! -x ./examples/client/client ] && echo -e "\n\nClient doesn't exist" && exit 1
|
|
./examples/client/client '-?' 2>&1 | grep -- 'Client not compiled in!'
|
|
if [ $? -eq 0 ]; then
|
|
exit 0
|
|
fi
|
|
./examples/server/server '-?' 2>&1 | grep -- 'Server not compiled in!'
|
|
if [ $? -eq 0 ]; then
|
|
exit 0
|
|
fi
|
|
./examples/client/client '-?' 2>&1 | grep -- 'Disable client cert/key loading'
|
|
if [ $? -eq 0 ]; then
|
|
CLIENT_AUTH_ENABLED=1
|
|
fi
|
|
|
|
# Usual psk server / psk client. This use case is tested in
|
|
# tests/unit.test and is used here for just checking if PSK is enabled
|
|
port=0
|
|
./examples/server/server -s -R "$ready_file" -p $port &
|
|
server_pid=$!
|
|
create_port
|
|
$TIMEOUT_KILL_2M ./examples/client/client -s -p $port
|
|
RESULT=$?
|
|
remove_ready_file
|
|
if timed_out $RESULT; then
|
|
echo -e "\n\nPSK probe client timed out"
|
|
do_cleanup
|
|
exit 1
|
|
fi
|
|
# if fail here then is a settings issue so return 0
|
|
if [ $RESULT -ne 0 ]; then
|
|
echo -e "\n\nPSK not enabled"
|
|
do_cleanup
|
|
exit 0
|
|
fi
|
|
echo ""
|
|
|
|
# client test against the server
|
|
###############################
|
|
|
|
$TIMEOUT_KILL_2M ./examples/client/client -v 3 2>&1 | grep -- 'Bad SSL version'
|
|
pipe_rc=("${PIPESTATUS[@]}")
|
|
if timed_out "${pipe_rc[0]}"; then
|
|
echo "client version probe timed out"
|
|
exit 1
|
|
fi
|
|
if [ "${pipe_rc[1]}" -ne 0 ]; then
|
|
# Usual server / client. This use case is tested in
|
|
# tests/unit.test and is used here for just checking if cipher suite
|
|
# is available (one case for example is with disable-asn)
|
|
port=0
|
|
./examples/server/server -R "$ready_file" -p $port -l DHE-RSA-AES128-SHA:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-DES-CBC3-SHA &
|
|
server_pid=$!
|
|
create_port
|
|
$TIMEOUT_KILL_2M ./examples/client/client -p $port
|
|
RESULT=$?
|
|
remove_ready_file
|
|
if timed_out $RESULT; then
|
|
echo -e "\n\nnon PSK suite probe client timed out"
|
|
do_cleanup
|
|
exit 1
|
|
fi
|
|
# if fail here then is a settings issue so return 0
|
|
if [ $RESULT -ne 0 ]; then
|
|
echo -e "\n\nIssue with chosen non PSK suites"
|
|
do_cleanup
|
|
exit 0
|
|
fi
|
|
echo ""
|
|
|
|
# psk server with non psk client
|
|
port=0
|
|
./examples/server/server -j -R "$ready_file" -p $port &
|
|
server_pid=$!
|
|
create_port
|
|
$TIMEOUT_KILL_2M ./examples/client/client -p $port
|
|
RESULT=$?
|
|
remove_ready_file
|
|
if [ $RESULT -ne 0 ]; then
|
|
echo -e "\n\nClient connection failed"
|
|
do_cleanup
|
|
exit 1
|
|
fi
|
|
echo ""
|
|
|
|
if [ "$CLIENT_AUTH_ENABLED" != "" ]; then
|
|
# check fail if no auth, psk server with non psk client
|
|
echo "Checking fail when not sending peer cert"
|
|
port=0
|
|
./examples/server/server -j -R "$ready_file" -p $port &
|
|
server_pid=$!
|
|
create_port
|
|
$TIMEOUT_KILL_2M ./examples/client/client -x -p $port
|
|
RESULT=$?
|
|
remove_ready_file
|
|
if timed_out $RESULT; then
|
|
echo -e "\n\nClient timed out, expected a connection failure"
|
|
do_cleanup
|
|
exit 1
|
|
fi
|
|
if [ $RESULT -eq 0 ]; then
|
|
echo -e "\n\nClient connected when supposed to fail"
|
|
do_cleanup
|
|
exit 1
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
echo -e "\nALL Tests Passed"
|
|
|
|
exit 0
|
|
|