Add --fips-key configuration parameter to fipsinstall application.
[openssl.git] / test / recipes / 30-test_evp_fetch_prov.t
1 #! /usr/bin/env perl
2 # Copyright 2015-2020 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 use strict;
10 use warnings;
11
12 use OpenSSL::Test qw(:DEFAULT bldtop_dir srctop_file srctop_dir bldtop_file);
13 use OpenSSL::Test::Utils;
14
15 BEGIN {
16 setup("test_evp_fetch_prov");
17 }
18
19 use lib srctop_dir('Configurations');
20 use lib bldtop_dir('.');
21 use platform;
22
23 my $no_fips = disabled('fips') || ($ENV{NO_FIPS} // 0);
24
25 my @types = ( "digest", "cipher" );
26
27 my @setups = ();
28 my @testdata = (
29     { config    => srctop_file("test", "default.cnf"),
30       providers => [ 'default' ],
31       tests  => [ { providers => [] },
32                   { },
33                   { args      => [ '-property', 'provider=default' ],
34                     message   => 'using property "provider=default"' },
35                   { args      => [ '-property', 'provider!=fips' ],
36                     message   => 'using property "provider!=fips"' },
37                   { args      => [ '-property', 'provider!=default', '-fetchfail' ],
38                     message   =>
39                         'using property "provider!=default" is expected to fail' },
40                   { args      => [ '-property', 'provider=fips', '-fetchfail' ],
41                     message   =>
42                         'using property "provider=fips" is expected to fail' } ] }
43 );
44
45 unless ($no_fips) {
46     push @setups, {
47         cmd     => app(['openssl', 'fipsinstall',
48                         '-out', bldtop_file('providers', 'fipsmodule.cnf'),
49                         '-module', bldtop_file('providers', platform->dso('fips')),
50                         '-provider_name', 'fips',
51                         '-section_name', 'fips_sect']),
52         message => "fipsinstall"
53     };
54     push @testdata, (
55         { config    => srctop_file("test", "fips.cnf"),
56           providers => [ 'fips' ],
57           tests     => [
58               { args    => [ '-property', '' ] },
59               { args    => [ '-property', 'provider=fips' ],
60                 message => 'using property "provider=fips"' },
61               { args    => [ '-property', 'provider!=default' ],
62                 message => 'using property "provider!=default"' },
63               { args      => [ '-property', 'provider=default', '-fetchfail' ],
64                 message   =>
65                     'using property "provider=default" is expected to fail' },
66               { args      => [ '-property', 'provider!=fips', '-fetchfail' ],
67                 message   =>
68                     'using property "provider!=fips" is expected to fail' },
69               { args    => [ '-property', 'fips=yes' ],
70                 message => 'using property "fips=yes"' },
71               { args    => [ '-property', 'fips!=no' ],
72                 message => 'using property "fips!=no"' },
73               { args    => [ '-property', '-fips' ],
74                 message => 'using property "-fips"' },
75               { args    => [ '-property', 'fips=no', '-fetchfail' ],
76                 message => 'using property "fips=no is expected to fail"' },
77               { args    => [ '-property', 'fips!=yes', '-fetchfail' ],
78                 message => 'using property "fips!=yes is expected to fail"' } ] },
79         { config    => srctop_file("test", "default-and-fips.cnf"),
80           providers => [ 'default', 'fips' ],
81           tests     => [
82               { args    => [ '-property', '' ] },
83               { args      => [ '-property', 'provider!=default' ],
84                 message   => 'using property "provider!=default"' },
85               { args      => [ '-property', 'provider=default' ],
86                 message   => 'using property "provider=default"' },
87               { args      => [ '-property', 'provider!=fips' ],
88                 message   => 'using property "provider!=fips"' },
89               { args      => [ '-property', 'provider=fips' ],
90                 message   => 'using property "provider=fips"' },
91               { args    => [ '-property', 'fips=yes' ],
92                 message => 'using property "fips=yes"' },
93               { args    => [ '-property', 'fips!=no' ],
94                 message => 'using property "fips!=no"' },
95               { args    => [ '-property', '-fips' ],
96                 message => 'using property "-fips"' },
97               { args    => [ '-property', 'fips=no' ],
98                 message => 'using property "fips=no"' },
99               { args    => [ '-property', 'fips!=yes' ],
100                 message => 'using property "fips!=yes"' } ] },
101     );
102 }
103
104 my $testcount = 0;
105 foreach (@testdata) {
106     $testcount += scalar @{$_->{tests}};
107 }
108
109 plan tests => 1 + scalar @setups + $testcount * scalar(@types);
110
111 ok(run(test(["evp_fetch_prov_test", "-defaultctx"])),
112    "running evp_fetch_prov_test using the default libctx");
113
114 foreach my $setup (@setups) {
115     ok(run($setup->{cmd}), $setup->{message});
116 }
117
118 foreach my $alg (@types) {
119     foreach my $testcase (@testdata) {
120         $ENV{OPENSSL_CONF} = "";
121         foreach my $test (@{$testcase->{tests}}) {
122             my @testproviders =
123                 @{ $test->{providers} // $testcase->{providers} };
124             my $testprovstr = @testproviders
125                 ? ' and loaded providers ' . join(' & ',
126                                                   map { "'$_'" } @testproviders)
127                 : '';
128             my @testargs = @{ $test->{args} // [] };
129             my $testmsg =
130                 defined $test->{message} ? ' '.$test->{message} : '';
131
132             my $message =
133                 "running evp_fetch_prov_test with $alg$testprovstr$testmsg";
134
135             ok(run(test(["evp_fetch_prov_test", "-type", "$alg",
136                          "-config", "$testcase->{config}",
137                          @testargs, @testproviders])),
138                $message);
139         }
140     }
141 }