]> git.ipfire.org Git - thirdparty/openssl.git/blame - test/recipes/80-test_ssl_new.t
Teach ssl_test_new how to test the FIPS module
[thirdparty/openssl.git] / test / recipes / 80-test_ssl_new.t
CommitLineData
596d6b7e 1#! /usr/bin/env perl
6738bf14 2# Copyright 2015-2018 The OpenSSL Project Authors. All Rights Reserved.
596d6b7e 3#
909f1a2e 4# Licensed under the Apache License 2.0 (the "License"). You may not use
596d6b7e
RS
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
453dfd8d
EK
9
10use strict;
11use warnings;
12
13use File::Basename;
14use File::Compare qw/compare_text/;
8d2214c0 15use OpenSSL::Glob;
682bc861 16use OpenSSL::Test qw/:DEFAULT srctop_dir srctop_file bldtop_file bldtop_dir/;
453dfd8d
EK
17use OpenSSL::Test::Utils qw/disabled alldisabled available_protocols/;
18
682bc861 19BEGIN {
453dfd8d 20setup("test_ssl_new");
682bc861
MC
21}
22
23use lib srctop_dir('Configurations');
24use lib bldtop_dir('.');
25use platform;
26
27my $no_fips = disabled('fips') || ($ENV{NO_FIPS} // 0);
453dfd8d 28
682bc861
MC
29$ENV{OPENSSL_MODULES} = bldtop_dir("providers");
30$ENV{OPENSSL_CONF_INCLUDE} = bldtop_dir("providers");
453dfd8d 31$ENV{TEST_CERTS_DIR} = srctop_dir("test", "certs");
433deaff 32$ENV{CTLOG_FILE} = srctop_file("test", "ct", "log_list.cnf");
453dfd8d 33
433deaff 34my @conf_srcs = glob(srctop_file("test", "ssl-tests", "*.cnf.in"));
1563102b 35map { s/;.*// } @conf_srcs if $^O eq "VMS";
d89f6641
RL
36my @conf_files = map { basename($_, ".in") } @conf_srcs;
37map { s/\^// } @conf_files if $^O eq "VMS";
453dfd8d 38
f4947bf1
RL
39# We hard-code the number of tests to double-check that the globbing above
40# finds all files as expected.
682bc861
MC
41plan tests => 30 # = scalar @conf_srcs
42 + ($no_fips ? 0 : 1); # fipsinstall
f4947bf1 43
3e82ae57
MC
44# Some test results depend on the configuration of enabled protocols. We only
45# verify generated sources in the default configuration.
74726750 46my $is_default_tls = (disabled("ssl3") && !disabled("tls1") &&
84a68336 47 !disabled("tls1_1") && !disabled("tls1_2") &&
f518cef4 48 !disabled("tls1_3"));
453dfd8d 49
74726750
EK
50my $is_default_dtls = (!disabled("dtls1") && !disabled("dtls1_2"));
51
54d028aa 52my @all_pre_tls1_3 = ("ssl3", "tls1", "tls1_1", "tls1_2");
74726750 53my $no_tls = alldisabled(available_protocols("tls"));
c423ecaa 54my $no_tls_below1_3 = $no_tls || (disabled("tls1_2") && !disabled("tls1_3"));
54d028aa 55my $no_pre_tls1_3 = alldisabled(@all_pre_tls1_3);
74726750 56my $no_dtls = alldisabled(available_protocols("dtls"));
ce2cdac2 57my $no_npn = disabled("nextprotoneg");
da085d27 58my $no_ct = disabled("ct");
be82f7b3 59my $no_ec = disabled("ec");
7c98706e
RL
60my $no_dh = disabled("dh");
61my $no_dsa = disabled("dsa");
0a307450 62my $no_ec2m = disabled("ec2m");
057c676a 63my $no_ocsp = disabled("ocsp");
74726750 64
15269e56
EK
65# Add your test here if the test conf.in generates test cases and/or
66# expectations dynamically based on the OpenSSL compile-time config.
74726750 67my %conf_dependent_tests = (
433deaff
RS
68 "02-protocol-version.cnf" => !$is_default_tls,
69 "04-client_auth.cnf" => !$is_default_tls || !$is_default_dtls
0f5df0f1 70 || !disabled("sctp"),
433deaff
RS
71 "05-sni.cnf" => disabled("tls1_1"),
72 "07-dtls-protocol-version.cnf" => !$is_default_dtls || !disabled("sctp"),
73 "10-resumption.cnf" => !$is_default_tls || $no_ec,
74 "11-dtls_resumption.cnf" => !$is_default_dtls || !disabled("sctp"),
75 "16-dtls-certstatus.cnf" => !$is_default_dtls || !disabled("sctp"),
76 "17-renegotiate.cnf" => disabled("tls1_2"),
77 "18-dtls-renegotiate.cnf" => disabled("dtls1_2") || !disabled("sctp"),
78 "19-mac-then-encrypt.cnf" => !$is_default_tls,
79 "20-cert-select.cnf" => !$is_default_tls || $no_dh || $no_dsa,
80 "22-compression.cnf" => !$is_default_tls,
81 "25-cipher.cnf" => disabled("poly1305") || disabled("chacha"),
82 "27-ticket-appdata.cnf" => !$is_default_tls,
83 "28-seclevel.cnf" => disabled("tls1_2") || $no_ec,
84 "30-extended-master-secret.cnf" => disabled("tls1_2"),
74726750
EK
85);
86
15269e56
EK
87# Add your test here if it should be skipped for some compile-time
88# configurations. Default is $no_tls but some tests have different skip
89# conditions.
74726750 90my %skip = (
433deaff
RS
91 "06-sni-ticket.cnf" => $no_tls_below1_3,
92 "07-dtls-protocol-version.cnf" => $no_dtls,
93 "08-npn.cnf" => (disabled("tls1") && disabled("tls1_1")
0f1e51ea 94 && disabled("tls1_2")) || $no_npn,
433deaff
RS
95 "10-resumption.cnf" => disabled("tls1_1") || disabled("tls1_2"),
96 "11-dtls_resumption.cnf" => disabled("dtls1") || disabled("dtls1_2"),
97 "12-ct.cnf" => $no_tls || $no_ct || $no_ec,
6dc99745
EK
98 # We could run some of these tests without TLS 1.2 if we had a per-test
99 # disable instruction but that's a bizarre configuration not worth
100 # special-casing for.
cf72c757 101 # TODO(TLS 1.3): We should review this once we have TLS 1.3.
433deaff
RS
102 "13-fragmentation.cnf" => disabled("tls1_2"),
103 "14-curves.cnf" => disabled("tls1_2") || $no_ec || $no_ec2m,
104 "15-certstatus.cnf" => $no_tls || $no_ocsp,
105 "16-dtls-certstatus.cnf" => $no_dtls || $no_ocsp,
106 "17-renegotiate.cnf" => $no_tls_below1_3,
107 "18-dtls-renegotiate.cnf" => $no_dtls,
108 "19-mac-then-encrypt.cnf" => $no_pre_tls1_3,
109 "20-cert-select.cnf" => disabled("tls1_2") || $no_ec,
110 "21-key-update.cnf" => disabled("tls1_3"),
111 "22-compression.cnf" => disabled("zlib") || $no_tls,
112 "23-srp.cnf" => (disabled("tls1") && disabled ("tls1_1")
ea1ecd98 113 && disabled("tls1_2")) || disabled("srp"),
433deaff
RS
114 "24-padding.cnf" => disabled("tls1_3"),
115 "25-cipher.cnf" => disabled("ec") || disabled("tls1_2"),
116 "26-tls13_client_auth.cnf" => disabled("tls1_3"),
117 "29-dtls-sctp-label-bug.cnf" => disabled("sctp") || disabled("sock"),
74726750 118);
453dfd8d 119
682bc861
MC
120unless ($no_fips) {
121 ok(run(app(['openssl', 'fipsinstall',
122 '-out', bldtop_file('providers', 'fipsinstall.cnf'),
123 '-module', bldtop_file('providers', platform->dso('fips')),
124 '-provider_name', 'fips', '-mac_name', 'HMAC',
125 '-macopt', 'digest:SHA256', '-macopt', 'hexkey:00',
126 '-section_name', 'fips_sect'])),
127 "fipsinstall");
128}
129
453dfd8d
EK
130foreach my $conf (@conf_files) {
131 subtest "Test configuration $conf" => sub {
682bc861 132 plan tests => 6 + ($no_fips ? 0 : 3);
578a0004 133 test_conf($conf,
74726750 134 $conf_dependent_tests{$conf} || $^O eq "VMS" ? 0 : 1,
ab5a02f7
MC
135 defined($skip{$conf}) ? $skip{$conf} : $no_tls,
136 "none");
137 test_conf($conf,
138 0,
139 defined($skip{$conf}) ? $skip{$conf} : $no_tls,
140 "default");
682bc861
MC
141 test_conf($conf,
142 0,
143 defined($skip{$conf}) ? $skip{$conf} : $no_tls,
144 "fips") unless $no_fips;
453dfd8d
EK
145 }
146}
147
453dfd8d 148sub test_conf {
ab5a02f7 149 my ($conf, $check_source, $skip, $provider) = @_;
453dfd8d
EK
150
151 my $conf_file = srctop_file("test", "ssl-tests", $conf);
a3f3ed65 152 my $input_file = $conf_file . ".in";
ab5a02f7 153 my $output_file = $conf . "." . $provider;
453dfd8d
EK
154 my $run_test = 1;
155
156 SKIP: {
157 # "Test" 1. Generate the source.
453dfd8d 158 skip 'failure', 2 unless
ab5a02f7 159 ok(run(perltest(["generate_ssl_tests.pl", $input_file, $provider],
cb6afcd6 160 interpreter_args => [ "-I", srctop_dir("util", "perl")],
a3f3ed65 161 stdout => $output_file)),
453dfd8d
EK
162 "Getting output from generate_ssl_tests.pl.");
163
164 SKIP: {
433deaff 165 # Test 2. Compare against existing output in test/ssl_tests.cnf.
453dfd8d
EK
166 skip "Skipping generated source test for $conf", 1
167 if !$check_source;
168
a3f3ed65 169 $run_test = is(cmp_text($output_file, $conf_file), 0,
453dfd8d
EK
170 "Comparing generated sources.");
171 }
172
173 # Test 3. Run the test.
74726750 174 skip "No tests available; skipping tests", 1 if $skip;
453dfd8d
EK
175 skip "Stale sources; skipping tests", 1 if !$run_test;
176
682bc861
MC
177 if ($provider eq "fips") {
178 ok(run(test(["ssl_test", $output_file, $provider,
179 srctop_file("test", "fips.cnf")])),
180 "running ssl_test $conf");
181 } else {
182 ok(run(test(["ssl_test", $output_file, $provider])),
183 "running ssl_test $conf");
184 }
453dfd8d 185 }
453dfd8d
EK
186}
187
188sub cmp_text {
189 return compare_text(@_, sub {
190 $_[0] =~ s/\R//g;
191 $_[1] =~ s/\R//g;
192 return $_[0] ne $_[1];
193 });
194}