From: Jakub Zelenka Date: Tue, 17 Sep 2024 13:21:33 +0000 (+0100) Subject: Fix smime-type for AuthEnvelopedData X-Git-Tag: openssl-3.1.8~75 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7a95946ff5d2cd008f85027c9a92e09f3092f6db;p=thirdparty%2Fopenssl.git Fix smime-type for AuthEnvelopedData Reviewed-by: Hugo Landau Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/25523) (cherry picked from commit 4c8c37e5720ac08cb777499a92b48fdae5aace9a) --- diff --git a/crypto/asn1/asn_mime.c b/crypto/asn1/asn_mime.c index 9fc52d04762..8bb7089292d 100644 --- a/crypto/asn1/asn_mime.c +++ b/crypto/asn1/asn_mime.c @@ -300,6 +300,8 @@ int SMIME_write_ASN1_ex(BIO *bio, ASN1_VALUE *val, BIO *data, int flags, if (ctype_nid == NID_pkcs7_enveloped) { msg_type = "enveloped-data"; + } else if (ctype_nid == NID_id_smime_ct_authEnvelopedData) { + msg_type = "authEnveloped-data"; } else if (ctype_nid == NID_pkcs7_signed) { if (econt_nid == NID_id_smime_ct_receipt) msg_type = "signed-receipt"; diff --git a/test/recipes/80-test_cms.t b/test/recipes/80-test_cms.t index ebef8a18403..ea378261105 100644 --- a/test/recipes/80-test_cms.t +++ b/test/recipes/80-test_cms.t @@ -609,6 +609,7 @@ my @smime_cms_param_tests = ( "-stream", "-out", "{output}.cms", "-recip", catfile($smdir, "smec1.pem"), "-aes128", "-keyopt", "ecdh_kdf_md:sha256" ], + sub { my %opts = @_; smimeType_matches("$opts{output}.cms", "enveloped-data"); }, [ "{cmd2}", @prov, "-decrypt", "-recip", catfile($smdir, "smec1.pem"), "-in", "{output}.cms", "-out", "{output}.txt" ], \&final_compare @@ -618,6 +619,7 @@ my @smime_cms_param_tests = ( [ "{cmd1}", @prov, "-encrypt", "-in", $smcont, "-stream", "-out", "{output}.cms", "-recip", catfile($smdir, "smec1.pem"), "-aes-128-gcm", "-keyopt", "ecdh_kdf_md:sha256" ], + sub { my %opts = @_; smimeType_matches("$opts{output}.cms", "authEnveloped-data"); }, [ "{cmd2}", "-decrypt", "-recip", catfile($smdir, "smec1.pem"), "-in", "{output}.cms", "-out", "{output}.txt" ], \&final_compare @@ -826,6 +828,28 @@ sub contentType_matches { return scalar(@c); } +# Returns 1 if the smime-type matches the passed parameter, otherwise 0. +sub smimeType_matches { + my ($in, $expected_smime_type) = @_; + + # Read the text file + open(my $fh, '<', $in) or die("open failed for $in : $!"); + local $/; + my $content = <$fh>; + close($fh); + + # Extract the Content-Type line with the smime-type attribute + if ($content =~ /Content-Type:\s*application\/pkcs7-mime.*smime-type=([^\s;]+)/) { + my $smime_type = $1; + + # Compare the extracted smime-type with the expected value + return ($smime_type eq $expected_smime_type) ? 1 : 0; + } + + # If no smime-type is found, return 0 + return 0; +} + sub rsapssSaltlen { my ($in) = @_; my $exit = 0;