]> www.infradead.org Git - users/dwmw2/openconnect.git/commitdiff
Allow tests to run over IPv6 as well as Legacy IP
authorDavid Woodhouse <dwmw2@infradead.org>
Fri, 5 Apr 2024 16:23:22 +0000 (17:23 +0100)
committerDavid Woodhouse <dwmw2@infradead.org>
Tue, 7 Jan 2025 12:17:08 +0000 (12:17 +0000)
When run in an environment with no Legacy IP addresses, or no IPv6 addresses,
AI_ADDRCONFIG will cause getaddrinfo() not to return addresses of that type.

So when running in an IPv6-only environment, ocserv doesn't listen on Legacy
IP. And thus the tests fail. Fix this by using a hostname 'sockwrap' for the
test connections, and providing '--resolve' arguments for both the Legacy IP
and IPv6 addresses handled by libsocket_wrapper.

Some of the python test servers which don't use AI_ADDRCONFIG do still work
on Legacy IP, so leave those alone for now.

We recently added '-4' to the socat invocation for the nullppp tests, for
similar reasons (becaose socat started listening on IPv6 by default). We
can remove that now too.

Closes #721

Signed-off-by: David Woodhouse <dwmw2@infradead.org>
13 files changed:
tests/auth-certificate
tests/auth-hwtpm
tests/auth-multicert
tests/auth-nonascii
tests/auth-pkcs11
tests/auth-swtpm
tests/auth-username-pass
tests/cert-fingerprint
tests/common.sh
tests/id-test
tests/obsolete-server-crypto
tests/pfs
tests/ppp-over-tls

index a0ebe8c121e9a6439425fa65de02e9b75f58edfe..b8a32f62acbdc2d4c02acec661955d0fea20581a 100755 (executable)
@@ -40,7 +40,7 @@ for KEY in ${key_list}; do
     else
        CERTARGS="--sslkey ${KEY} --key-password password -c ${KEY%-key-*}-cert.pem"
     fi
-    ( echo "test" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q $ADDRESS:443 -u test $CERTARGS --servercert=pin-sha256:xp3scfzy3rO --cookieonly --passwd-on-stdin --allow-insecure-crypto ) ||
+    ( echo "test" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q $SWRESOLVE sockwrap:443 -u test $CERTARGS --servercert=pin-sha256:xp3scfzy3rO --cookieonly --passwd-on-stdin --allow-insecure-crypto ) ||
        fail $PID "Could not connect with key ${KEY##*/}!"
 done
 
index 85f1cba5592b3fd80941968b851be23e03fa33b8..259f3cc68b506d3f40c8a83f40b102410f037dc0 100755 (executable)
@@ -44,7 +44,7 @@ for KEY in ${hwtpm_list}; do
        if [ ! -r "$CERT" ]; then CERT="${certdir}/$CERT"; fi
        CERTARGS="--sslkey ${KEY} -c ${CERT}"
     fi
-    if ! echo "test" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q $ADDRESS:443 -u test $CERTARGS --servercert=pin-sha256:xp3scfzy3rO --cookieonly -vvvvv --passwd-on-stdin; then
+    if ! echo "test" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q $SWRESOLVE sockwrap:443 -u test $CERTARGS --servercert=pin-sha256:xp3scfzy3rO --cookieonly -vvvvv --passwd-on-stdin; then
        fail $PID "Could not connect with key ${KEY##*/}!"
     fi
 done
index d2005559c409846d4c28c228a78e259dc7fddc3b..79972ea369d3e1015bf0eabb65c1efd33217aa74 100755 (executable)
@@ -43,7 +43,7 @@ echo -n "Authenticating using multiple certificate authentication... "
 ( echo "test" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT --cafile $CAFILE \
        --certificate $USERCERT --sslkey $USERKEY \
        --mca-certificate $USERCERT --mca-key $USERKEY \
-       -q $ADDRESS:443 $FINGERPRINT --authenticate >/dev/null 2>&1) ||
+       -q $SWRESOLVE sockwrap:443 $FINGERPRINT --authenticate >/dev/null 2>&1) ||
     fail $PID "Could not receive cookie from fake Cisco server"
 
 echo ok
index 08483395ddcbab2b46d8916ed866c3a07e0033c6..e36a471b8e39c9a1a5c6b1804d10ca98b88b86b5 100755 (executable)
@@ -36,7 +36,7 @@ set -x
 for CHARSET in UTF-8 ISO8859-2; do
     echo -n "Connecting to obtain cookie (with password charset ${CHARSET})... "
     CERTARGS="-c ${KEY} --key-password $(cat ${srcdir}/pass-${CHARSET})"
