Added an explicit yield (OP_SLEEP) to QUIC testing for cooperative threading.
[openssl.git] / test / recipes / 80-test_cms.t
index 7896bc9b1228b22b53cc3d1c66b823950b69cc4f..07014945a7d82683fedb6438f3afbff610bb521a 100644 (file)
@@ -1,5 +1,5 @@
 #! /usr/bin/env perl
-# Copyright 2015-2021 The OpenSSL Project Authors. All Rights Reserved.
+# Copyright 2015-2023 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,7 +13,7 @@ use warnings;
 use POSIX;
 use File::Spec::Functions qw/catfile/;
 use File::Compare qw/compare_text compare/;
-use OpenSSL::Test qw/:DEFAULT srctop_dir srctop_file bldtop_dir bldtop_file/;
+use OpenSSL::Test qw/:DEFAULT srctop_dir srctop_file bldtop_dir bldtop_file with data_file/;
 
 use OpenSSL::Test::Utils;
 
@@ -50,7 +50,9 @@ my ($no_des, $no_dh, $no_dsa, $no_ec, $no_ec2m, $no_rc2, $no_zlib)
 
 $no_rc2 = 1 if disabled("legacy");
 
-plan tests => 11;
+plan tests => 23;
+
+ok(run(test(["pkcs7_test"])), "test pkcs7");
 
 unless ($no_fips) {
     @config = ( "-config", srctop_file("test", "fips-and-base.cnf") );
@@ -62,22 +64,25 @@ my @prov = ("-provider-path", $provpath,
             @config,
             "-provider", $provname);
 
+my $smrsa1024 = catfile($smdir, "smrsa1024.pem");
+my $smrsa1 = catfile($smdir, "smrsa1.pem");
+my $smroot = catfile($smdir, "smroot.pem");
+
 my @smime_pkcs7_tests = (
 
     [ "signed content DER format, RSA key",
       [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "DER", "-nodetach",
-        "-certfile", catfile($smdir, "smroot.pem"),
-        "-signer", catfile($smdir, "smrsa1.pem"), "-out", "{output}.cms" ],
+        "-certfile", $smroot, "-signer", $smrsa1, "-out", "{output}.cms" ],
       [ "{cmd2}",  @prov, "-verify", "-in", "{output}.cms", "-inform", "DER",
-        "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt" ],
+        "-CAfile", $smroot, "-out", "{output}.txt" ],
       \&final_compare
     ],
 
     [ "signed detached content DER format, RSA key",
       [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "DER",
-        "-signer", catfile($smdir, "smrsa1.pem"), "-out", "{output}.cms" ],
+        "-signer", $smrsa1, "-out", "{output}.cms" ],
       [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "DER",
-        "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt",
+        "-CAfile", $smroot, "-out", "{output}.txt",
         "-content", $smcont ],
       \&final_compare
     ],
@@ -85,9 +90,9 @@ my @smime_pkcs7_tests = (
     [ "signed content test streaming BER format, RSA",
       [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "DER", "-nodetach",
         "-stream",
-        "-signer", catfile($smdir, "smrsa1.pem"), "-out", "{output}.cms" ],
+        "-signer", $smrsa1, "-out", "{output}.cms" ],
       [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "DER",
-        "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt" ],
+        "-CAfile", $smroot, "-out", "{output}.txt" ],
       \&final_compare
     ],
 
@@ -95,7 +100,7 @@ my @smime_pkcs7_tests = (
       [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "DER", "-nodetach",
         "-signer", catfile($smdir, "smdsa1.pem"), "-out", "{output}.cms" ],
       [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "DER",
-        "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt" ],
+        "-CAfile", $smroot, "-out", "{output}.txt" ],
       \&final_compare
     ],
 
@@ -103,7 +108,7 @@ my @smime_pkcs7_tests = (
       [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "DER",
         "-signer", catfile($smdir, "smdsa1.pem"), "-out", "{output}.cms" ],
       [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "DER",
-        "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt",
+        "-CAfile", $smroot, "-out", "{output}.txt",
         "-content", $smcont ],
       \&final_compare
     ],
@@ -112,9 +117,9 @@ my @smime_pkcs7_tests = (
       [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "DER",
         "-signer", catfile($smdir, "smdsa1.pem"), "-out", "{output}.cms" ],
       [ "{cmd1}", @prov, "-resign", "-in", "{output}.cms", "-inform", "DER", "-outform", "DER",
-        "-signer", catfile($smdir, "smrsa1.pem"), "-out", "{output}2.cms" ],
+        "-signer", $smrsa1, "-out", "{output}2.cms" ],
       [ "{cmd2}", @prov, "-verify", "-in", "{output}2.cms", "-inform", "DER",
-        "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt",
+        "-CAfile", $smroot, "-out", "{output}.txt",
         "-content", $smcont ],
       \&final_compare
     ],
