2 # Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
4 # Licensed under the OpenSSL license (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 bldtop_dir/;
11 use OpenSSL::Test::Utils;
12 use File::Temp qw(tempfile);
14 my $test_name = "test_tls13messages";
17 plan skip_all => "TLSProxy isn't usable on $^O"
18 if $^O =~ /^(VMS|MSWin32)$/;
20 plan skip_all => "$test_name needs the dynamic engine feature enabled"
21 if disabled("engine") || disabled("dynamic-engine");
23 plan skip_all => "$test_name needs the sock feature enabled"
26 plan skip_all => "$test_name needs TLS enabled"
27 if alldisabled(available_protocols("tls"));
29 $ENV{OPENSSL_ia32cap} = '~0x200000200000000';
32 DEFAULT_HANDSHAKE => 1,
34 RESUME_HANDSHAKE => 4,
35 CLIENT_AUTH_HANDSHAKE => 8,
36 RENEG_HANDSHAKE => 16,
42 [TLSProxy::Message::MT_CLIENT_HELLO, ALL_HANDSHAKES],
43 [TLSProxy::Message::MT_SERVER_HELLO, ALL_HANDSHAKES],
44 [TLSProxy::Message::MT_CERTIFICATE, ALL_HANDSHAKES & ~RESUME_HANDSHAKE],
45 [TLSProxy::Message::MT_CERTIFICATE_STATUS, OCSP_HANDSHAKE],
46 #ServerKeyExchange handshakes not currently supported by TLSProxy
47 [TLSProxy::Message::MT_CERTIFICATE_REQUEST, CLIENT_AUTH_HANDSHAKE],
48 [TLSProxy::Message::MT_SERVER_HELLO_DONE, ALL_HANDSHAKES & ~RESUME_HANDSHAKE],
49 [TLSProxy::Message::MT_CERTIFICATE, CLIENT_AUTH_HANDSHAKE],
50 [TLSProxy::Message::MT_CLIENT_KEY_EXCHANGE, ALL_HANDSHAKES & ~RESUME_HANDSHAKE],
51 [TLSProxy::Message::MT_CERTIFICATE_VERIFY, CLIENT_AUTH_HANDSHAKE],
52 [TLSProxy::Message::MT_FINISHED, ALL_HANDSHAKES],
53 [TLSProxy::Message::MT_NEW_SESSION_TICKET, ALL_HANDSHAKES & ~RESUME_HANDSHAKE],
54 [TLSProxy::Message::MT_FINISHED, ALL_HANDSHAKES],
55 [TLSProxy::Message::MT_CLIENT_HELLO, RENEG_HANDSHAKE],
56 [TLSProxy::Message::MT_SERVER_HELLO, RENEG_HANDSHAKE],
57 [TLSProxy::Message::MT_CERTIFICATE, RENEG_HANDSHAKE],
58 [TLSProxy::Message::MT_SERVER_HELLO_DONE, RENEG_HANDSHAKE],
59 [TLSProxy::Message::MT_CLIENT_KEY_EXCHANGE, RENEG_HANDSHAKE],
60 [TLSProxy::Message::MT_FINISHED, RENEG_HANDSHAKE],
61 [TLSProxy::Message::MT_NEW_SESSION_TICKET, RENEG_HANDSHAKE],
62 [TLSProxy::Message::MT_FINISHED, RENEG_HANDSHAKE],
66 my $proxy = TLSProxy::Proxy->new(
68 cmdstr(app(["openssl"]), display => 1),
69 srctop_file("apps", "server.pem"),
70 (!$ENV{HARNESS_ACTIVE} || $ENV{HARNESS_VERBOSE})
73 sub checkmessages($$);
75 #Test 1: Check we get all the right messages for a default handshake
76 (undef, my $session) = tempfile();
77 $proxy->serverconnects(2);
78 $proxy->clientflags("-no_tls1_3 -sess_out ".$session);
79 $proxy->start() or plan skip_all => "Unable to start up Proxy for tests";
81 checkmessages(DEFAULT_HANDSHAKE, "Default handshake test");
83 #Test 2: Resumption handshake
84 $proxy->clearClient();
85 $proxy->clientflags("-no_tls1_3 -sess_in ".$session);
86 $proxy->clientstart();
87 checkmessages(RESUME_HANDSHAKE, "Resumption handshake test");
90 #Test 3: A default handshake, but with a CertificateStatus message
92 #TODO: PR #1932 adds the "-status_file" option below. Once added we can enable
96 #$proxy->clientflags("-no_tls1_3 -status");
97 #$proxy->serverflags("-no_ticket -status_file "
98 # .srctop_file("test", "recipes", "ocsp-response.der"));
100 #checkmessages(OCSP_HANDSHAKE, "OCSP handshake test");
102 #Test 4: A client auth handshake
104 $proxy->clientflags("-no_tls1_3 -cert ".srctop_file("apps", "server.pem"));
105 $proxy->serverflags("-Verify 5");
107 checkmessages(CLIENT_AUTH_HANDSHAKE, "Client auth handshake test");
109 #Test 5: A handshake with a renegotiation
111 $proxy->clientflags("-no_tls1_3");
114 checkmessages(RENEG_HANDSHAKE, "Rengotiation handshake test");
116 #Test 6: A handshake with a renegotiation and client auth
118 $proxy->clientflags("-no_tls1_3 -cert ".srctop_file("apps", "server.pem"));
119 $proxy->serverflags("-Verify 5");
122 checkmessages(RENEG_HANDSHAKE | CLIENT_AUTH_HANDSHAKE,
123 "Renogitation and client auth handshake test");
125 sub checkmessages($$)
127 my ($handtype, $testname) = @_;
129 subtest $testname => sub {
133 #First count the number of tests
134 for ($numtests = 0; $handmessages[$loop][1] != 0; $loop++) {
135 $numtests++ if (($handmessages[$loop][1] & $handtype) != 0);
138 plan tests => $numtests;
142 for ($loop = 0; $handmessages[$loop][1] != 0; $loop++) {
143 next if (($handmessages[$loop][1] & $handtype) == 0);
144 if (scalar @{$proxy->message_list} > $nextmess) {
145 $message = ${$proxy->message_list}[$nextmess];
150 if (!defined $message) {
151 fail("Message type check. Got nothing, expected "
152 .$handmessages[$loop][0]);
154 ok($message->mt == $handmessages[$loop][0],
155 "Message type check. Got ".$message->mt
156 .", expected ".$handmessages[$loop][0]);