openldap/tests/scripts/test067-tls
2018-06-14 16:19:10 +01:00

141 lines
3.7 KiB
Bash
Executable File

#! /bin/sh
# $OpenLDAP$
## This work is part of OpenLDAP Software <http://www.openldap.org/>.
##
## Copyright 1998-2017 The OpenLDAP Foundation.
## All rights reserved.
##
## Redistribution and use in source and binary forms, with or without
## modification, are permitted only as authorized by the OpenLDAP
## Public License.
##
## A copy of this license is available in the file LICENSE in the
## top-level directory of the distribution or, alternatively, at
## <http://www.OpenLDAP.org/license.html>.
echo "running defines.sh"
. $SRCDIR/scripts/defines.sh
if test $WITH_TLS = no ; then
echo "TLS support not available, test skipped"
exit 0
fi
mkdir -p $TESTDIR $DBDIR1
cp -r $DATADIR/tls $TESTDIR
cd $TESTWD
echo "Starting ldap:/// slapd on TCP/IP port $PORT1 and ldaps:/// slapd on $PORT2..."
. $CONFFILTER $BACKEND $MONITORDB < $TLSCONF > $CONF1
$SLAPD -f $CONF1 -h "$URI1 $SURI2" -d $LVL $TIMING > $LOG1 2>&1 &
PID=$!
if test $WAIT != 0 ; then
echo PID $PID
read foo
fi
KILLPIDS="$PID"
sleep 1
for i in 0 1 2 3 4 5; do
$LDAPSEARCH -s base -b "" -H $URI1 \
'objectclass=*' > /dev/null 2>&1
RC=$?
if test $RC = 0 ; then
break
fi
echo "Waiting 5 seconds for slapd to start..."
sleep 5
done
if test $RC != 0 ; then
echo "ldapsearch failed ($RC)!"
test $KILLSERVERS != no && kill -HUP $KILLPIDS
exit $RC
fi
echo -n "Using ldapsearch with startTLS with no server cert validation...."
$LDAPSEARCH -o tls_reqcert=never -ZZ -b "" -s base -H $URIP1 \
'@extensibleObject' > $SEARCHOUT 2>&1
RC=$?
if test $RC != 0 ; then
echo "ldapsearch (startTLS) failed ($RC)!"
exit $RC
else
echo "success"
fi
echo -n "Using ldapsearch with startTLS with hard require cert...."
$LDAPSEARCH -o tls_cacert=$TESTDIR/tls/ca/certs/testsuiteCA.crt -o tls_reqcert=hard -ZZ -b "" -s base -H $URIP1 \
'@extensibleObject' > $SEARCHOUT 2>&1
RC=$?
if test $RC != 0 ; then
echo "ldapsearch (startTLS) failed ($RC)!"
exit $RC
else
echo "success"
fi
if test $WITH_TLS_TYPE = openssl ; then
echo -n "Using ldapsearch with startTLS and specific protocol version...."
$LDAPSEARCH -o tls_cacert=$TESTDIR/tls/ca/certs/testsuiteCA.crt -o tls_reqcert=hard -o tls_protocol_min=3.3 -ZZ -b "" -s base -H $URIP1 \
'@extensibleObject' > $SEARCHOUT 2>&1
RC=$?
if test $RC != 0 ; then
echo "ldapsearch (protocol-min) failed ($RC)!"
exit $RC
else
echo "success"
fi
fi
echo -n "Using ldapsearch on $SURI2 with no server cert validation..."
$LDAPSEARCH -o tls_reqcert=never -b "cn=Subschema" -s base -H $SURIP2 \
'(&(objectClasses=top)(objectClasses=2.5.6.0))' cn objectClass \
>> $SEARCHOUT 2>&1
RC=$?
if test $RC != 0 ; then
echo "ldapsearch (ldaps) failed($RC)!"
exit $RC
else
echo "success"
fi
echo -n "Using ldapsearch on $SURI2 with reqcert HARD and no CA cert. Should fail..."
$LDAPSEARCH -o tls_reqcert=hard -b "cn=Subschema" -s base -H $SURIP2 \
'(&(objectClasses=top)(objectClasses=2.5.6.0))' cn objectClass \
>> $SEARCHOUT 2>&1
RC=$?
if test $RC = 0 ; then
echo "ldapsearch (ldaps) succeeded when it should have failed($RC)!"
exit 1
else
echo "failed correctly with error code ($RC)"
fi
echo -n "Using ldapsearch on $SURI2 with CA cert and reqcert HARD..."
$LDAPSEARCH -o tls_cacert=$TESTDIR/tls/ca/certs/testsuiteCA.crt -o tls_reqcert=hard -b "cn=Subschema" -s base -H $SURIP2 \
'(&(objectClasses=top)(objectClasses=2.5.6.0))' cn objectClass \
>> $SEARCHOUT 2>&1
RC=$?
if test $RC != 0 ; then
echo "ldapsearch (ldaps) failed ($RC)!"
exit $RC
else
echo "success"
fi
test $KILLSERVERS != no && kill -HUP $KILLPIDS
if test $RC != 0 ; then
echo ">>>>> Test failed"
else
echo ">>>>> Test succeeded"
RC=0
fi
test $KILLSERVERS != no && wait
exit $RC