@@ -124,85 +129,84 @@ my @smime_pkcs7_tests = (
         "-nodetach", "-stream",
         "-signer", catfile($smdir, "smdsa1.pem"), "-out", "{output}.cms" ],
       [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "DER",
-        "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt" ],
+        "-CAfile", $smroot, "-out", "{output}.txt" ],
       \&final_compare
     ],
 
     [ "signed content test streaming BER format, 2 DSA and 2 RSA keys",
       [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "DER",
         "-nodetach", "-stream",
-        "-signer", catfile($smdir, "smrsa1.pem"),
+        "-signer", $smrsa1,
         "-signer", catfile($smdir, "smrsa2.pem"),
         "-signer", catfile($smdir, "smdsa1.pem"),
         "-signer", catfile($smdir, "smdsa2.pem"),
         "-out", "{output}.cms" ],
       [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "DER",
-        "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt" ],
+        "-CAfile", $smroot, "-out", "{output}.txt" ],
       \&final_compare
     ],
 
     [ "signed content test streaming BER format, 2 DSA and 2 RSA keys, no attributes",
       [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "DER",
         "-noattr", "-nodetach", "-stream",
-        "-signer", catfile($smdir, "smrsa1.pem"),
+        "-signer", $smrsa1,
         "-signer", catfile($smdir, "smrsa2.pem"),
         "-signer", catfile($smdir, "smdsa1.pem"),
         "-signer", catfile($smdir, "smdsa2.pem"),
         "-out", "{output}.cms" ],
       [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "DER",
-        "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt" ],
+        "-CAfile", $smroot, "-out", "{output}.txt" ],
       \&final_compare
     ],
 
     [ "signed content S/MIME format, RSA key SHA1",
       [ "{cmd1}", @defaultprov, "-sign", "-in", $smcont, "-md", "sha1",
-        "-certfile", catfile($smdir, "smroot.pem"),
-        "-signer", catfile($smdir, "smrsa1.pem"), "-out", "{output}.cms" ],
+        "-certfile", $smroot,
+        "-signer", $smrsa1, "-out", "{output}.cms" ],
       [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms",
-        "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt" ],
+        "-CAfile", $smroot, "-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" ],
+        "-certfile", $smroot, "-signer", $smrsa1, "-out", "{output}.cms" ],
       [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms",
-        "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt" ],
+        "-CAfile", $smroot, "-out", "{output}.txt" ],
       \&zero_compare
     ],
 
     [ "signed content test streaming S/MIME format, 2 DSA and 2 RSA keys",
       [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-nodetach",
-        "-signer", catfile($smdir, "smrsa1.pem"),
+        "-signer", $smrsa1,
         "-signer", catfile($smdir, "smrsa2.pem"),
         "-signer", catfile($smdir, "smdsa1.pem"),
         "-signer", catfile($smdir, "smdsa2.pem"),
         "-stream", "-out", "{output}.cms" ],
       [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms",
-        "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt" ],
+        "-CAfile", $smroot, "-out", "{output}.txt" ],
       \&final_compare
     ],
 
     [ "signed content test streaming multipart S/MIME format, 2 DSA and 2 RSA keys",
       [ "{cmd1}", @prov, "-sign", "-in", $smcont,
-        "-signer", catfile($smdir, "smrsa1.pem"),
+        "-signer", $smrsa1,
         "-signer", catfile($smdir, "smrsa2.pem"),
         "-signer", catfile($smdir, "smdsa1.pem"),
         "-signer", catfile($smdir, "smdsa2.pem"),
         "-stream", "-out", "{output}.cms" ],
       [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms",
-        "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt" ],
+        "-CAfile", $smroot, "-out", "{output}.txt" ],
       \&final_compare
     ],
 
     [ "enveloped content test streaming S/MIME format, DES, 3 recipients",
       [ "{cmd1}", @defaultprov, "-encrypt", "-in", $smcont,
         "-stream", "-out", "{output}.cms",
-        catfile($smdir, "smrsa1.pem"),
+        $smrsa1,
         catfile($smdir, "smrsa2.pem"),
         catfile($smdir, "smrsa3.pem") ],
-      [ "{cmd2}", @defaultprov, "-decrypt", "-recip", catfile($smdir, "smrsa1.pem"),
+      [ "{cmd2}", @defaultprov, "-decrypt", "-recip", $smrsa1,
         "-in", "{output}.cms", "-out", "{output}.txt" ],
       \&final_compare
     ],
@@ -210,7 +214,7 @@ my @smime_pkcs7_tests = (
     [ "enveloped content test streaming S/MIME format, DES, 3 recipients, 3rd used",
       [ "{cmd1}", @defaultprov, "-encrypt", "-in", $smcont,
         "-stream", "-out", "{output}.cms",
-        catfile($smdir, "smrsa1.pem"),
+        $smrsa1,
         catfile($smdir, "smrsa2.pem"),
         catfile($smdir, "smrsa3.pem") ],
       [ "{cmd2}", @defaultprov, "-decrypt", "-recip", catfile($smdir, "smrsa3.pem"),
@@ -218,13 +222,15 @@ my @smime_pkcs7_tests = (
       \&final_compare
     ],
 
-    [ "enveloped content test streaming S/MIME format, DES, 3 recipients, key only used",
+    [ "enveloped content test streaming S/MIME format, DES, 3 recipients, cert and key files used",
       [ "{cmd1}", @defaultprov, "-encrypt", "-in", $smcont,
         "-stream", "-out", "{output}.cms",
-        catfile($smdir, "smrsa1.pem"),
+        $smrsa1,
         catfile($smdir, "smrsa2.pem"),
-        catfile($smdir, "smrsa3.pem") ],
-      [ "{cmd2}", @defaultprov, "-decrypt", "-inkey", catfile($smdir, "smrsa3.pem"),
+        catfile($smdir, "smrsa3-cert.pem") ],
+      [ "{cmd2}", @defaultprov, "-decrypt",
+       "-recip", catfile($smdir, "smrsa3-cert.pem"),
+       "-inkey", catfile($smdir, "smrsa3-key.pem"),
         "-in", "{output}.cms", "-out", "{output}.txt" ],
       \&final_compare
     ],
@@ -232,10 +238,10 @@ my @smime_pkcs7_tests = (
     [ "enveloped content test streaming S/MIME format, AES-256 cipher, 3 recipients",
       [ "{cmd1}", @prov, "-encrypt", "-in", $smcont,
         "-aes256", "-stream", "-out", "{output}.cms",
-        catfile($smdir, "smrsa1.pem"),
+        $smrsa1,
         catfile($smdir, "smrsa2.pem"),
         catfile($smdir, "smrsa3.pem") ],
-      [ "{cmd2}", @prov, "-decrypt", "-recip", catfile($smdir, "smrsa1.pem"),
+      [ "{cmd2}", @prov, "-decrypt", "-recip", $smrsa1,
         "-in", "{output}.cms", "-out", "{output}.txt" ],
       \&final_compare
     ],
@@ -247,56 +253,56 @@ my @smime_cms_tests = (
     [ "signed content test streaming BER format, 2 DSA and 2 RSA keys, keyid",
       [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "DER",
         "-nodetach", "-keyid",
-        "-signer", catfile($smdir, "smrsa1.pem"),
+        "-signer", $smrsa1,
         "-signer", catfile($smdir, "smrsa2.pem"),
         "-signer", catfile($smdir, "smdsa1.pem"),
         "-signer", catfile($smdir, "smdsa2.pem"),
         "-stream", "-out", "{output}.cms" ],
       [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "DER",
-        "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt" ],
+        "-CAfile", $smroot, "-out", "{output}.txt" ],
       \&final_compare
     ],
 
     [ "signed content test streaming PEM format, 2 DSA and 2 RSA keys",
       [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "PEM", "-nodetach",
-        "-signer", catfile($smdir, "smrsa1.pem"),
+        "-signer", $smrsa1,
         "-signer", catfile($smdir, "smrsa2.pem"),
         "-signer", catfile($smdir, "smdsa1.pem"),
         "-signer", catfile($smdir, "smdsa2.pem"),
         "-stream", "-out", "{output}.cms" ],
       [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "PEM",
-        "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt" ],
+        "-CAfile", $smroot, "-out", "{output}.txt" ],
       \&final_compare
     ],
 
     [ "signed content MIME format, RSA key, signed receipt request",
       [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-nodetach",
-        "-signer", catfile($smdir, "smrsa1.pem"),
+        "-signer", $smrsa1,
         "-receipt_request_to", "test\@openssl.org", "-receipt_request_all",
         "-out", "{output}.cms" ],
       [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms",
-        "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt" ],
+        "-CAfile", $smroot, "-out", "{output}.txt" ],
       \&final_compare
     ],
 
     [ "signed receipt MIME format, RSA key",
       [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-nodetach",
-        "-signer", catfile($smdir, "smrsa1.pem"),
+        "-signer", $smrsa1,
         "-receipt_request_to", "test\@openssl.org", "-receipt_request_all",
         "-out", "{output}.cms" ],
       [ "{cmd1}", @prov, "-sign_receipt", "-in", "{output}.cms",
         "-signer", catfile($smdir, "smrsa2.pem"), "-out", "{output}2.cms" ],
       [ "{cmd2}", @prov, "-verify_receipt", "{output}2.cms", "-in", "{output}.cms",
-        "-CAfile", catfile($smdir, "smroot.pem") ]
+        "-CAfile", $smroot ]
     ],
 
     [ "enveloped content test streaming S/MIME format, DES, 3 recipients, keyid",
       [ "{cmd1}", @defaultprov, "-encrypt", "-in", $smcont,
         "-stream", "-out", "{output}.cms", "-keyid",
-        catfile($smdir, "smrsa1.pem"),
+        $smrsa1,
         catfile($smdir, "smrsa2.pem"),
         catfile($smdir, "smrsa3.pem") ],
-      [ "{cmd2}", @defaultprov, "-decrypt", "-recip", catfile($smdir, "smrsa1.pem"),
+      [ "{cmd2}", @defaultprov, "-decrypt", "-recip", $smrsa1,
         "-in", "{output}.cms", "-out", "{output}.txt" ],
       \&final_compare
     ],
@@ -388,6 +394,13 @@ my @smime_cms_tests = (
         "-out", "{output}.txt" ],
       \&final_compare
     ],
+
+    [ "encrypted content test streaming PEM format -noout, 128 bit AES key",
+      [ "{cmd1}", @prov, "-EncryptedData_encrypt", "-in", $smcont, "-outform", "PEM",
+       "-aes128", "-secretkey", "000102030405060708090A0B0C0D0E0F",
+       "-stream", "-noout" ],
+      [ "{cmd2}", @prov, "-help" ]
+    ],
 );
 
 my @smime_cms_cades_tests = (
@@ -395,56 +408,52 @@ 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" ],
+        "-certfile", $smroot, "-signer", $smrsa1, "-out", "{output}.cms" ],
       [ "{cmd2}", @prov, "-verify", "-cades", "-in", "{output}.cms", "-inform", "DER",
-        "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt" ],
+        "-CAfile", $smroot, "-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" ],
+        "DER", "-nodetach", "-certfile", $smroot,
+        "-signer", $smrsa1, "-out", "{output}.cms" ],
       [ "{cmd2}", @prov, "-verify", "-cades", "-in", "{output}.cms", "-inform", "DER",
-        "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt" ],
+        "-CAfile", $smroot, "-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" ],
+        "DER", "-nodetach", "-certfile", $smroot,
+        "-signer", $smrsa1, "-out", "{output}.cms" ],
       [ "{cmd2}", @prov, "-verify", "-cades", "-in", "{output}.cms", "-inform", "DER",
-        "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt" ],
+        "-CAfile", $smroot, "-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"),
+        "-certfile", $smroot, "-signer", $smrsa1,
         "-outform", "DER", "-out", "{output}.cms"  ],
       [ "{cmd2}", @prov, "-verify", "-cades", "-in", "{output}.cms", "-inform", "DER",
-        "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt" ],
+        "-CAfile", $smroot, "-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"),
+        "-certfile", $smroot, "-signer", $smrsa1,
         "-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"),
