1 | #! /usr/bin/env perl
|
---|
2 | # Copyright 2015-2023 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 |
|
---|
10 | use strict;
|
---|
11 | use warnings;
|
---|
12 |
|
---|
13 | use OpenSSL::Test qw(:DEFAULT data_file bldtop_dir srctop_file srctop_dir bldtop_file);
|
---|
14 | use OpenSSL::Test::Utils;
|
---|
15 |
|
---|
16 | BEGIN {
|
---|
17 | setup("test_evp");
|
---|
18 | }
|
---|
19 |
|
---|
20 | use lib srctop_dir('Configurations');
|
---|
21 | use lib bldtop_dir('.');
|
---|
22 |
|
---|
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_sm2 = disabled("sm2");
|
---|
30 |
|
---|
31 | # Default config depends on if the legacy module is built or not
|
---|
32 | my $defaultcnf = $no_legacy ? 'default.cnf' : 'default-and-legacy.cnf';
|
---|
33 |
|
---|
34 | my @configs = ( $defaultcnf );
|
---|
35 | # Only add the FIPS config if the FIPS module has been built
|
---|
36 | push @configs, 'fips-and-base.cnf' unless $no_fips;
|
---|
37 |
|
---|
38 | # A list of tests that run with both the default and fips provider.
|
---|
39 | my @files = qw(
|
---|
40 | evpciph_aes_ccm_cavs.txt
|
---|
41 | evpciph_aes_common.txt
|
---|
42 | evpciph_aes_cts.txt
|
---|
43 | evpciph_aes_wrap.txt
|
---|
44 | evpciph_aes_stitched.txt
|
---|
45 | evpciph_des3_common.txt
|
---|
46 | evpkdf_hkdf.txt
|
---|
47 | evpkdf_kbkdf_counter.txt
|
---|
48 | evpkdf_kbkdf_kmac.txt
|
---|
49 | evpkdf_pbkdf1.txt
|
---|
50 | evpkdf_pbkdf2.txt
|
---|
51 | evpkdf_ss.txt
|
---|
52 | evpkdf_ssh.txt
|
---|
53 | evpkdf_tls12_prf.txt
|
---|
54 | evpkdf_tls13_kdf.txt
|
---|
55 | evpkdf_x942.txt
|
---|
56 | evpkdf_x963.txt
|
---|
57 | evpmac_common.txt
|
---|
58 | evpmd_sha.txt
|
---|
59 | evppbe_pbkdf2.txt
|
---|
60 | evppkey_kdf_hkdf.txt
|
---|
61 | evppkey_rsa_common.txt
|
---|
62 | evprand.txt
|
---|
63 | );
|
---|
64 | push @files, qw(
|
---|
65 | evppkey_ffdhe.txt
|
---|
66 | evppkey_dh.txt
|
---|
67 | ) unless $no_dh;
|
---|
68 | push @files, qw(
|
---|
69 | evpkdf_x942_des.txt
|
---|
70 | evpmac_cmac_des.txt
|
---|
71 | ) unless $no_des;
|
---|
72 | push @files, qw(evppkey_dsa.txt) unless $no_dsa;
|
---|
73 | push @files, qw(evppkey_ecx.txt) unless $no_ec;
|
---|
74 | push @files, qw(
|
---|
75 | evppkey_ecc.txt
|
---|
76 | evppkey_ecdh.txt
|
---|
77 | evppkey_ecdsa.txt
|
---|
78 | evppkey_kas.txt
|
---|
79 | evppkey_mismatch.txt
|
---|
80 | ) unless $no_ec;
|
---|
81 |
|
---|
82 | # A list of tests that only run with the default provider
|
---|
83 | # (i.e. The algorithms are not present in the fips provider)
|
---|
84 | my @defltfiles = qw(
|
---|
85 | evpciph_aes_ocb.txt
|
---|
86 | evpciph_aes_siv.txt
|
---|
87 | evpciph_aria.txt
|
---|
88 | evpciph_bf.txt
|
---|
89 | evpciph_camellia.txt
|
---|
90 | evpciph_camellia_cts.txt
|
---|
91 | evpciph_cast5.txt
|
---|
92 | evpciph_chacha.txt
|
---|
93 | evpciph_des.txt
|
---|
94 | evpciph_idea.txt
|
---|
95 | evpciph_rc2.txt
|
---|
96 | evpciph_rc4.txt
|
---|
97 | evpciph_rc4_stitched.txt
|
---|
98 | evpciph_rc5.txt
|
---|
99 | evpciph_seed.txt
|
---|
100 | evpciph_sm4.txt
|
---|
101 | evpencod.txt
|
---|
102 | evpkdf_krb5.txt
|
---|
103 | evpkdf_scrypt.txt
|
---|
104 | evpkdf_tls11_prf.txt
|
---|
105 | evpmac_blake.txt
|
---|
106 | evpmac_poly1305.txt
|
---|
107 | evpmac_siphash.txt
|
---|
108 | evpmac_sm3.txt
|
---|
109 | evpmd_blake.txt
|
---|
110 | evpmd_md.txt
|
---|
111 | evpmd_mdc2.txt
|
---|
112 | evpmd_ripemd.txt
|
---|
113 | evpmd_sm3.txt
|
---|
114 | evpmd_whirlpool.txt
|
---|
115 | evppbe_scrypt.txt
|
---|
116 | evppbe_pkcs12.txt
|
---|
117 | evppkey_kdf_scrypt.txt
|
---|
118 | evppkey_kdf_tls1_prf.txt
|
---|
119 | evppkey_rsa.txt
|
---|
120 | );
|
---|
121 | push @defltfiles, qw(evppkey_brainpool.txt) unless $no_ec;
|
---|
122 | push @defltfiles, qw(evppkey_sm2.txt) unless $no_sm2;
|
---|
123 |
|
---|
124 | plan tests =>
|
---|
125 | + (scalar(@configs) * scalar(@files))
|
---|
126 | + scalar(@defltfiles)
|
---|
127 | + 3; # error output tests
|
---|
128 |
|
---|
129 | foreach (@configs) {
|
---|
130 | my $conf = srctop_file("test", $_);
|
---|
131 |
|
---|
132 | foreach my $f ( @files ) {
|
---|
133 | ok(run(test(["evp_test",
|
---|
134 | "-config", $conf,
|
---|
135 | data_file("$f")])),
|
---|
136 | "running evp_test -config $conf $f");
|
---|
137 | }
|
---|
138 | }
|
---|
139 |
|
---|
140 | my $conf = srctop_file("test", $defaultcnf);
|
---|
141 | foreach my $f ( @defltfiles ) {
|
---|
142 | ok(run(test(["evp_test",
|
---|
143 | "-config", $conf,
|
---|
144 | data_file("$f")])),
|
---|
145 | "running evp_test -config $conf $f");
|
---|
146 | }
|
---|
147 |
|
---|
148 | # test_errors OPTIONS
|
---|
149 | #
|
---|
150 | # OPTIONS may include:
|
---|
151 | #
|
---|
152 | # key => "filename" # expected to be found in $SRCDIR/test/certs
|
---|
153 | # out => "filename" # file to write error strings to
|
---|
154 | # args => [ ... extra openssl pkey args ... ]
|
---|
155 | # expected => regexps to match error lines against
|
---|
156 | sub test_errors { # actually tests diagnostics of OSSL_STORE
|
---|
157 | my %opts = @_;
|
---|
158 | my $infile = srctop_file('test', 'certs', $opts{key});
|
---|
159 | my @args = ( qw(openssl pkey -in), $infile, @{$opts{args} // []} );
|
---|
160 | my $res = !run(app([@args], stderr => $opts{out}));
|
---|
161 | my $found = !exists $opts{expected};
|
---|
162 | open(my $in, '<', $opts{out}) or die "Could not open file $opts{out}";
|
---|
163 | while(my $errline = <$in>) {
|
---|
164 | print $errline; # this may help debugging
|
---|
165 |
|
---|
166 | # output must not include ASN.1 parse errors
|
---|
167 | $res &&= $errline !~ m/asn1 encoding/;
|
---|
168 | # output must include what is expressed in $opts{$expected}
|
---|
169 | $found = 1
|
---|
170 | if exists $opts{expected} && $errline =~ m/$opts{expected}/;
|
---|
171 | }
|
---|
172 | close $in;
|
---|
173 | # $tmpfile is kept to help with investigation in case of failure
|
---|
174 | return $res && $found;
|
---|
175 | }
|
---|
176 |
|
---|
177 | SKIP: {
|
---|
178 | skip "DSA not disabled or ERR disabled", 2
|
---|
179 | if !disabled("dsa") || disabled("err");
|
---|
180 |
|
---|
181 | ok(test_errors(key => 'server-dsa-key.pem',
|
---|
182 | out => 'server-dsa-key.err'),
|
---|
183 | "expected error loading unsupported dsa private key");
|
---|
184 | ok(test_errors(key => 'server-dsa-pubkey.pem',
|
---|
185 | out => 'server-dsa-pubkey.err',
|
---|
186 | args => [ '-pubin' ],
|
---|
187 | expected => 'unsupported'),
|
---|
188 | "expected error loading unsupported dsa public key");
|
---|
189 | }
|
---|
190 |
|
---|
191 | SKIP: {
|
---|
192 | skip "SM2 not disabled", 1 if !disabled("sm2");
|
---|
193 |
|
---|
194 | ok(test_errors(key => 'sm2.key', out => 'sm2.err'),
|
---|
195 | "expected error loading unsupported sm2 private key");
|
---|
196 | }
|
---|