]> git.sur5r.net Git - openldap/blob - tests/scripts/test031-component-filter
8fad5e7274f951cb981ab3c32cf292b7959e510a
[openldap] / tests / scripts / test031-component-filter
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 you use this script then
20 ## Make sure that you turn on LDAP_COMP_MATCH in slapd source codes
21 ## and --enable-modules is configured yes
22 if test "$AC_WITH_MODULES_ENABLED" != "yes" ; then
23         echo "dynamic module disabled, test skipped"
24         exit 0
25 fi
26
27 mkdir -p $TESTDIR $DBDIR1
28
29 ## Make sure that you set a proper path to component matching 
30 ## module directory in $COMPCONF
31 ## moduleload path/to/component/library/compmatch.la
32 ## otherwise it fails to execute slapd
33 echo "Running slapadd to build slapd database..."
34 . $CONFFILTER $BACKEND $MONITORDB < $COMPCONF > $ADDCONF
35 $SLAPADD -f $ADDCONF -l $LDIFCOMPMATCH
36 RC=$?
37 if test $RC != 0 ; then
38         echo "slapadd failed ($RC)!"
39         echo "Be sure to have a certificate module in tests/data/comp_libs "
40         echo "The module is in openldap/contrib/slapd-modules/comp_match"
41         echo "Test skipped."
42         exit 0
43 fi
44
45 echo "Running slapindex to index slapd database..."
46 . $CONFFILTER $BACKEND $MONITORDB < $CONF > $CONF1
47 $SLAPINDEX -f $CONF1
48 RC=$?
49 if test $RC != 0 ; then
50         echo "warning: slapindex failed ($RC)"
51         echo "  assuming no indexing support"
52 fi
53
54 echo "Starting slapd on TCP/IP port $PORT1..."
55 $SLAPD -f $ADDCONF -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
56 PID=$!
57 if test $WAIT != 0 ; then
58     echo PID $PID
59     read foo
60 fi
61 KILLPIDS="$PID"
62
63 sleep 1
64
65 echo "Testing slapd searching..."
66 for i in 0 1 2 3 4 5; do
67         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
68                 'objectclass=*' > /dev/null 2>&1
69         RC=$?
70         if test $RC = 0 ; then
71                 break
72         fi
73         echo "Waiting 5 seconds for slapd to start..."
74         sleep 5
75 done
76
77 if test $RC != 0 ; then
78         echo "ldapsearch failed ($RC)!"
79         test $KILLSERVERS != no && kill -HUP $KILLPIDS
80         exit $RC
81 fi
82
83 cat /dev/null > $SEARCHOUT
84
85 echo "Testing Component Filter Match RFC3687 Certificate searching:"
86 echo "# Testing Component Filter Match RFC3687 Certificate searching:" >> $SEARCHOUT
87
88 FILTER="(userCertificate:componentFilterMatch:=item:{ component \"toBeSigned.serialNumber\", rule allComponentsMatch, value 0 })"
89 echo "        f=$FILTER ..."
90 echo "#         f=$FILTER ..." >> $SEARCHOUT
91 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
92         "$FILTER" >> $SEARCHOUT 2>&1
93
94 RC=$?
95 if test $RC != 0 ; then
96         echo "ldapsearch failed ($RC)!"
97         test $KILLSERVERS != no && kill -HUP $KILLPIDS
98         exit $RC
99 fi
100
101 FILTER="(userCertificate:componentFilterMatch:=item:{ component \"toBeSigned.version\", rule allComponentsMatch, value 2 })"
102 echo "        f=$FILTER ..."
103 echo "#         f=$FILTER ..." >> $SEARCHOUT
104 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
105         "$FILTER" >> $SEARCHOUT 2>&1
106
107 RC=$?
108 if test $RC != 0 ; then
109         echo "ldapsearch failed ($RC)!"
110         test $KILLSERVERS != no && kill -HUP $KILLPIDS
111         exit $RC
112 fi
113
114 FILTER="(userCertificate:componentFilterMatch:=item:{ component \"toBeSigned.issuer.rdnSequence.1.1.value\", rule caseExactMatch, value \"US\" })"
115 echo "        f=$FILTER ..."
116 echo "#         f=$FILTER ..." >> $SEARCHOUT
117 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
118         "$FILTER" >> $SEARCHOUT 2>&1
119
120 RC=$?
121 if test $RC != 0 ; then
122         echo "ldapsearch failed ($RC)!"
123         test $KILLSERVERS != no && kill -HUP $KILLPIDS
124         exit $RC
125 fi
126
127 FILTER="(userCertificate:componentFilterMatch:=item:{ component \"toBeSigned.issuer.rdnSequence.1.1.value\", rule allComponentsMatch, value \"US\" })"
128 echo "        f=$FILTER ..."
129 echo "#         f=$FILTER ..." >> $SEARCHOUT
130 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
131         "$FILTER" >> $SEARCHOUT 2>&1
132
133 RC=$?
134 if test $RC != 0 ; then
135         echo "ldapsearch failed ($RC)!"
136         test $KILLSERVERS != no && kill -HUP $KILLPIDS
137         exit $RC
138 fi
139
140 FILTER="(userCertificate:componentFilterMatch:=item:{ component \"toBeSigned.issuer.rdnSequence\", rule allComponentsMatch, value { { { type 2.5.4.6 , value \"US\" } } } })"
141 echo "        f=$FILTER ..."
142 echo "#         f=$FILTER ..." >> $SEARCHOUT
143 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
144         "$FILTER" >> $SEARCHOUT 2>&1
145
146 RC=$?
147 if test $RC != 0 ; then
148         echo "ldapsearch failed ($RC)!"
149         test $KILLSERVERS != no && kill -HUP $KILLPIDS
150         exit $RC
151 fi
152
153 FILTER="(userCertificate:componentFilterMatch:=item:{ component \"toBeSigned.extensions.0\", rule integerMatch, value 3 })"
154 echo "        f=$FILTER ..."
155 echo "#         f=$FILTER ..." >> $SEARCHOUT
156 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
157         "$FILTER" >> $SEARCHOUT 2>&1
158
159 RC=$?
160 if test $RC != 0 ; then
161         echo "ldapsearch failed ($RC)!"
162         test $KILLSERVERS != no && kill -HUP $KILLPIDS
163         exit $RC
164 fi
165
166 FILTER="(userCertificate:componentFilterMatch:=item:{ component \"toBeSigned.extensions.\2a.extnID\", rule allComponentsMatch, value 2.5.29.14 })"
167 echo "        f=$FILTER ..."
168 echo "#         f=$FILTER ..." >> $SEARCHOUT
169 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
170         "$FILTER" >> $SEARCHOUT 2>&1
171
172 RC=$?
173 if test $RC != 0 ; then
174         echo "ldapsearch failed ($RC)!"
175         test $KILLSERVERS != no && kill -HUP $KILLPIDS
176         exit $RC
177 fi
178
179 FILTER="(userCertificate:componentFilterMatch:=not:item:{ component \"toBeSigned.extensions.\2a\", rule allComponentsMatch, value { extnID 2.5.29.19 , extnValue '30030101FF'H })"
180 echo "        f=$FILTER ..."
181 echo "#         f=$FILTER ..." >> $SEARCHOUT
182 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
183         "$FILTER" >> $SEARCHOUT 2>&1
184
185 RC=$?
186 if test $RC != 0 ; then
187         echo "ldapsearch failed ($RC)!"
188         test $KILLSERVERS != no && kill -HUP $KILLPIDS
189         exit $RC
190 fi
191
192 FILTER="(userCertificate:componentFilterMatch:=item:{ component \"toBeSigned.issuer.rdnSequence\", rule distinguishedNameMatch, value \"c=US\" })"
193 echo "        f=$FILTER ..."
194 echo "#         f=$FILTER ..." >> $SEARCHOUT
195 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
196         "$FILTER" >> $SEARCHOUT 2>&1
197
198 RC=$?
199 if test $RC != 0 ; then
200         echo "ldapsearch failed ($RC)!"
201         test $KILLSERVERS != no && kill -HUP $KILLPIDS
202         exit $RC
203 fi
204
205 FILTER="(userCertificate:componentFilterMatch:=item:{ component \"toBeSigned.issuer.rdnSequence.1\", rule rdnMatch, value \"c=US\" })"
206 echo "        f=$FILTER ..."
207 echo "#         f=$FILTER ..." >> $SEARCHOUT
208 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
209         "$FILTER" >> $SEARCHOUT 2>&1
210
211 RC=$?
212 if test $RC != 0 ; then
213         echo "ldapsearch failed ($RC)!"
214         test $KILLSERVERS != no && kill -HUP $KILLPIDS
215         exit $RC
216 fi
217
218 FILTER="(userCertificate:componentFilterMatch:=item:{ component \"toBeSigned.extensions.\2a.extnValue.content.\282.5.29.35\29.authorityCertSerialNumber\", rule integerMatch, value 0 })"
219 echo "        f=$FILTER ..."
220 echo "#         f=$FILTER ..." >> $SEARCHOUT
221 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
222         "$FILTER" >> $SEARCHOUT 2>&1
223
224 RC=$?
225 if test $RC != 0 ; then
226         echo "ldapsearch failed ($RC)!"
227         test $KILLSERVERS != no && kill -HUP $KILLPIDS
228         exit $RC
229 fi
230
231
232 FILTER="(userCertificate:componentFilterMatch:=item:{ component \"toBeSigned.subject.rdnSequence.\2a\", rule rdnMatch, value \"c=US\" })"
233 echo "        f=$FILTER ..."
234 echo "#         f=$FILTER ..." >> $SEARCHOUT
235 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
236         "$FILTER" >> $SEARCHOUT 2>&1
237
238 RC=$?
239 if test $RC != 0 ; then
240         echo "ldapsearch failed ($RC)!"
241         test $KILLSERVERS != no && kill -HUP $KILLPIDS
242         exit $RC
243 fi
244
245 FILTER="(userCertificate:componentFilterMatch:=item:{ component \"toBeSigned.subject.rdnSequence.\2a.\2a.value.\282.5.4.6\29\", rule caseExactMatch, value \"US\" })"
246 echo "        f=$FILTER ..."
247 echo "#         f=$FILTER ..." >> $SEARCHOUT
248 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
249         "$FILTER" >> $SEARCHOUT 2>&1
250
251 RC=$?
252 if test $RC != 0 ; then
253         echo "ldapsearch failed ($RC)!"
254         test $KILLSERVERS != no && kill -HUP $KILLPIDS
255         exit $RC
256 fi
257
258 # extraction filter
259 FILTER="(x509CertificateIssuer=c=US)"
260 echo "        f=$FILTER ..."
261 echo "#         f=$FILTER ..." >> $SEARCHOUT
262 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
263         "$FILTER" >> $SEARCHOUT 2>&1
264
265 RC=$?
266 if test $RC != 0 ; then
267         echo "ldapsearch failed ($RC)!"
268         test $KILLSERVERS != no && kill -HUP $KILLPIDS
269         exit $RC
270 fi
271
272 # extraction filter
273 FILTER="(x509CertificateSerial=0)"
274 echo "        f=$FILTER ..."
275 echo "#         f=$FILTER ..." >> $SEARCHOUT
276 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
277         "$FILTER" >> $SEARCHOUT 2>&1
278
279 RC=$?
280 if test $RC != 0 ; then
281         echo "ldapsearch failed ($RC)!"
282         test $KILLSERVERS != no && kill -HUP $KILLPIDS
283         exit $RC
284 fi
285
286 # extraction filter
287 FILTER="(x509CertificateSerialAndIssuer:certificateExactMatch:=0\$c=US)"
288 echo "        f=$FILTER ..."
289 echo "#         f=$FILTER ..." >> $SEARCHOUT
290 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
291         "$FILTER" >> $SEARCHOUT 2>&1
292
293 RC=$?
294 if test $RC != 0 ; then
295         echo "ldapsearch failed ($RC)!"
296         test $KILLSERVERS != no && kill -HUP $KILLPIDS
297         exit $RC
298 fi
299
300 FILTER="(certificateRevocationList:componentFilterMatch:=item:{ component \"tbsCertList.revokedCertificates.\2a.userCertificate\", rule integerMatch, value 952069669 })"
301 echo "        f=$FILTER ..."
302 echo "#         f=$FILTER ..." >> $SEARCHOUT
303 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
304         "$FILTER" >> $SEARCHOUT 2>&1
305
306 RC=$?
307 if test $RC != 0 ; then
308         echo "ldapsearch failed ($RC)!"
309         test $KILLSERVERS != no && kill -HUP $KILLPIDS
310         exit $RC
311 fi
312
313
314 test $KILLSERVERS != no && kill -HUP $KILLPIDS
315
316 echo "Filtering ldapsearch results..."
317 $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
318 echo "Comparing filter output..."
319 $CMP $SEARCHFLT $COMPSEARCHOUT > $CMPOUT
320
321 if test $? != 0 ; then
322         echo "Comparison failed"
323         exit 1
324 fi
325
326 echo ">>>>> Test succeeded"
327
328 test $KILLSERVERS != no && wait
329
330 exit 0