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