Blame SOURCES/openldap-cbinding-ITS-9189_2-add-channel-bindings-tests.patch

ef2d9b
From 7b0017ad49a2290ec26cbcdffded8a527799e981 Mon Sep 17 00:00:00 2001
ef2d9b
From: Isaac Boukris <iboukris@gmail.com>
ef2d9b
Date: Sat, 18 Apr 2020 16:30:03 +0200
ef2d9b
Subject: [PATCH] ITS#9189 add channel-bindings tests
ef2d9b
ef2d9b
---
ef2d9b
 tests/data/slapd-sasl-gssapi.conf       |  3 +
ef2d9b
 tests/scripts/setup_kdc.sh              |  8 +++
ef2d9b
 tests/scripts/test068-sasl-tls-external | 22 +++++++
ef2d9b
 tests/scripts/test077-sasl-gssapi       | 83 ++++++++++++++++++++++++-
ef2d9b
 4 files changed, 113 insertions(+), 3 deletions(-)
ef2d9b
ef2d9b
diff --git a/tests/data/slapd-sasl-gssapi.conf b/tests/data/slapd-sasl-gssapi.conf
ef2d9b
index 611fc7097..29ab6040b 100644
ef2d9b
--- a/tests/data/slapd-sasl-gssapi.conf
ef2d9b
+++ b/tests/data/slapd-sasl-gssapi.conf
ef2d9b
@@ -63,3 +63,6 @@ rootpw          secret
ef2d9b
 
ef2d9b
 sasl-realm	@KRB5REALM@
ef2d9b
 sasl-host	localhost
ef2d9b
+
ef2d9b
+database	config
ef2d9b
+rootpw		secret
ef2d9b
diff --git a/tests/scripts/setup_kdc.sh b/tests/scripts/setup_kdc.sh
ef2d9b
index 1cb784075..98bcd9f96 100755
ef2d9b
--- a/tests/scripts/setup_kdc.sh
ef2d9b
+++ b/tests/scripts/setup_kdc.sh
ef2d9b
@@ -142,3 +142,11 @@ if test $RC != 0 ; then
ef2d9b
 		exit 0
ef2d9b
 	fi
ef2d9b
 fi
ef2d9b
+
ef2d9b
+HAVE_SASL_GSS_CBIND=no
ef2d9b
+
ef2d9b
+grep CHANNEL_BINDING $TESTDIR/plugin_out > /dev/null 2>&1
ef2d9b
+RC=$?
ef2d9b
+if test $RC = 0 ; then
ef2d9b
+	HAVE_SASL_GSS_CBIND=yes
ef2d9b
+fi
ef2d9b
diff --git a/tests/scripts/test068-sasl-tls-external b/tests/scripts/test068-sasl-tls-external
ef2d9b
index f647b1012..0b91aa197 100755
ef2d9b
--- a/tests/scripts/test068-sasl-tls-external
ef2d9b
+++ b/tests/scripts/test068-sasl-tls-external
ef2d9b
@@ -88,6 +88,28 @@ else
ef2d9b
 	echo "success"
ef2d9b
 fi
ef2d9b
 
ef2d9b
+# Exercise channel-bindings code in builds without SASL support
ef2d9b
+for cb in "none" "tls-unique" "tls-endpoint" ; do
ef2d9b
+
ef2d9b
+	echo -n "Using ldapwhoami with SASL/EXTERNAL and SASL_CBINDING (${cb})...."
ef2d9b
+
ef2d9b
+	$LDAPSASLWHOAMI -o tls_cacert=$TESTDIR/tls/ca/certs/testsuiteCA.crt     \
ef2d9b
+	-o tls_cert=$TESTDIR/tls/certs/bjensen@mailgw.example.com.crt           \
ef2d9b
+	-o tls_key=$TESTDIR/tls/private/bjensen@mailgw.example.com.key          \
ef2d9b
+	-o tls_reqcert=hard -o SASL_CBINDING=$cb -ZZ -Y EXTERNAL -H $URIP1      \
ef2d9b
+	> $TESTOUT 2>&1
ef2d9b
+
ef2d9b
+	RC=$?
ef2d9b
+	if test $RC != 0 ; then
ef2d9b
+		echo "ldapwhoami failed ($RC)!"
ef2d9b
+		test $KILLSERVERS != no && kill -HUP $PID
ef2d9b
+		exit $RC
ef2d9b
+	else
ef2d9b
+		echo "success"
ef2d9b
+	fi
ef2d9b
+done
ef2d9b
+
ef2d9b
+
ef2d9b
 test $KILLSERVERS != no && kill -HUP $KILLPIDS
