Update copyright year
[openssl.git] / test / recipes / 80-test_cms.t
index db2fce650d519e13f212a35099d9401b2c260190..8e1478c3869212c9ea14efb8efab396b4eddf31c 100644 (file)
@@ -1,5 +1,5 @@
 #! /usr/bin/env perl
-# Copyright 2015-2020 The OpenSSL Project Authors. All Rights Reserved.
+# Copyright 2015-2021 The OpenSSL Project Authors. All Rights Reserved.
 #
 # Licensed under the Apache License 2.0 (the "License").  You may not use
 # this file except in compliance with the License.  You can obtain a copy
@@ -13,190 +13,238 @@ use warnings;
 use POSIX;
 use File::Spec::Functions qw/catfile/;
 use File::Compare qw/compare_text/;
-use OpenSSL::Test qw/:DEFAULT srctop_dir srctop_file bldtop_dir/;
+use OpenSSL::Test qw/:DEFAULT srctop_dir srctop_file bldtop_dir bldtop_file/;
+
 use OpenSSL::Test::Utils;
 
-setup("test_cms");
+BEGIN {
+    setup("test_cms");
+}
+
+use lib srctop_dir('Configurations');
+use lib bldtop_dir('.');
+use platform;
+
+my $no_fips = disabled('fips') || ($ENV{NO_FIPS} // 0);
 
 plan skip_all => "CMS is not supported by this OpenSSL build"
     if disabled("cms");
 
 my $provpath = bldtop_dir("providers");
-my @prov = ("-provider_path", $provpath, "-provider", "default", "-provider", "legacy");
+
+# Some tests require legacy algorithms to be included.
+my @legacyprov = ("-provider-path", $provpath,
+                  "-provider", "default",
+                  "-provider", "legacy" );
+my @defaultprov = ("-provider-path", $provpath,
+                   "-provider", "default");
+
+my @config = ( );
+my $provname = 'default';
 
 my $datadir = srctop_dir("test", "recipes", "80-test_cms_data");
 my $smdir    = srctop_dir("test", "smime-certs");
 my $smcont   = srctop_file("test", "smcont.txt");
+my $smcont_zero = srctop_file("test", "smcont_zero.txt");
 my ($no_des, $no_dh, $no_dsa, $no_ec, $no_ec2m, $no_rc2, $no_zlib)
     = disabled qw/des dh dsa ec ec2m rc2 zlib/;
 
-plan tests => 7;
+$no_rc2 = 1 if disabled("legacy");
+
+plan tests =>
+    ($no_fips ? 0 : 1)          # FIPS install test
+    + 10;
+
+unless ($no_fips) {
+    my $infile = bldtop_file('providers', platform->dso('fips'));
+
+    ok(run(app(['openssl', 'fipsinstall',
+                '-out', bldtop_file('providers', 'fipsmodule.cnf'),
+                '-module', $infile])),
+       "fipsinstall");
+    @config = ( "-config", srctop_file("test", "fips-and-base.cnf") );
+    $provname = 'fips';
+}
+
+$ENV{OPENSSL_TEST_LIBCTX} = "1";
+my @prov = ("-provider-path", $provpath,
+            @config,
+            "-provider", $provname);
 
 my @smime_pkcs7_tests = (
 
     [ "signed content DER format, RSA key",
-      [ "{cmd1}", "-sign", "-in", $smcont, "-outform", "DER", "-nodetach",
+      [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "DER", "-nodetach",
         "-certfile", catfile($smdir, "smroot.pem"),
         "-signer", catfile($smdir, "smrsa1.pem"), "-out", "{output}.cms" ],
-      [ "{cmd2}", "-verify", "-in", "{output}.cms", "-inform", "DER",
+      [ "{cmd2}",  @prov, "-verify", "-in", "{output}.cms", "-inform", "DER",
         "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt" ],
       \&final_compare
     ],
 
     [ "signed detached content DER format, RSA key",
-      [ "{cmd1}", "-sign", "-in", $smcont, "-outform", "DER",
+      [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "DER",
         "-signer", catfile($smdir, "smrsa1.pem"), "-out", "{output}.cms" ],
-      [ "{cmd2}", "-verify", "-in", "{output}.cms", "-inform", "DER",
+      [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "DER",
         "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt",
         "-content", $smcont ],
       \&final_compare
     ],
 
     [ "signed content test streaming BER format, RSA",
-      [ "{cmd1}", "-sign", "-in", $smcont, "-outform", "DER", "-nodetach",
+      [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "DER", "-nodetach",
         "-stream",
         "-signer", catfile($smdir, "smrsa1.pem"), "-out", "{output}.cms" ],
-      [ "{cmd2}", "-verify", "-in", "{output}.cms", "-inform", "DER",
+      [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "DER",
         "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt" ],
       \&final_compare
     ],
 
     [ "signed content DER format, DSA key",
-      [ "{cmd1}", "-sign", "-in", $smcont, "-outform", "DER", "-nodetach",
+      [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "DER", "-nodetach",
         "-signer", catfile($smdir, "smdsa1.pem"), "-out", "{output}.cms" ],
-      [ "{cmd2}", "-verify", "-in", "{output}.cms", "-inform", "DER",
+      [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "DER",
         "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt" ],
       \&final_compare
     ],
 
     [ "signed detached content DER format, DSA key",
-      [ "{cmd1}", "-sign", "-in", $smcont, "-outform", "DER",
+      [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "DER",
         "-signer", catfile($smdir, "smdsa1.pem"), "-out", "{output}.cms" ],
-      [ "{cmd2}", "-verify", "-in", "{output}.cms", "-inform", "DER",
+      [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "DER",
         "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt",
         "-content", $smcont ],
       \&final_compare
     ],
 
     [ "signed detached content DER format, add RSA signer (with DSA existing)",
-      [ "{cmd1}", "-sign", "-in", $smcont, "-outform", "DER",
+      [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "DER",
         "-signer", catfile($smdir, "smdsa1.pem"), "-out", "{output}.cms" ],
-      [ "{cmd1}", "-resign", "-in", "{output}.cms", "-inform", "DER", "-outform", "DER",
+      [ "{cmd1}", @prov, "-resign", "-in", "{output}.cms", "-inform", "DER", "-outform", "DER",
         "-signer", catfile($smdir, "smrsa1.pem"), "-out", "{output}2.cms" ],
-      [ "{cmd2}", "-verify", "-in", "{output}2.cms", "-inform", "DER",
+      [ "{cmd2}", @prov, "-verify", "-in", "{output}2.cms", "-inform", "DER",
         "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt",
         "-content", $smcont ],
       \&final_compare
     ],
 
     [ "signed content test streaming BER format, DSA key",
-      [ "{cmd1}", "-sign", "-in", $smcont, "-outform", "DER",
+      [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "DER",
         "-nodetach", "-stream",
         "-signer", catfile($smdir, "smdsa1.pem"), "-out", "{output}.cms" ],
-      [ "{cmd2}", "-verify", "-in", "{output}.cms", "-inform", "DER",
+      [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "DER",
         "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt" ],
       \&final_compare
     ],
 
     [ "signed content test streaming BER format, 2 DSA and 2 RSA keys",
-      [ "{cmd1}", "-sign", "-in", $smcont, "-outform", "DER",
+      [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "DER",
         "-nodetach", "-stream",
         "-signer", catfile($smdir, "smrsa1.pem"),
         "-signer", catfile($smdir, "smrsa2.pem"),
         "-signer", catfile($smdir, "smdsa1.pem"),
         "-signer", catfile($smdir, "smdsa2.pem"),
         "-out", "{output}.cms" ],
-      [ "{cmd2}", "-verify", "-in", "{output}.cms", "-inform", "DER",
+      [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "DER",
         "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt" ],
       \&final_compare
     ],
 
     [ "signed content test streaming BER format, 2 DSA and 2 RSA keys, no attributes",
-      [ "{cmd1}", "-sign", "-in", $smcont, "-outform", "DER",
+      [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "DER",
         "-noattr", "-nodetach", "-stream",
         "-signer", catfile($smdir, "smrsa1.pem"),
         "-signer", catfile($smdir, "smrsa2.pem"),
         "-signer", catfile($smdir, "smdsa1.pem"),
         "-signer", catfile($smdir, "smdsa2.pem"),
         "-out", "{output}.cms" ],
-      [ "{cmd2}", "-verify", "-in", "{output}.cms", "-inform", "DER",
+      [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "DER",
         "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt" ],
       \&final_compare
     ],
 
     [ "signed content S/MIME format, RSA key SHA1",
-      [ "{cmd1}", "-sign", "-in", $smcont, "-md", "sha1",
+      [ "{cmd1}", @defaultprov, "-sign", "-in", $smcont, "-md", "sha1",
         "-certfile", catfile($smdir, "smroot.pem"),
         "-signer", catfile($smdir, "smrsa1.pem"), "-out", "{output}.cms" ],
-      [ "{cmd2}", "-verify", "-in", "{output}.cms",
+      [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms",
         "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt" ],
       \&final_compare
     ],
 
+    [ "signed zero-length content S/MIME format, RSA key SHA1",
+      [ "{cmd1}", @defaultprov, "-sign", "-in", $smcont_zero, "-md", "sha1",
+        "-certfile", catfile($smdir, "smroot.pem"),
+        "-signer", catfile($smdir, "smrsa1.pem"), "-out", "{output}.cms" ],
+      [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms",
+        "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt" ],
+      \&zero_compare
+    ],
+
     [ "signed content test streaming S/MIME format, 2 DSA and 2 RSA keys",
-      [ "{cmd1}", "-sign", "-in", $smcont, "-nodetach",
+      [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-nodetach",
         "-signer", catfile($smdir, "smrsa1.pem"),
         "-signer", catfile($smdir, "smrsa2.pem"),
         "-signer", catfile($smdir, "smdsa1.pem"),
         "-signer", catfile($smdir, "smdsa2.pem"),
         "-stream", "-out", "{output}.cms" ],
-      [ "{cmd2}", "-verify", "-in", "{output}.cms",
+      [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms",
         "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt" ],
       \&final_compare
     ],
 
     [ "signed content test streaming multipart S/MIME format, 2 DSA and 2 RSA keys",
-      [ "{cmd1}", "-sign", "-in", $smcont,
+      [ "{cmd1}", @prov, "-sign", "-in", $smcont,
         "-signer", catfile($smdir, "smrsa1.pem"),
         "-signer", catfile($smdir, "smrsa2.pem"),
         "-signer", catfile($smdir, "smdsa1.pem"),
         "-signer", catfile($smdir, "smdsa2.pem"),
         "-stream", "-out", "{output}.cms" ],
-      [ "{cmd2}", "-verify", "-in", "{output}.cms",
+      [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms",
         "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt" ],
       \&final_compare
     ],
 
     [ "enveloped content test streaming S/MIME format, DES, 3 recipients",
-      [ "{cmd1}", "-encrypt", "-in", $smcont,
+      [ "{cmd1}", @defaultprov, "-encrypt", "-in", $smcont,
         "-stream", "-out", "{output}.cms",
         catfile($smdir, "smrsa1.pem"),
         catfile($smdir, "smrsa2.pem"),
         catfile($smdir, "smrsa3.pem") ],
-      [ "{cmd2}", "-decrypt", "-recip", catfile($smdir, "smrsa1.pem"),
+      [ "{cmd2}", @defaultprov, "-decrypt", "-recip", catfile($smdir, "smrsa1.pem"),
         "-in", "{output}.cms", "-out", "{output}.txt" ],
       \&final_compare
     ],
 
     [ "enveloped content test streaming S/MIME format, DES, 3 recipients, 3rd used",
-      [ "{cmd1}", "-encrypt", "-in", $smcont,
+      [ "{cmd1}", @defaultprov, "-encrypt", "-in", $smcont,
         "-stream", "-out", "{output}.cms",
         catfile($smdir, "smrsa1.pem"),
         catfile($smdir, "smrsa2.pem"),
         catfile($smdir, "smrsa3.pem") ],
-      [ "{cmd2}", "-decrypt", "-recip", catfile($smdir, "smrsa3.pem"),
+      [ "{cmd2}", @defaultprov, "-decrypt", "-recip", catfile($smdir, "smrsa3.pem"),
         "-in", "{output}.cms", "-out", "{output}.txt" ],
       \&final_compare
     ],
 
     [ "enveloped content test streaming S/MIME format, DES, 3 recipients, key only used",
-      [ "{cmd1}", "-encrypt", "-in", $smcont,
+      [ "{cmd1}", @defaultprov, "-encrypt", "-in", $smcont,
         "-stream", "-out", "{output}.cms",
         catfile($smdir, "smrsa1.pem"),
         catfile($smdir, "smrsa2.pem"),
         catfile($smdir, "smrsa3.pem") ],
-      [ "{cmd2}", "-decrypt", "-inkey", catfile($smdir, "smrsa3.pem"),
+      [ "{cmd2}", @defaultprov, "-decrypt", "-inkey", catfile($smdir, "smrsa3.pem"),
         "-in", "{output}.cms", "-out", "{output}.txt" ],
       \&final_compare
     ],
 
     [ "enveloped content test streaming S/MIME format, AES-256 cipher, 3 recipients",
-      [ "{cmd1}", "-encrypt", "-in", $smcont,
+      [ "{cmd1}", @prov, "-encrypt", "-in", $smcont,
         "-aes256", "-stream", "-out", "{output}.cms",
         catfile($smdir, "smrsa1.pem"),
         catfile($smdir, "smrsa2.pem"),
         catfile($smdir, "smrsa3.pem") ],
-      [ "{cmd2}", "-decrypt", "-recip", catfile($smdir, "smrsa1.pem"),
+      [ "{cmd2}", @prov, "-decrypt", "-recip", catfile($smdir, "smrsa1.pem"),
         "-in", "{output}.cms", "-out", "{output}.txt" ],
       \&final_compare
     ],
@@ -206,84 +254,76 @@ my @smime_pkcs7_tests = (
 my @smime_cms_tests = (
 
     [ "signed content test streaming BER format, 2 DSA and 2 RSA keys, keyid",
-      [ "{cmd1}", "-sign", "-in", $smcont, "-outform", "DER",
+      [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "DER",
         "-nodetach", "-keyid",
         "-signer", catfile($smdir, "smrsa1.pem"),
         "-signer", catfile($smdir, "smrsa2.pem"),
         "-signer", catfile($smdir, "smdsa1.pem"),
         "-signer", catfile($smdir, "smdsa2.pem"),
         "-stream", "-out", "{output}.cms" ],
-      [ "{cmd2}", "-verify", "-in", "{output}.cms", "-inform", "DER",
+      [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "DER",
         "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt" ],
       \&final_compare
     ],
 
     [ "signed content test streaming PEM format, 2 DSA and 2 RSA keys",
-      [ "{cmd1}", "-sign", "-in", $smcont, "-outform", "PEM", "-nodetach",
+      [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "PEM", "-nodetach",
         "-signer", catfile($smdir, "smrsa1.pem"),
         "-signer", catfile($smdir, "smrsa2.pem"),
         "-signer", catfile($smdir, "smdsa1.pem"),
         "-signer", catfile($smdir, "smdsa2.pem"),
         "-stream", "-out", "{output}.cms" ],
-      [ "{cmd2}", "-verify", "-in", "{output}.cms", "-inform", "PEM",
+      [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "PEM",
         "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt" ],
       \&final_compare
     ],
 
     [ "signed content MIME format, RSA key, signed receipt request",
-      [ "{cmd1}", "-sign", "-in", $smcont, "-nodetach",
+      [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-nodetach",
         "-signer", catfile($smdir, "smrsa1.pem"),
         "-receipt_request_to", "test\@openssl.org", "-receipt_request_all",
         "-out", "{output}.cms" ],
-      [ "{cmd2}", "-verify", "-in", "{output}.cms",
+      [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms",
         "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt" ],
       \&final_compare
     ],
 
     [ "signed receipt MIME format, RSA key",
-      [ "{cmd1}", "-sign", "-in", $smcont, "-nodetach",
+      [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-nodetach",
         "-signer", catfile($smdir, "smrsa1.pem"),
         "-receipt_request_to", "test\@openssl.org", "-receipt_request_all",
         "-out", "{output}.cms" ],
-      [ "{cmd1}", "-sign_receipt", "-in", "{output}.cms",
+      [ "{cmd1}", @prov, "-sign_receipt", "-in", "{output}.cms",
         "-signer", catfile($smdir, "smrsa2.pem"), "-out", "{output}2.cms" ],
-      [ "{cmd2}", "-verify_receipt", "{output}2.cms", "-in", "{output}.cms",
+      [ "{cmd2}", @prov, "-verify_receipt", "{output}2.cms", "-in", "{output}.cms",
         "-CAfile", catfile($smdir, "smroot.pem") ]
     ],
 
-    [ "signed content DER format, RSA key, CAdES-BES compatible",
-      [ "{cmd1}", "-sign", "-cades", "-in", $smcont, "-outform", "DER",
-        "-nodetach",
-        "-certfile", catfile($smdir, "smroot.pem"),
-        "-signer", catfile($smdir, "smrsa1.pem"), "-out", "{output}.cms" ],
-      [ "{cmd2}", "-verify", "-in", "{output}.cms", "-inform", "DER",
-        "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt" ],
-      \&final_compare
-    ],
-
-    [ "signed content DER format, RSA key, SHA256 md, CAdES-BES compatible",
-      [ "{cmd1}", "-sign", "-cades", "-md", "sha256", "-in", $smcont,
-        "-outform", "DER", "-nodetach",
-        "-certfile", catfile($smdir, "smroot.pem"),
-        "-signer", catfile($smdir, "smrsa1.pem"), "-out", "{output}.cms" ],
-      [ "{cmd2}", "-verify", "-in", "{output}.cms", "-inform", "DER",
-        "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt" ],
-      \&final_compare
-    ],
-
     [ "enveloped content test streaming S/MIME format, DES, 3 recipients, keyid",
-      [ "{cmd1}", "-encrypt", "-in", $smcont,
+      [ "{cmd1}", @defaultprov, "-encrypt", "-in", $smcont,
         "-stream", "-out", "{output}.cms", "-keyid",
         catfile($smdir, "smrsa1.pem"),
         catfile($smdir, "smrsa2.pem"),
         catfile($smdir, "smrsa3.pem") ],
-      [ "{cmd2}", "-decrypt", "-recip", catfile($smdir, "smrsa1.pem"),
+      [ "{cmd2}", @defaultprov, "-decrypt", "-recip", catfile($smdir, "smrsa1.pem"),
         "-in", "{output}.cms", "-out", "{output}.txt" ],
       \&final_compare
     ],
 
-    [ "enveloped content test streaming PEM format, KEK",
-      [ "{cmd1}", "-encrypt", "-in", $smcont, "-outform", "PEM", "-aes128",
+    [ "enveloped content test streaming PEM format, AES-256-CBC cipher, KEK",
+      [ "{cmd1}", @prov, "-encrypt", "-in", $smcont, "-outform", "PEM", "-aes128",
+        "-stream", "-out", "{output}.cms",
+        "-secretkey", "000102030405060708090A0B0C0D0E0F",
+        "-secretkeyid", "C0FEE0" ],
+      [ "{cmd2}", @prov, "-decrypt", "-in", "{output}.cms", "-out", "{output}.txt",
+        "-inform", "PEM",
+        "-secretkey", "000102030405060708090A0B0C0D0E0F",
+        "-secretkeyid", "C0FEE0" ],
+      \&final_compare
+    ],
+
+    [ "enveloped content test streaming PEM format, AES-256-GCM cipher, KEK",
+      [ "{cmd1}", @prov, "-encrypt", "-in", $smcont, "-outform", "PEM", "-aes-128-gcm",
         "-stream", "-out", "{output}.cms",
         "-secretkey", "000102030405060708090A0B0C0D0E0F",
         "-secretkeyid", "C0FEE0" ],
@@ -295,30 +335,30 @@ my @smime_cms_tests = (
     ],
 
     [ "enveloped content test streaming PEM format, KEK, key only",
-      [ "{cmd1}", "-encrypt", "-in", $smcont, "-outform", "PEM", "-aes128",
+      [ "{cmd1}", @prov, "-encrypt", "-in", $smcont, "-outform", "PEM", "-aes128",
         "-stream", "-out", "{output}.cms",
         "-secretkey", "000102030405060708090A0B0C0D0E0F",
         "-secretkeyid", "C0FEE0" ],
-      [ "{cmd2}", "-decrypt", "-in", "{output}.cms", "-out", "{output}.txt",
+      [ "{cmd2}", @prov, "-decrypt", "-in", "{output}.cms", "-out", "{output}.txt",
         "-inform", "PEM",
         "-secretkey", "000102030405060708090A0B0C0D0E0F" ],
       \&final_compare
     ],
 
     [ "data content test streaming PEM format",
-      [ "{cmd1}", "-data_create", "-in", $smcont, "-outform", "PEM",
+      [ "{cmd1}", @prov, "-data_create", "-in", $smcont, "-outform", "PEM",
         "-nodetach", "-stream", "-out", "{output}.cms" ],
-      [ "{cmd2}", "-data_out", "-in", "{output}.cms", "-inform", "PEM",
+      [ "{cmd2}", @prov, "-data_out", "-in", "{output}.cms", "-inform", "PEM",
         "-out", "{output}.txt" ],
       \&final_compare
     ],
 
     [ "encrypted content test streaming PEM format, 128 bit RC2 key",
-      [ "{cmd1}", @prov, "-EncryptedData_encrypt",
+      [ "{cmd1}", @legacyprov, "-EncryptedData_encrypt",
         "-in", $smcont, "-outform", "PEM",
         "-rc2", "-secretkey", "000102030405060708090A0B0C0D0E0F",
         "-stream", "-out", "{output}.cms" ],
-      [ "{cmd2}", @prov, "-EncryptedData_decrypt", "-in", "{output}.cms",
+      [ "{cmd2}", @legacyprov, "-EncryptedData_decrypt", "-in", "{output}.cms",
         "-inform", "PEM",
         "-secretkey", "000102030405060708090A0B0C0D0E0F",
         "-out", "{output}.txt" ],
@@ -326,21 +366,21 @@ my @smime_cms_tests = (
     ],
 
     [ "encrypted content test streaming PEM format, 40 bit RC2 key",
-      [ "{cmd1}", @prov, "-EncryptedData_encrypt",
+      [ "{cmd1}", @legacyprov, "-EncryptedData_encrypt",
         "-in", $smcont, "-outform", "PEM",
         "-rc2", "-secretkey", "0001020304",
         "-stream", "-out", "{output}.cms" ],
-      [ "{cmd2}", @prov, "-EncryptedData_decrypt", "-in", "{output}.cms",
+      [ "{cmd2}", @legacyprov, "-EncryptedData_decrypt", "-in", "{output}.cms",
         "-inform", "PEM",
         "-secretkey", "0001020304", "-out", "{output}.txt" ],
       \&final_compare
     ],
 
     [ "encrypted content test streaming PEM format, triple DES key",
-      [ "{cmd1}", "-EncryptedData_encrypt", "-in", $smcont, "-outform", "PEM",
+      [ "{cmd1}", @prov, "-EncryptedData_encrypt", "-in", $smcont, "-outform", "PEM",
         "-des3", "-secretkey", "000102030405060708090A0B0C0D0E0F1011121314151617",
         "-stream", "-out", "{output}.cms" ],
-      [ "{cmd2}", "-EncryptedData_decrypt", "-in", "{output}.cms",
+      [ "{cmd2}", @prov, "-EncryptedData_decrypt", "-in", "{output}.cms",
         "-inform", "PEM",
         "-secretkey", "000102030405060708090A0B0C0D0E0F1011121314151617",
         "-out", "{output}.txt" ],
@@ -348,24 +388,104 @@ my @smime_cms_tests = (
     ],
 
     [ "encrypted content test streaming PEM format, 128 bit AES key",
-      [ "{cmd1}", "-EncryptedData_encrypt", "-in", $smcont, "-outform", "PEM",
+      [ "{cmd1}", @prov, "-EncryptedData_encrypt", "-in", $smcont, "-outform", "PEM",
         "-aes128", "-secretkey", "000102030405060708090A0B0C0D0E0F",
         "-stream", "-out", "{output}.cms" ],
-      [ "{cmd2}", "-EncryptedData_decrypt", "-in", "{output}.cms",
+      [ "{cmd2}", @prov, "-EncryptedData_decrypt", "-in", "{output}.cms",
         "-inform", "PEM",
         "-secretkey", "000102030405060708090A0B0C0D0E0F",
         "-out", "{output}.txt" ],
       \&final_compare
     ],
+);
+
+my @smime_cms_cades_tests = (
+
+    [ "signed content DER format, RSA key, CAdES-BES compatible",
+      [ "{cmd1}", @prov, "-sign", "-cades", "-in", $smcont, "-outform", "DER",
+         "-nodetach",
+        "-certfile", catfile($smdir, "smroot.pem"),
+        "-signer", catfile($smdir, "smrsa1.pem"), "-out", "{output}.cms" ],
+      [ "{cmd2}", @prov, "-verify", "-cades", "-in", "{output}.cms", "-inform", "DER",
+        "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt" ],
+      \&final_compare
+    ],
 
+    [ "signed content DER format, RSA key, SHA256 md, CAdES-BES compatible",
+      [ "{cmd1}", @prov, "-sign", "-cades", "-md", "sha256", "-in", $smcont, "-outform",
+        "DER", "-nodetach", "-certfile", catfile($smdir, "smroot.pem"),
+        "-signer", catfile($smdir, "smrsa1.pem"), "-out", "{output}.cms" ],
+      [ "{cmd2}", @prov, "-verify", "-cades", "-in", "{output}.cms", "-inform", "DER",
+        "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt" ],
+      \&final_compare
+    ],
+
+    [ "signed content DER format, RSA key, SHA512 md, CAdES-BES compatible",
+      [ "{cmd1}", @prov, "-sign", "-cades", "-md", "sha512", "-in", $smcont, "-outform",
+        "DER", "-nodetach", "-certfile", catfile($smdir, "smroot.pem"),
+        "-signer", catfile($smdir, "smrsa1.pem"), "-out", "{output}.cms" ],
+      [ "{cmd2}", @prov, "-verify", "-cades", "-in", "{output}.cms", "-inform", "DER",
+        "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt" ],
+      \&final_compare
+    ],
+
+    [ "signed content DER format, RSA key, SHA256 md, CAdES-BES compatible",
+      [ "{cmd1}", @prov, "-sign", "-cades", "-binary",  "-nodetach", "-nosmimecap", "-md", "sha256",
+        "-in", $smcont, "-outform", "DER", 
+        "-certfile", catfile($smdir, "smroot.pem"),
+        "-signer", catfile($smdir, "smrsa1.pem"),
+        "-outform", "DER", "-out", "{output}.cms"  ],
+      [ "{cmd2}", @prov, "-verify", "-cades", "-in", "{output}.cms", "-inform", "DER",
+        "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt" ],
+      \&final_compare
+    ],
+
+    [ "resigned content DER format, RSA key, SHA256 md, CAdES-BES compatible",
+      [ "{cmd1}", @prov, "-sign", "-cades", "-binary",  "-nodetach", "-nosmimecap", "-md", "sha256",
+        "-in", $smcont, "-outform", "DER", 
+        "-certfile", catfile($smdir, "smroot.pem"),
+        "-signer", catfile($smdir, "smrsa1.pem"),
+        "-outform", "DER", "-out", "{output}.cms"  ],
+      [ "{cmd1}", @prov, "-resign", "-cades", "-binary", "-nodetach", "-nosmimecap", "-md", "sha256",
+        "-inform", "DER", "-in", "{output}.cms",
+        "-certfile", catfile($smdir, "smroot.pem"),
+        "-signer", catfile($smdir, "smrsa2.pem"),
+        "-outform", "DER", "-out", "{output}2.cms" ],
+
+      [ "{cmd2}", @prov, "-verify", "-cades", "-in", "{output}2.cms", "-inform", "DER",
+        "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt" ],
+      \&final_compare
+    ],
+);
+
+my @smime_cms_cades_ko_tests = (
+    [ "signed content DER format, RSA key, but verified as CAdES-BES compatible",
+      [ @prov, "-sign", "-in", $smcont, "-outform", "DER", "-nodetach",
+        "-certfile", catfile($smdir, "smroot.pem"),
+        "-signer", catfile($smdir, "smrsa1.pem"), "-out", "{output}.cms" ],
+      [ @prov, "-verify", "-cades", "-in", "{output}.cms", "-inform", "DER",
+        "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt" ],
+      \&final_compare
+    ]
+);
+
+# cades options test - check that some combinations are rejected
+my @smime_cms_cades_invalid_option_tests = (
+    [
+        [ "-cades", "-noattr" ],
+    ],[
+        [ "-verify", "-cades", "-noattr" ],
+    ],[
+        [ "-verify", "-cades", "-noverify" ],
+    ],
 );
 
 my @smime_cms_comp_tests = (
 
     [ "compressed content test streaming PEM format",
-      [ "{cmd1}", "-compress", "-in", $smcont, "-outform", "PEM", "-nodetach",
+      [ "{cmd1}", @prov, "-compress", "-in", $smcont, "-outform", "PEM", "-nodetach",
         "-stream", "-out", "{output}.cms" ],
-      [ "{cmd2}", "-uncompress", "-in", "{output}.cms", "-inform", "PEM",
+      [ "{cmd2}", @prov, "-uncompress", "-in", "{output}.cms", "-inform", "PEM",
         "-out", "{output}.txt" ],
       \&final_compare
     ]
@@ -374,137 +494,146 @@ my @smime_cms_comp_tests = (
 
 my @smime_cms_param_tests = (
     [ "signed content test streaming PEM format, RSA keys, PSS signature",
-      [ "{cmd1}", "-sign", "-in", $smcont, "-outform", "PEM", "-nodetach",
+      [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "PEM", "-nodetach",
         "-signer", catfile($smdir, "smrsa1.pem"),
         "-keyopt", "rsa_padding_mode:pss",
         "-out", "{output}.cms" ],
-      [ "{cmd2}", "-verify", "-in", "{output}.cms", "-inform", "PEM",
+      [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "PEM",
         "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt" ],
       \&final_compare
     ],
 
     [ "signed content test streaming PEM format, RSA keys, PSS signature, saltlen=max",
-      [ "{cmd1}", "-sign", "-in", $smcont, "-outform", "PEM", "-nodetach",
+      [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "PEM", "-nodetach",
         "-signer", catfile($smdir, "smrsa1.pem"),
         "-keyopt", "rsa_padding_mode:pss", "-keyopt", "rsa_pss_saltlen:max",
         "-out", "{output}.cms" ],
-      [ "{cmd2}", "-verify", "-in", "{output}.cms", "-inform", "PEM",
+      [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "PEM",
         "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt" ],
       \&final_compare
     ],
 
     [ "signed content test streaming PEM format, RSA keys, PSS signature, no attributes",
-      [ "{cmd1}", "-sign", "-in", $smcont, "-outform", "PEM", "-nodetach",
+      [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "PEM", "-nodetach",
         "-noattr",
         "-signer", catfile($smdir, "smrsa1.pem"),
         "-keyopt", "rsa_padding_mode:pss",
         "-out", "{output}.cms" ],
-      [ "{cmd2}", "-verify", "-in", "{output}.cms", "-inform", "PEM",
+      [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "PEM",
         "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt" ],
       \&final_compare
     ],
 
     [ "signed content test streaming PEM format, RSA keys, PSS signature, SHA384 MGF1",
-      [ "{cmd1}", "-sign", "-in", $smcont, "-outform", "PEM", "-nodetach",
+      [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "PEM", "-nodetach",
         "-signer", catfile($smdir, "smrsa1.pem"),
         "-keyopt", "rsa_padding_mode:pss", "-keyopt", "rsa_mgf1_md:sha384",
         "-out", "{output}.cms" ],
-      [ "{cmd2}", "-verify", "-in", "{output}.cms", "-inform", "PEM",
+      [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "PEM",
         "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt" ],
       \&final_compare
     ],
 
     [ "enveloped content test streaming S/MIME format, DES, OAEP default parameters",
-      [ "{cmd1}", "-encrypt", "-in", $smcont,
+      [ "{cmd1}", @defaultprov, "-encrypt", "-in", $smcont,
         "-stream", "-out", "{output}.cms",
         "-recip", catfile($smdir, "smrsa1.pem"),
         "-keyopt", "rsa_padding_mode:oaep" ],
-      [ "{cmd2}", "-decrypt", "-recip", catfile($smdir, "smrsa1.pem"),
+      [ "{cmd2}", @defaultprov, "-decrypt", "-recip", catfile($smdir, "smrsa1.pem"),
         "-in", "{output}.cms", "-out", "{output}.txt" ],
       \&final_compare
     ],
 
     [ "enveloped content test streaming S/MIME format, DES, OAEP SHA256",
-      [ "{cmd1}", "-encrypt", "-in", $smcont,
+      [ "{cmd1}", @defaultprov, "-encrypt", "-in", $smcont,
         "-stream", "-out", "{output}.cms",
         "-recip", catfile($smdir, "smrsa1.pem"),
         "-keyopt", "rsa_padding_mode:oaep",
         "-keyopt", "rsa_oaep_md:sha256" ],
-      [ "{cmd2}", "-decrypt", "-recip", catfile($smdir, "smrsa1.pem"),
+      [ "{cmd2}", @defaultprov, "-decrypt", "-recip", catfile($smdir, "smrsa1.pem"),
         "-in", "{output}.cms", "-out", "{output}.txt" ],
       \&final_compare
     ],
 
     [ "enveloped content test streaming S/MIME format, DES, ECDH",
-      [ "{cmd1}", "-encrypt", "-in", $smcont,
+      [ "{cmd1}", @defaultprov, "-encrypt", "-in", $smcont,
         "-stream", "-out", "{output}.cms",
         "-recip", catfile($smdir, "smec1.pem") ],
-      [ "{cmd2}", "-decrypt", "-recip", catfile($smdir, "smec1.pem"),
+      [ "{cmd2}", @defaultprov, "-decrypt", "-recip", catfile($smdir, "smec1.pem"),
         "-in", "{output}.cms", "-out", "{output}.txt" ],
       \&final_compare
     ],
 
     [ "enveloped content test streaming S/MIME format, DES, ECDH, 2 recipients, key only used",
-      [ "{cmd1}", "-encrypt", "-in", $smcont,
+      [ "{cmd1}", @defaultprov, "-encrypt", "-in", $smcont,
         "-stream", "-out", "{output}.cms",
         catfile($smdir, "smec1.pem"),
         catfile($smdir, "smec3.pem") ],
-      [ "{cmd2}", "-decrypt", "-inkey", catfile($smdir, "smec3.pem"),
+      [ "{cmd2}", @defaultprov, "-decrypt", "-inkey", catfile($smdir, "smec3.pem"),
         "-in", "{output}.cms", "-out", "{output}.txt" ],
       \&final_compare
     ],
 
     [ "enveloped content test streaming S/MIME format, ECDH, DES, key identifier",
-      [ "{cmd1}", "-encrypt", "-keyid", "-in", $smcont,
+      [ "{cmd1}", @defaultprov, "-encrypt", "-keyid", "-in", $smcont,
         "-stream", "-out", "{output}.cms",
         "-recip", catfile($smdir, "smec1.pem") ],
-      [ "{cmd2}", "-decrypt", "-recip", catfile($smdir, "smec1.pem"),
+      [ "{cmd2}", @defaultprov, "-decrypt", "-recip", catfile($smdir, "smec1.pem"),
         "-in", "{output}.cms", "-out", "{output}.txt" ],
       \&final_compare
     ],
 
-    [ "enveloped content test streaming S/MIME format, ECDH, AES128, SHA256 KDF",
-      [ "{cmd1}", "-encrypt", "-in", $smcont,
+    [ "enveloped content test streaming S/MIME format, ECDH, AES-128-CBC, SHA256 KDF",
+      [ "{cmd1}", @prov, "-encrypt", "-in", $smcont,
         "-stream", "-out", "{output}.cms",
         "-recip", catfile($smdir, "smec1.pem"), "-aes128",
         "-keyopt", "ecdh_kdf_md:sha256" ],
+      [ "{cmd2}", @prov, "-decrypt", "-recip", catfile($smdir, "smec1.pem"),
+        "-in", "{output}.cms", "-out", "{output}.txt" ],
+      \&final_compare
+    ],
+
+    [ "enveloped content test streaming S/MIME format, ECDH, AES-128-GCM cipher, SHA256 KDF",
+      [ "{cmd1}", @prov, "-encrypt", "-in", $smcont,
+        "-stream", "-out", "{output}.cms",
+        "-recip", catfile($smdir, "smec1.pem"), "-aes-128-gcm", "-keyopt", "ecdh_kdf_md:sha256" ],
       [ "{cmd2}", "-decrypt", "-recip", catfile($smdir, "smec1.pem"),
         "-in", "{output}.cms", "-out", "{output}.txt" ],
       \&final_compare
     ],
 
     [ "enveloped content test streaming S/MIME format, ECDH, K-283, cofactor DH",
-      [ "{cmd1}", "-encrypt", "-in", $smcont,
+      [ "{cmd1}", @prov, "-encrypt", "-in", $smcont,
         "-stream", "-out", "{output}.cms",
         "-recip", catfile($smdir, "smec2.pem"), "-aes128",
         "-keyopt", "ecdh_kdf_md:sha256", "-keyopt", "ecdh_cofactor_mode:1" ],
-      [ "{cmd2}", "-decrypt", "-recip", catfile($smdir, "smec2.pem"),
+      [ "{cmd2}", @prov, "-decrypt", "-recip", catfile($smdir, "smec2.pem"),
         "-in", "{output}.cms", "-out", "{output}.txt" ],
       \&final_compare
     ],
 
     [ "enveloped content test streaming S/MIME format, X9.42 DH",
-      [ "{cmd1}", "-encrypt", "-in", $smcont,
+      [ "{cmd1}", @prov, "-encrypt", "-in", $smcont,
         "-stream", "-out", "{output}.cms",
         "-recip", catfile($smdir, "smdh.pem"), "-aes128" ],
-      [ "{cmd2}", "-decrypt", "-recip", catfile($smdir, "smdh.pem"),
+      [ "{cmd2}", @prov, "-decrypt", "-recip", catfile($smdir, "smdh.pem"),
         "-in", "{output}.cms", "-out", "{output}.txt" ],
       \&final_compare
     ]
-    );
+);
 
 my @contenttype_cms_test = (
     [ "signed content test - check that content type is added to additional signerinfo, RSA keys",
-      [ "{cmd1}", "-sign", "-binary", "-nodetach", "-stream", "-in", $smcont,
+      [ "{cmd1}", @prov, "-sign", "-binary", "-nodetach", "-stream", "-in", $smcont,
         "-outform", "DER",
         "-signer", catfile($smdir, "smrsa1.pem"), "-md", "SHA256",
         "-out", "{output}.cms" ],
-      [ "{cmd1}", "-resign", "-binary", "-nodetach", "-in", "{output}.cms",
+      [ "{cmd1}", @prov, "-resign", "-binary", "-nodetach", "-in", "{output}.cms",
         "-inform", "DER", "-outform", "DER",
         "-signer", catfile($smdir, "smrsa2.pem"), "-md", "SHA256",
         "-out", "{output}2.cms" ],
       sub { my %opts = @_; contentType_matches("$opts{output}2.cms") == 2; },
-      [ "{cmd2}", "-verify", "-in", "{output}2.cms", "-inform", "DER",
+      [ "{cmd2}", @prov, "-verify", "-in", "{output}2.cms", "-inform", "DER",
         "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt" ]
     ],
 );
@@ -542,7 +671,7 @@ sub runner_loop {
                       $x;
                   } @$_;
 
-                  diag "CMD: openssl", join(" ", @cmd);
+                  diag "CMD: openssl ", join(" ", @cmd);
                   $ok &&= run(app(["openssl", @cmd]));
                   $opts{input} = $opts{output};
               }
@@ -560,6 +689,13 @@ sub final_compare {
     return compare_text($smcont, "$opts{output}.txt") == 0;
 }
 
+sub zero_compare {
+    my %opts = @_;
+
+    diag "Checking for zero-length file";
+    return (-e "$opts{output}.txt" && -z "$opts{output}.txt");
+}
+
 subtest "CMS => PKCS#7 compatibility tests\n" => sub {
     plan tests => scalar @smime_pkcs7_tests;
 
@@ -629,7 +765,7 @@ subtest "CMS Check that bad attributes fail when verifying signers\n" => sub {
     foreach my $name (@incorrect_attribute_cms_test) {
         my $out = "incorrect-$cnt.txt";
 
-        ok(!run(app(["openssl", "cms", "-verify", "-in",
+        ok(!run(app(["openssl", "cms", @prov, "-verify", "-in",
                      catfile($datadir, $name), "-inform", "DER", "-CAfile",
                      catfile($smdir, "smroot.pem"), "-out", $out ])),
             $name);
@@ -645,7 +781,7 @@ subtest "CMS Decrypt message encrypted with OpenSSL 1.1.1\n" => sub {
 
         my $out = "smtst.txt";
 
-        ok(run(app(["openssl", "cms", "-decrypt",
+        ok(run(app(["openssl", "cms", @defaultprov, "-decrypt",
                     "-inkey", catfile($smdir, "smec3.pem"),
                     "-in", catfile($datadir, "ciphertext_from_1_1_1.cms"),
                     "-out", $out ]))
@@ -654,6 +790,36 @@ subtest "CMS Decrypt message encrypted with OpenSSL 1.1.1\n" => sub {
     }
 };
 
+subtest "CAdES <=> CAdES consistency tests\n" => sub {
+    plan tests => (scalar @smime_cms_cades_tests);
+
+    runner_loop(prefix => 'cms-cades', cmd1 => 'cms', cmd2 => 'cms',
+                tests => [ @smime_cms_cades_tests ]);
+};
+
+subtest "CAdES; cms incompatible arguments tests\n" => sub {
+    plan tests => (scalar @smime_cms_cades_invalid_option_tests);
+
+    foreach (@smime_cms_cades_invalid_option_tests) {
+        ok(!run(app(["openssl", "cms", @{$$_[0]} ] )));
+    }
+};
+
+subtest "CAdES ko tests\n" => sub {
+    plan tests => (scalar @smime_cms_cades_ko_tests);
+
+    foreach (@smime_cms_cades_ko_tests) {
+      SKIP: {
+        my $skip_reason = check_availability($$_[0]);
+        skip $skip_reason, 1 if $skip_reason;
+
+        ok(run(app(["openssl", "cms", @{$$_[1]}]))
+            && !run(app(["openssl", "cms", @{$$_[2]}])),
+            $$_[0]);
+        }
+    }
+};
+
 sub check_availability {
     my $tnam = shift;