xref: /freebsd/crypto/openssl/test/recipes/15-test_rsa.t (revision e0c4386e7e71d93b0edc0c8fa156263fc4a8b0b6)
1*e0c4386eSCy Schubert#! /usr/bin/env perl
2*e0c4386eSCy Schubert# Copyright 2015-2021 The OpenSSL Project Authors. All Rights Reserved.
3*e0c4386eSCy Schubert#
4*e0c4386eSCy Schubert# Licensed under the Apache License 2.0 (the "License").  You may not use
5*e0c4386eSCy Schubert# this file except in compliance with the License.  You can obtain a copy
6*e0c4386eSCy Schubert# in the file LICENSE in the source distribution or at
7*e0c4386eSCy Schubert# https://www.openssl.org/source/license.html
8*e0c4386eSCy Schubert
9*e0c4386eSCy Schubert
10*e0c4386eSCy Schubertuse strict;
11*e0c4386eSCy Schubertuse warnings;
12*e0c4386eSCy Schubert
13*e0c4386eSCy Schubertuse File::Spec;
14*e0c4386eSCy Schubertuse OpenSSL::Test qw/:DEFAULT srctop_file/;
15*e0c4386eSCy Schubertuse OpenSSL::Test::Utils;
16*e0c4386eSCy Schubert
17*e0c4386eSCy Schubertsetup("test_rsa");
18*e0c4386eSCy Schubert
19*e0c4386eSCy Schubertplan tests => 12;
20*e0c4386eSCy Schubert
21*e0c4386eSCy Schubertrequire_ok(srctop_file('test', 'recipes', 'tconversion.pl'));
22*e0c4386eSCy Schubert
23*e0c4386eSCy Schubertok(run(test(["rsa_test"])), "running rsatest");
24*e0c4386eSCy Schubert
25*e0c4386eSCy Schubertrun_rsa_tests("pkey");
26*e0c4386eSCy Schubert
27*e0c4386eSCy Schubertrun_rsa_tests("rsa");
28*e0c4386eSCy Schubert
29*e0c4386eSCy Schubertsub run_rsa_tests {
30*e0c4386eSCy Schubert    my $cmd = shift;
31*e0c4386eSCy Schubert
32*e0c4386eSCy Schubert    ok(run(app([ 'openssl', $cmd, '-check', '-in', srctop_file('test', 'testrsa.pem'), '-noout'])),
33*e0c4386eSCy Schubert           "$cmd -check" );
34*e0c4386eSCy Schubert
35*e0c4386eSCy Schubert    SKIP: {
36*e0c4386eSCy Schubert         skip "Skipping $cmd conversion test", 3
37*e0c4386eSCy Schubert             if disabled("rsa");
38*e0c4386eSCy Schubert
39*e0c4386eSCy Schubert         subtest "$cmd conversions -- private key" => sub {
40*e0c4386eSCy Schubert             tconversion( -type => $cmd, -prefix => "$cmd-priv",
41*e0c4386eSCy Schubert                          -in => srctop_file("test", "testrsa.pem") );
42*e0c4386eSCy Schubert         };
43*e0c4386eSCy Schubert         subtest "$cmd conversions -- private key PKCS#8" => sub {
44*e0c4386eSCy Schubert             tconversion( -type => $cmd, -prefix => "$cmd-pkcs8",
45*e0c4386eSCy Schubert                          -in => srctop_file("test", "testrsa.pem"),
46*e0c4386eSCy Schubert                          -args => ["pkey"] );
47*e0c4386eSCy Schubert         };
48*e0c4386eSCy Schubert    }
49*e0c4386eSCy Schubert
50*e0c4386eSCy Schubert    SKIP: {
51*e0c4386eSCy Schubert         skip "Skipping msblob conversion test", 1
52*e0c4386eSCy Schubert             if disabled($cmd) || $cmd eq 'pkey';
53*e0c4386eSCy Schubert
54*e0c4386eSCy Schubert         subtest "$cmd conversions -- public key" => sub {
55*e0c4386eSCy Schubert             tconversion( -type => 'msb', -prefix => "$cmd-msb-pub",
56*e0c4386eSCy Schubert                          -in => srctop_file("test", "testrsapub.pem"),
57*e0c4386eSCy Schubert                          -args => ["rsa", "-pubin", "-pubout"] );
58*e0c4386eSCy Schubert         };
59*e0c4386eSCy Schubert    }
60*e0c4386eSCy Schubert    SKIP: {
61*e0c4386eSCy Schubert         skip "Skipping PVK conversion test", 1
62*e0c4386eSCy Schubert             if disabled($cmd) || $cmd eq 'pkey' || disabled("rc4")
63*e0c4386eSCy Schubert                || disabled ("legacy");
64*e0c4386eSCy Schubert
65*e0c4386eSCy Schubert         subtest "$cmd conversions -- private key" => sub {
66*e0c4386eSCy Schubert             tconversion( -type => 'pvk', -prefix => "$cmd-pvk",
67*e0c4386eSCy Schubert                          -in => srctop_file("test", "testrsa.pem"),
68*e0c4386eSCy Schubert                          -args => ["rsa", "-passin", "pass:testpass",
69*e0c4386eSCy Schubert                                    "-passout", "pass:testpass",
70*e0c4386eSCy Schubert                                    "-provider", "default",
71*e0c4386eSCy Schubert                                    "-provider", "legacy"] );
72*e0c4386eSCy Schubert         };
73*e0c4386eSCy Schubert    }
74*e0c4386eSCy Schubert}
75