From a44eb8421d0e84c069a5fa55ced796878e6b0966 Mon Sep 17 00:00:00 2001 From: Tomas Mraz Date: Thu, 2 Dec 2021 22:08:25 +0100 Subject: [PATCH] test_rsa: Test for PVK format conversion Reviewed-by: Tim Hudson Reviewed-by: Richard Levitte Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/17181) --- test/recipes/15-test_rsa.t | 20 +++++++++++++++++--- test/recipes/tconversion.pl | 6 ++++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/test/recipes/15-test_rsa.t b/test/recipes/15-test_rsa.t index 301368b69bf..420a57f8c10 100644 --- a/test/recipes/15-test_rsa.t +++ b/test/recipes/15-test_rsa.t @@ -16,7 +16,7 @@ use OpenSSL::Test::Utils; setup("test_rsa"); -plan tests => 10; +plan tests => 12; require_ok(srctop_file('test', 'recipes', 'tconversion.pl')); @@ -32,7 +32,7 @@ sub run_rsa_tests { ok(run(app([ 'openssl', $cmd, '-check', '-in', srctop_file('test', 'testrsa.pem'), '-noout'])), "$cmd -check" ); - SKIP: { + SKIP: { skip "Skipping $cmd conversion test", 3 if disabled("rsa"); @@ -47,7 +47,7 @@ sub run_rsa_tests { }; } - SKIP: { + SKIP: { skip "Skipping msblob conversion test", 1 if disabled($cmd) || $cmd eq 'pkey'; @@ -57,4 +57,18 @@ sub run_rsa_tests { -args => ["rsa", "-pubin", "-pubout"] ); }; } + SKIP: { + skip "Skipping PVK conversion test", 1 + if disabled($cmd) || $cmd eq 'pkey' || disabled("rc4") + || disabled ("legacy"); + + subtest "$cmd conversions -- private key" => sub { + tconversion( -type => 'pvk', -prefix => "$cmd-pvk", + -in => srctop_file("test", "testrsa.pem"), + -args => ["rsa", "-passin", "pass:testpass", + "-passout", "pass:testpass", + "-provider", "default", + "-provider", "legacy"] ); + }; + } } diff --git a/test/recipes/tconversion.pl b/test/recipes/tconversion.pl index f60954c0ba2..063be620a31 100644 --- a/test/recipes/tconversion.pl +++ b/test/recipes/tconversion.pl @@ -19,6 +19,7 @@ my %conversionforms = ( # specific test types as key. "*" => [ "d", "p" ], "msb" => [ "d", "p", "msblob" ], + "pvk" => [ "d", "p", "pvk" ], ); sub tconversion { my %opts = @_; @@ -45,8 +46,9 @@ sub tconversion { + $n # initial conversions from p to all forms (A) + $n*$n # conversion from result of A to all forms (B) + 1 # comparing original test file to p form of A - + $n*($n-1); # comparing first conversion to each fom in A with B + + $n*($n-1); # comparing first conversion to each form in A with B $totaltests-- if ($testtype eq "p7d"); # no comparison of original test file + $totaltests -= $n if ($testtype eq "pvk"); # no comparisons of the pvk form plan tests => $totaltests; my @cmd = ("openssl", @openssl_args); @@ -91,7 +93,7 @@ sub tconversion { } foreach my $to (@conversionforms) { - next if $to eq "d"; + next if $to eq "d" or $to eq "pvk"; foreach my $from (@conversionforms) { is(cmp_text("$prefix-f.$to", "$prefix-ff.$from$to"), 0, "comparing $to to $from$to"); -- 2.47.2