No empty .Rs/.Re
[netbsd-mini2440.git] / crypto / dist / heimdal / tests / kdc / check-pkinit.in
blob239cc6bf62e750407dad3de1e0d14c2ac16c060f
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 # $Heimdal: check-pkinit.in 22474 2008-01-17 11:16:25Z lha $
35 # $NetBSD$
38 srcdir="@srcdir@"
39 objdir="@objdir@"
40 EGREP="@EGREP@"
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
47 R=TEST.H5L.SE
49 port=@port@
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"
65 export KRB5_CONFIG
67 rsa=yes
68 pkinit=no
69 if ${hxtool} info | grep 'rsa: hx509 null RSA' > /dev/null ; then
70 rsa=no
72 if ${hxtool} info | grep 'rand: not available' > /dev/null ; then
73 rsa=no
76 if ${kinit} --help 2>&1 | grep "CA certificates" > /dev/null; then
77 pkinit=yes
80 # If we doesn't support pkinit and have RSA, give up
81 if test "$pkinit" != yes -o "$rsa" != yes ; then
82 exit 77
86 rm -f current-db*
87 rm -f out-*
88 rm -f mkey.file*
90 > messages.log
92 echo Creating database
93 ${kadmin} \
94 init \
95 --realm-max-ticket-life=1day \
96 --realm-max-renewable-life=1month \
97 ${R} || exit 1
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 \
125 --self-signed \
126 --issue-ca \
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
165 echo Starting kdc
166 ${kdc} &
167 kdcpid=$!
169 sh ${srcdir}/wait-kdc.sh
170 if [ "$?" != 0 ] ; then
171 kill ${kdcpid}
172 exit 1
175 trap "kill ${kdcpid}; echo signal killing kdc; cat ca.crt kdc.crt pkinit.crt ;exit 1;" EXIT
177 ec=0
179 echo "Trying pk-init (principal in cert)"; > messages.log
180 base="${objdir}"
181 ${kinit} -C FILE:${base}/pkinit.crt,${keyfile2} bar@${R} || \
182 { ec=1 ; eval "${testfailed}"; }
183 ${kgetcred} ${server}@${R} || { ec=1 ; eval "${testfailed}"; }
184 ${kdestroy}
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}"; }
190 ${kdestroy}
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}"; }
196 ${kdestroy}
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}"; }
202 ${kdestroy}
204 KRB5_CONFIG="${objdir}/krb5-pkinit-win.conf"
205 export KRB5_CONFIG
207 echo "Duplicated tests, now in windows 2000 mode"
209 echo "Trying pk-init (principal in cert)"; > messages.log
210 base="${objdir}"
211 ${kinit} -C FILE:${base}/pkinit.crt,${keyfile2} bar@${R} || \
212 { ec=1 ; eval "${testfailed}"; }
213 ${kgetcred} ${server}@${R} || { ec=1 ; eval "${testfailed}"; }
214 ${kdestroy}
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}"; }
220 ${kdestroy}
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}"; }
226 ${kdestroy}
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}"; }
232 ${kdestroy}
235 KRB5_CONFIG="${objdir}/krb5-pkinit.conf"
236 export KRB5_CONFIG
238 echo "Trying PKCS11 support"
240 cat > test-rc-file.rc <<EOF
241 certificate cert User certificate FILE:${base}/pkinit.crt,${keyfile2}
242 app-fatal true
245 SOFTPKCS11RC="test-rc-file.rc"
246 export SOFTPKCS11RC
248 dir=${base}/../../lib/hx509
249 file=
251 for a in libhx509.so .libs/libhx509.so libhx509.dylib .libs/libhx509.dylib ; do
252 if [ -f $dir/$a ] ; then
253 file=$dir/$a
254 break
256 done
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}"; }
264 ${kdestroy}
269 echo "killing kdc (${kdcpid})"
270 kill $kdcpid || exit 1
272 trap "" EXIT
274 exit $ec