3 # Copyright (c) 2005 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: test_cms.in 21311 2007-06-25 18:26:37Z lha $
41 stat
="--statistic-file=${objdir}/statfile"
43 hxtool
="${TESTS_ENVIRONMENT} ./hxtool ${stat}"
45 if ${hxtool} info |
grep 'rsa: hcrypto null RSA' > /dev
/null
; then
48 if ${hxtool} info |
grep 'rand: not available' > /dev
/null
; then
52 echo "create signed data"
53 ${hxtool} cms-create-sd \
54 --certificate=FILE
:$srcdir/data
/test.crt
,$srcdir/data
/test.key \
55 "$srcdir/test_chain.in" \
56 sd.data
> /dev
/null ||
exit 1
58 echo "verify signed data"
59 ${hxtool} cms-verify-sd \
61 --anchors=FILE
:$srcdir/data
/ca.crt \
62 sd.data sd.data.out
> /dev
/null ||
exit 1
63 cmp "$srcdir/test_chain.in" sd.data.out ||
exit 1
65 echo "create signed data (id-by-name)"
66 ${hxtool} cms-create-sd \
67 --certificate=FILE
:$srcdir/data
/test.crt
,$srcdir/data
/test.key \
69 "$srcdir/test_chain.in" \
70 sd.data
> /dev
/null ||
exit 1
72 echo "verify signed data"
73 ${hxtool} cms-verify-sd \
75 --anchors=FILE
:$srcdir/data
/ca.crt \
76 sd.data sd.data.out
> /dev
/null ||
exit 1
77 cmp "$srcdir/test_chain.in" sd.data.out ||
exit 1
79 echo "verify signed data (EE cert as anchor)"
80 ${hxtool} cms-verify-sd \
82 --anchors=FILE
:$srcdir/data
/test.crt \
83 sd.data sd.data.out
> /dev
/null ||
exit 1
84 cmp "$srcdir/test_chain.in" sd.data.out ||
exit 1
86 echo "create signed data (password)"
87 ${hxtool} cms-create-sd \
89 --certificate=FILE
:$srcdir/data
/test.crt
,$srcdir/data
/test-pw.key \
90 "$srcdir/test_chain.in" \
91 sd.data
> /dev
/null ||
exit 1
93 echo "verify signed data"
94 ${hxtool} cms-verify-sd \
96 --anchors=FILE
:$srcdir/data
/ca.crt \
97 sd.data sd.data.out
> /dev
/null ||
exit 1
98 cmp "$srcdir/test_chain.in" sd.data.out ||
exit 1
100 echo "create signed data (combined)"
101 ${hxtool} cms-create-sd \
102 --certificate=FILE
:$srcdir/data
/test.combined.crt \
103 "$srcdir/test_chain.in" \
104 sd.data
> /dev
/null ||
exit 1
106 echo "verify signed data"
107 ${hxtool} cms-verify-sd \
109 --anchors=FILE
:$srcdir/data
/ca.crt \
110 sd.data sd.data.out
> /dev
/null ||
exit 1
111 cmp "$srcdir/test_chain.in" sd.data.out ||
exit 1
113 echo "create signed data (content info)"
114 ${hxtool} cms-create-sd \
115 --certificate=FILE
:$srcdir/data
/test.crt
,$srcdir/data
/test.key \
117 "$srcdir/test_chain.in" \
118 sd.data
> /dev
/null ||
exit 1
120 echo "verify signed data (content info)"
121 ${hxtool} cms-verify-sd \
123 --anchors=FILE
:$srcdir/data
/ca.crt \
125 sd.data sd.data.out
> /dev
/null ||
exit 1
126 cmp "$srcdir/test_chain.in" sd.data.out ||
exit 1
128 echo "create signed data (content type)"
129 ${hxtool} cms-create-sd \
130 --certificate=FILE
:$srcdir/data
/test.crt
,$srcdir/data
/test.key \
131 --content-type=1.1.1.1 \
132 "$srcdir/test_chain.in" \
133 sd.data
> /dev
/null ||
exit 1
135 echo "verify signed data (content type)"
136 ${hxtool} cms-verify-sd \
138 --anchors=FILE
:$srcdir/data
/ca.crt \
139 sd.data sd.data.out
> /dev
/null ||
exit 1
140 cmp "$srcdir/test_chain.in" sd.data.out ||
exit 1
142 echo "create signed data (pem)"
143 ${hxtool} cms-create-sd \
144 --certificate=FILE
:$srcdir/data
/test.crt
,$srcdir/data
/test.key \
146 "$srcdir/test_chain.in" \
147 sd.data
> /dev
/null ||
exit 1
149 echo "create signed data (pem, detached)"
150 ${hxtool} cms-create-sd \
151 --certificate=FILE
:$srcdir/data
/test.crt
,$srcdir/data
/test.key \
152 --detached-signature \
154 "$srcdir/test_chain.in" \
155 sd.data
> /dev
/null ||
exit 1
157 echo "create signed data (p12)"
158 ${hxtool} cms-create-sd \
160 --certificate=PKCS12
:$srcdir/data
/test.p12 \
161 --signer=friendlyname-test \
162 "$srcdir/test_chain.in" \
163 sd.data
> /dev
/null ||
exit 1
165 echo "verify signed data"
166 ${hxtool} cms-verify-sd \
168 --anchors=FILE
:$srcdir/data
/ca.crt \
170 "$srcdir/data/test-signed-data" sd.data.out
> /dev
/null ||
exit 1
171 cmp "$srcdir/data/static-file" sd.data.out ||
exit 1
173 echo "verify signed data (no attr)"
174 ${hxtool} cms-verify-sd \
176 --anchors=FILE
:$srcdir/data
/ca.crt \
178 "$srcdir/data/test-signed-data-noattr" sd.data.out
> /dev
/null ||
exit 1
179 cmp "$srcdir/data/static-file" sd.data.out ||
exit 1
181 echo "verify failure signed data (no attr, no certs)"
182 ${hxtool} cms-verify-sd \
184 --anchors=FILE
:$srcdir/data
/ca.crt \
186 "$srcdir/data/test-signed-data-noattr-nocerts" \
187 sd.data.out
> /dev
/null
2>/dev
/null
&& exit 1
189 echo "verify signed data (no attr, no certs)"
190 ${hxtool} cms-verify-sd \
192 --anchors=FILE
:$srcdir/data
/ca.crt \
193 --certificate=FILE
:$srcdir/data
/test.crt \
195 "$srcdir/data/test-signed-data-noattr-nocerts" \
196 sd.data.out
> /dev
/null ||
exit 1
197 cmp "$srcdir/data/static-file" sd.data.out ||
exit 1
199 echo "create signed data (subcert, no certs)"
200 ${hxtool} cms-create-sd \
201 --certificate=FILE
:$srcdir/data
/sub-cert.crt
,$srcdir/data
/sub-cert.key \
202 "$srcdir/test_chain.in" \
203 sd.data
> /dev
/null ||
exit 1
205 echo "verify failure signed data"
206 ${hxtool} cms-verify-sd \
208 --anchors=FILE
:$srcdir/data
/ca.crt \
209 sd.data sd.data.out
> /dev
/null
2> /dev
/null
&& exit 1
211 echo "verify success signed data"
212 ${hxtool} cms-verify-sd \
214 --certificate=FILE
:$srcdir/data
/sub-ca.crt \
215 --anchors=FILE
:$srcdir/data
/ca.crt \
216 sd.data sd.data.out
> /dev
/null ||
exit 1
217 cmp "$srcdir/test_chain.in" sd.data.out ||
exit 1
219 echo "create signed data (subcert, certs)"
220 ${hxtool} cms-create-sd \
221 --certificate=FILE
:$srcdir/data
/sub-cert.crt
,$srcdir/data
/sub-cert.key \
222 --pool=FILE
:$srcdir/data
/sub-ca.crt \
223 --anchors=FILE
:$srcdir/data
/ca.crt \
224 "$srcdir/test_chain.in" \
225 sd.data
> /dev
/null ||
exit 1
227 echo "verify success signed data"
228 ${hxtool} cms-verify-sd \
230 --anchors=FILE
:$srcdir/data
/ca.crt \
231 sd.data sd.data.out
> /dev
/null ||
exit 1
232 cmp "$srcdir/test_chain.in" sd.data.out ||
exit 1
234 echo "create signed data (subcert, certs, no-root)"
235 ${hxtool} cms-create-sd \
236 --certificate=FILE
:$srcdir/data
/sub-cert.crt
,$srcdir/data
/sub-cert.key \
237 --pool=FILE
:$srcdir/data
/sub-ca.crt \
238 "$srcdir/test_chain.in" \
239 sd.data
> /dev
/null ||
exit 1
241 echo "verify success signed data"
242 ${hxtool} cms-verify-sd \
244 --anchors=FILE
:$srcdir/data
/ca.crt \
245 sd.data sd.data.out
> /dev
/null ||
exit 1
246 cmp "$srcdir/test_chain.in" sd.data.out ||
exit 1
248 echo "create signed data (subcert, no-subca, no-root)"
249 ${hxtool} cms-create-sd \
250 --certificate=FILE
:$srcdir/data
/sub-cert.crt
,$srcdir/data
/sub-cert.key \
251 "$srcdir/test_chain.in" \
252 sd.data
> /dev
/null ||
exit 1
254 echo "verify failure signed data"
255 ${hxtool} cms-verify-sd \
257 --anchors=FILE
:$srcdir/data
/ca.crt \
258 sd.data sd.data.out
> /dev
/null
2>/dev
/null
&& exit 1
260 echo "create signed data (sd cert)"
261 ${hxtool} cms-create-sd \
262 --certificate=FILE
:$srcdir/data
/test-ds-only.crt
,$srcdir/data
/test-ds-only.key \
263 "$srcdir/test_chain.in" \
264 sd.data
> /dev
/null ||
exit 1
266 echo "create signed data (ke cert)"
267 ${hxtool} cms-create-sd \
268 --certificate=FILE
:$srcdir/data
/test-ke-only.crt
,$srcdir/data
/test-ke-only.key \
269 "$srcdir/test_chain.in" \
270 sd.data
> /dev
/null
2>/dev
/null
&& exit 1
272 echo "create signed data (sd + ke certs)"
273 ${hxtool} cms-create-sd \
274 --certificate=FILE
:$srcdir/data
/test-ke-only.crt
,$srcdir/data
/test-ke-only.key \
275 --certificate=FILE
:$srcdir/data
/test-ds-only.crt
,$srcdir/data
/test-ds-only.key \
276 "$srcdir/test_chain.in" \
277 sd.data
> /dev
/null ||
exit 1
279 echo "create signed data (ke + sd certs)"
280 ${hxtool} cms-create-sd \
281 --certificate=FILE
:$srcdir/data
/test-ds-only.crt
,$srcdir/data
/test-ds-only.key \
282 --certificate=FILE
:$srcdir/data
/test-ke-only.crt
,$srcdir/data
/test-ke-only.key \
283 "$srcdir/test_chain.in" \
284 sd.data
> /dev
/null ||
exit 1
286 echo "create signed data (detached)"
287 ${hxtool} cms-create-sd \
288 --certificate=FILE
:$srcdir/data
/test.crt
,$srcdir/data
/test.key \
289 --detached-signature \
290 "$srcdir/test_chain.in" \
291 sd.data
> /dev
/null ||
exit 1
293 echo "verify signed data (detached)"
294 ${hxtool} cms-verify-sd \
296 --signed-content="$srcdir/test_chain.in" \
297 --anchors=FILE
:$srcdir/data
/ca.crt \
298 sd.data sd.data.out
> /dev
/null ||
exit 1
299 cmp "$srcdir/test_chain.in" sd.data.out ||
exit 1
301 echo "verify failure signed data (detached)"
302 ${hxtool} cms-verify-sd \
304 --anchors=FILE
:$srcdir/data
/ca.crt \
305 sd.data sd.data.out
> /dev
/null
2>/dev
/null
&& exit 1
307 echo "create signed data (rsa)"
308 ${hxtool} cms-create-sd \
309 --peer-alg=1.2.840.113549.1.1.1 \
310 --certificate=FILE
:$srcdir/data
/test.crt
,$srcdir/data
/test.key \
311 "$srcdir/test_chain.in" \
312 sd.data
> /dev
/null ||
exit 1
314 echo "verify signed data (rsa)"
315 ${hxtool} cms-verify-sd \
317 --anchors=FILE
:$srcdir/data
/ca.crt \
318 sd.data sd.data.out
> /dev
/null
2>/dev
/null ||
exit 1
319 cmp "$srcdir/test_chain.in" sd.data.out ||
exit 1
321 echo "envelope data (content-type)"
322 ${hxtool} cms-envelope \
323 --certificate=FILE
:$srcdir/data
/test.crt \
324 --content-type=1.1.1.1 \
325 "$srcdir/data/static-file" \
326 ev.data
> /dev
/null ||
exit 1
328 echo "unenvelope data (content-type)"
329 ${hxtool} cms-unenvelope \
330 --certificate=FILE
:$srcdir/data
/test.crt
,$srcdir/data
/test.key \
331 ev.data ev.data.out \
332 FILE
:$srcdir/data
/test.crt
,$srcdir/data
/test.key
> /dev
/null ||
exit 1
333 cmp "$srcdir/data/static-file" ev.data.out ||
exit 1
335 echo "envelope data (content-info)"
336 ${hxtool} cms-envelope \
337 --certificate=FILE
:$srcdir/data
/test.crt \
339 "$srcdir/data/static-file" \
340 ev.data
> /dev
/null ||
exit 1
342 echo "unenvelope data (content-info)"
343 ${hxtool} cms-unenvelope \
344 --certificate=FILE
:$srcdir/data
/test.crt
,$srcdir/data
/test.key \
346 ev.data ev.data.out \
347 FILE
:$srcdir/data
/test.crt
,$srcdir/data
/test.key
> /dev
/null ||
exit 1
348 cmp "$srcdir/data/static-file" ev.data.out ||
exit 1
350 for a
in des-ede3 aes-128 aes-256
; do
352 rm -f ev.data ev.data.out
353 echo "envelope data ($a)"
354 ${hxtool} cms-envelope \
355 --encryption-type="$a-cbc" \
356 --certificate=FILE
:$srcdir/data
/test.crt \
357 "$srcdir/data/static-file" \
360 echo "unenvelope data ($a)"
361 ${hxtool} cms-unenvelope \
362 --certificate=FILE
:$srcdir/data
/test.crt
,$srcdir/data
/test.key \
363 ev.data ev.data.out
> /dev
/null ||
exit 1
364 cmp "$srcdir/data/static-file" ev.data.out ||
exit 1
367 for a
in rc2-40 rc2-64 rc2-128 des-ede3 aes-128 aes-256
; do
368 echo "static unenvelope data ($a)"
371 ${hxtool} cms-unenvelope \
372 --certificate=FILE
:$srcdir/data
/test.crt
,$srcdir/data
/test.key \
374 "$srcdir/data/test-enveloped-$a" ev.data.out
> /dev
/null ||
exit 1
375 cmp "$srcdir/data/static-file" ev.data.out ||
exit 1