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

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