#! /usr/bin/env perl
-# Copyright 2015-2022 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
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;
$no_rc2 = 1 if disabled("legacy");
-plan tests => 17;
+plan tests => 23;
ok(run(test(["pkcs7_test"])), "test pkcs7");
\&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",
$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
],
"-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 = (
my $pssparam_offset = -1;
while ($_ = shift @asn1parse) {
chomp;
- next unless /:rsassaPss$/;
+ 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;
# 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]+)$/) {
+ if ($pssparam[-1] =~ /prim:\s+INTEGER\s+:([A-Fa-f0-9]+)/) {
$saltlen = hex($1);
}
"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;
"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");
+};