3 # Copyright (c) 2006 - 2008 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
34 # $Heimdal: check-pkinit.in 22474 2008-01-17 11:16:25Z lha $
42 testfailed
="echo test failed; cat messages.log; exit 1"
44 # If there is no useful db support compile in, disable test
45 ..
/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 cache
="FILE:${objdir}/cache.krb5"
56 keyfile
="${srcdir}/../../lib/hx509/data/key.der"
57 keyfile2
="${srcdir}/../../lib/hx509/data/key2.der"
59 kinit
="${TESTS_ENVIRONMENT} ../../kuser/kinit -c $cache --no-afslog"
60 kgetcred
="${TESTS_ENVIRONMENT} ../../kuser/kgetcred -c $cache"
61 kdestroy
="${TESTS_ENVIRONMENT} ../../kuser/kdestroy -c $cache --no-unlog"
62 hxtool
="${TESTS_ENVIRONMENT} ../../lib/hx509/hxtool"
64 KRB5_CONFIG
="${objdir}/krb5-pkinit.conf"
69 if ${hxtool} info |
grep 'rsa: hx509 null RSA' > /dev
/null
; then
72 if ${hxtool} info |
grep 'rand: not available' > /dev
/null
; then
76 if ${kinit} --help 2>&1 |
grep "CA certificates" > /dev
/null
; then
80 # If we doesn't support pkinit and have RSA, give up
81 if test "$pkinit" != yes -o "$rsa" != yes ; then
92 echo Creating database
95 --realm-max-ticket-life=1day \
96 --realm-max-renewable-life=1month \
99 ${kadmin} add
-p foo
--use-defaults foo@
${R} ||
exit 1
100 ${kadmin} add
-p bar
--use-defaults bar@
${R} ||
exit 1
101 ${kadmin} add
-p baz
--use-defaults baz@
${R} ||
exit 1
102 ${kadmin} modify
--pkinit-acl="CN=baz,DC=test,DC=h5l,DC=se" baz@
${R} ||
exit 1
104 ${kadmin} add -p kaka --use-defaults ${server}@${R} ||
exit 1
106 echo "Doing database check"
107 ${kadmin} check
${R} ||
exit 1
109 echo "Setting up certificates"
110 ${hxtool} request-create \
111 --subject="CN=kdc,DC=test,DC=h5l,DC=se" \
112 --key=FILE
:${keyfile2} \
113 req-kdc.der ||
exit 1
114 ${hxtool} request-create \
115 --subject="CN=bar,DC=test,DC=h5l,DC=se" \
116 --key=FILE
:${keyfile2} \
117 req-pkinit.der ||
exit 1
118 ${hxtool} request-create \
119 --subject="CN=baz,DC=test,DC=h5l,DC=se" \
120 --key=FILE
:${keyfile2} \
121 req-pkinit2.der ||
exit 1
123 echo "issue self-signed ca cert"
124 ${hxtool} issue-certificate \
127 --ca-private-key=FILE
:${keyfile} \
128 --subject="CN=CA,DC=test,DC=h5l,DC=se" \
129 --certificate="FILE:ca.crt" ||
exit 1
131 echo "issue kdc certificate"
132 ${hxtool} issue-certificate \
133 --ca-certificate=FILE
:$objdir/ca.crt
,${keyfile} \
134 --type="pkinit-kdc" \
135 --pk-init-principal="krbtgt/TEST.H5L.SE@TEST.H5L.SE" \
136 --req="PKCS10:req-kdc.der" \
137 --certificate="FILE:kdc.crt" ||
exit 1
139 echo "issue user certificate (pkinit san)"
140 ${hxtool} issue-certificate \
141 --ca-certificate=FILE
:$objdir/ca.crt
,${keyfile} \
142 --type="pkinit-client" \
143 --pk-init-principal="bar@TEST.H5L.SE" \
144 --req="PKCS10:req-pkinit.der" \
145 --certificate="FILE:pkinit.crt" ||
exit 1
147 echo "issue user 2 certificate (no san)"
148 ${hxtool} issue-certificate \
149 --ca-certificate=FILE
:$objdir/ca.crt
,${keyfile} \
150 --type="pkinit-client" \
151 --req="PKCS10:req-pkinit2.der" \
152 --certificate="FILE:pkinit2.crt" ||
exit 1
154 echo "issue user 3 certificate (ms san)"
155 ${hxtool} issue-certificate \
156 --ca-certificate=FILE
:$objdir/ca.crt
,${keyfile} \
157 --type="pkinit-client" \
158 --ms-upn="bar@test.h5l.se" \
159 --req="PKCS10:req-pkinit2.der" \
160 --certificate="FILE:pkinit3.crt" ||
exit 1
163 echo foo
> ${objdir}/foopassword
169 sh
${srcdir}/wait-kdc.sh
170 if [ "$?" != 0 ] ; then
175 trap "kill ${kdcpid}; echo signal killing kdc; cat ca.crt kdc.crt pkinit.crt ;exit 1;" EXIT
179 echo "Trying pk-init (principal in cert)"; > messages.log
181 ${kinit} -C FILE:${base}/pkinit.crt,${keyfile2} bar@${R} || \
182 { ec
=1 ; eval "${testfailed}"; }
183 ${kgetcred} ${server}@${R} || { ec=1 ; eval "${testfailed}"; }
186 echo "Trying pk-init (principal in pki-mapping file) "; > messages.log
187 ${kinit} -C FILE:${base}/pkinit.crt,${keyfile2} foo@${R} || \
188 { ec
=1 ; eval "${testfailed}"; }
189 ${kgetcred} ${server}@${R} || { ec=1 ; eval "${testfailed}"; }
192 echo "Trying pk-init (principal subject in DB)"; > messages.log
193 ${kinit} -C FILE:${base}/pkinit2.crt,${keyfile2} baz@${R} || \
194 { ec
=1 ; eval "${testfailed}"; }
195 ${kgetcred} ${server}@${R} || { ec=1 ; eval "${testfailed}"; }
198 echo "Trying pk-init (ms upn)"; > messages.log
199 ${kinit} -C FILE:${base}/pkinit3.crt,${keyfile2} bar@${R} || \
200 { ec
=1 ; eval "${testfailed}"; }
201 ${kgetcred} ${server}@${R} || { ec=1 ; eval "${testfailed}"; }
204 KRB5_CONFIG
="${objdir}/krb5-pkinit-win.conf"
207 echo "Duplicated tests, now in windows 2000 mode"
209 echo "Trying pk-init (principal in cert)"; > messages.log
211 ${kinit} -C FILE:${base}/pkinit.crt,${keyfile2} bar@${R} || \
212 { ec
=1 ; eval "${testfailed}"; }
213 ${kgetcred} ${server}@${R} || { ec=1 ; eval "${testfailed}"; }
216 echo "Trying pk-init (principal in pki-mapping file) "; > messages.log
217 ${kinit} -C FILE:${base}/pkinit.crt,${keyfile2} foo@${R} || \
218 { ec
=1 ; eval "${testfailed}"; }
219 ${kgetcred} ${server}@${R} || { ec=1 ; eval "${testfailed}"; }
222 echo "Trying pk-init (principal subject in DB)"; > messages.log
223 ${kinit} -C FILE:${base}/pkinit2.crt,${keyfile2} baz@${R} || \
224 { ec
=1 ; eval "${testfailed}"; }
225 ${kgetcred} ${server}@${R} || { ec=1 ; eval "${testfailed}"; }
228 echo "Trying pk-init (ms upn)"; > messages.log
229 ${kinit} -C FILE:${base}/pkinit3.crt,${keyfile2} bar@${R} || \
230 { ec
=1 ; eval "${testfailed}"; }
231 ${kgetcred} ${server}@${R} || { ec=1 ; eval "${testfailed}"; }
235 KRB5_CONFIG
="${objdir}/krb5-pkinit.conf"
238 echo "Trying PKCS11 support"
240 cat > test-rc-file.rc
<<EOF
241 certificate cert User certificate FILE:${base}/pkinit.crt,${keyfile2}
245 SOFTPKCS11RC
="test-rc-file.rc"
248 dir
=${base}/..
/..
/lib
/hx509
251 for a
in libhx509.so .libs
/libhx509.so libhx509.dylib .libs
/libhx509.dylib
; do
252 if [ -f $dir/$a ] ; then
258 if [ X
"$file" != X
-a @DLOPEN@
] ; then
260 echo "Trying pk-init (principal in pki-mapping file) "; > messages.log
261 ${kinit} -C PKCS11:${file} foo@${R} || \
262 { ec
=1 ; eval "${testfailed}"; }
263 ${kgetcred} ${server}@${R} || { ec=1 ; eval "${testfailed}"; }
269 echo "killing kdc (${kdcpid})"
270 kill $kdcpid ||
exit 1