# CMS, PKCS7 consistency test script. Run extensive tests on
# OpenSSL PKCS#7 and CMS implementations.
+my $ossl_path;
-my $ossl_path = "../apps/openssl";
-my $cmd = "$ossl_path cms ";
-my $cmd2 = "$ossl_path smime ";
-my $smdir = "smime-certs";
+if ( -f "../apps/openssl" ) {
+ $ossl_path = "../util/shlib_wrap.sh ../apps/openssl";
+}
+elsif ( -f "..\\out32dll\\openssl.exe" ) {
+ $ossl_path = "..\\out32dll\\openssl.exe";
+}
+elsif ( -f "..\\out32\\openssl.exe" ) {
+ $ossl_path = "..\\out32\\openssl.exe";
+}
+else {
+ die "Can't find OpenSSL executable";
+}
+
+my $pk7cmd = "$ossl_path smime ";
+my $cmscmd = "$ossl_path cms ";
+my $smdir = "smime-certs";
+my $halt_err = 1;
my $badcmd = 0;
"-sign -in smcont.txt -outform DER -nodetach"
. " -signer $smdir/smrsa1.pem -out test.cms",
"-verify -in test.cms -inform DER "
- . " -CAfile $smdir/smroot.pem -out smtst.txt"
+ . " -CAfile $smdir/smroot.pem -out smtst.txt"
],
[
"signed detached content DER format, RSA key",
-
"-sign -in smcont.txt -outform DER"
. " -signer $smdir/smrsa1.pem -out test.cms",
"-verify -in test.cms -inform DER "
"-sign -in smcont.txt -outform DER -nodetach"
. " -stream -signer $smdir/smrsa1.pem -out test.cms",
"-verify -in test.cms -inform DER "
- . " -CAfile $smdir/smroot.pem -out smtst.txt"
+ . " -CAfile $smdir/smroot.pem -out smtst.txt"
],
[
"-sign -in smcont.txt -outform DER -nodetach"
. " -signer $smdir/smdsa1.pem -out test.cms",
"-verify -in test.cms -inform DER "
- . " -CAfile $smdir/smroot.pem -out smtst.txt"
+ . " -CAfile $smdir/smroot.pem -out smtst.txt"
],
[
"signed detached content DER format, DSA key",
-
"-sign -in smcont.txt -outform DER"
. " -signer $smdir/smdsa1.pem -out test.cms",
"-verify -in test.cms -inform DER "
[
"signed detached content DER format, add RSA signer",
-
"-resign -inform DER -in test.cms -outform DER"
. " -signer $smdir/smrsa1.pem -out test2.cms",
"-verify -in test2.cms -inform DER "
"-sign -in smcont.txt -outform DER -nodetach"
. " -stream -signer $smdir/smdsa1.pem -out test.cms",
"-verify -in test.cms -inform DER "
- . " -CAfile $smdir/smroot.pem -out smtst.txt"
+ . " -CAfile $smdir/smroot.pem -out smtst.txt"
],
[
. " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
. " -stream -out test.cms",
"-verify -in test.cms -inform DER "
- . " -CAfile $smdir/smroot.pem -out smtst.txt"
+ . " -CAfile $smdir/smroot.pem -out smtst.txt"
],
[
. " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
. " -stream -out test.cms",
"-verify -in test.cms -inform DER "
- . " -CAfile $smdir/smroot.pem -out smtst.txt"
+ . " -CAfile $smdir/smroot.pem -out smtst.txt"
],
[
. " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem"
. " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
. " -stream -out test.cms",
- "-verify -in test.cms "
- . " -CAfile $smdir/smroot.pem -out smtst.txt"
+ "-verify -in test.cms " . " -CAfile $smdir/smroot.pem -out smtst.txt"
],
[
. " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem"
. " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
. " -stream -out test.cms",
- "-verify -in test.cms "
- . " -CAfile $smdir/smroot.pem -out smtst.txt"
+ "-verify -in test.cms " . " -CAfile $smdir/smroot.pem -out smtst.txt"
],
[
. " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
. " -stream -out test.cms",
"-verify -in test.cms -inform DER "
- . " -CAfile $smdir/smroot.pem -out smtst.txt"
+ . " -CAfile $smdir/smroot.pem -out smtst.txt"
],
[
. " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
. " -stream -out test.cms",
"-verify -in test.cms -inform PEM "
- . " -CAfile $smdir/smroot.pem -out smtst.txt"
+ . " -CAfile $smdir/smroot.pem -out smtst.txt"
+ ],
+
+ [
+ "enveloped content test streaming S/MIME format, 3 recipients, keyid",
+ "-encrypt -in smcont.txt"
+ . " -stream -out test.cms -keyid"
+ . " $smdir/smrsa1.pem $smdir/smrsa2.pem $smdir/smrsa3.pem ",
+ "-decrypt -recip $smdir/smrsa1.pem -in test.cms -out smtst.txt"
+ ],
+
+ [
+ "enveloped content test streaming PEM format, KEK",
+ "-encrypt -in smcont.txt -outform PEM -aes128"
+ . " -stream -out test.cms "
+ . " -secretkey 000102030405060708090A0B0C0D0E0F "
+ . " -secretkeyid C0FEE0",
+ "-decrypt -in test.cms -out smtst.txt -inform PEM"
+ . " -secretkey 000102030405060708090A0B0C0D0E0F "
+ . " -secretkeyid C0FEE0"
+ ],
+
+ [
+ "enveloped content test streaming PEM format, KEK, key only",
+ "-encrypt -in smcont.txt -outform PEM -aes128"
+ . " -stream -out test.cms "
+ . " -secretkey 000102030405060708090A0B0C0D0E0F "
+ . " -secretkeyid C0FEE0",
+ "-decrypt -in test.cms -out smtst.txt -inform PEM"
+ . " -secretkey 000102030405060708090A0B0C0D0E0F "
],
[
print "CMS => PKCS#7 compatibility tests\n";
-run_smime_tests( \$badcmd, \@smime_pkcs7_tests, $cmd, $cmd2 );
+run_smime_tests( \$badcmd, \@smime_pkcs7_tests, $cmscmd, $pk7cmd );
print "CMS <= PKCS#7 compatibility tests\n";
-run_smime_tests( \$badcmd, \@smime_pkcs7_tests, $cmd2, $cmd );
+run_smime_tests( \$badcmd, \@smime_pkcs7_tests, $pk7cmd, $cmscmd );
print "CMS <=> CMS consistency tests\n";
-run_smime_tests( \$badcmd, \@smime_pkcs7_tests, $cmd, $cmd );
-run_smime_tests( \$badcmd, \@smime_cms_tests, $cmd, $cmd );
+run_smime_tests( \$badcmd, \@smime_pkcs7_tests, $cmscmd, $cmscmd );
+run_smime_tests( \$badcmd, \@smime_cms_tests, $cmscmd, $cmscmd );
if ( `$ossl_path version -f` =~ /ZLIB/ ) {
- run_smime_tests( \$badcmd, \@smime_cms_comp_tests, $cmd, $cmd );
+ run_smime_tests( \$badcmd, \@smime_cms_comp_tests, $cmscmd, $cmscmd );
}
else {
print "Zlib not supported: compression tests skipped\n";
print "ALL TESTS SUCCESSFUL.\n";
}
+unlink "test.cms";
+unlink "test2.cms";
+unlink "smtst.txt";
+unlink "cms.out";
+unlink "cms.err";
+
sub run_smime_tests {
my ( $rv, $aref, $scmd, $vcmd ) = @_;
foreach $smtst (@$aref) {
my ( $tnam, $rscmd, $rvcmd ) = @$smtst;
- system( $scmd . $rscmd );
+ system("$scmd$rscmd 2>cms.err 1>cms.out");
if ($?) {
print "$tnam: generation error\n";
$$rv++;
+ exit 1 if $halt_err;
next;
}
- system( $vcmd . $rvcmd );
+ system("$vcmd$rvcmd 2>cms.err 1>cms.out");
if ($?) {
print "$tnam: verify error\n";
$$rv++;
+ exit 1 if $halt_err;
next;
}
+ if (!cmp_files("smtst.txt", "smcont.txt")) {
+ print "$tnam: content verify error\n";
+ $$rv++;
+ exit 1 if $halt_err;
+ next;
+ }
print "$tnam: OK\n";
}
}
+sub cmp_files {
+ my ( $f1, $f2 ) = @_;
+ my ( $fp1, $fp2 );
+
+ my ( $rd1, $rd2 );
+
+ if ( !open( $fp1, "<$f1" ) ) {
+ print STDERR "Can't Open file $f1\n";
+ return 0;
+ }
+
+ if ( !open( $fp2, "<$f2" ) ) {
+ print STDERR "Can't Open file $f2\n";
+ return 0;
+ }
+
+ binmode $fp1;
+ binmode $fp2;
+
+ my $ret = 0;
+
+ for ( ; ; ) {
+ $n1 = sysread $fp1, $rd1, 4096;
+ $n2 = sysread $fp2, $rd2, 4096;
+ last if ( $n1 != $n2 );
+ last if ( $rd1 ne $rd2 );
+
+ if ( $n1 == 0 ) {
+ $ret = 1;
+ last;
+ }
+
+ }
+
+ close $fp1;
+ close $fp2;
+
+ return $ret;
+
+}
+