+        "-certfile", $smroot, "-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" ],
+        "-CAfile", $smroot, "-out", "{output}.txt" ],
       \&final_compare
     ],
 );
@@ -452,11 +461,10 @@ my @smime_cms_cades_tests = (
 my @smime_cms_cades_ko_tests = (
     [ "sign content DER format, RSA key, not CAdES-BES compatible",
       [ @prov, "-sign", "-in", $smcont, "-outform", "DER", "-nodetach",
-        "-certfile", catfile($smdir, "smroot.pem"),
-        "-signer", catfile($smdir, "smrsa1.pem"), "-out", "{output}.cms" ],
+        "-certfile", $smroot, "-signer", $smrsa1, "-out", "cades-ko.cms" ],
       "fail to verify token since requiring CAdES-BES compatibility",
-      [ @prov, "-verify", "-cades", "-in", "{output}.cms", "-inform", "DER",
-        "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt" ],
+      [ @prov, "-verify", "-cades", "-in", "cades-ko.cms", "-inform", "DER",
+        "-CAfile", $smroot, "-out", "cades-ko.txt" ],
       \&final_compare
     ]
 );
@@ -487,51 +495,74 @@ my @smime_cms_comp_tests = (
 my @smime_cms_param_tests = (
     [ "signed content test streaming PEM format, RSA keys, PSS signature",
       [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "PEM", "-nodetach",
-        "-signer", catfile($smdir, "smrsa1.pem"),
+        "-signer", $smrsa1,
         "-keyopt", "rsa_padding_mode:pss",
         "-out", "{output}.cms" ],
       [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "PEM",
-        "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt" ],
+        "-CAfile", $smroot, "-out", "{output}.txt" ],
       \&final_compare
     ],
 
     [ "signed content test streaming PEM format, RSA keys, PSS signature, saltlen=max",
       [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "PEM", "-nodetach",
-        "-signer", catfile($smdir, "smrsa1.pem"),
+        "-signer", $smrsa1,
         "-keyopt", "rsa_padding_mode:pss", "-keyopt", "rsa_pss_saltlen:max",
         "-out", "{output}.cms" ],
+      sub { my %opts = @_; rsapssSaltlen("$opts{output}.cms") == 222; },
       [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "PEM",
-        "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt" ],
+        "-CAfile", $smroot, "-out", "{output}.txt" ],
       \&final_compare
     ],
 
     [ "signed content test streaming PEM format, RSA keys, PSS signature, no attributes",
       [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "PEM", "-nodetach",
-        "-noattr",
-        "-signer", catfile($smdir, "smrsa1.pem"),
+        "-noattr", "-signer", $smrsa1,
         "-keyopt", "rsa_padding_mode:pss",
         "-out", "{output}.cms" ],
       [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "PEM",
-        "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt" ],
+        "-CAfile", $smroot, "-out", "{output}.txt" ],
       \&final_compare
     ],
 
     [ "signed content test streaming PEM format, RSA keys, PSS signature, SHA384 MGF1",
       [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "PEM", "-nodetach",
-        "-signer", catfile($smdir, "smrsa1.pem"),
+        "-signer", $smrsa1,
         "-keyopt", "rsa_padding_mode:pss", "-keyopt", "rsa_mgf1_md:sha384",
         "-out", "{output}.cms" ],
       [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "PEM",
-        "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt" ],
+        "-CAfile", $smroot, "-out", "{output}.txt" ],
+      \&final_compare
+    ],
+
+    [ "signed content test streaming PEM format, RSA keys, PSS signature, saltlen=16",
+      [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "PEM", "-nodetach",
+        "-signer", $smrsa1, "-md", "sha256",
+        "-keyopt", "rsa_padding_mode:pss", "-keyopt", "rsa_pss_saltlen:16",
+        "-out", "{output}.cms" ],
+      sub { my %opts = @_; rsapssSaltlen("$opts{output}.cms") == 16; },
+      [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "PEM",
+        "-CAfile", $smroot, "-out", "{output}.txt" ],
+      \&final_compare
+    ],
+
+    [ "signed content test streaming PEM format, RSA keys, PSS signature, saltlen=digest",
+      [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "PEM", "-nodetach",
+        "-signer", $smrsa1, "-md", "sha256",
+        "-keyopt", "rsa_padding_mode:pss", "-keyopt", "rsa_pss_saltlen:digest",
+        "-out", "{output}.cms" ],
+      # digest is SHA-256, which produces 32 bytes of output
+      sub { my %opts = @_; rsapssSaltlen("$opts{output}.cms") == 32; },
+      [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "PEM",
+        "-CAfile", $smroot, "-out", "{output}.txt" ],
       \&final_compare
     ],
 
     [ "enveloped content test streaming S/MIME format, DES, OAEP default parameters",
       [ "{cmd1}", @defaultprov, "-encrypt", "-in", $smcont,
         "-stream", "-out", "{output}.cms",
-        "-recip", catfile($smdir, "smrsa1.pem"),
+        "-recip", $smrsa1,
         "-keyopt", "rsa_padding_mode:oaep" ],
-      [ "{cmd2}", @defaultprov, "-decrypt", "-recip", catfile($smdir, "smrsa1.pem"),
+      [ "{cmd2}", @defaultprov, "-decrypt", "-recip", $smrsa1,
         "-in", "{output}.cms", "-out", "{output}.txt" ],
       \&final_compare
     ],
@@ -539,10 +570,10 @@ my @smime_cms_param_tests = (
     [ "enveloped content test streaming S/MIME format, DES, OAEP SHA256",
       [ "{cmd1}", @defaultprov, "-encrypt", "-in", $smcont,
         "-stream", "-out", "{output}.cms",
-        "-recip", catfile($smdir, "smrsa1.pem"),
+        "-recip", $smrsa1,
         "-keyopt", "rsa_padding_mode:oaep",
         "-keyopt", "rsa_oaep_md:sha256" ],
-      [ "{cmd2}", @defaultprov, "-decrypt", "-recip", catfile($smdir, "smrsa1.pem"),
+      [ "{cmd2}", @defaultprov, "-decrypt", "-recip", $smrsa1,
         "-in", "{output}.cms", "-out", "{output}.txt" ],
       \&final_compare
     ],
@@ -614,11 +645,38 @@ my @smime_cms_param_tests = (
     ]
 );
 
+my @smime_cms_param_tests_autodigestmax = (
+    [ "signed content test streaming PEM format, RSA keys, PSS signature, saltlen=auto-digestmax, digestsize < maximum salt length",
+      [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "PEM", "-nodetach",
+        "-signer", $smrsa1, "-md", "sha256",
+        "-keyopt", "rsa_padding_mode:pss", "-keyopt", "rsa_pss_saltlen:auto-digestmax",
+        "-out", "{output}.cms" ],
+      # digest is SHA-256, which produces 32, bytes of output
+      sub { my %opts = @_; rsapssSaltlen("$opts{output}.cms") == 32; },
+      [ "{cmd2}", @defaultprov, "-verify", "-in", "{output}.cms", "-inform", "PEM",
+        "-CAfile", $smroot, "-out", "{output}.txt" ],
+      \&final_compare
+    ],
+
+    [ "signed content test streaming PEM format, RSA keys, PSS signature, saltlen=auto-digestmax, digestsize > maximum salt length",
+      [ "{cmd1}", @defaultprov, "-sign", "-in", $smcont, "-outform", "PEM", "-nodetach",
+        "-signer", $smrsa1024, "-md", "sha512",
+        "-keyopt", "rsa_padding_mode:pss", "-keyopt", "rsa_pss_saltlen:auto-digestmax",
+        "-out", "{output}.cms" ],
+      # digest is SHA-512, which produces 64, bytes of output, but an RSA-PSS
+      # signature with a 1024 bit RSA key can only accommodate 62
+      sub { my %opts = @_; rsapssSaltlen("$opts{output}.cms") == 62; },
+      [ "{cmd2}", @defaultprov, "-verify", "-in", "{output}.cms", "-inform", "PEM",
+        "-CAfile", $smroot, "-out", "{output}.txt" ],
+      \&final_compare
+    ]
+);
+
+
 my @contenttype_cms_test = (
     [ "signed content test - check that content type is added to additional signerinfo, RSA keys",
       [ "{cmd1}", @prov, "-sign", "-binary", "-nodetach", "-stream", "-in", $smcont,
-        "-outform", "DER",
-        "-signer", catfile($smdir, "smrsa1.pem"), "-md", "SHA256",
+        "-outform", "DER", "-signer", $smrsa1, "-md", "SHA256",
         "-out", "{output}.cms" ],
       [ "{cmd1}", @prov, "-resign", "-binary", "-nodetach", "-in", "{output}.cms",
         "-inform", "DER", "-outform", "DER",
@@ -626,7 +684,7 @@ my @contenttype_cms_test = (
         "-out", "{output}2.cms" ],
       sub { my %opts = @_; contentType_matches("$opts{output}2.cms") == 2; },
       [ "{cmd2}", @prov, "-verify", "-in", "{output}2.cms", "-inform", "DER",
-        "-CAfile", catfile($smdir, "smroot.pem"), "-out", "{output}.txt" ]
+        "-CAfile", $smroot, "-out", "{output}.txt" ]
     ],
 );
 
@@ -712,7 +770,21 @@ subtest "CMS <=> CMS consistency tests\n" => sub {
 
 subtest "CMS <=> CMS consistency tests, modified key parameters\n" => sub {
     plan tests =>
-        (scalar @smime_cms_param_tests) + (scalar @smime_cms_comp_tests);
+        (scalar @smime_cms_param_tests) + (scalar @smime_cms_comp_tests) +
+        (scalar @smime_cms_param_tests_autodigestmax) + 1;
+
+    ok(run(app(["openssl", "cms", @prov,
+                "-sign", "-in", $smcont,
+                "-outform", "PEM",
+                "-nodetach",
+                "-signer", $smrsa1,
+                "-keyopt", "rsa_padding_mode:pss",
+                "-keyopt", "rsa_pss_saltlen:auto-digestmax",
+                "-out", "digestmaxtest.cms"])));
+    # Providers that do not support rsa_pss_saltlen:auto-digestmax will parse
+    # it as 0
+    my $no_autodigestmax = rsapssSaltlen("digestmaxtest.cms") == 0;
+    1 while unlink "digestmaxtest.cms";
 
     runner_loop(prefix => 'cms2cms-mod', cmd1 => 'cms', cmd2 => 'cms',
                 tests => [ @smime_cms_param_tests ]);
@@ -724,6 +796,15 @@ subtest "CMS <=> CMS consistency tests, modified key parameters\n" => sub {
       runner_loop(prefix => 'cms2cms-comp', cmd1 => 'cms', cmd2 => 'cms',
                   tests => [ @smime_cms_comp_tests ]);
     }
+
+  SKIP: {
+    skip("rsa_pss_saltlen:auto-digestmax not supported",
+         scalar @smime_cms_param_tests_autodigestmax)
+       if $no_autodigestmax;
+
+       runner_loop(prefix => 'cms2cms-comp', 'cmd1' => 'cms', cmd2 => 'cms',
+                   tests => [ @smime_cms_param_tests_autodigestmax ]);
+  }
 };
 
 # Returns the number of matches of a Content Type Attribute in a binary file.
@@ -742,6 +823,57 @@ sub contentType_matches {
   return scalar(@c);
 }
 
+sub rsapssSaltlen {
+  my ($in) = @_;
+  my $exit = 0;
+
+  my @asn1parse = run(app(["openssl", "asn1parse", "-in", $in, "-dump"]),
+                      capture => 1,
+                      statusvar => $exit);
+  return -1 if $exit != 0;
+
+  my $pssparam_offset = -1;
+  while ($_ = shift @asn1parse) {
+    chomp;
+    next unless /:rsassaPss/;
+    # This line contains :rsassaPss, the next line contains a raw dump of the
+    # RSA_PSS_PARAMS sequence; obtain its offset
+    $_ = shift @asn1parse;
+    if (/^\s*(\d+):/) {
+      $pssparam_offset = int($1);
+    }
+  }
+
+  if ($pssparam_offset == -1) {
+    note "Failed to determine RSA_PSS_PARAM offset in CMS. " +
+         "Was the file correctly signed with RSASSA-PSS?";
+    return -1;
+  }
+
+  my @pssparam = run(app(["openssl", "asn1parse", "-in", $in,
+                          "-strparse", $pssparam_offset]),
+                     capture => 1,
+                     statusvar => $exit);
+  return -1 if $exit != 0;
+
+  my $saltlen = -1;
+  # Can't use asn1parse -item RSA_PSS_PARAMS here, because that's deprecated.
+  # This assumes the salt length is the last field, which may possibly be
+  # incorrect if there is a non-standard trailer field, but there almost never
+  # is in PSS.
+  if ($pssparam[-1] =~ /prim:\s+INTEGER\s+:([A-Fa-f0-9]+)/) {
+    $saltlen = hex($1);
+  }
+
+  if ($saltlen == -1) {
+    note "Failed to determine salt length from RSA_PSS_PARAM struct. " +
+         "Was the file correctly signed with RSASSA-PSS?";
+    return -1;
+  }
+
+  return $saltlen;
+}
+
 subtest "CMS Check the content type attribute is added for additional signers\n" => sub {
     plan tests => (scalar @contenttype_cms_test);
 
@@ -759,11 +891,29 @@ subtest "CMS Check that bad attributes fail when verifying signers\n" => sub {
 
         ok(!run(app(["openssl", "cms", @prov, "-verify", "-in",
                      catfile($datadir, $name), "-inform", "DER", "-CAfile",
-                     catfile($smdir, "smroot.pem"), "-out", $out ])),
+                     $smroot, "-out", $out ])),
             $name);
     }
 };
 
