]> git.ipfire.org Git - thirdparty/openssl.git/blob - test/ssl-tests/02-protocol-version.conf.in
New SSL test framework
[thirdparty/openssl.git] / test / ssl-tests / 02-protocol-version.conf.in
1 # -*- mode: perl; -*-
2
3 ## Test version negotiation
4
5 package ssltests;
6
7 use List::Util qw/max min/;
8
9 use OpenSSL::Test;
10 use OpenSSL::Test::Utils qw/anydisabled alldisabled/;
11 setup("no_test_here");
12
13 my @protocols = ("SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2");
14 # undef stands for "no limit".
15 my @min_protocols = (undef, "SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2");
16 my @max_protocols = ("SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2", undef);
17
18 my @is_disabled = anydisabled("ssl3", "tls1", "tls1_1", "tls1_2");
19
20 my $min_enabled; my $max_enabled;
21
22 # Protocol configuration works in cascades, i.e.,
23 # $no_tls1_1 disables TLSv1.1 and below.
24 #
25 # $min_enabled and $max_enabled will be correct if there is at least one
26 # protocol enabled.
27 foreach my $i (0..$#protocols) {
28 if (!$is_disabled[$i]) {
29 $min_enabled = $i;
30 last;
31 }
32 }
33
34 foreach my $i (0..$#protocols) {
35 if (!$is_disabled[$i]) {
36 $max_enabled = $i;
37 }
38 }
39
40 our @tests = ();
41
42 sub generate_tests() {
43 foreach my $c_min (0..$#min_protocols) {
44 my $c_max_min = $c_min == 0 ? 0 : $c_min - 1;
45 foreach my $c_max ($c_max_min..$#max_protocols) {
46 foreach my $s_min (0..$#min_protocols) {
47 my $s_max_min = $s_min == 0 ? 0 : $s_min - 1;
48 foreach my $s_max ($s_max_min..$#max_protocols) {
49 my ($result, $protocol) =
50 expected_result($c_min, $c_max, $s_min, $s_max);
51 push @tests, {
52 "name" => "version-negotiation",
53 "client" => {
54 "MinProtocol" => $min_protocols[$c_min],
55 "MaxProtocol" => $max_protocols[$c_max],
56 },
57 "server" => {
58 "MinProtocol" => $min_protocols[$s_min],
59 "MaxProtocol" => $max_protocols[$s_max],
60 },
61 "test" => {
62 "ExpectedResult" => $result,
63 "Protocol" => $protocol
64 }
65 };
66 }
67 }
68 }
69 }
70 }
71
72 sub expected_result {
73 my $no_tls = alldisabled("ssl3", "tls1", "tls1_1", "tls1_2");
74 if ($no_tls) {
75 return ("InternalError", undef);
76 }
77
78 my ($c_min, $c_max, $s_min, $s_max) = @_;
79
80 # Adjust for "undef" (no limit).
81 $c_min = $c_min == 0 ? 0 : $c_min - 1;
82 $c_max = $c_max == scalar(@max_protocols) - 1 ? $c_max - 1 : $c_max;
83 $s_min = $s_min == 0 ? 0 : $s_min - 1;
84 $s_max = $s_max == scalar(@max_protocols) - 1 ? $s_max - 1 : $s_max;
85
86 # We now have at least one protocol enabled, so $min_enabled and
87 # $max_enabled are well-defined.
88 $c_min = max $c_min, $min_enabled;
89 $s_min = max $s_min, $min_enabled;
90 $c_max = min $c_max, $max_enabled;
91 $s_max = min $s_max, $max_enabled;
92
93 if ($c_min > $c_max) {
94 # Client should fail to even send a hello.
95 # This results in an internal error since the server will be
96 # waiting for input that never arrives.
97 return ("InternalError", undef);
98 } elsif ($s_min > $s_max) {
99 # Server has no protocols, should always fail.
100 return ("ServerFail", undef);
101 } elsif ($s_min > $c_max) {
102 # Server doesn't support the client range.
103 return ("ServerFail", undef);
104 } elsif ($c_min > $s_max) {
105 # Server will try with a version that is lower than the lowest
106 # supported client version.
107 return ("ClientFail", undef);
108 } else {
109 # Server and client ranges overlap.
110 my $max_common = $s_max < $c_max ? $s_max : $c_max;
111 return ("Success", $protocols[$max_common]);
112 }
113 }
114
115 generate_tests();