]> git.sur5r.net Git - openldap/blob - tests/scripts/test067-tls
2b245f5f546a3d3c2835432ef39c97e28560ef71
[openldap] / tests / scripts / test067-tls
1 #! /bin/sh
2 # $OpenLDAP$
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 1998-2017 The OpenLDAP Foundation.
6 ## All rights reserved.
7 ##
8 ## Redistribution and use in source and binary forms, with or without
9 ## modification, are permitted only as authorized by the OpenLDAP
10 ## Public License.
11 ##
12 ## A copy of this license is available in the file LICENSE in the
13 ## top-level directory of the distribution or, alternatively, at
14 ## <http://www.OpenLDAP.org/license.html>.
15
16 echo "running defines.sh"
17 . $SRCDIR/scripts/defines.sh
18
19 if test $WITH_TLS = no ; then
20         echo "TLS support not available, test skipped"
21         exit 0
22 fi
23
24 mkdir -p $TESTDIR $DBDIR1
25 cp -r $DATADIR/tls $TESTDIR
26
27 cd $TESTWD
28
29 echo "Starting ldap:/// slapd on TCP/IP port $PORT1 and ldaps:/// slapd on $PORT2..."
30 . $CONFFILTER $BACKEND $MONITORDB < $TLSCONF > $CONF1
31 $SLAPD -f $CONF1 -h "$URI1 $SURI2" -d $LVL $TIMING > $LOG1 2>&1 &
32 PID=$!
33 if test $WAIT != 0 ; then
34     echo PID $PID
35     read foo
36 fi
37 KILLPIDS="$PID"
38
39 sleep 1
40
41 for i in 0 1 2 3 4 5; do
42         $LDAPSEARCH -s base -b "" -H $URI1 \
43                 'objectclass=*' > /dev/null 2>&1
44         RC=$?
45         if test $RC = 0 ; then
46                 break
47         fi
48         echo "Waiting 5 seconds for slapd to start..."
49         sleep 5
50 done
51
52 if test $RC != 0 ; then
53         echo "ldapsearch failed ($RC)!"
54         test $KILLSERVERS != no && kill -HUP $KILLPIDS
55         exit $RC
56 fi
57
58 echo -n "Using ldapsearch with startTLS with no server cert validation...."
59 $LDAPSEARCH -o tls_reqcert=never -ZZ -b "" -s base -H $URIP1 \
60         '@extensibleObject' > $SEARCHOUT 2>&1
61 RC=$?
62 if test $RC != 0 ; then
63         echo "ldapsearch (startTLS) failed ($RC)!"
64         exit $RC
65 else
66         echo "success"
67 fi
68
69 echo -n "Using ldapsearch with startTLS with hard require cert...."
70 $LDAPSEARCH -o tls_cacert=$TESTDIR/tls/ca/certs/testsuiteCA.crt -o tls_reqcert=hard -ZZ -b "" -s base -H $URIP1 \
71         '@extensibleObject' > $SEARCHOUT 2>&1
72 RC=$?
73 if test $RC != 0 ; then
74         echo "ldapsearch (startTLS) failed ($RC)!"
75         exit $RC
76 else
77         echo "success"
78 fi
79
80 if test $WITH_TLS_TYPE = openssl ; then
81         echo -n "Using ldapsearch with startTLS and specific protocol version...."
82         $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 \
83                 '@extensibleObject' > $SEARCHOUT 2>&1
84         RC=$?
85         if test $RC != 0 ; then
86                 echo "ldapsearch (protocol-min) failed ($RC)!"
87                 exit $RC
88         else
89                 echo "success"
90         fi
91 fi
92
93 echo -n "Using ldapsearch on $SURI2 with no server cert validation..."
94 $LDAPSEARCH -o tls_reqcert=never -b "cn=Subschema" -s base -H $SURIP2 \
95         '(&(objectClasses=top)(objectClasses=2.5.6.0))' cn objectClass \
96         >> $SEARCHOUT  2>&1
97 RC=$?
98 if test $RC != 0 ; then
99         echo "ldapsearch (ldaps) failed($RC)!"
100         exit $RC
101 else
102         echo "success"
103 fi
104
105 echo -n "Using ldapsearch on $SURI2 with reqcert HARD and no CA cert.  Should fail..."
106 $LDAPSEARCH -o tls_reqcert=hard -b "cn=Subschema" -s base -H $SURIP2 \
107         '(&(objectClasses=top)(objectClasses=2.5.6.0))' cn objectClass \
108         >> $SEARCHOUT  2>&1
109 RC=$?
110 if test $RC = 0 ; then
111         echo "ldapsearch (ldaps) succeeded when it should have failed($RC)!"
112         exit 1
113 else
114         echo "failed correctly with error code ($RC)"
115 fi
116
117 echo -n "Using ldapsearch on $SURI2 with CA cert and reqcert HARD..."
118 $LDAPSEARCH -o tls_cacert=$TESTDIR/tls/ca/certs/testsuiteCA.crt -o tls_reqcert=hard -b "cn=Subschema" -s base -H $SURIP2 \
119         '(&(objectClasses=top)(objectClasses=2.5.6.0))' cn objectClass \
120         >> $SEARCHOUT  2>&1
121 RC=$?
122 if test $RC != 0 ; then
123         echo "ldapsearch (ldaps) failed ($RC)!"
124         exit $RC
125 else
126         echo "success"
127 fi
128
129 test $KILLSERVERS != no && kill -HUP $KILLPIDS
130
131 if test $RC != 0 ; then
132         echo ">>>>> Test failed"
133 else
134         echo ">>>>> Test succeeded"
135         RC=0
136 fi
137
138 test $KILLSERVERS != no && wait
139
140 exit $RC