2 # Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
5 # ====================================================================
6 # Copyright (c) 2008 The OpenSSL Project. All rights reserved.
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
12 # 1. Redistributions of source code must retain the above copyright
13 # notice, this list of conditions and the following disclaimer.
15 # 2. Redistributions in binary form must reproduce the above copyright
16 # notice, this list of conditions and the following disclaimer in
17 # the documentation and/or other materials provided with the
20 # 3. All advertising materials mentioning features or use of this
21 # software must display the following acknowledgment:
22 # "This product includes software developed by the OpenSSL Project
23 # for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
25 # 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 # endorse or promote products derived from this software without
27 # prior written permission. For written permission, please contact
28 # licensing@OpenSSL.org.
30 # 5. Products derived from this software may not be called "OpenSSL"
31 # nor may "OpenSSL" appear in their names without prior written
32 # permission of the OpenSSL Project.
34 # 6. Redistributions of any form whatsoever must retain the following
36 # "This product includes software developed by the OpenSSL Project
37 # for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
39 # THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 # EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 # ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 # OF THE POSSIBILITY OF SUCH DAMAGE.
51 # ====================================================================
53 # CMS, PKCS7 consistency test script. Run extensive tests on
54 # OpenSSL PKCS#7 and CMS implementations.
57 my $ossl_path = "../apps/openssl";
58 my $cmd = "$ossl_path cms ";
59 my $cmd2 = "$ossl_path smime ";
60 my $smdir = "smime-certs";
64 my @smime_pkcs7_tests = (
67 "signed content DER format, RSA key",
68 "-sign -in smcont.txt -outform DER -nodetach"
69 . " -signer $smdir/smrsa1.pem -out test.cms",
70 "-verify -in test.cms -inform DER "
71 . " -CAfile $smdir/smroot.pem -out smtst.txt"
75 "signed detached content DER format, RSA key",
77 "-sign -in smcont.txt -outform DER"
78 . " -signer $smdir/smrsa1.pem -out test.cms",
79 "-verify -in test.cms -inform DER "
80 . " -CAfile $smdir/smroot.pem -out smtst.txt -content smcont.txt"
84 "signed content test streaming BER format, RSA",
85 "-sign -in smcont.txt -outform DER -nodetach"
86 . " -stream -signer $smdir/smrsa1.pem -out test.cms",
87 "-verify -in test.cms -inform DER "
88 . " -CAfile $smdir/smroot.pem -out smtst.txt"
92 "signed content DER format, DSA key",
93 "-sign -in smcont.txt -outform DER -nodetach"
94 . " -signer $smdir/smdsa1.pem -out test.cms",
95 "-verify -in test.cms -inform DER "
96 . " -CAfile $smdir/smroot.pem -out smtst.txt"
100 "signed detached content DER format, DSA key",
102 "-sign -in smcont.txt -outform DER"
103 . " -signer $smdir/smdsa1.pem -out test.cms",
104 "-verify -in test.cms -inform DER "
105 . " -CAfile $smdir/smroot.pem -out smtst.txt -content smcont.txt"
109 "signed detached content DER format, add RSA signer",
111 "-resign -inform DER -in test.cms -outform DER"
112 . " -signer $smdir/smrsa1.pem -out test2.cms",
113 "-verify -in test2.cms -inform DER "
114 . " -CAfile $smdir/smroot.pem -out smtst.txt -content smcont.txt"
118 "signed content test streaming BER format, DSA key",
119 "-sign -in smcont.txt -outform DER -nodetach"
120 . " -stream -signer $smdir/smdsa1.pem -out test.cms",
121 "-verify -in test.cms -inform DER "
122 . " -CAfile $smdir/smroot.pem -out smtst.txt"
126 "signed content test streaming BER format, 2 DSA and 2 RSA keys",
127 "-sign -in smcont.txt -outform DER -nodetach"
128 . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem"
129 . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
130 . " -stream -out test.cms",
131 "-verify -in test.cms -inform DER "
132 . " -CAfile $smdir/smroot.pem -out smtst.txt"
136 "signed content test streaming BER format, 2 DSA and 2 RSA keys, no attributes",
137 "-sign -in smcont.txt -outform DER -noattr -nodetach"
138 . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem"
139 . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
140 . " -stream -out test.cms",
141 "-verify -in test.cms -inform DER "
142 . " -CAfile $smdir/smroot.pem -out smtst.txt"
146 "signed content test streaming S/MIME format, 2 DSA and 2 RSA keys",
147 "-sign -in smcont.txt -nodetach"
148 . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem"
149 . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
150 . " -stream -out test.cms",
151 "-verify -in test.cms "
152 . " -CAfile $smdir/smroot.pem -out smtst.txt"
156 "signed content test streaming multipart S/MIME format, 2 DSA and 2 RSA keys",
157 "-sign -in smcont.txt"
158 . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem"
159 . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
160 . " -stream -out test.cms",
161 "-verify -in test.cms "
162 . " -CAfile $smdir/smroot.pem -out smtst.txt"
166 "enveloped content test streaming S/MIME format, 3 recipients",
167 "-encrypt -in smcont.txt"
168 . " -stream -out test.cms"
169 . " $smdir/smrsa1.pem $smdir/smrsa2.pem $smdir/smrsa3.pem ",
170 "-decrypt -recip $smdir/smrsa1.pem -in test.cms -out smtst.txt"
174 "enveloped content test streaming S/MIME format, 3 recipients, 3rd used",
175 "-encrypt -in smcont.txt"
176 . " -stream -out test.cms"
177 . " $smdir/smrsa1.pem $smdir/smrsa2.pem $smdir/smrsa3.pem ",
178 "-decrypt -recip $smdir/smrsa3.pem -in test.cms -out smtst.txt"
182 "enveloped content test streaming S/MIME format, 3 recipients, key only used",
183 "-encrypt -in smcont.txt"
184 . " -stream -out test.cms"
185 . " $smdir/smrsa1.pem $smdir/smrsa2.pem $smdir/smrsa3.pem ",
186 "-decrypt -inkey $smdir/smrsa3.pem -in test.cms -out smtst.txt"
190 "enveloped content test streaming S/MIME format, AES-256 cipher, 3 recipients",
191 "-encrypt -in smcont.txt"
192 . " -aes256 -stream -out test.cms"
193 . " $smdir/smrsa1.pem $smdir/smrsa2.pem $smdir/smrsa3.pem ",
194 "-decrypt -recip $smdir/smrsa1.pem -in test.cms -out smtst.txt"
199 my @smime_cms_tests = (
202 "signed content test streaming BER format, 2 DSA and 2 RSA keys, keyid",
203 "-sign -in smcont.txt -outform DER -nodetach -keyid"
204 . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem"
205 . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
206 . " -stream -out test.cms",
207 "-verify -in test.cms -inform DER "
208 . " -CAfile $smdir/smroot.pem -out smtst.txt"
212 "signed content test streaming PEM format, 2 DSA and 2 RSA keys",
213 "-sign -in smcont.txt -outform PEM -nodetach"
214 . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem"
215 . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
216 . " -stream -out test.cms",
217 "-verify -in test.cms -inform PEM "
218 . " -CAfile $smdir/smroot.pem -out smtst.txt"
222 "data content test streaming PEM format",
223 "-data_create -in smcont.txt -outform PEM -nodetach"
224 . " -stream -out test.cms",
225 "-data_out -in test.cms -inform PEM -out smtst.txt"
229 "encrypted content test streaming PEM format, 128 bit RC2 key",
230 "-EncryptedData_encrypt -in smcont.txt -outform PEM"
231 . " -rc2 -secretkey 000102030405060708090A0B0C0D0E0F"
232 . " -stream -out test.cms",
233 "-EncryptedData_decrypt -in test.cms -inform PEM "
234 . " -secretkey 000102030405060708090A0B0C0D0E0F -out smtst.txt"
238 "encrypted content test streaming PEM format, 40 bit RC2 key",
239 "-EncryptedData_encrypt -in smcont.txt -outform PEM"
240 . " -rc2 -secretkey 0001020304"
241 . " -stream -out test.cms",
242 "-EncryptedData_decrypt -in test.cms -inform PEM "
243 . " -secretkey 0001020304 -out smtst.txt"
247 "encrypted content test streaming PEM format, triple DES key",
248 "-EncryptedData_encrypt -in smcont.txt -outform PEM"
249 . " -des3 -secretkey 000102030405060708090A0B0C0D0E0F1011121314151617"
250 . " -stream -out test.cms",
251 "-EncryptedData_decrypt -in test.cms -inform PEM "
252 . " -secretkey 000102030405060708090A0B0C0D0E0F1011121314151617"
257 "encrypted content test streaming PEM format, 128 bit AES key",
258 "-EncryptedData_encrypt -in smcont.txt -outform PEM"
259 . " -aes128 -secretkey 000102030405060708090A0B0C0D0E0F"
260 . " -stream -out test.cms",
261 "-EncryptedData_decrypt -in test.cms -inform PEM "
262 . " -secretkey 000102030405060708090A0B0C0D0E0F -out smtst.txt"
267 my @smime_cms_comp_tests = (
270 "compressed content test streaming PEM format",
271 "-compress -in smcont.txt -outform PEM -nodetach"
272 . " -stream -out test.cms",
273 "-uncompress -in test.cms -inform PEM -out smtst.txt"
278 print "CMS => PKCS#7 compatibility tests\n";
280 run_smime_tests( \$badcmd, \@smime_pkcs7_tests, $cmd, $cmd2 );
282 print "CMS <= PKCS#7 compatibility tests\n";
284 run_smime_tests( \$badcmd, \@smime_pkcs7_tests, $cmd2, $cmd );
286 print "CMS <=> CMS consistency tests\n";
288 run_smime_tests( \$badcmd, \@smime_pkcs7_tests, $cmd, $cmd );
289 run_smime_tests( \$badcmd, \@smime_cms_tests, $cmd, $cmd );
291 if ( `$ossl_path version -f` =~ /ZLIB/ ) {
292 run_smime_tests( \$badcmd, \@smime_cms_comp_tests, $cmd, $cmd );
295 print "Zlib not supported: compression tests skipped\n";
299 print "$badcmd TESTS FAILED!!\n";
302 print "ALL TESTS SUCCESSFUL.\n";
305 sub run_smime_tests {
306 my ( $rv, $aref, $scmd, $vcmd ) = @_;
308 foreach $smtst (@$aref) {
309 my ( $tnam, $rscmd, $rvcmd ) = @$smtst;
310 system( $scmd . $rscmd );
312 print "$tnam: generation error\n";
316 system( $vcmd . $rvcmd );
318 print "$tnam: verify error\n";