]>
git.ipfire.org Git - thirdparty/openssl.git/blob - test/recipes/30-test_evp.t
df343d410914aeb1c7c6a6a27d54b2a26daa3a10
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
13 use OpenSSL
::Test
qw(:DEFAULT data_file bldtop_dir srctop_file srctop_dir bldtop_file);
14 use OpenSSL
::Test
::Utils
;
20 use lib srctop_dir
('Configurations');
21 use lib bldtop_dir
('.');
24 my $no_fips = disabled
('fips') || ($ENV{NO_FIPS
} // 0);
25 my $no_legacy = disabled
('legacy') || ($ENV{NO_LEGACY
} // 0);
26 my $no_dh = disabled
("dh");
27 my $no_dsa = disabled
("dsa");
28 my $no_ec = disabled
("ec");
29 my $no_gost = disabled
("gost");
30 my $no_sm2 = disabled
("sm2");
32 # Default config depends on if the legacy module is built or not
33 my $defaultcnf = $no_legacy ?
'default.cnf' : 'default-and-legacy.cnf';
35 my @configs = ( $defaultcnf );
36 # Only add the FIPS config if the FIPS module has been built
37 push @configs, 'fips-and-base.cnf' unless $no_fips;
39 # A list of tests that run with both the default and fips provider.
41 evpciph_aes_ccm_cavs.txt
42 evpciph_aes_common.txt
45 evpciph_des3_common.txt
57 evppkey_rsa_common.txt
60 push @files, qw(evppkey_ffdhe.txt) unless $no_dh;
61 push @files, qw(evppkey_dsa.txt) unless $no_dsa;
62 push @files, qw(evppkey_ecx.txt) unless $no_ec;
69 ) unless $no_ec || $no_gost;
71 # A list of tests that only run with the default provider
72 # (i.e. The algorithms are not present in the fips provider)
104 evppkey_kdf_scrypt.txt
105 evppkey_kdf_tls1_prf.txt
108 push @defltfiles, qw(evppkey_brainpool.txt) unless $no_ec;
109 push @defltfiles, qw(evppkey_sm2.txt) unless $no_sm2;
112 ($no_fips ?
0 : 1) # FIPS install test
113 + (scalar(@configs) * scalar(@files))
114 + scalar(@defltfiles)
115 + 3; # error output tests
118 my $infile = bldtop_file
('providers', platform
->dso('fips'));
120 ok
(run
(app
(['openssl', 'fipsinstall',
121 '-out', bldtop_file
('providers', 'fipsmodule.cnf'),
122 '-module', $infile])),
127 my $conf = srctop_file
("test", $_);
129 foreach my $f ( @files ) {
130 ok
(run
(test
(["evp_test",
133 "running evp_test -config $conf $f");
137 my $conf = srctop_file
("test", $defaultcnf);
138 foreach my $f ( @defltfiles ) {
139 ok
(run
(test
(["evp_test",
142 "running evp_test -config $conf $f");
145 sub test_errors
{ # actually tests diagnostics of OSSL_STORE
146 my ($expected, $key, @opts) = @_;
147 my $infile = srctop_file
('test', 'certs', $key);
148 my @args = qw(openssl pkey -in);
149 push(@args, $infile, @opts);
150 my $tmpfile = 'out.txt';
151 my $res = !run
(app
([@args], stderr
=> $tmpfile));
153 open(my $in, '<', $tmpfile) or die "Could not open file $tmpfile";
155 print; # this may help debugging
156 $res &&= !m/asn1 encoding/; # output must not include ASN.1 parse errors
157 $found = 1 if m/$expected/; # output must include $expected
160 # $tmpfile is kept to help with investigation in case of failure
161 return $res && $found;
165 skip
"DSA not disabled", 2 if !disabled
("dsa");
167 ok
(test_errors
("unsupported algorithm", "server-dsa-key.pem"),
168 "error loading unsupported dsa private key");
169 ok
(test_errors
("unsupported algorithm", "server-dsa-pubkey.pem", "-pubin"),
170 "error loading unsupported dsa public key");
174 skip
"sm2 not disabled", 1 if !disabled
("sm2");
176 ok
(test_errors
("unknown group|unsupported algorithm", "sm2.key"),
177 "error loading unsupported sm2 private key");