-    ( echo "test" | LC_ALL=cs_CZ.${CHARSET} LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q $ADDRESS:443 -u test $CERTARGS --servercert=pin-sha256:xp3scfzy3rO --cookieonly --passwd-on-stdin ) ||
+    ( echo "test" | LC_ALL=cs_CZ.${CHARSET} LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q $SWRESOLVE sockwrap:443 -u test $CERTARGS --servercert=pin-sha256:xp3scfzy3rO --cookieonly --passwd-on-stdin ) ||
        fail $PID "Could not connect with charset ${CHARSET}!"
 done
 
index 6f7e9a669c6c236e77dd3d923438471a645a3415..3ca7e7720ddd7902996b3cac46d42a773da9c3a9 100755 (executable)
@@ -39,7 +39,7 @@ for TOKEN in ${pkcs11_tokens}; do
        echo -n "Connecting to obtain cookie (token ${TOKEN} key ${KEY})... "
        CERTURI="pkcs11:token=${TOKEN};${KEY};pin-value=1234"
        ( echo "test" | SOFTHSM2_CONF=softhsm2.conf LD_PRELOAD=libsocket_wrapper.so \
-                           $OPENCONNECT -q $ADDRESS:443 -u test -c "${CERTURI}" --key-password 1234 --servercert=pin-sha256:xp3scfzy3rO --cookieonly --passwd-on-stdin ) ||
+                           $OPENCONNECT -q $SWRESOLVE sockwrap:443 -u test -c "${CERTURI}" --key-password 1234 --servercert=pin-sha256:xp3scfzy3rO --cookieonly --passwd-on-stdin ) ||
            fail $PID "Could not connect with token ${TOKEN} key ${KEY##*/}!"
     done
 done
index 15155c2e58a85fd735761ec7bff234b9eff7b6c5..d0be8b2b33c5781db01b0af9e540d65676250e45 100755 (executable)
@@ -66,7 +66,7 @@ for KEY in ${swtpm_list}; do
        if [ ! -r "$CERT" ]; then CERT="${certdir}/$CERT"; fi
        CERTARGS="--sslkey ${KEY} -c ${CERT}"
     fi
-    if ! echo "test" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q $ADDRESS:443 -u test $CERTARGS --servercert=pin-sha256:xp3scfzy3rO --cookieonly -vvvvv --passwd-on-stdin; then
+    if ! echo "test" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q $SWRESOLVE sockwrap:443 -u test $CERTARGS --servercert=pin-sha256:xp3scfzy3rO --cookieonly -vvvvv --passwd-on-stdin; then
        LD_PRELOAD=libsocket_wrapper.so ${SWTPM_IOCTL} --tcp 127.0.0.1:2322 -s
        fail $PID "Could not connect with key ${KEY##*/}!"
     fi
index c93ec2f8515df6fba7d18fcf17d9bb7857ffb4b4..cb7594779ee68d1fae07975c6067bba450273cf3 100755 (executable)
@@ -32,13 +32,13 @@ PID=$!
 wait_server $PID
 
 echo -n "Connecting to obtain cookie... "
-( echo "test" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q $ADDRESS:443 -u test --servercert=pin-sha256:xp3scfzy3rO --cookieonly >/dev/null 2>&1) ||
+( echo "test" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q $SWRESOLVE sockwrap:443 -u test --servercert=pin-sha256:xp3scfzy3rO --cookieonly >/dev/null 2>&1) ||
        fail $PID "Could not receive cookie from server"
 
 echo ok
 
 echo -n "Connecting to obtain cookie with wrong password... "
-( echo "tost" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q $ADDRESS:443 -u test --servercert=pin-sha256:xp3scfzy3rO --cookieonly >/dev/null 2>&1) &&
+( echo "tost" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q $SWRESOLVE sockwrap:443 -u test --servercert=pin-sha256:xp3scfzy3rO --cookieonly >/dev/null 2>&1) &&
        fail $PID "Received cookie when we shouldn't"
 
 echo ok
@@ -46,13 +46,13 @@ echo ok
 #test special characters
 
 echo -n "Connecting to obtain cookie... "
