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 $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, encrypted, cont"],
81 ["7.2.bin" => "encode, encrypted, cont"]
84 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";
88 print STDERR "FATAL ERROR: examples directory missing!!\n";
92 system ("$convcmd -in $exdir/CarlDSSSelf.cer -out $exdir/CarlDSSSelf.pem");
93 system ("$convcmd -in $exdir/CarlRSASelf.cer -out $exdir/CarlRSASelf.pem");
95 $cafile = "$cmsdir/CarlRSASelf.pem" if $tlist =~ /rsa/;
97 foreach (@test_list) {
98 my ($file, $tlist) = @$_;
99 print "Example file $file:\n";
100 if ($tlist =~ /encode/)
102 run_reencode_test($exdir, $file);
104 if ($tlist =~ /dataout/)
106 run_dataout_test($exdir, $file);
108 if ($tlist =~ /verify/)
110 run_verify_test($exdir, $tlist, $file);
112 if ($tlist =~ /digest/)
114 run_digest_test($exdir, $tlist, $file);
116 if ($tlist =~ /encrypted/)
118 run_encrypted_test($exdir, $tlist, $file, $secretkey);
129 print "\n$badtest TESTS FAILED!!\n";
131 print "\n***All tests successful***\n";
135 sub run_reencode_test
137 my ($cmsdir, $tfile) = @_;
140 system ("$cmscmd -cmsout -inform DER -outform DER" .
141 " -in $cmsdir/$tfile -out tmp.der");
145 print "\tReencode command FAILED!!\n";
148 elsif (!cmp_files("$cmsdir/$tfile", "tmp.der"))
150 print "\tReencode FAILED!!\n";
155 print "\tReencode passed\n" if $verbose;
161 my ($cmsdir, $tfile) = @_;
164 system ("$cmscmd -data_out -inform DER" .
165 " -in $cmsdir/$tfile -out tmp.txt");
169 print "\tDataout command FAILED!!\n";
172 elsif (!cmp_files("$cmsdir/ExContent.bin", "tmp.txt"))
174 print "\tDataout compare FAILED!!\n";
179 print "\tDataout passed\n" if $verbose;
185 my ($cmsdir, $tlist, $tfile) = @_;
188 $form = "DER" if $tlist =~ /verifyder/;
189 $form = "SMIME" if $tlist =~ /verifymime/;
190 $cafile = "$cmsdir/CarlDSSSelf.pem" if $tlist =~ /dss/;
191 $cafile = "$cmsdir/CarlRSASelf.pem" if $tlist =~ /rsa/;
193 $cmd = "$cmscmd -verify -inform $form" .
195 " -in $cmsdir/$tfile -out tmp.txt";
197 $cmd .= " -content $cmsdir/ExContent.bin" if $tlist =~ /cont_extern/;
199 system ("$cmd 2>cms.err 1>cms.out");
203 print "\tVerify command FAILED!!\n";
206 elsif ($tlist =~ /cont/ &&
207 !cmp_files("$cmsdir/ExContent.bin", "tmp.txt"))
209 print "\tVerify content compare FAILED!!\n";
214 print "\tVerify passed\n" if $verbose;
220 my ($cmsdir, $tlist, $tfile) = @_;
223 system ("$cmscmd -digest_verify -inform DER" .
224 " -in $cmsdir/$tfile -out tmp.txt");
228 print "\tDigest verify command FAILED!!\n";
231 elsif ($tlist =~ /cont/ &&
232 !cmp_files("$cmsdir/ExContent.bin", "tmp.txt"))
234 print "\tDigest verify content compare FAILED!!\n";
239 print "\tDigest verify passed\n" if $verbose;
243 sub run_encrypted_test
245 my ($cmsdir, $tlist, $tfile, $key) = @_;
248 system ("$cmscmd -EncryptedData_decrypt -inform DER" .
250 " -in $cmsdir/$tfile -out tmp.txt");
254 print "\tEncrypted Data command FAILED!!\n";
257 elsif ($tlist =~ /cont/ &&
258 !cmp_files("$cmsdir/ExContent.bin", "tmp.txt"))
260 print "\tEncrypted Data content compare FAILED!!\n";
265 print "\tEncryptedData verify passed\n" if $verbose;
276 if (!open($fp1, "<$f1") ) {
277 print STDERR "Can't Open file $f1\n";
281 if (!open($fp2, "<$f2") ) {
282 print STDERR "Can't Open file $f2\n";
293 $n1 = sysread $fp1, $rd1, 4096;
294 $n2 = sysread $fp2, $rd2, 4096;
295 last if ($n1 != $n2);
296 last if ($rd1 ne $rd2);