Skip to content

Commit

Permalink
Fix smime-type for AuthEnvelopedData
Browse files Browse the repository at this point in the history
Reviewed-by: Hugo Landau <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from openssl#25523)

(cherry picked from commit 4c8c37e)
  • Loading branch information
bukka authored and t8m committed Nov 5, 2024
1 parent 524aec8 commit fb5a57d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions crypto/asn1/asn_mime.c
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
24 changes: 24 additions & 0 deletions test/recipes/80-test_cms.t
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,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
Expand All @@ -625,6 +626,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
Expand Down Expand Up @@ -833,6 +835,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;
Expand Down

0 comments on commit fb5a57d

Please sign in to comment.