2 # Copyright 2015-2016 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" );
27 $ENV{OPENSSL_MODULES} = bldtop_dir("providers");
28 $ENV{OPENSSL_CONF_INCLUDE} = bldtop_dir("providers");
32 { config => srctop_file("test", "default.cnf"),
33 providers => [ 'default' ],
34 tests => [ { providers => [] },
36 { args => [ '-property', 'provider=default' ],
37 message => 'using property "provider=default"' },
38 { args => [ '-property', 'provider!=fips' ],
39 message => 'using property "provider!=fips"' },
40 { args => [ '-property', 'provider!=default', '-fetchfail' ],
42 'using property "provider!=default" is expected to fail' },
43 { args => [ '-property', 'provider=fips', '-fetchfail' ],
45 'using property "provider=fips" is expected to fail' } ] }
50 cmd => app(['openssl', 'fipsinstall',
51 '-out', bldtop_file('providers', 'fipsinstall.conf'),
52 '-module', bldtop_file('providers', platform->dso('fips')),
53 '-provider_name', 'fips', '-mac_name', 'HMAC',
54 '-macopt', 'digest:SHA256', '-macopt', 'hexkey:00',
55 '-section_name', 'fips_sect']),
56 message => "fipsinstall"
59 { config => srctop_file("test", "fips.cnf"),
60 providers => [ 'fips' ],
62 { args => [ '-property', '' ] },
63 { args => [ '-property', 'provider=fips' ],
64 message => 'using property "provider=fips"' },
65 { args => [ '-property', 'provider!=default' ],
66 message => 'using property "provider!=default"' },
67 { args => [ '-property', 'provider=default', '-fetchfail' ],
69 'using property "provider=default" is expected to fail' },
70 { args => [ '-property', 'provider!=fips', '-fetchfail' ],
72 'using property "provider!=fips" is expected to fail' },
73 { args => [ '-property', 'fips=yes' ],
74 message => 'using property "fips=yes"' },
75 { args => [ '-property', 'fips!=no' ],
76 message => 'using property "fips!=no"' },
77 { args => [ '-property', '-fips' ],
78 message => 'using property "-fips"' },
79 { args => [ '-property', 'fips=no', '-fetchfail' ],
80 message => 'using property "fips=no is expected to fail"' },
81 { args => [ '-property', 'fips!=yes', '-fetchfail' ],
82 message => 'using property "fips!=yes is expected to fail"' } ] },
83 { config => srctop_file("test", "default-and-fips.cnf"),
84 providers => [ 'default', 'fips' ],
86 { args => [ '-property', '' ] },
87 { args => [ '-property', 'provider!=default' ],
88 message => 'using property "provider!=default"' },
89 { args => [ '-property', 'provider=default' ],
90 message => 'using property "provider=default"' },
91 { args => [ '-property', 'provider!=fips' ],
92 message => 'using property "provider!=fips"' },
93 { args => [ '-property', 'provider=fips' ],
94 message => 'using property "provider=fips"' },
95 { args => [ '-property', 'fips=yes' ],
96 message => 'using property "fips=yes"' },
97 { args => [ '-property', 'fips!=no' ],
98 message => 'using property "fips!=no"' },
99 { args => [ '-property', '-fips' ],
100 message => 'using property "-fips"' },
101 { args => [ '-property', 'fips=no' ],
102 message => 'using property "fips=no"' },
103 { args => [ '-property', 'fips!=yes' ],
104 message => 'using property "fips!=yes"' } ] },
109 foreach (@testdata) {
110 $testcount += scalar @{$_->{tests}};
113 plan tests => 1 + scalar @setups + $testcount * scalar(@types);
115 ok(run(test(["evp_fetch_prov_test", "-defaultctx"])),
116 "running evp_fetch_prov_test using the default libctx");
118 foreach my $setup (@setups) {
119 ok(run($setup->{cmd}), $setup->{message});
122 foreach my $alg (@types) {
123 foreach my $testcase (@testdata) {
124 $ENV{OPENSSL_CONF} = $testcase->{config};
125 foreach my $test (@{$testcase->{tests}}) {
127 @{ $test->{providers} // $testcase->{providers} };
128 my $testprovstr = @testproviders
129 ? ' and loaded providers ' . join(' & ',
130 map { "'$_'" } @testproviders)
132 my @testargs = @{ $test->{args} // [] };
134 defined $test->{message} ? ' '.$test->{message} : '';
137 "running evp_fetch_prov_test with $alg$testprovstr$testmsg";
139 ok(run(test(["evp_fetch_prov_test", "-type", "$alg",
140 @testargs, @testproviders])),