summaryrefslogtreecommitdiffstats
path: root/test/recipes/91-test_pkey_check.t
diff options
context:
space:
mode:
authorTomas Mraz <tomas@openssl.org>2022-04-13 12:44:34 +0200
committerTomas Mraz <tomas@openssl.org>2022-06-15 11:02:30 +0200
commit08e0aad293f1c283dccf7e9065ec28af5e143304 (patch)
tree6f2aff8c6664f142ed876562a46d7e0139bc4cf6 /test/recipes/91-test_pkey_check.t
parent0615cedecda7ed18300db48b0bb56cec6d3527bd (diff)
test_pkey_check: Positive testcase for private key with unknown parameters
Reviewed-by: Shane Lontis <shane.lontis@oracle.com> Reviewed-by: Paul Dale <pauli@openssl.org> (Merged from https://github.com/openssl/openssl/pull/18099)
Diffstat (limited to 'test/recipes/91-test_pkey_check.t')
-rw-r--r--test/recipes/91-test_pkey_check.t41
1 files changed, 30 insertions, 11 deletions
diff --git a/test/recipes/91-test_pkey_check.t b/test/recipes/91-test_pkey_check.t
index a415fee24a..354e33575e 100644
--- a/test/recipes/91-test_pkey_check.t
+++ b/test/recipes/91-test_pkey_check.t
@@ -14,21 +14,30 @@ use File::Spec;
use OpenSSL::Test qw/:DEFAULT data_file/;
use OpenSSL::Test::Utils;
-sub check_key {
+sub pkey_check {
my $f = shift;
return run(app(['openssl', 'pkey', '-check', '-text',
'-in', $f]));
}
-sub check_key_notok {
+sub check_key {
my $f = shift;
- my $str = "$f should fail validation";
+ my $should_fail = shift;
+ my $str;
+
+
+ $str = "$f should fail validation" if $should_fail;
+ $str = "$f should pass validation" unless $should_fail;
$f = data_file($f);
if ( -s $f ) {
- ok(!check_key($f), $str);
+ if ($should_fail) {
+ ok(!pkey_check($f), $str);
+ } else {
+ ok(pkey_check($f), $str);
+ }
} else {
fail("Missing file $f");
}
@@ -36,26 +45,36 @@ sub check_key_notok {
setup("test_pkey_check");
-my @tests = ();
+my @negative_tests = ();
-push(@tests, (
+push(@negative_tests, (
# For EC keys the range for the secret scalar `k` is `1 <= k <= n-1`
"ec_p256_bad_0.pem", # `k` set to `n` (equivalent to `0 mod n`, invalid)
"ec_p256_bad_1.pem", # `k` set to `n+1` (equivalent to `1 mod n`, invalid)
)) unless disabled("ec");
-push(@tests, (
+push(@negative_tests, (
# For SM2 keys the range for the secret scalar `k` is `1 <= k < n-1`
"sm2_bad_neg1.pem", # `k` set to `n-1` (invalid, because SM2 range)
"sm2_bad_0.pem", # `k` set to `n` (equivalent to `0 mod n`, invalid)
"sm2_bad_1.pem", # `k` set to `n+1` (equivalent to `1 mod n`, invalid)
)) unless disabled("sm2");
+my @positive_tests = ();
+
+push(@positive_tests, (
+ "dhpkey.pem"
+ )) unless disabled("dh");
+
plan skip_all => "No tests within the current enabled feature set"
- unless @tests;
+ unless @negative_tests && @positive_tests;
-plan tests => scalar(@tests);
+plan tests => scalar(@negative_tests) + scalar(@positive_tests);
+
+foreach my $t (@negative_tests) {
+ check_key($t, 1);
+}
-foreach my $t (@tests) {
- check_key_notok($t);
+foreach my $t (@positive_tests) {
+ check_key($t, 0);
}