VirtualBox

source: vbox/trunk/src/libs/openssl-3.1.7/test/recipes/80-test_ssl_new.t@ 107935

Last change on this file since 107935 was 104078, checked in by vboxsync, 11 months ago

openssl-3.1.5: Applied and adjusted our OpenSSL changes to 3.1.4. bugref:10638

File size: 7.7 KB
Line 
1#! /usr/bin/env perl
2# Copyright 2015-2022 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# For manually running these tests, set specific environment variables like this:
10# CTLOG_FILE=test/ct/log_list.cnf
11# TEST_CERTS_DIR=test/certs
12# For details on the environment variables needed, see test/README.ssltest.md
13
14use strict;
15use warnings;
16
17use File::Basename;
18use File::Compare qw/compare_text/;
19use OpenSSL::Glob;
20use OpenSSL::Test qw/:DEFAULT srctop_dir srctop_file bldtop_file bldtop_dir/;
21use OpenSSL::Test::Utils qw/disabled alldisabled available_protocols/;
22
23BEGIN {
24setup("test_ssl_new");
25}
26
27use lib srctop_dir('Configurations');
28use lib bldtop_dir('.');
29
30my $no_fips = disabled('fips') || ($ENV{NO_FIPS} // 0);
31
32$ENV{TEST_CERTS_DIR} = srctop_dir("test", "certs");
33
34my @conf_srcs = ();
35if (defined $ENV{SSL_TESTS}) {
36 my @conf_list = split(' ', $ENV{SSL_TESTS});
37 foreach my $conf_file (@conf_list) {
38 push (@conf_srcs, glob(srctop_file("test", "ssl-tests", $conf_file)));
39 }
40 plan tests => scalar @conf_srcs;
41} else {
42 @conf_srcs = glob(srctop_file("test", "ssl-tests", "*.cnf.in"));
43 # We hard-code the number of tests to double-check that the globbing above
44 # finds all files as expected.
45 plan tests => 30;
46}
47map { s/;.*// } @conf_srcs if $^O eq "VMS";
48my @conf_files = map { basename($_, ".in") } @conf_srcs;
49map { s/\^// } @conf_files if $^O eq "VMS";
50
51# Some test results depend on the configuration of enabled protocols. We only
52# verify generated sources in the default configuration.
53my $is_default_tls = (disabled("ssl3") && !disabled("tls1") &&
54 !disabled("tls1_1") && !disabled("tls1_2") &&
55 !disabled("tls1_3") && (!disabled("ec") || !disabled("dh")));
56
57my $is_default_dtls = (!disabled("dtls1") && !disabled("dtls1_2"));
58
59my @all_pre_tls1_3 = ("ssl3", "tls1", "tls1_1", "tls1_2");
60my $no_tls = alldisabled(available_protocols("tls"));
61my $no_tls_below1_3 = $no_tls || (disabled("tls1_2") && !disabled("tls1_3"));
62if (!$no_tls && $no_tls_below1_3 && disabled("ec") && disabled("dh")) {
63 $no_tls = 1;
64}
65my $no_pre_tls1_3 = alldisabled(@all_pre_tls1_3);
66my $no_dtls = alldisabled(available_protocols("dtls"));
67my $no_npn = disabled("nextprotoneg");
68my $no_ct = disabled("ct");
69my $no_ec = disabled("ec");
70my $no_dh = disabled("dh");
71my $no_dsa = disabled("dsa");
72my $no_ec2m = disabled("ec2m");
73my $no_ocsp = disabled("ocsp");
74
75# Add your test here if the test conf.in generates test cases and/or
76# expectations dynamically based on the OpenSSL compile-time config.
77my %conf_dependent_tests = (
78 "02-protocol-version.cnf" => !$is_default_tls,
79 "04-client_auth.cnf" => !$is_default_tls || !$is_default_dtls
80 || !disabled("sctp"),
81 "05-sni.cnf" => disabled("tls1_1"),
82 "07-dtls-protocol-version.cnf" => !$is_default_dtls || !disabled("sctp"),
83 "10-resumption.cnf" => !$is_default_tls || $no_ec,
84 "11-dtls_resumption.cnf" => !$is_default_dtls || !disabled("sctp"),
85 "16-dtls-certstatus.cnf" => !$is_default_dtls || !disabled("sctp"),
86 "17-renegotiate.cnf" => disabled("tls1_2"),
87 "18-dtls-renegotiate.cnf" => disabled("dtls1_2") || !disabled("sctp"),
88 "19-mac-then-encrypt.cnf" => !$is_default_tls,
89 "20-cert-select.cnf" => !$is_default_tls || $no_dh || $no_dsa,
90 "22-compression.cnf" => !$is_default_tls,
91 "25-cipher.cnf" => disabled("poly1305") || disabled("chacha"),
92 "27-ticket-appdata.cnf" => !$is_default_tls,
93 "28-seclevel.cnf" => disabled("tls1_2") || $no_ec,
94 "30-extended-master-secret.cnf" => disabled("tls1_2"),
95);
96
97# Add your test here if it should be skipped for some compile-time
98# configurations. Default is $no_tls but some tests have different skip
99# conditions.
100my %skip = (
101 "06-sni-ticket.cnf" => $no_tls_below1_3,
102 "07-dtls-protocol-version.cnf" => $no_dtls,
103 "08-npn.cnf" => (disabled("tls1") && disabled("tls1_1")
104 && disabled("tls1_2")) || $no_npn,
105 "10-resumption.cnf" => disabled("tls1_1") || disabled("tls1_2"),
106 "11-dtls_resumption.cnf" => disabled("dtls1") || disabled("dtls1_2"),
107 "12-ct.cnf" => $no_tls || $no_ct || $no_ec,
108 # We could run some of these tests without TLS 1.2 if we had a per-test
109 # disable instruction but that's a bizarre configuration not worth
110 # special-casing for.
111 # TODO(TLS 1.3): We should review this once we have TLS 1.3.
112 "13-fragmentation.cnf" => disabled("tls1_2"),
113 "14-curves.cnf" => disabled("tls1_2") || disabled("tls1_3")
114 || $no_ec || $no_ec2m,
115 "15-certstatus.cnf" => $no_tls || $no_ocsp,
116 "16-dtls-certstatus.cnf" => $no_dtls || $no_ocsp,
117 "17-renegotiate.cnf" => $no_tls_below1_3,
118 "18-dtls-renegotiate.cnf" => $no_dtls,
119 "19-mac-then-encrypt.cnf" => $no_pre_tls1_3,
120 "20-cert-select.cnf" => disabled("tls1_2") || $no_ec,
121 "21-key-update.cnf" => disabled("tls1_3") || ($no_ec && $no_dh),
122 "22-compression.cnf" => disabled("zlib") || $no_tls,
123 "23-srp.cnf" => (disabled("tls1") && disabled ("tls1_1")
124 && disabled("tls1_2")) || disabled("srp"),
125 "24-padding.cnf" => disabled("tls1_3") || ($no_ec && $no_dh),
126 "25-cipher.cnf" => disabled("ec") || disabled("tls1_2"),
127 "26-tls13_client_auth.cnf" => disabled("tls1_3") || ($no_ec && $no_dh),
128 "29-dtls-sctp-label-bug.cnf" => disabled("sctp") || disabled("sock"),
129);
130
131foreach my $conf (@conf_files) {
132 subtest "Test configuration $conf" => sub {
133 plan tests => 6 + ($no_fips ? 0 : 3);
134 test_conf($conf,
135 $conf_dependent_tests{$conf} || $^O eq "VMS" ? 0 : 1,
136 defined($skip{$conf}) ? $skip{$conf} : $no_tls,
137 "none");
138 test_conf($conf,
139 0,
140 defined($skip{$conf}) ? $skip{$conf} : $no_tls,
141 "default");
142 test_conf($conf,
143 0,
144 defined($skip{$conf}) ? $skip{$conf} : $no_tls,
145 "fips") unless $no_fips;
146 }
147}
148
149sub test_conf {
150 my ($conf, $check_source, $skip, $provider) = @_;
151
152 my $conf_file = srctop_file("test", "ssl-tests", $conf);
153 my $input_file = $conf_file . ".in";
154 my $output_file = $conf . "." . $provider;
155 my $run_test = 1;
156
157 SKIP: {
158 # "Test" 1. Generate the source.
159 skip 'failure', 2 unless
160 ok(run(perltest(["generate_ssl_tests.pl", $input_file, $provider],
161 interpreter_args => [ "-I", srctop_dir("util", "perl")],
162 stdout => $output_file)),
163 "Getting output from generate_ssl_tests.pl.");
164
165 SKIP: {
166 # Test 2. Compare against existing output in test/ssl-tests/
167 skip "Skipping generated source test for $conf", 1
168 if !$check_source;
169
170 $run_test = is(cmp_text($output_file, $conf_file), 0,
171 "Comparing generated $output_file with $conf_file.");
172 }
173
174 # Test 3. Run the test.
175 skip "No tests available; skipping tests", 1 if $skip;
176 skip "Stale sources; skipping tests", 1 if !$run_test;
177
178 my $msg = "running CTLOG_FILE=test/ct/log_list.cnf". # $ENV{CTLOG_FILE}.
179 " TEST_CERTS_DIR=test/certs". # $ENV{TEST_CERTS_DIR}.
180 " test/ssl_test test/ssl-tests/$conf $provider";
181 if ($provider eq "fips") {
182 ok(run(test(["ssl_test", $output_file, $provider,
183 srctop_file("test", "fips-and-base.cnf")])), $msg);
184 } else {
185 ok(run(test(["ssl_test", $output_file, $provider])), $msg);
186 }
187 }
188}
189
190sub cmp_text {
191 return compare_text(@_, sub {
192 $_[0] =~ s/\R//g;
193 $_[1] =~ s/\R//g;
194 return $_[0] ne $_[1];
195 });
196}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette