From 34e9fd7e85b3acf48f8511cf5a5013f69ac6caa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Frauenschl=C3=A4ger?= Date: Thu, 26 Nov 2026 12:13:40 +0100 Subject: [PATCH 1/4] test.h: report the ephemeral UDP port in single-threaded builds udp_accept resolved a -p 0 bind with getsockname only without SINGLE_THREADED, so a single-threaded DTLS server wrote port 0 to its ready file. dtls.test and dtlscid.test skipped in those builds, and any script that starts every DTLS server with -p 0 -R fails there. The lookup does not depend on threads; keep only the TIRTOS exclusion, and drop the threading requirement from the comments and skip messages of dtls.test and dtlscid.test. --- scripts/dtls.test | 13 +++---------- scripts/dtlscid.test | 12 +++--------- wolfssl/test.h | 2 +- 3 files changed, 7 insertions(+), 20 deletions(-) diff --git a/scripts/dtls.test b/scripts/dtls.test index eb1d835bf81..8524d924545 100755 --- a/scripts/dtls.test +++ b/scripts/dtls.test @@ -124,10 +124,7 @@ print(s.getsockname()[1]) s.close()' } -# A usable port is a non-zero decimal below 65536. Worth checking rather than -# assuming: a SINGLE_THREADED build never resolves the ephemeral port in -# udp_accept(), so the ready file legitimately contains 0 there, and pointing -# the proxy at port 0 would report every test as a DTLS failure instead. +# A usable port is a non-zero decimal below 65536. valid_port() { case "$1" in ''|*[!0-9]*) return 1 ;; @@ -162,11 +159,7 @@ if [ "$DTLS_VERSION" = "-v4" ]; then UDP_PROXY_EXTRA_ARGS="-u" fi -# Everything below depends on the server being able to report the port it bound. -# A SINGLE_THREADED or WOLFSSL_TIRTOS build never resolves an ephemeral port in -# udp_accept(), and a NO_FILESYSTEM or NETOS build compiles write_ready_file() -# to a no-op, so probe the capability once here rather than rediscovering it on -# every one of the tests below. +# Probe once whether the server can report the port it bound with -p 0 -R. check_ready_file_support() { local probe_pid counter port @@ -199,7 +192,7 @@ check_ready_file_support() { if ! check_ready_file_support; then echo 'skipping dtls.test because the server cannot report an ephemeral port' 1>&2 - echo 'with -p 0 -R (needs threads and a filesystem in the build).' 1>&2 + echo 'with -p 0 -R (needs a filesystem in the build).' 1>&2 exit 77 fi diff --git a/scripts/dtlscid.test b/scripts/dtlscid.test index 93a4d98d792..16e1f48bb55 100755 --- a/scripts/dtlscid.test +++ b/scripts/dtlscid.test @@ -68,9 +68,7 @@ WOLFSSL_ROOT=$(pwd) # runs - a second "make check" in another source tree, say - from sharing one. READY_FILE="$WOLFSSL_ROOT/wolfssl_dtlscid_ready$$" -# A usable port is a non-zero decimal below 65536. Worth checking rather than -# assuming: a SINGLE_THREADED or WOLFSSL_TIRTOS build never resolves the -# ephemeral port in udp_accept(), so the ready file legitimately contains 0. +# A usable port is a non-zero decimal below 65536. valid_port() { case "$1" in ''|*[!0-9]*) return 1 ;; @@ -78,11 +76,7 @@ valid_port() { [ "$1" -gt 0 ] && [ "$1" -lt 65536 ] } -# The test below depends on the server being able to report the port it bound. -# Besides the SINGLE_THREADED/WOLFSSL_TIRTOS case above, a NO_FILESYSTEM or -# NETOS build compiles write_ready_file() to a no-op and never creates the file -# at all. Probe the capability once and skip, rather than report a build-wide -# limitation as a CID test failure. +# Probe once whether the server can report the port it bound with -p 0 -R. check_ready_file_support() { local probe_pid counter port @@ -115,7 +109,7 @@ check_ready_file_support() { if ! check_ready_file_support; then echo 'skipping dtlscid.test because the server cannot report an ephemeral' 1>&2 - echo 'port with -p 0 -R (needs threads and a filesystem in the build).' 1>&2 + echo 'port with -p 0 -R (needs a filesystem in the build).' 1>&2 exit 77 fi diff --git a/wolfssl/test.h b/wolfssl/test.h index 3e1f42b00cf..c69d9a28473 100644 --- a/wolfssl/test.h +++ b/wolfssl/test.h @@ -1974,7 +1974,7 @@ static WC_INLINE void udp_accept(SOCKET_T* sockfd, SOCKET_T* clientfd, if (bind(*sockfd, (const struct sockaddr*)&addr, sizeof(addr)) != 0) err_sys_with_errno("tcp bind failed"); - #if !defined(WOLFSSL_TIRTOS) && !defined(SINGLE_THREADED) + #if !defined(WOLFSSL_TIRTOS) if (port == 0) { socklen_t len = sizeof(addr); if (getsockname(*sockfd, (struct sockaddr*)&addr, &len) == 0) { From ebd1afa5cbe1b788365acb079e3347e3e1828ca0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Frauenschl=C3=A4ger?= Date: Thu, 26 Nov 2026 13:01:39 +0100 Subject: [PATCH 2/4] test.h: store the ready port in single-threaded builds udp_accept and tcp_accept set ready->ready and ready->port only without SINGLE_THREADED, although the fields exist in every build and only the condition variable needs threads. The example server copies ready->port back when started with -p 0, so a single-threaded DTLS server looping with -r or -i kept port 0 and bound a new ephemeral port on every accept, and a client resuming to the reported port got no answer. WOLFSSL_COND is never defined with SINGLE_THREADED, so its guards alone keep the signalling out of those builds. --- wolfssl/test.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/wolfssl/test.h b/wolfssl/test.h index c69d9a28473..6092249b4a9 100644 --- a/wolfssl/test.h +++ b/wolfssl/test.h @@ -1990,7 +1990,6 @@ static WC_INLINE void udp_accept(SOCKET_T* sockfd, SOCKET_T* clientfd, #endif if (args != NULL && args->signal != NULL) { -#ifndef SINGLE_THREADED tcp_ready* ready = args->signal; #ifdef WOLFSSL_COND THREAD_CHECK_RET(wolfSSL_CondStart(&ready->cond)); @@ -2002,7 +2001,6 @@ static WC_INLINE void udp_accept(SOCKET_T* sockfd, SOCKET_T* clientfd, THREAD_CHECK_RET(wolfSSL_CondSignal(&ready->cond)); THREAD_CHECK_RET(wolfSSL_CondEnd(&ready->cond)); #endif -#endif /* !SINGLE_THREADED */ } else { fprintf(stderr, "args or args->signal was NULL. Not setting ready info."); @@ -2032,7 +2030,6 @@ static WC_INLINE void tcp_accept(SOCKET_T* sockfd, SOCKET_T* clientfd, if(do_listen) { tcp_listen(sockfd, &port, useAnyAddr, udp, sctp); -#ifndef SINGLE_THREADED /* signal ready to tcp_accept */ if (args) ready = args->signal; @@ -2047,7 +2044,6 @@ static WC_INLINE void tcp_accept(SOCKET_T* sockfd, SOCKET_T* clientfd, THREAD_CHECK_RET(wolfSSL_CondEnd(&ready->cond)); #endif } -#endif /* !SINGLE_THREADED */ if (ready_file) { write_ready_file(args, port); From 452357ca3c01ceebca4e1ba189538a5dbbefc25a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Frauenschl=C3=A4ger?= Date: Thu, 26 Nov 2026 12:01:16 +0100 Subject: [PATCH 3/4] rsapss.test: let the kernel pick the server ports The script drew a random port from 49512-65535 for each of its cases and checked it with ss or netstat before starting the server. On macOS that range is the ephemeral port range, there is no bwrap to isolate the run, and the netstat check is a snapshot: an outbound connection from a test running in parallel can take the port before the server binds it. The Jenkins aarch64 macOS leg fails with "tcp bind failed: Address already in use" since the script landed. Start the wolfSSL server with -p 0 -R and read the bound port from the ready file, as resume.test and dtls.test do, and start s_server with -accept 0 and read the port from its ACCEPT line. Both also signal that the server is listening, so the netstat polling goes away. A case whose server never reports a port fails without running the client. --- scripts/rsapss.test | 100 +++++++++++--------------------------------- 1 file changed, 24 insertions(+), 76 deletions(-) diff --git a/scripts/rsapss.test b/scripts/rsapss.test index d39f69c47e3..599944cca58 100755 --- a/scripts/rsapss.test +++ b/scripts/rsapss.test @@ -107,63 +107,6 @@ elif [ "${AM_BWRAPPED-}" != "yes" ]; then unset AM_BWRAPPED fi -# need a unique port since may run the same time as testsuite -# Track ports already assigned in this script run to prevent intra-run collisions -used_ports=() - -generate_port() { - #-------------------------------------------------------------------------# - # Generate a random port number, guaranteed unique within this script run. - # Checks both the intra-run used_ports list and system-level bound ports. - #-------------------------------------------------------------------------# - local attempts=0 collision p - - while true; do - if [[ "$OSTYPE" == "linux"* ]]; then - p=$(($(od -An -N2 /dev/urandom) % (65535-49512) + 49512)) - elif [[ "$OSTYPE" == "darwin"* ]]; then - p=$(($(od -An -N2 /dev/random) % (65535-49512) + 49512)) - else - echo "skipping due to unsupported OS" - exit 0 - fi - - # Check against ports already assigned in this run - collision=0 - for up in "${used_ports[@]}"; do - if [ "$up" = "$p" ]; then - collision=1 - break - fi - done - - # Also check if the port is already bound on this system - if [ "$collision" -eq 0 ]; then - # TCP and UDP, established as well as listening, matched on the - # local port. -lnt saw only TCP listeners, so it was blind to the - # UDP sockets the DTLS cases here bind and to a port held by an - # unrelated outbound connection - both of which still block bind. - # A false positive only costs another iteration of this loop. - if command -v ss &>/dev/null; then - [ -n "$(ss -Hantu "sport = :${p}" 2>/dev/null)" ] && collision=1 - elif command -v netstat &>/dev/null; then - netstat -an 2>/dev/null | grep -q "[:.]${p}[[:space:]]" && collision=1 - fi - fi - - [ "$collision" -eq 0 ] && break - - ((attempts++)) - if [ "$attempts" -ge 100 ]; then - echo "ERROR: generate_port could not find a free port after 100 attempts" - exit 1 - fi - done - - port=$p - used_ports+=("$p") -} - WOLFSSL_SERVER=./examples/server/server WOLFSSL_CLIENT=./examples/client/client @@ -204,7 +147,7 @@ fail_case() { echo "--- wolfSSL/OpenSSL server output ---" cat rsapss.server.log echo "--- client output ---" - cat rsapss.client.log + cat rsapss.client.log 2>/dev/null fails=$((fails+1)) } @@ -219,22 +162,25 @@ no_connection() { grep -q "can't load" rsapss.server.log } -# Wait up to five seconds for the server to bind $port: a fixed pause falls -# short on a loaded machine. Without ss or netstat, pause as before. -wait_for_server() { +# Wait up to five seconds for the server to report the port it bound. +wait_for_port() { local i=0 + port="" while [ "$i" -lt 50 ]; do - if command -v ss >/dev/null 2>&1; then - [ -n "$(ss -Hantu "sport = :$port" 2>/dev/null)" ] && return - elif command -v netstat >/dev/null 2>&1; then - netstat -an 2>/dev/null | grep -q "[:.]${port}[[:space:]]" && return - else - sleep 1 - return - fi + port="$("$@" 2>/dev/null)" + [ -n "$port" ] && return 0 + kill -0 "$server_pid" 2>/dev/null || return 1 sleep 0.1 i=$((i+1)) done + return 1 +} + +no_port_case() { + kill $server_pid 2>/dev/null + wait $server_pid 2>/dev/null + fail_case "$1: server reported no port" + rm -f rsapss.server.log rsapss.ready } # SignatureScheme code point (RFC 8446 4.2.3) of a scheme name. @@ -308,11 +254,12 @@ wire_sig_scheme() { wolfssl_server_case() { local name="$1" expect="$2" sargs="$3" cargs="$4" result cases=$((cases+1)) - generate_port - $TIMEOUT_KILL_2M $WOLFSSL_SERVER -p "$port" $SVR_NO_CRL $sargs \ + rm -f rsapss.ready + $TIMEOUT_KILL_2M $WOLFSSL_SERVER -p 0 -R rsapss.ready $SVR_NO_CRL $sargs \ > rsapss.server.log 2>&1 & server_pid=$! - wait_for_server + wait_for_port sed -n '/^[1-9][0-9]*$/p' rsapss.ready || + { no_port_case "$name"; return; } echo "test connection" | $TIMEOUT_KILL_2M $OPENSSL s_client $V4V6_FLAG \ -connect "$LOCALHOST:$port" -msg -cipher DEFAULT:!kRSA \ -legacy_renegotiation $cargs > rsapss.client.log 2>&1 @@ -332,7 +279,7 @@ wolfssl_server_case() { "$(scheme_code "$expect")" ]; then fail_case "$name: server did not sign with $expect" fi - rm -f rsapss.server.log rsapss.client.log + rm -f rsapss.server.log rsapss.client.log rsapss.ready } # OpenSSL s_server with client auth, wolfSSL client: $1 name, $2 scheme the @@ -343,13 +290,14 @@ openssl_server_case() { local name="$1" expect="$2" sargs="$3" cargs="$4" ccert="$5" cca="$6" local result cases=$((cases+1)) - generate_port - $TIMEOUT_KILL_2M $OPENSSL s_server $V4V6_FLAG -www -accept "$port" \ + rm -f rsapss.server.log + $TIMEOUT_KILL_2M $OPENSSL s_server $V4V6_FLAG -www -accept 0 \ -Verify 1 -CAfile "$cca" \ -cert "$CERT_DIR"/server-cert.pem -key "$CERT_DIR"/server-key.pem \ -msg $sargs > rsapss.server.log 2>&1 & server_pid=$! - wait_for_server + wait_for_port sed -n 's/^ACCEPT .*:\([1-9][0-9]*\)$/\1/p' rsapss.server.log || + { no_port_case "$name"; return; } $TIMEOUT_KILL_2M $WOLFSSL_CLIENT -p "$port" $CLI_NO_CRL -g \ -A "$CERT_DIR"/ca-cert.pem $ccert $cargs > rsapss.client.log 2>&1 result=$? From 334ed6583a4a33877e28ef55575d628c5153d659 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Frauenschl=C3=A4ger?= Date: Thu, 26 Nov 2026 15:51:20 +0100 Subject: [PATCH 4/4] rsapss.test: pin the OpenSSL client certificate signature to SHA-256 The "PSS server, PSS client certificate" case fails on a Jenkins leg with OpenSSL 1.1.1: s_client signs its CertificateVerify with rsa_pss_pss_sha512, the first PSS scheme in the wolfSSL server's CertificateRequest, and its id-RSASSA-PSS key, which declares SHA-256, refuses with "digest not allowed". OpenSSL 1.1.1f picks rsa_pss_pss_sha256 for the same handshake, so the result depends on which 1.1.1 build the host has, and the version check lets every 1.1.1 through. Offer that client only rsa_pss_pss_sha256 for its own signature with -client_sigalgs, the one scheme the key allows. --- scripts/rsapss.test | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/rsapss.test b/scripts/rsapss.test index 599944cca58..fbe1bc293e6 100755 --- a/scripts/rsapss.test +++ b/scripts/rsapss.test @@ -356,8 +356,10 @@ for ver in tls12 tls13 dtls12; do wolfssl_server_case "$ver PSS server, rsa_pss_rsae_* only offered" FAIL \ "$sv -d $PSS_SVR" "$cv -sigalgs rsa_pss_rsae_sha256" if [ "$SVR_CLI_CERT" = yes ]; then + # Older OpenSSL 1.1.1 clients ignore the key's SHA-256 restriction. wolfssl_server_case "$ver PSS server, PSS client certificate" rsa_pss_pss_sha256 \ - "$sv $PSS_SVR -A $CERT_DIR/rsapss/client-rsapss.pem" "$cv $PSS_CLI_OPENSSL" + "$sv $PSS_SVR -A $CERT_DIR/rsapss/client-rsapss.pem" \ + "$cv $PSS_CLI_OPENSSL -client_sigalgs rsa_pss_pss_sha256" fi wolfssl_server_case "$ver rsaEncryption server, rsa_pss_rsae_*" rsa_pss_rsae_sha256 \ "$sv -d $RSA_SVR" "$cv -sigalgs rsa_pss_rsae_sha256:rsa_pss_pss_sha256"