]>
git.ipfire.org Git - thirdparty/openssl.git/blob - test/recipes/70-test_tls13psk.t
2 # Copyright 2017-2023 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
10 use OpenSSL
::Test qw
/:DEFAULT cmdstr srctop_file srctop_dir bldtop_dir/;
11 use OpenSSL
::Test
::Utils
;
12 use File
::Temp
qw(tempfile);
15 my $test_name = "test_tls13psk";
18 plan skip_all
=> "TLSProxy isn't usable on $^O"
21 plan skip_all
=> "$test_name needs the dynamic engine feature enabled"
22 if disabled
("engine") || disabled
("dynamic-engine");
24 plan skip_all
=> "$test_name needs the sock feature enabled"
27 plan skip_all
=> "$test_name needs TLSv1.3 enabled"
28 if disabled
("tls1_3") || (disabled
("ec") && disabled
("dh"));
30 my $proxy = TLSProxy
::Proxy
->new(
32 cmdstr
(app
(["openssl"]), display
=> 1),
33 srctop_file
("apps", "server.pem"),
34 (!$ENV{HARNESS_ACTIVE
} || $ENV{HARNESS_VERBOSE
})
38 PSK_LAST_FIRST_CH
=> 0,
39 ILLEGAL_EXT_SECOND_CH
=> 1
42 #Most PSK tests are done in test_ssl_new. This tests various failure scenarios
45 #Test 1: First get a session
46 (undef, my $session) = tempfile
();
47 $proxy->clientflags("-sess_out ".$session);
48 $proxy->serverflags("-servername localhost");
49 $proxy->sessionfile($session);
50 $proxy->start() or plan skip_all
=> "Unable to start up Proxy for tests";
52 ok
(TLSProxy
::Message
->success(), "Initial connection");
54 #Test 2: Attempt a resume with PSK not in last place. Should fail
56 $proxy->clientflags("-sess_in ".$session);
57 $proxy->filter(\
&modify_psk_filter
);
58 my $testtype = PSK_LAST_FIRST_CH
;
60 ok
(TLSProxy
::Message
->fail(), "PSK not last");
62 #Test 3: Attempt a resume after an HRR where PSK hash matches selected
63 # ciphersuite. Should see PSK on second ClientHello
65 $proxy->clientflags("-sess_in ".$session);
67 $proxy->serverflags("-curves ffdhe3072");
69 $proxy->serverflags("-curves P-384");
71 $proxy->filter(undef);
73 #Check if the PSK is present in the second ClientHello
74 my $ch2 = ${$proxy->message_list}[2];
75 my $ch2seen = defined $ch2 && $ch2->mt() == TLSProxy
::Message
::MT_CLIENT_HELLO
;
76 my $pskseen = $ch2seen
77 && defined ${$ch2->{extension_data
}}{TLSProxy
::Message
::EXT_PSK
};
78 ok
($pskseen, "PSK hash matches");
80 #Test 4: Attempt a resume after an HRR where PSK hash does not match selected
81 # ciphersuite. Should not see PSK on second ClientHello
83 $proxy->clientflags("-sess_in ".$session);
84 $proxy->filter(\
&modify_psk_filter
);
86 $proxy->serverflags("-curves ffdhe3072");
88 $proxy->serverflags("-curves P-384");
90 $proxy->ciphersuitesc("TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384");
91 $proxy->ciphersuitess("TLS_AES_256_GCM_SHA384");
92 #We force an early failure because TLS Proxy doesn't actually support
93 #TLS_AES_256_GCM_SHA384. That doesn't matter for this test though.
94 $testtype = ILLEGAL_EXT_SECOND_CH
;
96 #Check if the PSK is present in the second ClientHello
97 $ch2 = ${$proxy->message_list}[2];
98 $ch2seen = defined $ch2 && $ch2->mt() == TLSProxy
::Message
::MT_CLIENT_HELLO
;
100 && defined ${$ch2->extension_data}{TLSProxy
::Message
::EXT_PSK
};
101 ok
($ch2seen && !$pskseen, "PSK hash does not match");
103 #Test 5: Attempt a resume without a sig agls extension. Should succeed because
104 # sig algs is not needed in a resumption.
106 $proxy->clientflags("-sess_in ".$session);
107 $proxy->filter(\
&remove_sig_algs_filter
);
109 ok
(TLSProxy
::Message
->success(), "Remove sig algs");
113 sub modify_psk_filter
119 if ($testtype == PSK_LAST_FIRST_CH
) {
125 # Only look at the first or second ClientHello
126 return if $proxy->flight != $flight;
128 if ($testtype == PSK_LAST_FIRST_CH
) {
129 $message = ${$proxy->message_list}[0];
131 $message = ${$proxy->message_list}[2];
134 return if (!defined $message
135 || $message->mt != TLSProxy
::Message
::MT_CLIENT_HELLO
);
137 if ($testtype == PSK_LAST_FIRST_CH
) {
138 $message->set_extension(TLSProxy
::Message
::EXT_FORCE_LAST
, "");
140 #Deliberately break the connection
141 $message->set_extension(TLSProxy
::Message
::EXT_SUPPORTED_GROUPS
, "");
146 sub remove_sig_algs_filter
151 # Only look at the first ClientHello
152 return if $proxy->flight != 0;
154 $message = ${$proxy->message_list}[0];
155 $message->delete_extension(TLSProxy
::Message
::EXT_SIG_ALGS
);