Add test for openssl ecparam with fips and base providers
authorTomas Mraz <tomas@openssl.org>
Wed, 30 Mar 2022 14:04:55 +0000 (16:04 +0200)
committerTomas Mraz <tomas@openssl.org>
Mon, 11 Apr 2022 10:00:37 +0000 (12:00 +0200)
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17981)

(cherry picked from commit 269c349a7688daae48d95e582e62ff181888c854)

test/recipes/15-test_ecparam.t

index 766524e8cfa924a0e9da81d82cb0fcefb0ebdb7b..80bac6741290281d57a3731e045e5bda1c3acb99 100644 (file)
@@ -13,7 +13,7 @@ use warnings;
 use File::Spec;
 use File::Compare qw/compare_text/;
 use OpenSSL::Glob;
-use OpenSSL::Test qw/:DEFAULT data_file/;
+use OpenSSL::Test qw/:DEFAULT data_file srctop_file bldtop_dir/;
 use OpenSSL::Test::Utils;
 
 setup("test_ecparam");
@@ -25,7 +25,7 @@ my @valid = glob(data_file("valid", "*.pem"));
 my @noncanon = glob(data_file("noncanon", "*.pem"));
 my @invalid = glob(data_file("invalid", "*.pem"));
 
-plan tests => 11;
+plan tests => 12;
 
 sub checkload {
     my $files = shift; # List of files
@@ -59,6 +59,8 @@ sub checkcompare {
     }
 }
 
+my $no_fips = disabled('fips') || ($ENV{NO_FIPS} // 0);
+
 subtest "Check loading valid parameters by ecparam with -check" => sub {
     plan tests => scalar(@valid);
     checkload(\@valid, 1, "ecparam", "-check");
@@ -113,3 +115,31 @@ subtest "Check pkeyparam does not change the parameter file on output" => sub {
     plan tests => 2 * scalar(@valid);
     checkcompare(\@valid, "pkeyparam");
 };
+
+subtest "Check loading of fips and non-fips params" => sub {
+    plan skip_all => "FIPS is disabled"
+        if $no_fips;
+    plan tests => 3;
+
+    my $fipsconf = srctop_file("test", "fips-and-base.cnf");
+    my $defaultconf = srctop_file("test", "default.cnf");
+
+    $ENV{OPENSSL_CONF} = $fipsconf;
+
+    ok(run(app(['openssl', 'ecparam',
+                '-in', data_file('valid', 'secp384r1-explicit.pem'),
+                '-check'])),
+       "Loading explicitly encoded valid curve");
+
+    ok(run(app(['openssl', 'ecparam',
+                '-in', data_file('valid', 'secp384r1-named.pem'),
+                '-check'])),
+       "Loading named valid curve");
+
+    ok(!run(app(['openssl', 'ecparam',
+                '-in', data_file('valid', 'secp112r1-named.pem'),
+                '-check'])),
+       "Fail loading named non-fips curve");
+
+    $ENV{OPENSSL_CONF} = $defaultconf;
+};