2 # Copyright 2015-2021 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('.');
23 my $no_fips = disabled('fips') || ($ENV{NO_FIPS} // 0);
24 my $no_legacy = disabled('legacy') || ($ENV{NO_LEGACY} // 0);
25 my $no_des = disabled("des");
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_aes_stitched.txt
46 evpciph_des3_common.txt
48 evpkdf_kbkdf_counter.txt
61 evppkey_rsa_common.txt
72 push @files, qw(evppkey_dsa.txt) unless $no_dsa;
73 push @files, qw(evppkey_ecx.txt) unless $no_ec;
80 ) unless $no_ec || $no_gost;
82 # A list of tests that only run with the default provider
83 # (i.e. The algorithms are not present in the fips provider)
90 evpciph_camellia_cts.txt
97 evpciph_rc4_stitched.txt
116 evppkey_kdf_scrypt.txt
117 evppkey_kdf_tls1_prf.txt
120 push @defltfiles, qw(evppkey_brainpool.txt) unless $no_ec;
121 push @defltfiles, qw(evppkey_sm2.txt) unless $no_sm2;
124 + (scalar(@configs) * scalar(@files))
125 + scalar(@defltfiles)
126 + 3; # error output tests
129 my $conf = srctop_file("test", $_);
131 foreach my $f ( @files ) {
132 ok(run(test(["evp_test",
135 "running evp_test -config $conf $f");
139 my $conf = srctop_file("test", $defaultcnf);
140 foreach my $f ( @defltfiles ) {
141 ok(run(test(["evp_test",
144 "running evp_test -config $conf $f");
147 # test_errors OPTIONS
149 # OPTIONS may include:
151 # key => "filename" # expected to be found in $SRCDIR/test/certs
152 # out => "filename" # file to write error strings to
153 # args => [ ... extra openssl pkey args ... ]
154 # expected => regexps to match error lines against
155 sub test_errors { # actually tests diagnostics of OSSL_STORE
157 my $infile = srctop_file('test', 'certs', $opts{key});
158 my @args = ( qw(openssl pkey -in), $infile, @{$opts{args} // []} );
159 my $res = !run(app([@args], stderr => $opts{out}));
160 my $found = !exists $opts{expected};
161 open(my $in, '<', $opts{out}) or die "Could not open file $opts{out}";
162 while(my $errline = <$in>) {
163 print $errline; # this may help debugging
165 # output must not include ASN.1 parse errors
166 $res &&= $errline !~ m/asn1 encoding/;
167 # output must include what is expressed in $opts{$expected}
169 if exists $opts{expected} && $errline =~ m/$opts{expected}/;
172 # $tmpfile is kept to help with investigation in case of failure
173 return $res && $found;
177 skip "DSA not disabled", 2 if !disabled("dsa");
179 ok(test_errors(key => 'server-dsa-key.pem',
180 out => 'server-dsa-key.err'),
181 "expected error loading unsupported dsa private key");
182 ok(test_errors(key => 'server-dsa-pubkey.pem',
183 out => 'server-dsa-pubkey.err',
184 args => [ '-pubin' ],
185 expected => 'unsupported'),
186 "expected error loading unsupported dsa public key");
190 skip "SM2 not disabled", 1 if !disabled("sm2");
192 ok(test_errors(key => 'sm2.key', out => 'sm2.err'),
193 "expected error loading unsupported sm2 private key");