mrc0mmand / rpms / openldap

Forked from rpms/openldap 3 years ago
Clone

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

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