ef2d9b
 
ef2d9b
 if test $RC != 0 ; then
ef2d9b
diff --git a/tests/scripts/test077-sasl-gssapi b/tests/scripts/test077-sasl-gssapi
ef2d9b
index 64abe16fe..19f665622 100755
ef2d9b
--- a/tests/scripts/test077-sasl-gssapi
ef2d9b
+++ b/tests/scripts/test077-sasl-gssapi
ef2d9b
@@ -21,7 +21,10 @@ if test $WITH_SASL = no ; then
ef2d9b
         exit 0
ef2d9b
 fi
ef2d9b
 
ef2d9b
-mkdir -p $TESTDIR $DBDIR1
ef2d9b
+SLAPTEST="$TESTWD/../servers/slapd/slaptest"
ef2d9b
+CONFDIR=$TESTDIR/slapd.d
ef2d9b
+
ef2d9b
+mkdir -p $TESTDIR $DBDIR1 $CONFDIR
ef2d9b
 cp -r $DATADIR/tls $TESTDIR
ef2d9b
 
ef2d9b
 cd $TESTWD
ef2d9b
@@ -32,7 +35,8 @@ echo "Starting KDC for SASL/GSSAPI tests..."
ef2d9b
 
ef2d9b
 echo "Running slapadd to build slapd database..."
ef2d9b
 . $CONFFILTER $BACKEND $MONITORDB < $SASLGSSAPICONF > $CONF1
ef2d9b
-$SLAPADD -f $CONF1 -l $LDIFORDERED
ef2d9b
+$SLAPTEST -f $CONF1 -F $CONFDIR
ef2d9b
+$SLAPADD -F $CONFDIR -l $LDIFORDERED
ef2d9b
 RC=$?
ef2d9b
 if test $RC != 0 ; then
ef2d9b
 	echo "slapadd failed ($RC)!"
ef2d9b
@@ -41,7 +45,7 @@ if test $RC != 0 ; then
ef2d9b
 fi
ef2d9b
 
ef2d9b
 echo "Starting ldap:/// slapd on TCP/IP port $PORT1 and ldaps:/// slapd on $PORT2..."
ef2d9b
-$SLAPD -f $CONF1 -h "$URI1 $SURI2" -d $LVL $TIMING > $LOG1 2>&1 &
ef2d9b
+$SLAPD -F $CONFDIR -h "$URI1 $SURI2" -d $LVL $TIMING > $LOG1 2>&1 &
ef2d9b
 PID=$!
ef2d9b
 if test $WAIT != 0 ; then
ef2d9b
     echo PID $PID
ef2d9b
@@ -144,6 +148,79 @@ else
ef2d9b
 	fi
ef2d9b
 fi
ef2d9b
 
