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 = "../apps/openssl cms";
60 my $convcmd = "../apps/openssl x509 -inform DER";
61 my $exdir = "examples";
64 ["3.1.bin" => "dataout"],
65 ["3.2.bin" => "encode, dataout"],
66 ["4.1.bin" => "encode, verifyder, content, dss"],
67 ["4.2.bin" => "encode, verifyder, cont, rsa"],
68 ["4.3.bin" => "encode, verifyder, cont_extern, dss"],
69 ["4.4.bin" => "encode, verifyder, cont, dss"],
70 ["4.5.bin" => "verifyder, content, rsa"],
71 ["4.6.bin" => "encode, verifyder, cont, dss"],
72 ["4.7.bin" => "encode, verifyder, cont, dss"],
73 ["4.8.eml" => "verifymime, dss"],
74 ["4.9.eml" => "verifymime, dss"],
75 ["4.10.bin" => "encode, verifyder, cont, dss"],
76 ["4.11.bin" => "encode"],
77 ["5.1.bin" => "encode"],
78 ["5.2.bin" => "encode"],
79 ["6.0.bin" => "encode, digest, cont"],
80 ["7.1.bin" => "encode"],
81 ["7.2.bin" => "encode"]
86 print STDERR "FATAL ERROR: examples directory missing!!\n";
90 system ("$convcmd -in $exdir/CarlDSSSelf.cer -out $exdir/CarlDSSSelf.pem");
91 system ("$convcmd -in $exdir/CarlRSASelf.cer -out $exdir/CarlRSASelf.pem");
93 $cafile = "$cmsdir/CarlRSASelf.pem" if $tlist =~ /rsa/;
95 foreach (@test_list) {
96 my ($file, $tlist) = @$_;
97 print "Example file $file:\n";
98 if ($tlist =~ /encode/)
100 run_reencode_test($exdir, $file);
102 if ($tlist =~ /dataout/)
104 run_dataout_test($exdir, $file);
106 if ($tlist =~ /verify/)
108 run_verify_test($exdir, $tlist, $file);
110 if ($tlist =~ /digest/)
112 run_digest_test($exdir, $tlist, $file);
123 print "\n$badtest TESTS FAILED!!\n";
125 print "\n***All tests successful***\n";
129 sub run_reencode_test
131 my ($cmsdir, $tfile) = @_;
134 system ("$cmscmd -cmsout -inform DER -outform DER" .
135 " -in $cmsdir/$tfile -out tmp.der");
139 print "\tReencode command FAILED!!\n";
142 elsif (!cmp_files("$cmsdir/$tfile", "tmp.der"))
144 print "\tReencode FAILED!!\n";
149 print "\tReencode passed\n" if $verbose;
155 my ($cmsdir, $tfile) = @_;
158 system ("$cmscmd -data_out -inform DER" .
159 " -in $cmsdir/$tfile -out tmp.txt");
163 print "\tDataout command FAILED!!\n";
166 elsif (!cmp_files("$cmsdir/ExContent.bin", "tmp.txt"))
168 print "\tDataout compare FAILED!!\n";
173 print "\tDataout passed\n" if $verbose;
179 my ($cmsdir, $tlist, $tfile) = @_;
182 $form = "DER" if $tlist =~ /verifyder/;
183 $form = "SMIME" if $tlist =~ /verifymime/;
184 $cafile = "$cmsdir/CarlDSSSelf.pem" if $tlist =~ /dss/;
185 $cafile = "$cmsdir/CarlRSASelf.pem" if $tlist =~ /rsa/;
187 $cmd = "$cmscmd -verify -inform $form" .
189 " -in $cmsdir/$tfile -out tmp.txt";
191 $cmd .= " -content $cmsdir/ExContent.bin" if $tlist =~ /cont_extern/;
193 system ("$cmd 2>cms.err 1>cms.out");
197 print "\tVerify command FAILED!!\n";
200 elsif ($tlist =~ /cont/ &&
201 !cmp_files("$cmsdir/ExContent.bin", "tmp.txt"))
203 print "\tVerify content compare FAILED!!\n";
208 print "\tVerify passed\n" if $verbose;
214 my ($cmsdir, $tlist, $tfile) = @_;
217 system ("$cmscmd -digest_verify -inform DER" .
218 " -in $cmsdir/$tfile -out tmp.txt");
222 print "\tDigest verify command FAILED!!\n";
225 elsif ($tlist =~ /cont/ &&
226 !cmp_files("$cmsdir/ExContent.bin", "tmp.txt"))
228 print "\tDigest verify content compare FAILED!!\n";
233 print "\tDigest verify passed\n" if $verbose;
244 if (!open($fp1, "<$f1") ) {
245 print STDERR "Can't Open file $f1\n";
249 if (!open($fp2, "<$f2") ) {
250 print STDERR "Can't Open file $f2\n";
261 $n1 = sysread $fp1, $rd1, 4096;
262 $n2 = sysread $fp2, $rd2, 4096;
263 last if ($n1 != $n2);
264 last if ($rd1 ne $rd2);