-( echo "!@#$%^&*()<>" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q $ADDRESS:443 -u "sp@c/al" --servercert=pin-sha256:xp3scfzy3rO --cookieonly >/dev/null 2>&1 ) ||
+( echo "!@#$%^&*()<>" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q $SWRESOLVE sockwrap:443 -u "sp@c/al" --servercert=pin-sha256:xp3scfzy3rO --cookieonly >/dev/null 2>&1 ) ||
        fail $PID "Could not receive cookie from server"
 
 echo ok
 
 echo -n "Connecting to obtain cookie with empty password... "
-( echo "" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q $ADDRESS:443 -u "empty" --servercert=pin-sha256:xp3scfzy3rO --cookieonly >/dev/null 2>&1 ) ||
+( echo "" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q $SWRESOLVE sockwrap:443 -u "empty" --servercert=pin-sha256:xp3scfzy3rO --cookieonly >/dev/null 2>&1 ) ||
        fail $PID "Could not receive cookie from server"
 
 echo ok
index cf4daf61250badece2702cfbdc61973e19f4b6ce..bc3ed37cda941b73dd8d7e73edf8d64e4f886e13 100755 (executable)
@@ -34,7 +34,7 @@ wait_server $PID
 expect_cert_fail() {
     SERVERCERT=$1
     echo -n "Testing with cert fingerprint $SERVERCERT..."
-    ( echo "test" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q $ADDRESS:443 -u test --servercert $SERVERCERT --cookieonly >/dev/null 2>&1) &&
+    ( echo "test" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q $SWRESOLVE sockwrap:443 -u test --servercert $SERVERCERT --cookieonly >/dev/null 2>&1) &&
        fail $PID "Accepted wrong fingerprint $SERVERCERT"
 
     echo "ok (rejected)"
@@ -43,7 +43,7 @@ expect_cert_fail() {
 expect_cert_success() {
     SERVERCERT=$1
     echo -n "Testing with cert fingerprint $SERVERCERT..."
-    ( echo "test" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q $ADDRESS:443 -u test --servercert $SERVERCERT --cookieonly >/dev/null 2>&1) ||
+    ( echo "test" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q $SWRESOLVE sockwrap:443 -u test --servercert $SERVERCERT --cookieonly >/dev/null 2>&1) ||
        fail $PID "Rejected good fingerprint $SERVERCERT"
 
     echo "ok (accepted)"
index 0383267e9a7e37b4ff258c57a9b680f659fb33d1..aecf9e273661c016925c66bcc5641a2e717f618a 100644 (file)
@@ -39,6 +39,7 @@ mkdir -p $SOCKDIR
 export SOCKET_WRAPPER_DIR=$SOCKDIR
 export SOCKET_WRAPPER_DEFAULT_IFACE=2
 ADDRESS=127.0.0.$SOCKET_WRAPPER_DEFAULT_IFACE
+SWRESOLVE="--resolve sockwrap:fd00::5357:5f0$SOCKET_WRAPPER_DEFAULT_IFACE --resolve sockwrap:127.0.0.$SOCKET_WRAPPER_DEFAULT_IFACE"
 OPENCONNECT="${OPENCONNECT:-${top_builddir}/openconnect}"${EXEEXT}
 LOGFILE="$SOCKDIR/log.$$.tmp"
 OCCTL_SOCKET="${OCCTL_SOCKET:-./occtl-comp-$$.socket}"
@@ -103,7 +104,7 @@ launch_simple_pppd() {
        #    the config packets exchanged, causing retries and leading to a longer negotiation period.
        #    [use `socat -x` for a hex log of I/O to/from the connected sockets]
 
-       LD_PRELOAD=libsocket_wrapper.so socat -t 120 -T 120 -4 -d -d \
+       LD_PRELOAD=libsocket_wrapper.so socat -t 120 -T 120 -d -d \
                 SYSTEM:"LD_PRELOAD= $SUDO $PPPD noauth local debug nodefaultroute logfile '$LOGFILE' $*",pty,raw,echo=0 \
                 OPENSSL-LISTEN:443,verify=0,cert="$CERT",key="$KEY" 2>&1 &
        PID=$!
index 68ba124059ce70b08bbf95c964ff169a9ae3fa64..3059a2f5c0a9dd854d04d1f4d066a40af71afd40 100755 (executable)
@@ -32,31 +32,31 @@ PID=$!
 wait_server $PID
 
 echo -n "Connecting with legacy hash... "
-( echo "test" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q $ADDRESS:443 -u test --servercert=e597837de5390ba6eaa0f9d656f035c8be6ec02b --cookieonly >/dev/null 2>&1) ||
+( echo "test" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q $SWRESOLVE sockwrap:443 -u test --servercert=e597837de5390ba6eaa0f9d656f035c8be6ec02b --cookieonly >/dev/null 2>&1) ||
        fail $PID "Could not receive cookie from server"
 
 echo ok
 
 echo -n "Connecting with SHA1 ID... "
-( echo "test" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q $ADDRESS:443 -u test --servercert=sha1:a82547f68f44d6351bef6cacd1d7b96e84f9dfa3 --cookieonly >/dev/null 2>&1) ||
+( echo "test" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q $SWRESOLVE sockwrap:443 -u test --servercert=sha1:a82547f68f44d6351bef6cacd1d7b96e84f9dfa3 --cookieonly >/dev/null 2>&1) ||
        fail $PID "Could not receive cookie from server"
 
 echo ok
 
 echo -n "Connecting with SHA256 ID... "
-( echo "test" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q $ADDRESS:443 -u test --servercert=sha256:c69dec71fcf2deb390b2ff4d70ebdeffc61556ffa91ebe2a3425c45eb365e6cf --cookieonly >/dev/null 2>&1) ||
+( echo "test" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q $SWRESOLVE sockwrap:443 -u test --servercert=sha256:c69dec71fcf2deb390b2ff4d70ebdeffc61556ffa91ebe2a3425c45eb365e6cf --cookieonly >/dev/null 2>&1) ||
        fail $PID "Could not receive cookie from server"
 
 echo ok
 
 echo -n "Connecting with SHA256 partial ID... "
-( echo "test" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q $ADDRESS:443 -u test --servercert=sha256:c69dec --cookieonly >/dev/null 2>&1) ||
+( echo "test" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q $SWRESOLVE sockwrap:443 -u test --servercert=sha256:c69dec --cookieonly >/dev/null 2>&1) ||
        fail $PID "Could not receive cookie from server"
 
 echo ok
 
 echo -n "Connecting with wrong SHA256 ID... "
-( echo "test" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q $ADDRESS:443 -u test --servercert=sha256:c69ded --cookieonly >/dev/null 2>&1) &&
+( echo "test" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q $SWRESOLVE sockwrap:443 -u test --servercert=sha256:c69ded --cookieonly >/dev/null 2>&1) &&
        fail $PID "Did connect to the server with wrong ID"
 
 echo ok
index 58d10dc9823e80e4d71f26c0d3063fce0d6055b3..060999dc8d5b21f7f611127f666df6e99449f687 100755 (executable)
@@ -55,13 +55,13 @@ PID=$!
 wait_server $PID
 
 echo -n "Connecting without --allow-insecure-crypto... "
-( echo "test" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q $ADDRESS:$PORT -u test --servercert=pin-sha256:xp3scfzy3rO --cookieonly >/dev/null 2>&1) &&
+( echo "test" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q $SWRESOLVE sockwrap:$PORT -u test --servercert=pin-sha256:xp3scfzy3rO --cookieonly >/dev/null 2>&1) &&
        fail $PID "Connected successfully when we shouldn't"
 
 echo ok
 
 echo -n "Connecting with --allow-insecure-crypto... "
-( echo "test" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q $ADDRESS:$PORT -u test --servercert=pin-sha256:xp3scfzy3rO --allow-insecure-crypto --cookieonly >/dev/null 2>&1) ||
+( echo "test" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q $SWRESOLVE sockwrap:$PORT -u test --servercert=pin-sha256:xp3scfzy3rO --allow-insecure-crypto --cookieonly >/dev/null 2>&1) ||
        fail $PID "Could not connect and obtain cookie with --allow-insecure-crypto"
 
 echo ok
index 596912cc4387dac2c32e970e6c02e81f79967a1a..451844aee21d302a072613b51cc609358ad556a2 100755 (executable)
--- a/tests/pfs
+++ b/tests/pfs
@@ -43,13 +43,13 @@ PID=$!
 wait_server $PID
 
 echo -n "Connecting with --pfs... "
-( echo "test" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q $ADDRESS:$PORT -u test --servercert=pin-sha256:xp3scfzy3rO --pfs --cookieonly >/dev/null 2>&1) &&
+( echo "test" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q $SWRESOLVE sockwrap:$PORT -u test --servercert=pin-sha256:xp3scfzy3rO --pfs --cookieonly >/dev/null 2>&1) &&
        fail $PID "Connected successfully when we shouldn't"
 
 echo ok
 
 echo -n "Connecting without --pfs... "
-( echo "test" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q $ADDRESS:$PORT -u test --servercert=pin-sha256:xp3scfzy3rO --cookieonly >/dev/null 2>&1) ||
+( echo "test" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q $SWRESOLVE sockwrap:$PORT -u test --servercert=pin-sha256:xp3scfzy3rO --cookieonly >/dev/null 2>&1) ||
        fail $PID "Could not connect and obtain cookie without --pfs"
 
 echo ok
index 03eb11962cf49ee10850ddff3f984ba3db45a978..9dd789b92b9bf39b1d76f54dcb29bcd293d7d7a7 100755 (executable)
@@ -54,7 +54,7 @@ echo "started in $(( $(date +%s) - start )) seconds"
 wait_server "$PID"
 echo -n "Connecting to it with openconnect --protocol=nullppp... "
 start=$(date +%s)
-LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q --protocol=nullppp $ADDRESS:443 -u test $FINGERPRINT --cookie "hdlc,term" -Ss '' >/dev/null 2>&1
+LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q --protocol=nullppp $SWRESOLVE sockwrap:443 -u test $FINGERPRINT --cookie "hdlc,term" -Ss '' >/dev/null 2>&1
 took=$(( $(date +%s) - start ))
 if grep -qF "$IPV4_SUCCESS_1" $LOGFILE && grep -qF "$IPV4_SUCCESS_2" $LOGFILE && grep -qF "$IPV6_SUCCESS_1" $LOGFILE && grep -qF "$IPV6_SUCCESS_2" $LOGFILE; then
     echo "ok (took $took seconds)"
@@ -75,7 +75,7 @@ echo "started in $(( $(date +%s) - start )) seconds"
 wait_server "$PID"
 echo -n "Connecting to it with openconnect --protocol=nullppp... "
 start=$(date +%s)
-LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q --protocol=nullppp $ADDRESS:443 -u test $FINGERPRINT --cookie "hdlc,term" -Ss '' >/dev/null 2>&1
+LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q --protocol=nullppp $SWRESOLVE sockwrap:443 -u test $FINGERPRINT --cookie "hdlc,term" -Ss '' >/dev/null 2>&1
 took=$(( $(date +%s) - start ))
 if grep -qF "$IPV4_SUCCESS_1" $LOGFILE && grep -qF "$IPV4_SUCCESS_2" $LOGFILE && grep -qF "$IPV6_SUCCESS_1" $LOGFILE && grep -qF "$IPV6_SUCCESS_2" $LOGFILE; then
     echo "ok (took $took seconds)"
@@ -96,7 +96,7 @@ echo "started in $(( $(date +%s) - start )) seconds"
 wait_server "$PID"
 echo -n "Connecting to it with openconnect --protocol=nullppp... "
 start=$(date +%s)
-LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q --protocol=nullppp $ADDRESS:443 -u test $FINGERPRINT --cookie "hdlc,term" -Ss '' >/dev/null 2>&1
+LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q --protocol=nullppp $SWRESOLVE sockwrap:443 -u test $FINGERPRINT --cookie "hdlc,term" -Ss '' >/dev/null 2>&1
 took=$(( $(date +%s) - start ))
 if grep -qF "$IPV4_SUCCESS_1" $LOGFILE && grep -qF "$IPV4_SUCCESS_2" $LOGFILE; then
     echo "ok (took $took seconds)"
@@ -117,7 +117,7 @@ echo "started in $(( $(date +%s) - start )) seconds"
 wait_server "$PID"
 echo -n "Connecting to it with openconnect --protocol=nullppp... "
 start=$(date +%s)
-LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q --protocol=nullppp $ADDRESS:443 -u test $FINGERPRINT --cookie "hdlc" -Ss '' >/dev/null 2>&1
+LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q --protocol=nullppp $SWRESOLVE sockwrap:443 -u test $FINGERPRINT --cookie "hdlc" -Ss '' >/dev/null 2>&1
 took=$(( $(date +%s) - start ))
 if grep -qF "$IPV6_SUCCESS_1" $LOGFILE && grep -qF "$IPV6_SUCCESS_2" $LOGFILE; then
     echo "ok (took $took seconds)"