From 3daedcfefdabe0fb9de3aee850ac2cca2d5fa945 Mon Sep 17 00:00:00 2001 From: Matt Caswell Date: Fri, 19 Jan 2024 14:32:18 +0000 Subject: Add some tests for various PKCS12 files with NULL ContentInfo PKCS7 ContentInfo fields held within a PKCS12 file can be NULL, even if the type has been set to a valid value. CVE-2024-0727 is a result of OpenSSL attempting to dereference the NULL pointer as a result of this. We add test for various instances of this problem. Reviewed-by: Tomas Mraz Reviewed-by: Hugo Landau Reviewed-by: Neil Horman (Merged from https://github.com/openssl/openssl/pull/23361) (cherry picked from commit 8a85df7c60ba1372ee98acc5982e902d75f52130) --- test/recipes/80-test_pkcs12.t | 25 +++++++++++++++++++++++-- test/recipes/80-test_pkcs12_data/bad1.p12 | Bin 0 -> 85 bytes test/recipes/80-test_pkcs12_data/bad2.p12 | Bin 0 -> 104 bytes test/recipes/80-test_pkcs12_data/bad3.p12 | Bin 0 -> 104 bytes 4 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 test/recipes/80-test_pkcs12_data/bad1.p12 create mode 100644 test/recipes/80-test_pkcs12_data/bad2.p12 create mode 100644 test/recipes/80-test_pkcs12_data/bad3.p12 (limited to 'test') diff --git a/test/recipes/80-test_pkcs12.t b/test/recipes/80-test_pkcs12.t index 7970e3225b..f1d5efd741 100644 --- a/test/recipes/80-test_pkcs12.t +++ b/test/recipes/80-test_pkcs12.t @@ -9,7 +9,7 @@ use strict; use warnings; -use OpenSSL::Test qw/:DEFAULT srctop_file/; +use OpenSSL::Test qw/:DEFAULT srctop_file with/; use OpenSSL::Test::Utils; use Encode; @@ -54,7 +54,7 @@ if (eval { require Win32::API; 1; }) { } $ENV{OPENSSL_WIN32_UTF8}=1; -plan tests => 24; +plan tests => 28; # Test different PKCS#12 formats ok(run(test(["pkcs12_format_test"])), "test pkcs12 formats"); @@ -170,6 +170,27 @@ ok(grep(/Trusted key usage (Oracle)/, @pkcs12info) == 0, ok(scalar @match > 0 ? 0 : 1, "test_export_pkcs12_outerr6_empty"); } +# Test some bad pkcs12 files +my $bad1 = srctop_file("test", "recipes", "80-test_pkcs12_data", "bad1.p12"); +my $bad2 = srctop_file("test", "recipes", "80-test_pkcs12_data", "bad2.p12"); +my $bad3 = srctop_file("test", "recipes", "80-test_pkcs12_data", "bad3.p12"); + +with({ exit_checker => sub { return shift == 1; } }, + sub { + ok(run(app(["openssl", "pkcs12", "-in", $bad1, "-password", "pass:"])), + "test bad pkcs12 file 1"); + + ok(run(app(["openssl", "pkcs12", "-in", $bad1, "-password", "pass:", + "-nomacver"])), + "test bad pkcs12 file 1 (nomacver)"); + + ok(run(app(["openssl", "pkcs12", "-in", $bad2, "-password", "pass:"])), + "test bad pkcs12 file 2"); + + ok(run(app(["openssl", "pkcs12", "-in", $bad3, "-password", "pass:"])), + "test bad pkcs12 file 3"); + }); + # Test with Oracle Trusted Key Usage specified in openssl.cnf { ok(run(app(["openssl", "pkcs12", "-export", "-out", $outfile7, diff --git a/test/recipes/80-test_pkcs12_data/bad1.p12 b/test/recipes/80-test_pkcs12_data/bad1.p12 new file mode 100644 index 0000000000..8f3387c7e3 Binary files /dev/null and b/test/recipes/80-test_pkcs12_data/bad1.p12 differ diff --git a/test/recipes/80-test_pkcs12_data/bad2.p12 b/test/recipes/80-test_pkcs12_data/bad2.p12 new file mode 100644 index 0000000000..113cb6f1cd Binary files /dev/null and b/test/recipes/80-test_pkcs12_data/bad2.p12 differ diff --git a/test/recipes/80-test_pkcs12_data/bad3.p12 b/test/recipes/80-test_pkcs12_data/bad3.p12 new file mode 100644 index 0000000000..ef86a1d86f Binary files /dev/null and b/test/recipes/80-test_pkcs12_data/bad3.p12 differ -- cgit v1.2.3