test_rsa: Test for PVK format conversion
authorTomas Mraz <tomas@openssl.org>
Thu, 2 Dec 2021 21:08:25 +0000 (22:08 +0100)
committerTomas Mraz <tomas@openssl.org>
Mon, 6 Dec 2021 15:38:03 +0000 (16:38 +0100)
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17181)

test/recipes/15-test_rsa.t
test/recipes/tconversion.pl

index 301368b69bfa746e7946c84a06f559109e221512..420a57f8c10d56dbab3a75317bcf9cd406cd8240 100644 (file)
@@ -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"] );
+         };
+    }
 }
index f60954c0ba2408aa711f3b231c5262280ce6f1cf..063be620a312d4f792eaa18db0e3f53ce5668901 100644 (file)
@@ -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");