3 # Copyright (c) 2006 - 2007 Kungliga Tekniska Högskolan
4 # (Royal Institute of Technology, Stockholm, Sweden).
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
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
41 testfailed
="echo test failed; cat messages.log; exit 1"
43 # If there is no useful db support compile in, disable test
44 ..
/db
/have-db ||
exit 77
51 kadmin
="${TESTS_ENVIRONMENT} ../../kadmin/kadmin -l -r $R"
52 kdc
="${TESTS_ENVIRONMENT} ../../kdc/kdc --addresses=localhost -P $port"
54 server
=host
/datan.
test.h5l.se
55 server2
=host
/computer.example.com
56 cache
="FILE:${objdir}/cache.krb5"
57 ocache
="FILE:${objdir}/ocache.krb5"
58 o2cache
="FILE:${objdir}/o2cache.krb5"
59 icache
="FILE:${objdir}/icache.krb5"
60 keytabfile
=${objdir}/server.keytab
61 keytab
="FILE:${keytabfile}"
62 ps
="proxy-service@${R}"
63 aesenctype
="aes256-cts-hmac-sha1-96"
65 kinit
="${TESTS_ENVIRONMENT} ../../kuser/kinit -c $cache --no-afslog"
66 klist
="${TESTS_ENVIRONMENT} ../../kuser/klist -c $cache"
67 kgetcred
="${TESTS_ENVIRONMENT} ../../kuser/kgetcred -c $cache"
68 kgetcred_imp
="${TESTS_ENVIRONMENT} ../../kuser/kgetcred -c $cache --out-cache=${ocache}"
69 kdestroy
="${TESTS_ENVIRONMENT} ../../kuser/kdestroy -c $cache --no-unlog"
70 ktutil
="${TESTS_ENVIRONMENT} ../../admin/ktutil"
71 hxtool
="${TESTS_ENVIRONMENT} ../../lib/hx509/hxtool"
72 kimpersonate
="${TESTS_ENVIRONMENT} ../../kuser/kimpersonate -k ${keytab} --ccache=${ocache}"
73 test_renew
="${TESTS_ENVIRONMENT} ../../lib/krb5/test_renew"
75 KRB5_CONFIG
="${objdir}/krb5.conf"
85 echo Creating database
88 --realm-max-ticket-life=1day \
89 --realm-max-renewable-life=1month \
94 --realm-max-ticket-life=1day \
95 --realm-max-renewable-life=1month \
98 ${kadmin} cpw -r krbtgt/${R}@${R} ||
exit 1
99 ${kadmin} cpw -r krbtgt/${R}@${R} ||
exit 1
100 ${kadmin} cpw -r krbtgt/${R}@${R} ||
exit 1
101 ${kadmin} cpw -r krbtgt/${R}@${R} ||
exit 1
103 ${kadmin} add
-p foo
--use-defaults foo@
${R} ||
exit 1
104 ${kadmin} add
-p bar
--use-defaults bar@
${R} ||
exit 1
105 ${kadmin} add
-p foo
--use-defaults remove@
${R} ||
exit 1
106 ${kadmin} add -p kaka --use-defaults ${server}@${R} ||
exit 1
107 ${kadmin} add -p kaka --use-defaults ${server}-des3@${R} ||
exit 1
108 ${kadmin} add
-p foo
--use-defaults ${ps} ||
exit 1
109 ${kadmin} modify
--attributes=+trusted-for-delegation
${ps} ||
exit 1
110 ${kadmin} modify --constrained-delegation=${server} ${ps} ||
exit 1
111 ${kadmin} ext -k ${keytab} ${server}@${R} ||
exit 1
112 ${kadmin} ext -k ${keytab} ${ps} ||
exit 1
114 ${kadmin} add -p kaka --use-defaults ${server2}@${R2} ||
exit 1
115 ${kadmin} ext -k ${keytab} ${server2}@${R2} ||
exit 1
116 ${kadmin} add
-p foo
--use-defaults remove2@
${R2} ||
exit 1
118 ${kadmin} add -p cross1 --use-defaults krbtgt/${R2}@${R} ||
exit 1
119 ${kadmin} add -p cross2 --use-defaults krbtgt/${R}@${R2} ||
exit 1
121 ${kadmin} add
-p foo
--use-defaults -- -p ||
exit 1
122 ${kadmin} delete
-- -p ||
exit 1
124 echo "Doing database check"
125 ${kadmin} check
${R} ||
exit 1
126 ${kadmin} check
${R2} ||
exit 1
128 echo "Extracting enctypes"
129 ${ktutil} -k ${keytab} list
> tempfile ||
exit 1
130 ${EGREP} -v '^FILE:' tempfile | ${EGREP} -v '^Vno' | ${EGREP} -v '^$' | \
131 awk '$1 !~ /1/ { exit 1 }' ||
exit 1
133 ${kadmin} get foo@
${R} > tempfile ||
exit 1
134 enctypes
=`grep Keytypes: tempfile | sed 's/(pw-salt)//g' | sed 's/,//g' | sed 's/Keytypes://'`
136 enctype_sans_aes
=`echo $enctypes | sed 's/aes[^ ]*//g'`
137 enctype_sans_des3
=`echo $enctypes | sed 's/des3-cbc-sha1//g'`
139 echo foo
> ${objdir}/foopassword
145 sh
${srcdir}/wait-kdc.sh
146 if [ "$?" != 0 ] ; then
151 trap "kill ${kdcpid}; echo signal killing kdc; exit 1;" EXIT
155 echo "Getting client initial tickets"; > messages.log
156 ${kinit} --password-file=${objdir}/foopassword foo@
$R || \
157 { ec
=1 ; eval "${testfailed}"; }
158 echo "Getting tickets"; > messages.log
159 ${kgetcred} ${server}@${R} || { ec=1 ; eval "${testfailed}"; }
160 echo "Listing tickets"; > messages.log
161 ${klist} > /dev/null || { ec=1 ; eval "${testfailed}"; }
162 .
/ap-req
${server}@${R} ${keytab} ${cache} || \
163 { ec
=1 ; eval "${testfailed}"; }
166 echo "Specific enctype"; > messages.log
167 ${kinit} --password-file=${objdir}/foopassword \
168 -e ${aesenctype} -e ${aesenctype} \
170 { ec
=1 ; eval "${testfailed}"; }
172 for a
in $enctypes; do
173 echo "Getting client initial tickets ($a)"; > messages.log
174 ${kinit} --enctype=$a --password-file=${objdir}/foopassword foo@$R || { ec=1 ; eval "${testfailed}"; }
175 echo "Getting tickets"; > messages.log
176 ${kgetcred} ${server}@${R} || { ec=1 ; eval "${testfailed}"; }
177 .
/ap-req
${server}@${R} ${keytab} ${cache} || { ec=1 ; eval "${testfailed}"; }
182 echo "Getting client initial tickets"; > messages.log
183 ${kinit} --password-file=${objdir}/foopassword foo@
$R || \
184 { ec
=1 ; eval "${testfailed}"; }
185 for a
in $enctypes; do
186 echo "Getting tickets ($a)"; > messages.log
187 ${kgetcred} -e $a ${server}@${R} || { ec=1 ; eval "${testfailed}"; }
188 .
/ap-req
${server}@${R} ${keytab} ${cache} || \
189 { ec
=1 ; eval "${testfailed}"; }
190 ${kdestroy} --credential=${server}@${R}
194 echo "Getting client initial tickets for cross realm case"; > messages.log
195 ${kinit} --password-file=${objdir}/foopassword foo@$R || { ec=1 ; eval "${testfailed}"; }
196 for a
in $enctypes; do
197 echo "Getting cross realm tickets ($a)"; > messages.log
198 ${kgetcred} -e $a ${server2}@${R2} || { ec=1 ; eval "${testfailed}"; }
199 .
/ap-req
${server2}@${R2} ${keytab} ${cache} || \
200 { ec
=1 ; eval "${testfailed}"; }
201 ${kdestroy} --credential=${server2}@${R2}
205 echo "try all permutations"; > messages.log
206 for a
in $enctypes; do
207 echo "Getting client initial tickets ($a)"; > messages.log
208 ${kinit} --enctype=$a --password-file=${objdir}/foopassword foo@
$R || \
209 { ec
=1 ; eval "${testfailed}"; }
210 for b
in $enctypes; do
211 echo "Getting tickets ($a -> $b)"; > messages.log
212 ${kgetcred} -e $b ${server}@${R} || \
213 { ec
=1 ; eval "${testfailed}"; }
214 .
/ap-req
${server}@${R} ${keytab} ${cache} || \
215 { ec
=1 ; eval "${testfailed}"; }
216 ${kdestroy} --credential=${server}@${R}
221 echo "Getting server initial tickets"; > messages.log
222 ${kinit} --keytab=${keytab} ${server}@$R || { ec=1 ; eval "${testfailed}"; }
223 echo "Listing tickets"; > messages.log
224 ${klist} |
grep "Principal: ${server}" > /dev
/null || \
225 { ec
=1 ; eval "${testfailed}"; }
228 echo "initial tickets for deleted user test case"; > messages.log
229 ${kinit} --password-file=${objdir}/foopassword remove@
$R || \
230 { ec
=1 ; eval "${testfailed}"; }
231 ${kadmin} delete remove@${R} || { ec=1 ; eval "${testfailed}"; }
232 echo "try getting ticket with deleted user"; > messages.log
233 ${kgetcred} ${server}@${R} 2> /dev/null && { ec=1 ; eval "${testfailed}"; }
236 echo "cross realm case (removed user)"; > messages.log
237 ${kinit} --password-file=${objdir}/foopassword remove2@
$R2 || \
238 { ec
=1 ; eval "${testfailed}"; }
239 ${kgetcred} krbtgt/${R}@${R2} 2> /dev
/null || \
240 { ec
=1 ; eval "${testfailed}"; }
241 ${kadmin} delete remove2@
${R2} ||
exit 1
242 ${kgetcred} ${server}@${R} 2> /dev
/null || \
243 { ec
=1 ; eval "${testfailed}"; }
246 echo "rename user"; > messages.log
247 ${kadmin} add
-p foo
--use-defaults rename@
${R} ||
exit 1
248 ${kinit} --password-file=${objdir}/foopassword rename@${R} || \
249 { ec
=1 ; eval "${testfailed}"; }
250 ${kadmin} rename rename@${R} rename2@${R} ||
exit 1
251 ${kinit} --password-file=${objdir}/foopassword rename2@${R} || \
252 { ec
=1 ; eval "${testfailed}"; }
254 ${kadmin} delete rename2@
${R} ||
exit 1
256 echo "rename user to another realm"; > messages.log
257 ${kadmin} add
-p foo
--use-defaults rename@
${R} ||
exit 1
258 ${kinit} --password-file=${objdir}/foopassword rename@${R} || \
259 { ec
=1 ; eval "${testfailed}"; }
260 ${kadmin} rename rename@${R} rename@${R2} ||
exit 1
261 ${kinit} --password-file=${objdir}/foopassword rename@${R2} || \
262 { ec
=1 ; eval "${testfailed}"; }
264 ${kadmin} delete rename@
${R2} ||
exit 1
266 echo deleting all but aes enctypes on krbtgt
267 ${kadmin} del_enctype krbtgt/${R}@${R} ${enctype_sans_aes} ||
exit 1
269 echo deleting all but des enctypes on server-des3
270 ${kadmin} del_enctype ${server}-des3@${R} ${enctype_sans_des3} ||
exit 1
271 ${kadmin} ext -k ${keytab} ${server}-des3@${R} ||
exit 1
273 echo "try all permutations (only aes)"; > messages.log
274 for a
in $enctypes; do
275 echo "Getting client initial tickets ($a)"; > messages.log
276 ${kinit} --enctype=$a --password-file=${objdir}/foopassword foo@${R} ||\
277 { ec
=1 ; eval "${testfailed}"; }
278 for b
in $enctypes; do
279 echo "Getting tickets ($a -> $b)"; > messages.log
280 ${kgetcred} -e $b ${server}@${R} || \
281 { ec
=1 ; eval "${testfailed}"; }
282 .
/ap-req
${server}@${R} ${keytab} ${cache} || \
283 { ec
=1 ; eval "${testfailed}"; }
285 echo "Getting tickets ($a -> $b) (server des3 only)"; > messages.log
286 ${kgetcred} ${server}-des3@${R} || \
287 { ec
=1 ; eval "${testfailed}"; }
288 .
/ap-req
${server}-des3@${R} ${keytab} ${cache} || \
289 { ec
=1 ; eval "${testfailed}"; }
291 ${kdestroy} --credential=${server}@${R}
292 ${kdestroy} --credential=${server}-des3@${R}
297 echo deleting all enctypes on krbtgt
298 ${kadmin} del_enctype krbtgt/${R}@${R} aes256-cts-hmac-sha1-96 || \
299 { ec
=1 ; eval "${testfailed}"; }
300 echo "try initial ticket w/o and keys on krbtgt"
301 ${kinit} --password-file=${objdir}/foopassword foo@${R} 2>/dev
/null
&& \
302 { ec
=1 ; eval "${testfailed}"; }
303 echo "adding random aes key"
304 ${kadmin} add_enctype -r krbtgt/${R}@${R} aes256-cts-hmac-sha1-96 || \
305 { ec
=1 ; eval "${testfailed}"; }
306 echo "try initial ticket with random aes key on krbtgt"
307 ${kinit} --password-file=${objdir}/foopassword foo@${R} || \
308 { ec
=1 ; eval "${testfailed}"; }
312 if ${hxtool} info |
grep 'rsa: hx509 null RSA' > /dev
/null
; then
315 if ${hxtool} info |
grep 'rand: not available' > /dev
/null
; then
318 if ${kinit} --help 2>&1 |
grep "CA certificates" > /dev
/null
; then
322 # If we support pkinit and have RSA, lets try that
323 if test "$pkinit" = yes -a "$rsa" = yes ; then
325 for type in "" "--pk-use-enckey"; do
326 echo "Trying pk-init (principal in certificate) $type"; > messages.log
327 base
="${srcdir}/../../lib/hx509/data"
328 ${kinit} $type -C FILE:${base}/pkinit.crt,${base}/pkinit.key bar@${R} || \
329 { ec
=1 ; eval "${testfailed}"; }
330 ${kgetcred} ${server}@${R} || { ec=1 ; eval "${testfailed}"; }
333 echo "Trying pk-init (principal in pki-mapping) $type"; > messages.log
334 ${kinit} $type -C FILE:${base}/pkinit.crt,${base}/pkinit.key foo@${R} || \
335 { ec
=1 ; eval "${testfailed}"; }
336 ${kgetcred} ${server}@${R} || { ec=1 ; eval "${testfailed}"; }
339 echo "Trying pk-init (password protected key) $type"; > messages.log
340 ${kinit} $type -C FILE:${base}/pkinit.crt,${base}/pkinit-pw.key --password-file=${objdir}/foopassword foo@${R} || \
341 { ec
=1 ; eval "${testfailed}"; }
342 ${kgetcred} ${server}@${R} || \
343 { ec
=1 ; eval "${testfailed}"; }
346 echo "Trying pk-init (proxy cert) $type"; > messages.log
347 base
="${srcdir}/../../lib/hx509/data"
348 ${kinit} $type -C FILE:${base}/pkinit-proxy-chain.crt,${base}/pkinit-proxy.key foo@${R} || \
349 { ec
=1 ; eval "${testfailed}"; }
350 ${kgetcred} ${server}@${R} || { ec=1 ; eval "${testfailed}"; }
355 echo "no pkinit (pkinit: $pkinit, rsa: $rsa)"; > messages.log
358 echo "tickets for impersonate test case"; > messages.log
359 ${kinit} --forwardable --password-file=${objdir}/foopassword ${ps} || \
360 { ec
=1 ; eval "${testfailed}"; }
361 ${kgetcred_imp} --impersonate=bar@${R} ${ps} || \
362 { ec
=1 ; eval "${testfailed}"; }
363 .
/ap-req
${ps} ${keytab} ${ocache} || \
364 { ec
=1 ; eval "${testfailed}"; }
365 ${kgetcred_imp} --impersonate=bar@${R} foo@${R} 2>/dev
/null
&& \
366 { ec
=1 ; eval "${testfailed}"; }
367 echo test constrained delegation
368 ${kgetcred_imp} --forward --impersonate=bar@${R} ${ps} || \
369 { ec
=1 ; eval "${testfailed}"; }
370 ${kgetcred} --out-cache=${o2cache} --delegation-credential-cache=${ocache} ${server}@${R} || \
371 { ec
=1 ; eval "${testfailed}"; }
372 .
/ap-req
${server}@${R} ${keytab} ${o2cache} || \
373 { ec
=1 ; eval "${testfailed}"; }
374 ${kgetcred} --out-cache=${o2cache} --delegation-credential-cache=${ocache} bar@${R} 2>/dev
/null
&& \
375 { ec
=1 ; eval "${testfailed}"; }
377 echo "test constrained delegation impersonation (non forward)"; > messages.log
379 ${kimpersonate} -s ${ps} -c bar@${R} -t ${aesenctype} || \
380 { ec
=1 ; eval "${testfailed}"; }
381 ${kgetcred} --out-cache=${o2cache} --delegation-credential-cache=${ocache} ${server}@${R} > /dev
/null
2>/dev
/null
&& \
382 { ec
=1 ; eval "${testfailed}"; }
384 echo "test constrained delegation impersonation (missing KRB5SignedPath)"; > messages.log
386 ${kimpersonate} -s ${ps} -c bar@${R} -t ${aesenctype} -f forwardable || \
387 { ec
=1 ; eval "${testfailed}"; }
388 ${kgetcred} --out-cache=${o2cache} --delegation-credential-cache=${ocache} ${server}@${R} > /dev
/null
2>/dev
/null
&& \
389 { ec
=1 ; eval "${testfailed}"; }
393 echo "check renewing" > messages.log
394 ${kinit} --renewable --password-file=${objdir}/foopassword foo@
$R || \
395 { ec
=1 ; eval "${testfailed}"; }
398 { ec
=1 ; eval "${testfailed}"; }
399 echo "check renewing MIT interface" > messages.log
400 ${kinit} --renewable --password-file=${objdir}/foopassword foo@
$R || \
401 { ec
=1 ; eval "${testfailed}"; }
403 env KRB5CCNAME
=${cache} ${test_renew} || \
404 { ec
=1 ; eval "${testfailed}"; }
408 echo "killing kdc (${kdcpid})"
409 kill $kdcpid ||
exit 1