Export krb5_principal_get_num_comp
[heimdal.git] / tests / gss / check-context.in
blob1a8384777bb5df19583dcacdd499fd20278852d5
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 --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 exitcode=0
128 echo "Getting client initial tickets"
129 ${kinit} --password-file=${objdir}/foopassword --forwardable user1@${R} || exitcode=1
131 echo "======test unreadable/non existant keytab and its error message"
132 ${context} --mech-type=krb5 host@lucid.test.h5l.se || \
133 { exitcode=1 ; echo "test failed"; }
135 mv ${keytabfile} ${keytabfile}.no
137 echo "checking non existant keytabfile (krb5)"
138 ${context} --mech-type=krb5 host@lucid.test.h5l.se > test_context.log 2>&1 && \
139 { exitcode=1 ; echo "test failed"; }
140 grep ${keytabfile} test_context.log > /dev/null || \
141 { exitcode=1 ; echo "string missing failed"; }
142 echo "checking non existant keytabfile (spengo)"
143 ${context} --mech-type=spnego host@lucid.test.h5l.se > test_context.log 2>&1 && \
144 { exitcode=1 ; echo "test failed"; }
145 grep ${keytabfile} test_context.log > /dev/null || \
146 { exitcode=1 ; echo "string missing failed"; }
148 mv ${keytabfile}.no ${keytabfile}
150 echo "======test naming combinations"
151 echo "plain"
152 ${context} --name-type=hostbased-service host@lucid.test.h5l.se || \
153 { exitcode=1 ; echo "test failed"; }
154 echo "plain (krb5)"
155 ${context} --name-type=krb5-principal-name host/lucid.test.h5l.se@${R} || \
156 { exitcode=1 ; echo "test failed"; }
157 echo "plain (krb5 realmless)"
158 ${context} --name-type=krb5-principal-name host/lucid.test.h5l.se || \
159 { exitcode=1 ; echo "test failed"; }
160 echo "dns canon on (long name) OFF, need dns_wrapper"
161 #${context} --dns-canon host@lucid.test.h5l.se || \
162 # { exitcode=1 ; echo "test failed"; }
163 echo "dns canon off (long name)"
164 ${context} --no-dns-canon host@lucid.test.h5l.se || \
165 { exitcode=1 ; echo "test failed"; }
166 echo "dns canon off (short name)"
167 ${context} --no-dns-canon host@lucid || \
168 { exitcode=1 ; echo "test failed"; }
169 echo "dns canon off (short name, krb5)"
170 ${context} --no-dns-canon --name-type=krb5-principal-name host/lucid@${R} || \
171 { exitcode=1 ; echo "test failed"; }
172 echo "dns canon off (short name, krb5)"
173 ${context} --no-dns-canon --name-type=krb5-principal-name host/lucid || \
174 { exitcode=1 ; echo "test failed"; }
176 echo "======test context building"
177 for mech in krb5 krb5iov spnego spnegoiov; do
178 if [ "$mech" = "krb5iov" ] ; then
179 mech="krb5"
180 iov="--iov"
182 if [ "$mech" = "spnegoiov" ] ; then
183 mech="spnego"
184 iov="--iov"
187 echo "${mech} no-mutual ${iov}"
188 ${context} --mech-type=${mech} \
189 --wrapunwrap ${iov} \
190 --name-type=hostbased-service host@lucid.test.h5l.se || \
191 { exitcode=1 ; echo "test failed"; }
193 echo "${mech} mutual ${iov}"
194 ${context} --mech-type=${mech} \
195 --mutual \
196 --wrapunwrap ${iov} \
197 --name-type=hostbased-service host@lucid.test.h5l.se || \
198 { exitcode=1 ; echo "test failed"; }
200 echo "${mech} delegate ${iov}"
201 ${context} --mech-type=${mech} \
202 --delegate \
203 --wrapunwrap ${iov} \
204 --name-type=hostbased-service host@lucid.test.h5l.se || \
205 { exitcode=1 ; echo "test failed"; }
207 echo "${mech} mutual delegate ${iov}"
208 ${context} --mech-type=${mech} \
209 --mutual --delegate \
210 --wrapunwrap ${iov} \
211 --name-type=hostbased-service host@lucid.test.h5l.se || \
212 { exitcode=1 ; echo "test failed"; }
213 done
215 echo "======dce-style"
216 for mech in krb5 krb5iov spnego; do
217 iov=""
218 if [ "$mech" = "krb5iov" ] ; then
219 mech="krb5"
220 iov="--iov"
222 if [ "$mech" = "spnegoiov" ] ; then
223 mech="spnego"
224 iov="--iov"
227 echo "${mech}: dce-style ${iov}"
228 ${context} \
229 --mech-type=${mech} \
230 --mutual \
231 --dce-style \
232 --wrapunwrap ${iov} \
233 --name-type=hostbased-service host@lucid.test.h5l.se || \
234 { exitcode=1 ; echo "test failed"; }
236 done
238 echo "test gsskrb5_register_acceptor_identity (both positive and negative)"
240 cp ${keytabfile} ${keytabfile}.new
241 for mech in krb5 spnego; do
242 echo "${mech}: acceptor_identity positive"
243 ${context} --gsskrb5-acceptor-identity=${keytabfile}.new \
244 --mech-type=$mech host@lucid.test.h5l.se || \
245 { exitcode=1 ; echo "test failed"; }
247 echo "${mech}: acceptor_identity negative"
248 ${context} --gsskrb5-acceptor-identity=${keytabfile}.foo \
249 --mech-type=$mech host@lucid.test.h5l.se 2>/dev/null && \
250 { exitcode=1 ; echo "test failed"; }
251 done
253 rm ${keytabfile}.new
256 #echo "sasl-digest-md5"
257 #${context} --mech-type=sasl-digest-md5 \
258 # --name-type=hostbased-service \
259 # host@lucid.test.h5l.se || \
260 # { exitcode=1 ; echo "test failed"; }
263 echo "====== gss-api session key check"
265 # this will break when oneone invents a cooler enctype then aes256-cts-hmac-sha1-96
266 coolenctype="aes256-cts-hmac-sha1-96"
268 echo "Getting client initial tickets"
269 ${kinit} --password-file=${objdir}/foopassword user1@${R} || \
270 { echo "kinit failed"; exitcode=1; }
272 echo "Building context on cred w/o aes, but still ${coolenctype} session key"
273 ${context} \
274 --mech-type=krb5 \
275 --mutual-auth \
276 --session-enctype=${coolenctype} \
277 --name-type=hostbased-service host@no-aes.test.h5l.se || \
278 { exitcode=1 ; echo "test failed"; }
280 echo "====== ok-as-delegate"
282 echo "Getting client initial tickets"
283 ${kinit} --forwardable \
284 --password-file=${objdir}/foopassword user1@${R} || exitcode=1
286 echo "ok-as-delegate not used"
287 ${context} \
288 --mech-type=krb5 \
289 --delegate \
290 --name-type=hostbased-service host@lucid.test.h5l.se || \
291 { exitcode=1 ; echo "test failed"; }
293 echo "host without ok-as-delegate with policy-delegate"
294 ${context} \
295 --mech-type=krb5 \
296 --policy-delegate \
297 --server-no-delegate \
298 --name-type=hostbased-service host@lucid.test.h5l.se || \
299 { exitcode=1 ; echo "test failed"; }
301 echo "ok-as-delegate used by policy"
302 ${context} \
303 --mech-type=krb5 \
304 --policy-delegate \
305 --name-type=hostbased-service host@ok-delegate.test.h5l.se || \
306 { exitcode=1 ; echo "test failed"; }
308 echo "Getting client initial tickets with --ok-as-delgate"
309 ${kinit} --ok-as-delegate --forwardable \
310 --password-file=${objdir}/foopassword user1@${R} || exitcode=1
312 echo "policy delegate to non delegate host"
313 ${context} \
314 --mech-type=krb5 \
315 --policy-delegate \
316 --server-no-delegate \
317 --name-type=hostbased-service host@lucid.test.h5l.se || \
318 { exitcode=1 ; echo "test failed"; }
320 echo "ok-as-delegate"
321 ${context} \
322 --mech-type=krb5 \
323 --delegate \
324 --name-type=hostbased-service host@lucid.test.h5l.se || \
325 { exitcode=1 ; echo "test failed"; }
327 echo "======export/import cred"
329 echo "export-import cred (krb5)"
330 ${context} \
331 --mech-type=krb5 \
332 --delegate \
333 --export-import-cred \
334 --name-type=hostbased-service host@ok-delegate.test.h5l.se || \
335 { exitcode=1 ; echo "test failed"; }
337 echo "export-import cred (spnego)"
338 ${context} \
339 --mech-type=spnego \
340 --delegate \
341 --export-import-cred \
342 --name-type=hostbased-service host@ok-delegate.test.h5l.se || \
343 { exitcode=1 ; echo "test failed"; }
346 echo "======time diffs between client and server"
348 echo "Getting client initial ticket"
349 ${kinit} --password-file=${objdir}/foopassword user1@${R} || exitcode=1
351 echo "No time offset"
352 ${context} \
353 --mech-type=krb5 \
354 --name-type=hostbased-service host@lucid.test.h5l.se || \
355 { exitcode=1 ; echo "test failed"; }
357 echo "Getting client initial ticket"
358 ${kinit} --password-file=${objdir}/foopassword user1@${R} || exitcode=1
360 echo "Server time offset"
361 ${context} \
362 --mech-type=krb5 \
363 --mutual-auth \
364 --server-time-offset=3600 \
365 --max-loops=3 \
366 --name-type=hostbased-service host@lucid.test.h5l.se || \
367 { exitcode=1 ; echo "test failed"; }
369 echo "Server time offset (cached ?)"
370 ${context} \
371 --mech-type=krb5 \
372 --mutual-auth \
373 --server-time-offset=3600 \
374 --max-loops=2 \
375 --name-type=hostbased-service host@lucid.test.h5l.se || \
376 { exitcode=1 ; echo "test failed"; }
378 echo "Getting client initial ticket"
379 ${kinit} --password-file=${objdir}/foopassword user1@${R} || exitcode=1
380 # Pre-poplute the cache since tgs-req will fail since our time is wrong
381 ${kgetcred} host/lucid.test.h5l.se@${R} || exitcode=1
383 echo "Client time offset"
384 ${context} \
385 --mech-type=krb5 \
386 --mutual-auth \
387 --client-time-offset=3600 \
388 --name-type=hostbased-service host@lucid.test.h5l.se || \
389 { exitcode=1 ; echo "test failed"; }
391 echo "Getting client initial tickets (use-referrals)"
392 ${kinit} \
393 --password-file=${objdir}/foopassword \
394 --use-referrals user1@${R} || exitcode=1
396 # XXX these tests really need to use somethat that resolve to something
397 ${context} \
398 --mech-type=krb5 \
399 host@short || \
400 { exitcode=1 ; echo "test failed"; }
402 ${context} \
403 --mech-type=krb5 \
404 --name-type=krb5-principal-name host/short || \
405 { exitcode=1 ; echo "test failed"; }
407 ${context} \
408 --mech-type=krb5 \
409 host@long.test.h5l.se || \
410 { exitcode=1 ; echo "test failed"; }
412 ${context} \
413 --mech-type=krb5 \
414 --name-type=krb5-principal-name \
415 host/long.test.h5l.se || \
416 { exitcode=1 ; echo "test failed"; }
418 trap "" EXIT
420 echo "killing kdc (${kdcpid})"
421 kill ${kdcpid} 2> /dev/null
423 [ "$exitcode" = 0 ] && echo "all ok"
425 exit $exitcode