Skip to content

Commit

Permalink
To verify MAC, we need a MAC
Browse files Browse the repository at this point in the history
Fixes openssl#26106

Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from openssl#26140)
  • Loading branch information
beldmit authored and t8m committed Dec 11, 2024
1 parent fe89f30 commit 8ad98cc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
6 changes: 6 additions & 0 deletions apps/pkcs12.c
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,12 @@ int pkcs12_main(int argc, char **argv)
const ASN1_OBJECT *macobj;

PKCS12_get0_mac(NULL, &macalgid, NULL, NULL, p12);

if (macalgid == NULL) {
BIO_printf(bio_err, "Warning: MAC is absent!\n");
goto dump;
}

X509_ALGOR_get0(&macobj, NULL, NULL, macalgid);

if (OBJ_obj2nid(macobj) != NID_pbmac1) {
Expand Down
9 changes: 8 additions & 1 deletion test/recipes/80-test_pkcs12.t
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ $ENV{OPENSSL_WIN32_UTF8}=1;

my $no_fips = disabled('fips') || ($ENV{NO_FIPS} // 0);

plan tests => $no_fips ? 46 : 52;
plan tests => $no_fips ? 47 : 53;

# Test different PKCS#12 formats
ok(run(test(["pkcs12_format_test"])), "test pkcs12 formats");
Expand Down Expand Up @@ -288,6 +288,13 @@ with({ exit_checker => sub { return shift == 1; } },
"test bad pkcs12 file 3 (info)");
});

# Test that mac verification doesn't fail when mac is absent in the file
{
my $nomac = srctop_file("test", "recipes", "80-test_pkcs12_data", "nomac_parse.p12");
ok(run(app(["openssl", "pkcs12", "-in", $nomac, "-passin", "pass:testpassword"])),
"test pkcs12 file without MAC");
}

# Test with Oracle Trusted Key Usage specified in openssl.cnf
{
ok(run(app(["openssl", "pkcs12", "-export", "-out", $outfile7,
Expand Down
Binary file added test/recipes/80-test_pkcs12_data/nomac_parse.p12
Binary file not shown.

0 comments on commit 8ad98cc

Please sign in to comment.