2 # Copyright 2015-2020 The OpenSSL Project Authors. All Rights Reserved.
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
12 use OpenSSL::Test qw(:DEFAULT bldtop_dir srctop_file srctop_dir bldtop_file);
13 use OpenSSL::Test::Utils;
16 setup("test_evp_fetch_prov");
19 use lib srctop_dir('Configurations');
20 use lib bldtop_dir('.');
23 my $no_fips = disabled('fips') || ($ENV{NO_FIPS} // 0);
25 my @types = ( "digest", "cipher" );
29 { config => srctop_file("test", "default.cnf"),
30 providers => [ 'default' ],
31 tests => [ { providers => [] },
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' ],
39 'using property "provider!=default" is expected to fail' },
40 { args => [ '-property', 'provider=fips', '-fetchfail' ],
42 'using property "provider=fips" is expected to fail' } ] }
47 cmd => app(['openssl', 'fipsinstall',
48 '-out', bldtop_file('providers', 'fipsmodule.cnf'),
49 '-module', bldtop_file('providers', platform->dso('fips')),
50 '-provider_name', 'fips', '-mac_name', 'HMAC',
51 '-macopt', 'digest:SHA256', '-macopt', 'hexkey:00',
52 '-section_name', 'fips_sect']),
53 message => "fipsinstall"
56 { config => srctop_file("test", "fips.cnf"),
57 providers => [ 'fips' ],
59 { args => [ '-property', '' ] },
60 { args => [ '-property', 'provider=fips' ],
61 message => 'using property "provider=fips"' },
62 { args => [ '-property', 'provider!=default' ],
63 message => 'using property "provider!=default"' },
64 { args => [ '-property', 'provider=default', '-fetchfail' ],
66 'using property "provider=default" is expected to fail' },
67 { args => [ '-property', 'provider!=fips', '-fetchfail' ],
69 'using property "provider!=fips" is expected to fail' },
70 { args => [ '-property', 'fips=yes' ],
71 message => 'using property "fips=yes"' },
72 { args => [ '-property', 'fips!=no' ],
73 message => 'using property "fips!=no"' },
74 { args => [ '-property', '-fips' ],
75 message => 'using property "-fips"' },
76 { args => [ '-property', 'fips=no', '-fetchfail' ],
77 message => 'using property "fips=no is expected to fail"' },
78 { args => [ '-property', 'fips!=yes', '-fetchfail' ],
79 message => 'using property "fips!=yes is expected to fail"' } ] },
80 { config => srctop_file("test", "default-and-fips.cnf"),
81 providers => [ 'default', 'fips' ],
83 { args => [ '-property', '' ] },
84 { args => [ '-property', 'provider!=default' ],
85 message => 'using property "provider!=default"' },
86 { args => [ '-property', 'provider=default' ],
87 message => 'using property "provider=default"' },
88 { args => [ '-property', 'provider!=fips' ],
89 message => 'using property "provider!=fips"' },
90 { args => [ '-property', 'provider=fips' ],
91 message => 'using property "provider=fips"' },
92 { args => [ '-property', 'fips=yes' ],
93 message => 'using property "fips=yes"' },
94 { args => [ '-property', 'fips!=no' ],
95 message => 'using property "fips!=no"' },
96 { args => [ '-property', '-fips' ],
97 message => 'using property "-fips"' },
98 { args => [ '-property', 'fips=no' ],
99 message => 'using property "fips=no"' },
100 { args => [ '-property', 'fips!=yes' ],
101 message => 'using property "fips!=yes"' } ] },
106 foreach (@testdata) {
107 $testcount += scalar @{$_->{tests}};
110 plan tests => 1 + scalar @setups + $testcount * scalar(@types);
112 ok(run(test(["evp_fetch_prov_test", "-defaultctx"])),
113 "running evp_fetch_prov_test using the default libctx");
115 foreach my $setup (@setups) {
116 ok(run($setup->{cmd}), $setup->{message});
119 foreach my $alg (@types) {
120 foreach my $testcase (@testdata) {
121 $ENV{OPENSSL_CONF} = "";
122 foreach my $test (@{$testcase->{tests}}) {
124 @{ $test->{providers} // $testcase->{providers} };
125 my $testprovstr = @testproviders
126 ? ' and loaded providers ' . join(' & ',
127 map { "'$_'" } @testproviders)
129 my @testargs = @{ $test->{args} // [] };
131 defined $test->{message} ? ' '.$test->{message} : '';
134 "running evp_fetch_prov_test with $alg$testprovstr$testmsg";
136 ok(run(test(["evp_fetch_prov_test", "-type", "$alg",
137 "-config", "$testcase->{config}",
138 @testargs, @testproviders])),