+subtest "CMS Check that bad encryption algorithm fails\n" => sub {
+    plan tests => 1;
+
+    SKIP: {
+        skip "DES or Legacy isn't supported in this build", 1
+            if disabled("des") || disabled("legacy");
+
+        my $out = "smtst.txt";
+
+        ok(!run(app(["openssl", "cms", @legacyprov, "-encrypt",
+                    "-in", $smcont,
+                    "-stream", "-recip", $smrsa1,
+                    "-des-ede3",
+                    "-out", $out ])),
+           "Decrypt message from OpenSSL 1.1.1");
+    }
+};
+
 subtest "CMS Decrypt message encrypted with OpenSSL 1.1.1\n" => sub {
     plan tests => 1;
 
@@ -804,6 +954,7 @@ subtest "CAdES ko tests\n" => sub {
       SKIP: {
         my $skip_reason = check_availability($$_[0]);
         skip $skip_reason, 1 if $skip_reason;
+        1 while unlink "cades-ko.txt";
 
         ok(run(app(["openssl", "cms", @{$$_[1]}])), $$_[0]);
         ok(!run(app(["openssl", "cms", @{$$_[3]}])), $$_[2]);
@@ -815,45 +966,147 @@ subtest "CMS binary input tests\n" => sub {
     my $input = srctop_file("test", "smcont.bin");
     my $signed = "smcont.signed";
     my $verified = "smcont.verified";
-    my $cert = srctop_file("test", "certs", "ee-self-signed.pem");
-    my $key = srctop_file("test", "certs", "ee-key.pem");
 
-    plan skip_all => "Binary input tests currently disabled on Windows" if $^O =~ /^MSWin32$/;
     plan tests => 11;
 
-    ok(run(app(["openssl", "cms", "-sign", "-md", "sha256",
-                "-signer", $cert, "-inkey", $key,
+    ok(run(app(["openssl", "cms", "-sign", "-md", "sha256", "-signer", $smrsa1,
                 "-binary", "-in", $input, "-out", $signed])),
        "sign binary input with -binary");
-    ok(run(app(["openssl", "cms", "-verify", "-CAfile", $cert,
+    ok(run(app(["openssl", "cms", "-verify", "-CAfile", $smroot,
                 "-binary", "-in", $signed, "-out", $verified])),
        "verify binary input with -binary");
     is(compare($input, $verified), 0, "binary input retained with -binary");
-    ok(run(app(["openssl", "cms", "-sign", "-md", "sha256",
-                "-signer", $cert, "-inkey", $key,
-                "-in", $input, "-out", $signed])),
+
+    ok(run(app(["openssl", "cms", "-sign", "-md", "sha256", "-signer", $smrsa1,
+                "-in", $input, "-out", $signed.".nobin"])),
        "sign binary input without -binary");
-    ok(run(app(["openssl", "cms", "-verify", "-CAfile", $cert,
-                "-in", $signed, "-out", $verified])),
+    ok(run(app(["openssl", "cms", "-verify", "-CAfile", $smroot,
+                "-in", $signed.".nobin", "-out", $verified.".nobin"])),
        "verify binary input without -binary");
-    is(compare($input, $verified), 1, "binary input not retained without -binary");
-    ok(!run(app(["openssl", "cms", "-verify", "-CAfile", $cert, "-crlfeol",
-                "-binary", "-in", $signed, "-out", $verified])),
+    is(compare($input, $verified.".nobin"), 1, "binary input not retained without -binary");
+    ok(!run(app(["openssl", "cms", "-verify", "-CAfile", $smroot, "-crlfeol",
+                "-binary", "-in", $signed, "-out", $verified.".crlfeol"])),
        "verify binary input wrong crlfeol");
 
-    ok(run(app(["openssl", "cms", "-sign", "-md", "sha256", "-crlfeol",
-                "-signer", $cert, "-inkey", $key,
+    ok(run(app(["openssl", "cms", "-sign", "-md", "sha256", "-signer", $smrsa1,
+                "-crlfeol",
                 "-binary", "-in", $input, "-out", $signed.".crlf"])),
-       "sign binary input crlfeol");
-    ok(run(app(["openssl", "cms", "-verify", "-CAfile", $cert, "-crlfeol",
-                "-binary", "-in", $signed.".crlf", "-out", $verified.".crlf"])),
-       "verify binary input crlfeol");
-    is(compare($input, $verified.".crlf"), 0);
-    ok(!run(app(["openssl", "cms", "-verify", "-CAfile", $cert,
+       "sign binary input with -binary -crlfeol");
+    ok(run(app(["openssl", "cms", "-verify", "-CAfile", $smroot, "-crlfeol",
                 "-binary", "-in", $signed.".crlf", "-out", $verified.".crlf"])),
-       "verify binary input missing crlfeol");
+       "verify binary input with -binary -crlfeol");
+    is(compare($input, $verified.".crlf"), 0,
+       "binary input retained with -binary -crlfeol");
+    ok(!run(app(["openssl", "cms", "-verify", "-CAfile", $smroot,
+                "-binary", "-in", $signed.".crlf", "-out", $verified.".crlf2"])),
+       "verify binary input with -binary missing -crlfeol");
+};
+
+subtest "CMS signed digest, DER format" => sub {
+    plan tests => 2;
+
+    # Pre-computed SHA256 digest of $smcont in hexadecimal form
+    my $digest = "ff236ef61b396355f75a4cc6e1c306d4c309084ae271a9e2ad6888f10a101b32";
+
+    my $sig_file = "signature.der";
+    ok(run(app(["openssl", "cms", @prov, "-sign", "-digest", $digest,
+                    "-outform", "DER",
+                    "-certfile", catfile($smdir, "smroot.pem"),
+                    "-signer", catfile($smdir, "smrsa1.pem"),
+                    "-out", $sig_file])),
+        "CMS sign pre-computed digest, DER format");
+
+    ok(run(app(["openssl", "cms", @prov, "-verify", "-in", $sig_file,
+                    "-inform", "DER",
+                    "-CAfile", catfile($smdir, "smroot.pem"),
+                    "-content", $smcont])),
+       "Verify CMS signed digest, DER format");
+};
+
+subtest "CMS signed digest, S/MIME format" => sub {
+    plan tests => 2;
+
+    # Pre-computed SHA256 digest of $smcont in hexadecimal form
+    my $digest = "ff236ef61b396355f75a4cc6e1c306d4c309084ae271a9e2ad6888f10a101b32";
+
+    my $sig_file = "signature.smime";
+    ok(run(app(["openssl", "cms", @prov, "-sign", "-digest", $digest,
+                    "-outform", "SMIME",
+                    "-certfile", catfile($smdir, "smroot.pem"),
+                    "-signer", catfile($smdir, "smrsa1.pem"),
+                    "-out", $sig_file])),
+        "CMS sign pre-computed digest, S/MIME format");
+
+    ok(run(app(["openssl", "cms", @prov, "-verify", "-in", $sig_file,
+                    "-inform", "SMIME",
+                    "-CAfile", catfile($smdir, "smroot.pem"),
+                    "-content", $smcont])),
+       "Verify CMS signed digest, S/MIME format");
+};
+
+subtest "CMS code signing test" => sub {
+    plan tests => 7;
+    my $sig_file = "signature.p7s";
+    ok(run(app(["openssl", "cms", @prov, "-sign", "-in", $smcont,
+                   "-certfile", catfile($smdir, "smroot.pem"),
+                   "-signer", catfile($smdir, "smrsa1.pem"),
+                   "-out", $sig_file])),
+       "accept perform CMS signature with smime certificate");
+
+    ok(run(app(["openssl", "cms", @prov, "-verify", "-in", $sig_file,
+                    "-CAfile", catfile($smdir, "smroot.pem"),
+                    "-content", $smcont])),
+       "accept verify CMS signature with smime certificate");
+
+    ok(!run(app(["openssl", "cms", @prov, "-verify", "-in", $sig_file,
+                    "-CAfile", catfile($smdir, "smroot.pem"),
+                    "-purpose", "codesign",
+                    "-content", $smcont])),
+       "fail verify CMS signature with smime certificate for purpose code signing");
+
+    ok(!run(app(["openssl", "cms", @prov, "-verify", "-in", $sig_file,
+                    "-CAfile", catfile($smdir, "smroot.pem"),
+                    "-purpose", "football",
+                    "-content", $smcont])),
+       "fail verify CMS signature with invalid purpose argument");
+
+    ok(run(app(["openssl", "cms", @prov, "-sign", "-in", $smcont,
+                   "-certfile", catfile($smdir, "smroot.pem"),
+                   "-signer", catfile($smdir, "csrsa1.pem"),
+                   "-out", $sig_file])),
+        "accept perform CMS signature with code signing certificate");
+
+    ok(run(app(["openssl", "cms", @prov, "-verify", "-in", $sig_file,
+                    "-CAfile", catfile($smdir, "smroot.pem"),
+                    "-purpose", "codesign",
+                    "-content", $smcont])),
+       "accept verify CMS signature with code signing certificate for purpose code signing");
+
+    ok(!run(app(["openssl", "cms", @prov, "-verify", "-in", $sig_file,
+                    "-CAfile", catfile($smdir, "smroot.pem"),
+                    "-content", $smcont])),
+       "fail verify CMS signature with code signing certificate for purpose smime_sign");
 };
 
+# Test case for missing MD algorithm (must not segfault)
+
+with({ exit_checker => sub { return shift == 4; } },
+    sub {
+        ok(run(app(['openssl', 'smime', '-verify', '-noverify',
+                    '-inform', 'PEM',
+                    '-in', data_file("pkcs7-md4.pem"),
+                   ])),
+            "Check failure of EVP_DigestInit in PKCS7 signed is handled");
+
+        ok(run(app(['openssl', 'smime', '-decrypt',
+                    '-inform', 'PEM',
+                    '-in', data_file("pkcs7-md4-encrypted.pem"),
+                    '-recip', srctop_file("test", "certs", "ee-cert.pem"),
+                    '-inkey', srctop_file("test", "certs", "ee-key.pem")
+                   ])),
+            "Check failure of EVP_DigestInit in PKCS7 signedAndEnveloped is handled");
+    });
+
 sub check_availability {
     my $tnam = shift;
 
@@ -874,3 +1127,98 @@ sub check_availability {
 
     return "";
 }
+
+# Test case for the locking problem reported in #19643.
+# This will fail if the fix is in and deadlock on Windows (and possibly
+# other platforms) if not.
+ok(!run(app(['openssl', 'cms', '-verify',
+             '-CAfile', srctop_file("test/certs", "pkitsta.pem"),
+             '-policy', 'anyPolicy',
+             '-in', srctop_file("test/smime-eml",
+                                "SignedInvalidMappingFromanyPolicyTest7.eml")
+            ])),
+   "issue#19643");
+
+# Check that we get the expected failure return code
+with({ exit_checker => sub { return shift == 6; } },
+    sub {
+        ok(run(app(['openssl', 'cms', '-encrypt',
+                    '-in', srctop_file("test", "smcont.txt"),
+                    '-aes128', '-stream', '-recip',
+                    srctop_file("test/smime-certs", "badrsa.pem"),
+                   ])),
+            "Check failure during BIO setup with -stream is handled correctly");
+    });
+
+# Test case for return value mis-check reported in #21986
+with({ exit_checker => sub { return shift == 3; } },
+    sub {
+        SKIP: {
+          skip "DSA is not supported in this build", 1 if $no_dsa;
+
+          ok(run(app(['openssl', 'cms', '-sign',
+                      '-in', srctop_file("test", "smcont.txt"),
+                      '-signer', srctop_file("test/smime-certs", "smdsa1.pem"),
+                      '-md', 'SHAKE256'])),
+            "issue#21986");
+        }
+    });
+
+# Test for problem reported in #22225
+with({ exit_checker => sub { return shift == 3; } },
+    sub {
+       ok(run(app(['openssl', 'cms', '-encrypt',
+                   '-in', srctop_file("test", "smcont.txt"),
+                   '-aes-256-ctr', '-recip',
+                   catfile($smdir, "smec1.pem"),
+                  ])),
+          "Check for failure when cipher does not have an assigned OID (issue#22225)");
+     });
+
+# Test encrypt to three recipients, and decrypt using key-only;
+# i.e. do not follow the recommended practice of providing the
+# recipient cert in the decrypt op.
+#
+# Use RSAES-OAEP for key-transport, not RSAES-PKCS-v1_5.
+#
+# Because the cert is not provided during decrypt, all RSA ciphertexts
+# are decrypted in turn, and when/if there is a valid decryption, it
+# is assumed the correct content-key has been recovered.
+#
+# That process may fail with RSAES-PKCS-v1_5 b/c there is a
+# non-negligible chance that decrypting a random input using
+# RSAES-PKCS-v1_5 can result in a valid plaintext (so two content-keys
+# could be recovered and the wrong one might be used).
+#
+# See https://github.com/openssl/project/issues/380
+subtest "encrypt to three recipients with RSA-OAEP, key only decrypt" => sub {
+    plan tests => 3;
+
+    my $pt = srctop_file("test", "smcont.txt");
+    my $ct = "smtst.cms";
+    my $ptpt = "smtst.txt";
+
+    ok(run(app(['openssl', 'cms',
+               @defaultprov,
+               '-encrypt', '-aes128',
+               '-in', $pt,
+               '-out', $ct,
+               '-stream',
+               '-recip', catfile($smdir, "smrsa1.pem"),
+               '-keyopt', 'rsa_padding_mode:oaep',
+               '-recip', catfile($smdir, "smrsa2.pem"),
+               '-keyopt', 'rsa_padding_mode:oaep',
+               '-recip', catfile($smdir, "smrsa3-cert.pem"),
+               '-keyopt', 'rsa_padding_mode:oaep',
+              ])),
+       "encrypt to three recipients with RSA-OAEP (avoid openssl/project issue#380)");
+    ok(run(app(['openssl', 'cms',
+               @defaultprov,
+               '-decrypt', '-aes128',
+               '-in', $ct,
+               '-out', $ptpt,
+               '-inkey', catfile($smdir, "smrsa3-key.pem"),
+              ])),
+       "decrypt with key only");
+    is(compare($pt, $ptpt), 0, "compare original message with decrypted ciphertext");
+};