remove <heimbase.h> since its not used
[heimdal.git] / tests / gss / check-context.in
blob1b01e4917e3dd2899020433fcd3bd3c4bab480fc
1 #!/bin/sh
3 # Copyright (c) 2006 - 2008 Kungliga Tekniska Högskolan
4 # (Royal Institute of Technology, Stockholm, Sweden).
5 # All rights reserved.
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
9 # are met:
11 # 1. Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
14 # 2. Redistributions in binary form must reproduce the above copyright
15 # notice, this list of conditions and the following disclaimer in the
16 # documentation and/or other materials provided with the distribution.
18 # 3. Neither the name of the Institute nor the names of its contributors
19 # may be used to endorse or promote products derived from this software
20 # without specific prior written permission.
22 # THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
23 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 # ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
26 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 # SUCH DAMAGE.
34 # $Id$
37 srcdir="@srcdir@"
38 objdir="@objdir@"
40 # If there is no useful db support compile in, disable test
41 ../db/have-db || exit 77
43 R=TEST.H5L.SE
45 port=@port@
47 keytabfile=${objdir}/server.keytab
48 keytab="FILE:${keytabfile}"
49 nokeytab="FILE:no-such-keytab"
50 cache="FILE:krb5ccfile"
52 kinit="${TESTS_ENVIRONMENT} ../../kuser/kinit -c $cache ${afs_no_afslog}"
53 klist="${TESTS_ENVIRONMENT} ../../kuser/klist -c $cache"
54 kgetcred="${TESTS_ENVIRONMENT} ../../kuser/kgetcred -c $cache"
55 kadmin="${TESTS_ENVIRONMENT} ../../kadmin/kadmin -l -r $R"
56 kdc="${TESTS_ENVIRONMENT} ../../kdc/kdc --addresses=localhost -P $port"
57 ktutil="${TESTS_ENVIRONMENT} ../../admin/ktutil"
59 context="${TESTS_ENVIRONMENT} ../../lib/gssapi/test_context"
61 KRB5_CONFIG="${objdir}/krb5.conf"
62 export KRB5_CONFIG
64 KRB5CCNAME=${cache}
65 export KRB5CCNAME
67 rm -f ${keytabfile}
68 rm -f current-db*
69 rm -f out-*
70 rm -f mkey.file*
72 > messages.log
74 echo Creating database
75 ${kadmin} \
76 init \
77 --realm-max-ticket-life=1day \
78 --realm-max-renewable-life=1month \
79 ${R} || exit 1
81 # add both lucid and lucid.test.h5l.se to simulate aliases
82 ${kadmin} add -p p1 --use-defaults host/lucid.test.h5l.se@${R} || exit 1
83 ${kadmin} ext -k ${keytab} host/lucid.test.h5l.se@${R} || exit 1
84 ${kadmin} add -p p1 --use-defaults host/lucid@${R} || exit 1
85 ${kadmin} ext -k ${keytab} host/lucid@${R} || exit 1
87 ${kadmin} add -p p1 --use-defaults host/ok-delegate.test.h5l.se@${R} || exit 1
88 ${kadmin} mod --attributes=+ok-as-delegate host/ok-delegate.test.h5l.se@${R} || exit 1
89 ${kadmin} ext -k ${keytab} host/ok-delegate.test.h5l.se@${R} || exit 1
92 ${kadmin} add -p p1 --use-defaults host/short@${R} || exit 1
93 ${kadmin} mod --alias=host/long.test.h5l.se@${R} host/short@${R} || exit 1
94 # XXX ext should ext aliases too
95 ${kadmin} ext -k ${keytab} host/short@${R} || exit 1
96 ${ktutil} -k ${keytab} rename --no-delete host/short@${R} host/long.test.h5l.se@${R} || exit 1
98 ${kadmin} add -p kaka --use-defaults digest/${R}@${R} || exit 1
100 ${kadmin} add -p u1 --use-defaults user1@${R} || exit 1
102 # Create a server principal with no AES
103 ${kadmin} add -p p1 --use-defaults host/no-aes.test.h5l.se@${R} || exit 1
104 ${kadmin} get host/no-aes.test.h5l.se@${R} > tempfile || exit 1
105 ${kadmin} del_enctype host/no-aes.test.h5l.se@${R} \
106 aes256-cts-hmac-sha1-96 aes128-cts-hmac-sha1-96 || exit 1
107 ${kadmin} ext -k ${keytab} host/no-aes.test.h5l.se@${R} || exit 1
109 echo "Doing database check"
110 ${kadmin} check ${R} || exit 1
112 echo u1 > ${objdir}/foopassword
114 echo Starting kdc
115 ${kdc} &
116 kdcpid=$!
118 sh ${srcdir}/../kdc/wait-kdc.sh
119 if [ "$?" != 0 ] ; then
120 kill ${kdcpid}
121 exit 1
124 trap "kill ${kdcpid}; echo signal killing kdc; exit 1;" EXIT
126 testfailed="echo test failed; cat messages.log; exit 1"
128 echo "Getting client initial tickets" ; > messages.log
129 ${kinit} --password-file=${objdir}/foopassword --forwardable user1@${R} || \
130 { eval "$testfailed"; }
132 echo "======test unreadable/non existant keytab and its error message" ; > messages.log
133 ${context} --mech-type=krb5 host@lucid.test.h5l.se || \
134 { eval "$testfailed"; }
136 mv ${keytabfile} ${keytabfile}.no
138 echo "checking non existant keytabfile (krb5)" ; > messages.log
139 ${context} --mech-type=krb5 host@lucid.test.h5l.se > test_context.log 2>&1 && \
140 { eval "$testfailed"; }
141 grep ${keytabfile} test_context.log > /dev/null || \
142 { echo "string missing failed"; cat test_context.log ; eval "$testfailed"; }
143 echo "checking non existant keytabfile (spengo)" ; > messages.log
144 ${context} --mech-type=spnego host@lucid.test.h5l.se > test_context.log 2>&1 && \
145 { eval "$testfailed"; }
146 grep ${keytabfile} test_context.log > /dev/null || \
147 { echo "string missing failed"; cat test_context.log ; eval "$testfailed"; }
149 mv ${keytabfile}.no ${keytabfile}
151 echo "======test naming combinations"
152 echo "plain" ; > messages.log
153 ${context} --name-type=hostbased-service host@lucid.test.h5l.se || \
154 { eval "$testfailed"; }
155 echo "plain (krb5)" ; > messages.log
156 ${context} --name-type=krb5-principal-name host/lucid.test.h5l.se@${R} || \
157 { eval "$testfailed"; }
158 echo "plain (krb5 realmless)" ; > messages.log
159 ${context} --name-type=krb5-principal-name host/lucid.test.h5l.se || \
160 { eval "$testfailed"; }
161 echo "dns canon on (long name) OFF, need dns_wrapper" ; > messages.log
162 #${context} --dns-canon host@lucid.test.h5l.se || \
163 # { eval "$testfailed"; }
164 echo "dns canon off (long name)" ; > messages.log
165 ${context} --no-dns-canon host@lucid.test.h5l.se || \
166 { eval "$testfailed"; }
167 echo "dns canon off (short name)" ; > messages.log
168 ${context} --no-dns-canon host@lucid || \
169 { eval "$testfailed"; }
170 echo "dns canon off (short name, krb5)" ; > messages.log
171 ${context} --no-dns-canon --name-type=krb5-principal-name host/lucid@${R} || \
172 { eval "$testfailed"; }
173 echo "dns canon off (short name, krb5)" ; > messages.log
174 ${context} --no-dns-canon --name-type=krb5-principal-name host/lucid || \
175 { eval "$testfailed"; }
177 echo "======test context building"
178 for mech in krb5 krb5iov spnego spnegoiov; do
179 if [ "$mech" = "krb5iov" ] ; then
180 mech="krb5"
181 iov="--iov"
183 if [ "$mech" = "spnegoiov" ] ; then
184 mech="spnego"
185 iov="--iov"
188 echo "${mech} no-mutual ${iov}" ; > messages.log
189 ${context} --mech-type=${mech} \
190 --wrapunwrap ${iov} \
191 --name-type=hostbased-service host@lucid.test.h5l.se || \
192 { eval "$testfailed"; }
194 echo "${mech} mutual ${iov}" ; > messages.log
195 ${context} --mech-type=${mech} \
196 --mutual \
197 --wrapunwrap ${iov} \
198 --name-type=hostbased-service host@lucid.test.h5l.se || \
199 { eval "$testfailed"; }
201 echo "${mech} delegate ${iov}" ; > messages.log
202 ${context} --mech-type=${mech} \
203 --delegate \
204 --wrapunwrap ${iov} \
205 --name-type=hostbased-service host@lucid.test.h5l.se || \
206 { eval "$testfailed"; }
208 echo "${mech} mutual delegate ${iov}" ; > messages.log
209 ${context} --mech-type=${mech} \
210 --mutual --delegate \
211 --wrapunwrap ${iov} \
212 --name-type=hostbased-service host@lucid.test.h5l.se || \
213 { eval "$testfailed"; }
214 done
216 echo "======dce-style"
217 for mech in krb5 krb5iov spnego; do
218 iov=""
219 if [ "$mech" = "krb5iov" ] ; then
220 mech="krb5"
221 iov="--iov"
223 if [ "$mech" = "spnegoiov" ] ; then
224 mech="spnego"
225 iov="--iov"
228 echo "${mech}: dce-style ${iov}" ; > messages.log
229 ${context} \
230 --mech-type=${mech} \
231 --mutual \
232 --dce-style \
233 --wrapunwrap ${iov} \
234 --name-type=hostbased-service host@lucid.test.h5l.se || \
235 { eval "$testfailed"; }
237 done
239 echo "test gsskrb5_register_acceptor_identity (both positive and negative)"
241 cp ${keytabfile} ${keytabfile}.new
242 for mech in krb5 spnego; do
243 echo "${mech}: acceptor_identity positive" ; > messages.log
244 ${context} --gsskrb5-acceptor-identity=${keytabfile}.new \
245 --mech-type=$mech host@lucid.test.h5l.se || \
246 { eval "$testfailed"; }
248 echo "${mech}: acceptor_identity negative" ; > messages.log
249 ${context} --gsskrb5-acceptor-identity=${keytabfile}.foo \
250 --mech-type=$mech host@lucid.test.h5l.se 2>/dev/null && \
251 { eval "$testfailed"; }
252 done
254 rm ${keytabfile}.new
257 #echo "sasl-digest-md5"
258 #${context} --mech-type=sasl-digest-md5 \
259 # --name-type=hostbased-service \
260 # host@lucid.test.h5l.se || \
261 # { eval "$testfailed"; }
264 echo "====== gss-api session key check"
266 # this will break when oneone invents a cooler enctype then aes256-cts-hmac-sha1-96
267 coolenctype="aes256-cts-hmac-sha1-96"
268 limit_enctype="des3-cbc-sha1"
270 echo "Getting client initial tickets" ; > messages.log
271 ${kinit} --password-file=${objdir}/foopassword user1@${R} || \
272 { eval "$testfailed"; }
275 echo "Building context on cred w/o aes, but still ${coolenctype} session key" ; > messages.log
276 ${context} \
277 --mech-type=krb5 \
278 --mutual-auth \
279 --session-enctype=${coolenctype} \
280 --name-type=hostbased-service host@no-aes.test.h5l.se || \
281 { eval "$testfailed"; }
283 echo "Building context on cred, check if its limited still" ; > messages.log
284 ${context} \
285 --mech-type=krb5 \
286 --client-name=user1@${R} \
287 --limit-enctype="${limit_enctype}" \
288 --mutual-auth \
289 --name-type=hostbased-service host@no-aes.test.h5l.se || \
290 { eval "$testfailed"; }
293 echo "====== ok-as-delegate"
295 echo "Getting client initial tickets" ; > messages.log
296 ${kinit} --forwardable \
297 --password-file=${objdir}/foopassword user1@${R} || \
298 { eval "$testfailed"; }
300 echo "ok-as-delegate not used" ; > messages.log
301 ${context} \
302 --mech-type=krb5 \
303 --delegate \
304 --name-type=hostbased-service host@lucid.test.h5l.se || \
305 { eval "$testfailed"; }
307 echo "host without ok-as-delegate with policy-delegate" ; > messages.log
308 ${context} \
309 --mech-type=krb5 \
310 --policy-delegate \
311 --server-no-delegate \
312 --name-type=hostbased-service host@lucid.test.h5l.se || \
313 { eval "$testfailed"; }
315 echo "ok-as-delegate used by policy" ; > messages.log
316 ${context} \
317 --mech-type=krb5 \
318 --policy-delegate \
319 --name-type=hostbased-service host@ok-delegate.test.h5l.se || \
320 { eval "$testfailed"; }
322 echo "Getting client initial tickets with --ok-as-delgate" ; > messages.log
323 ${kinit} --ok-as-delegate --forwardable \
324 --password-file=${objdir}/foopassword user1@${R} || \
325 { eval "$testfailed"; }
327 echo "policy delegate to non delegate host" ; > messages.log
328 ${context} \
329 --mech-type=krb5 \
330 --policy-delegate \
331 --server-no-delegate \
332 --name-type=hostbased-service host@lucid.test.h5l.se || \
333 { eval "$testfailed"; }
335 echo "ok-as-delegate" ; > messages.log
336 ${context} \
337 --mech-type=krb5 \
338 --delegate \
339 --name-type=hostbased-service host@lucid.test.h5l.se || \
340 { eval "$testfailed"; }
342 echo "======export/import cred"
344 echo "export-import cred (krb5)" ; > messages.log
345 ${context} \
346 --mech-type=krb5 \
347 --delegate \
348 --export-import-cred \
349 --name-type=hostbased-service host@ok-delegate.test.h5l.se || \
350 { eval "$testfailed"; }
352 echo "export-import cred (spnego)" ; > messages.log
353 ${context} \
354 --mech-type=spnego \
355 --delegate \
356 --export-import-cred \
357 --name-type=hostbased-service host@ok-delegate.test.h5l.se || \
358 { eval "$testfailed"; }
361 echo "======time diffs between client and server"
363 echo "Getting client initial ticket" ; > messages.log
364 ${kinit} --password-file=${objdir}/foopassword user1@${R} || \
365 { eval "$testfailed"; }
367 echo "No time offset" ; > messages.log
368 ${context} \
369 --mech-type=krb5 \
370 --name-type=hostbased-service host@lucid.test.h5l.se || \
371 { eval "$testfailed"; }
373 echo "Getting client initial ticket" ; > messages.log
374 ${kinit} --password-file=${objdir}/foopassword user1@${R} || \
375 { eval "$testfailed"; }
377 echo "Server time offset" ; > messages.log
378 ${context} \
379 --mech-type=krb5 \
380 --mutual-auth \
381 --server-time-offset=3600 \
382 --max-loops=3 \
383 --name-type=hostbased-service host@lucid.test.h5l.se || \
384 { eval "$testfailed"; }
386 echo "Server time offset (cached ?)" ; > messages.log
387 ${context} \
388 --mech-type=krb5 \
389 --mutual-auth \
390 --server-time-offset=3600 \
391 --max-loops=2 \
392 --name-type=hostbased-service host@lucid.test.h5l.se || \
393 { eval "$testfailed"; }
395 echo "Getting client initial ticket" ; > messages.log
396 ${kinit} --password-file=${objdir}/foopassword user1@${R} || \
397 { eval "$testfailed"; }
398 # Pre-poplute the cache since tgs-req will fail since our time is wrong
399 ${kgetcred} host/lucid.test.h5l.se@${R} || \
400 { eval "$testfailed"; }
402 echo "Client time offset" ; > messages.log
403 ${context} \
404 --mech-type=krb5 \
405 --mutual-auth \
406 --client-time-offset=3600 \
407 --name-type=hostbased-service host@lucid.test.h5l.se || \
408 { eval "$testfailed"; }
410 echo "Getting client initial tickets (use-referrals)" ; > messages.log
411 ${kinit} \
412 --password-file=${objdir}/foopassword \
413 --use-referrals user1@${R} || \
414 { eval "$testfailed"; }
416 # XXX these tests really need to use somethat that resolve to something
417 ${context} \
418 --mech-type=krb5 \
419 host@short || \
420 { eval "$testfailed"; }
422 ${context} \
423 --mech-type=krb5 \
424 --name-type=krb5-principal-name host/short || \
425 { eval "$testfailed"; }
427 ${context} \
428 --mech-type=krb5 \
429 host@long.test.h5l.se || \
430 { eval "$testfailed"; }
432 ${context} \
433 --mech-type=krb5 \
434 --name-type=krb5-principal-name \
435 host/long.test.h5l.se || \
436 { eval "$testfailed"; }
438 trap "" EXIT
440 echo "killing kdc (${kdcpid})"
441 kill ${kdcpid} 2> /dev/null
443 exit 0