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 # Perl script to run tests against S/MIME examples in RFC4134
54 # Assumes all files are extracted in an directory called "examples"
59 my $cmscmd = "../util/shlib_wrap.sh ../apps/openssl cms";
60 my $convcmd = "../util/shlib_wrap.sh ../apps/openssl x509 -inform DER";
61 my $pconvcmd = "../util/shlib_wrap.sh ../apps/openssl rsa -inform DER";
62 my $exdir = "examples";
65 ["3.1.bin" => "dataout"],
66 ["3.2.bin" => "encode, dataout"],
67 ["4.1.bin" => "encode, verifyder, content, dss"],
68 ["4.2.bin" => "encode, verifyder, cont, rsa"],
69 ["4.3.bin" => "encode, verifyder, cont_extern, dss"],
70 ["4.4.bin" => "encode, verifyder, cont, dss"],
71 ["4.5.bin" => "verifyder, content, rsa"],
72 ["4.6.bin" => "encode, verifyder, cont, dss"],
73 ["4.7.bin" => "encode, verifyder, cont, dss"],
74 ["4.8.eml" => "verifymime, dss"],
75 ["4.9.eml" => "verifymime, dss"],
76 ["4.10.bin" => "encode, verifyder, cont, dss"],
77 ["4.11.bin" => "encode"],
78 ["5.1.bin" => "encode, envelopeder, cont"],
79 ["5.2.bin" => "encode, envelopeder, cont"],
80 ["5.3.eml" => "envelopemime, cont"],
81 ["6.0.bin" => "encode, digest, cont"],
82 ["7.1.bin" => "encode, encrypted, cont"],
83 ["7.2.bin" => "encode, encrypted, cont"]
86 my $secretkey = "73:7c:79:1f:25:ea:d0:e0:46:29:25:43:52:f7:dc:62:91:e5:cb:26:91:7a:da:32";
90 print STDERR "FATAL ERROR: examples directory missing!!\n";
94 system ("$convcmd -in $exdir/CarlDSSSelf.cer -out $exdir/CarlDSSSelf.pem");
95 system ("$convcmd -in $exdir/CarlRSASelf.cer -out $exdir/CarlRSASelf.pem");
96 system ("$convcmd -in $exdir/BobRSASignByCarl.cer -out $exdir/BobRSASignByCarl.pem");
97 system ("$pconvcmd -in $exdir/BobPrivRSAEncrypt.pri -out $exdir/BobPrivRSAEncrypt.pem");
99 foreach (@test_list) {
100 my ($file, $tlist) = @$_;
101 print "Example file $file:\n";
102 if ($tlist =~ /encode/)
104 run_reencode_test($exdir, $file);
106 if ($tlist =~ /dataout/)
108 run_dataout_test($exdir, $file);
110 if ($tlist =~ /verify/)
112 run_verify_test($exdir, $tlist, $file);
114 if ($tlist =~ /digest/)
116 run_digest_test($exdir, $tlist, $file);
118 if ($tlist =~ /encrypted/)
120 run_encrypted_test($exdir, $tlist, $file, $secretkey);
122 if ($tlist =~ /envelope/)
124 run_envelope_test($exdir, $tlist, $file);
135 print "\n$badtest TESTS FAILED!!\n";
137 print "\n***All tests successful***\n";
141 sub run_reencode_test
143 my ($cmsdir, $tfile) = @_;
146 system ("$cmscmd -cmsout -inform DER -outform DER" .
147 " -in $cmsdir/$tfile -out tmp.der");
151 print "\tReencode command FAILED!!\n";
154 elsif (!cmp_files("$cmsdir/$tfile", "tmp.der"))
156 print "\tReencode FAILED!!\n";
161 print "\tReencode passed\n" if $verbose;
167 my ($cmsdir, $tfile) = @_;
170 system ("$cmscmd -data_out -inform DER" .
171 " -in $cmsdir/$tfile -out tmp.txt");
175 print "\tDataout command FAILED!!\n";
178 elsif (!cmp_files("$cmsdir/ExContent.bin", "tmp.txt"))
180 print "\tDataout compare FAILED!!\n";
185 print "\tDataout passed\n" if $verbose;
191 my ($cmsdir, $tlist, $tfile) = @_;
194 $form = "DER" if $tlist =~ /verifyder/;
195 $form = "SMIME" if $tlist =~ /verifymime/;
196 $cafile = "$cmsdir/CarlDSSSelf.pem" if $tlist =~ /dss/;
197 $cafile = "$cmsdir/CarlRSASelf.pem" if $tlist =~ /rsa/;
199 $cmd = "$cmscmd -verify -inform $form" .
201 " -in $cmsdir/$tfile -out tmp.txt";
203 $cmd .= " -content $cmsdir/ExContent.bin" if $tlist =~ /cont_extern/;
205 system ("$cmd 2>cms.err 1>cms.out");
209 print "\tVerify command FAILED!!\n";
212 elsif ($tlist =~ /cont/ &&
213 !cmp_files("$cmsdir/ExContent.bin", "tmp.txt"))
215 print "\tVerify content compare FAILED!!\n";
220 print "\tVerify passed\n" if $verbose;
224 sub run_envelope_test
226 my ($cmsdir, $tlist, $tfile) = @_;
229 $form = "DER" if $tlist =~ /envelopeder/;
230 $form = "SMIME" if $tlist =~ /envelopemime/;
232 $cmd = "$cmscmd -decrypt -inform $form" .
233 " -recip $cmsdir/BobRSASignByCarl.pem" .
234 " -inkey $cmsdir/BobPrivRSAEncrypt.pem" .
235 " -in $cmsdir/$tfile -out tmp.txt";
237 system ("$cmd 2>cms.err 1>cms.out");
241 print "\tDecrypt command FAILED!!\n";
244 elsif ($tlist =~ /cont/ &&
245 !cmp_files("$cmsdir/ExContent.bin", "tmp.txt"))
247 print "\tDecrypt content compare FAILED!!\n";
252 print "\tDecrypt passed\n" if $verbose;
258 my ($cmsdir, $tlist, $tfile) = @_;
261 my $cmd = "$cmscmd -digest_verify -inform DER" .
262 " -in $cmsdir/$tfile -out tmp.txt";
264 system ("$cmd 2>cms.err 1>cms.out");
268 print "\tDigest verify command FAILED!!\n";
271 elsif ($tlist =~ /cont/ &&
272 !cmp_files("$cmsdir/ExContent.bin", "tmp.txt"))
274 print "\tDigest verify content compare FAILED!!\n";
279 print "\tDigest verify passed\n" if $verbose;
283 sub run_encrypted_test
285 my ($cmsdir, $tlist, $tfile, $key) = @_;
288 system ("$cmscmd -EncryptedData_decrypt -inform DER" .
290 " -in $cmsdir/$tfile -out tmp.txt");
294 print "\tEncrypted Data command FAILED!!\n";
297 elsif ($tlist =~ /cont/ &&
298 !cmp_files("$cmsdir/ExContent.bin", "tmp.txt"))
300 print "\tEncrypted Data content compare FAILED!!\n";
305 print "\tEncryptedData verify passed\n" if $verbose;
316 if (!open($fp1, "<$f1") ) {
317 print STDERR "Can't Open file $f1\n";
321 if (!open($fp2, "<$f2") ) {
322 print STDERR "Can't Open file $f2\n";
333 $n1 = sysread $fp1, $rd1, 4096;
334 $n2 = sysread $fp2, $rd2, 4096;
335 last if ($n1 != $n2);
336 last if ($rd1 ne $rd2);