xref: /netbsd-src/external/bsd/openldap/dist/tests/scripts/test068-sasl-tls-external (revision e670fd5c413e99c2f6a37901bb21c537fcd322d2)
1*e670fd5cSchristos#! /bin/sh
2*e670fd5cSchristos# $OpenLDAP$
3*e670fd5cSchristos## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4*e670fd5cSchristos##
5*e670fd5cSchristos## Copyright 1998-2021 The OpenLDAP Foundation.
6*e670fd5cSchristos## All rights reserved.
7*e670fd5cSchristos##
8*e670fd5cSchristos## Redistribution and use in source and binary forms, with or without
9*e670fd5cSchristos## modification, are permitted only as authorized by the OpenLDAP
10*e670fd5cSchristos## Public License.
11*e670fd5cSchristos##
12*e670fd5cSchristos## A copy of this license is available in the file LICENSE in the
13*e670fd5cSchristos## top-level directory of the distribution or, alternatively, at
14*e670fd5cSchristos## <http://www.OpenLDAP.org/license.html>.
15*e670fd5cSchristos
16*e670fd5cSchristosecho "running defines.sh"
17*e670fd5cSchristos. $SRCDIR/scripts/defines.sh
18*e670fd5cSchristos
19*e670fd5cSchristosif test $WITH_TLS = no ; then
20*e670fd5cSchristos        echo "TLS support not available, test skipped"
21*e670fd5cSchristos        exit 0
22*e670fd5cSchristosfi
23*e670fd5cSchristos
24*e670fd5cSchristosif test $WITH_SASL = no ; then
25*e670fd5cSchristos	echo "SASL support not available, test skipped"
26*e670fd5cSchristos	exit 0
27*e670fd5cSchristosfi
28*e670fd5cSchristos
29*e670fd5cSchristosmkdir -p $TESTDIR $DBDIR1
30*e670fd5cSchristoscp -r $DATADIR/tls $TESTDIR
31*e670fd5cSchristos
32*e670fd5cSchristoscd $TESTWD
33*e670fd5cSchristos
34*e670fd5cSchristosecho "Running slapadd to build slapd database..."
35*e670fd5cSchristos. $CONFFILTER $BACKEND < $TLSSASLCONF > $CONF1
36*e670fd5cSchristos$SLAPADD -f $CONF1 -l $LDIFORDERED
37*e670fd5cSchristosRC=$?
38*e670fd5cSchristosif test $RC != 0 ; then
39*e670fd5cSchristos        echo "slapadd failed ($RC)!"
40*e670fd5cSchristos        exit $RC
41*e670fd5cSchristosfi
42*e670fd5cSchristos
43*e670fd5cSchristosecho "Starting ldap:/// slapd on TCP/IP port $PORT1 and ldaps:/// slapd on $PORT2..."
44*e670fd5cSchristos$SLAPD -f $CONF1 -h "$URI1 $SURI2" -d $LVL > $LOG1 2>&1 &
45*e670fd5cSchristosPID=$!
46*e670fd5cSchristosif test $WAIT != 0 ; then
47*e670fd5cSchristos    echo PID $PID
48*e670fd5cSchristos    read foo
49*e670fd5cSchristosfi
50*e670fd5cSchristosKILLPIDS="$PID"
51*e670fd5cSchristos
52*e670fd5cSchristossleep 1
53*e670fd5cSchristos
54*e670fd5cSchristosfor i in 0 1 2 3 4 5; do
55*e670fd5cSchristos	$LDAPSEARCH -s base -b "" -H $URI1 \
56*e670fd5cSchristos		'objectclass=*' > /dev/null 2>&1
57*e670fd5cSchristos        RC=$?
58*e670fd5cSchristos        if test $RC = 0 ; then
59*e670fd5cSchristos                break
60*e670fd5cSchristos        fi
61*e670fd5cSchristos        echo "Waiting 5 seconds for slapd to start..."
62*e670fd5cSchristos        sleep 5
63*e670fd5cSchristosdone
64*e670fd5cSchristos
65*e670fd5cSchristosif test $RC != 0 ; then
66*e670fd5cSchristos	echo "ldapsearch failed ($RC)!"
67*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
68*e670fd5cSchristos	exit $RC
69*e670fd5cSchristosfi
70*e670fd5cSchristos
71*e670fd5cSchristosecho -n "Using ldapwhoami with SASL/EXTERNAL...."
72*e670fd5cSchristos$LDAPSASLWHOAMI -o tls_cacert=$TESTDIR/tls/ca/certs/testsuiteCA.crt -o tls_reqcert=hard \
73*e670fd5cSchristos	-o tls_cert=$TESTDIR/tls/certs/bjensen@mailgw.example.com.crt -o tls_key=$TESTDIR/tls/private/bjensen@mailgw.example.com.key -ZZ -Y EXTERNAL -H $URIP1 \
74*e670fd5cSchristos	> $TESTOUT 2>&1
75*e670fd5cSchristosRC=$?
76*e670fd5cSchristosif test $RC != 0 ; then
77*e670fd5cSchristos	echo "ldapwhoami (startTLS) failed ($RC)!"
78*e670fd5cSchristos	exit $RC
79*e670fd5cSchristoselse
80*e670fd5cSchristos	echo "success"
81*e670fd5cSchristosfi
82*e670fd5cSchristos
83*e670fd5cSchristosecho -n "Validating mapped SASL ID..."
84*e670fd5cSchristosecho 'dn:cn=barbara jensen,ou=information technology division,ou=people,dc=example,dc=com' > $TESTDIR/dn.out
85*e670fd5cSchristos$CMP $TESTDIR/dn.out $TESTOUT > $CMPOUT
86*e670fd5cSchristos
87*e670fd5cSchristosRC=$?
88*e670fd5cSchristosif test $RC != 0 ; then
89*e670fd5cSchristos	echo "Comparison failed"
90*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $PID
91*e670fd5cSchristos	exit $RC
92*e670fd5cSchristoselse
93*e670fd5cSchristos	echo "success"
94*e670fd5cSchristosfi
95*e670fd5cSchristos
96*e670fd5cSchristos# Exercise channel-bindings code in builds without SASL support
97*e670fd5cSchristosfor cb in "none" "tls-unique" "tls-endpoint" ; do
98*e670fd5cSchristos
99*e670fd5cSchristos	echo -n "Using ldapwhoami with SASL/EXTERNAL and SASL_CBINDING (${cb})...."
100*e670fd5cSchristos
101*e670fd5cSchristos	$LDAPSASLWHOAMI -o tls_cacert=$TESTDIR/tls/ca/certs/testsuiteCA.crt     \
102*e670fd5cSchristos	-o tls_cert=$TESTDIR/tls/certs/bjensen@mailgw.example.com.crt           \
103*e670fd5cSchristos	-o tls_key=$TESTDIR/tls/private/bjensen@mailgw.example.com.key          \
104*e670fd5cSchristos	-o tls_reqcert=hard -o SASL_CBINDING=$cb -ZZ -Y EXTERNAL -H $URIP1      \
105*e670fd5cSchristos	> $TESTOUT 2>&1
106*e670fd5cSchristos
107*e670fd5cSchristos	RC=$?
108*e670fd5cSchristos	if test $RC != 0 ; then
109*e670fd5cSchristos		echo "ldapwhoami failed ($RC)!"
110*e670fd5cSchristos		test $KILLSERVERS != no && kill -HUP $PID
111*e670fd5cSchristos		exit $RC
112*e670fd5cSchristos	else
113*e670fd5cSchristos		echo "success"
114*e670fd5cSchristos	fi
115*e670fd5cSchristosdone
116*e670fd5cSchristos
117*e670fd5cSchristos
118*e670fd5cSchristostest $KILLSERVERS != no && kill -HUP $KILLPIDS
119*e670fd5cSchristos
120*e670fd5cSchristosif test $RC != 0 ; then
121*e670fd5cSchristos	echo ">>>>> Test failed"
122*e670fd5cSchristoselse
123*e670fd5cSchristos	echo ">>>>> Test succeeded"
124*e670fd5cSchristos	RC=0
125*e670fd5cSchristosfi
126*e670fd5cSchristos
127*e670fd5cSchristostest $KILLSERVERS != no && wait
128*e670fd5cSchristos
129*e670fd5cSchristosexit $RC
130