ef2d9b
+if test $WITH_TLS = no ; then
ef2d9b
+        echo "TLS support not available, skipping channe-binding test"
ef2d9b
+elif test $HAVE_SASL_GSS_CBIND = no ; then
ef2d9b
+        echo "SASL has no channel-binding support in GSSAPI, test skipped"
ef2d9b
+else
ef2d9b
+	echo "Testing SASL/GSSAPI with SASL_CBINDING..."
ef2d9b
+
ef2d9b
+	for acb in "none" "tls-unique" "tls-endpoint" ; do
ef2d9b
+
ef2d9b
+		echo "Modifying slapd's olcSaslCBinding to ${acb} ..."
ef2d9b
+		$LDAPMODIFY -D cn=config -H $URI1 -w secret <<EOF > $TESTOUT 2>&1
ef2d9b
+dn: cn=config
ef2d9b
+changetype: modify
ef2d9b
+replace: olcSaslCBinding
ef2d9b
+olcSaslCBinding: ${acb}
ef2d9b
+EOF
ef2d9b
+		RC=$?
ef2d9b
+		if test $RC != 0 ; then
ef2d9b
+			echo "ldapmodify failed ($RC)!"
ef2d9b
+			kill $KDCPROC
ef2d9b
+			test $KILLSERVERS != no && kill -HUP $KILLPIDS
ef2d9b
+			exit $RC
ef2d9b
+		fi
ef2d9b
+
ef2d9b
+		for icb in "none" "tls-unique" "tls-endpoint" ; do
ef2d9b
+
ef2d9b
+			# The gnutls implemantation of "tls-unique" seems broken
ef2d9b
+			if test $icb = "tls-unique" -o $acb = "tls-unique" ; then
ef2d9b
+				if test $WITH_TLS_TYPE == gnutls  ; then
ef2d9b
+					continue
ef2d9b
+				fi
ef2d9b
+			fi
ef2d9b
+
ef2d9b
+			fail="no"
ef2d9b
+			if test $icb != $acb -a $acb != "none" ; then
ef2d9b
+				# This currently fails in MIT, but it is planned to be
ef2d9b
+				# fixed not to fail like in heimdal - avoid testing.
ef2d9b
+				if test $icb = "none" ; then
ef2d9b
+					continue
ef2d9b
+				fi
ef2d9b
+				# Otherwise unmatching bindings are expected to fail.
ef2d9b
+				fail="yes"
ef2d9b
+			fi
ef2d9b
+
ef2d9b
+			echo -n "Using ldapwhoami with SASL/GSSAPI and SASL_CBINDING "
ef2d9b
+			echo -ne "(client: ${icb},\tserver: ${acb}): "
ef2d9b
+
ef2d9b
+			$LDAPSASLWHOAMI -N -Y GSSAPI -H $URI1 -ZZ -o tls_reqcert=allow	\
ef2d9b
+			-o tls_cacert=$TESTDIR/tls/ca/certs/testsuiteCA.crt	\
ef2d9b
+			-o SASL_CBINDING=$icb > $TESTOUT 2>&1
ef2d9b
+
ef2d9b
+			RC=$?
ef2d9b
+			if test $RC != 0 ; then
ef2d9b
+				if test $fail = "no" ; then
ef2d9b
+					echo "test failed ($RC)!"
ef2d9b
+					kill $KDCPROC
ef2d9b
+					test $KILLSERVERS != no && kill -HUP $KILLPIDS
ef2d9b
+					exit $RC
ef2d9b
+				fi
ef2d9b
+			elif test $fail = "yes" ; then
ef2d9b
+				echo "failed: command succeeded unexpectedly."
ef2d9b
+				kill $KDCPROC
ef2d9b
+				test $KILLSERVERS != no && kill -HUP $KILLPIDS
ef2d9b
+				exit 1
ef2d9b
+			fi
ef2d9b
+
ef2d9b
+			echo "success"
ef2d9b
+			RC=0
ef2d9b
+		done
ef2d9b
+	done
ef2d9b
+fi
ef2d9b
+
ef2d9b
+
ef2d9b
 kill $KDCPROC
ef2d9b
 test $KILLSERVERS != no && kill -HUP $KILLPIDS
ef2d9b
 
ef2d9b
-- 
ef2d9b
2.26.2
ef2d9b