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
9 package recipes::checkhandshake;
11 use OpenSSL::Test qw/:DEFAULT cmdstr srctop_file srctop_dir bldtop_dir/;
12 use OpenSSL::Test::Utils;
16 our @ISA = 'Exporter';
17 our @EXPORT = qw(@handmessages @extensions checkhandshake);
20 DEFAULT_HANDSHAKE => 1,
22 RESUME_HANDSHAKE => 4,
23 CLIENT_AUTH_HANDSHAKE => 8,
24 RENEG_HANDSHAKE => 16,
30 #DEFAULT ALSO INCLUDES SESSION_TICKET_SRV_EXTENSION
31 DEFAULT_EXTENSIONS => 0x00000003,
32 SESSION_TICKET_SRV_EXTENSION => 0x00000002,
33 SERVER_NAME_CLI_EXTENSION => 0x00000004,
34 SERVER_NAME_SRV_EXTENSION => 0x00000008,
35 STATUS_REQUEST_CLI_EXTENSION => 0x00000010,
36 STATUS_REQUEST_SRV_EXTENSION => 0x00000020,
37 ALPN_CLI_EXTENSION => 0x00000040,
38 ALPN_SRV_EXTENSION => 0x00000080,
39 SCT_CLI_EXTENSION => 0x00000100,
40 RENEGOTIATE_CLI_EXTENSION => 0x00000200
43 our @handmessages = ();
46 sub checkhandshake($$$$)
48 my ($proxy, $handtype, $exttype, $testname) = @_;
50 subtest $testname => sub {
54 my $clienthelloseen = 0;
56 #First count the number of tests
57 for ($numtests = 0; $handmessages[$loop][1] != 0; $loop++) {
58 $numtests++ if (($handmessages[$loop][1] & $handtype) != 0);
61 #Add number of extensions we check plus 2 for the number of messages
62 #that contain extensions
63 $numtests += $#extensions + 2;
64 #In a renegotiation we will have double the number of extension tests
65 if (($handtype & RENEG_HANDSHAKE) != 0) {
66 $numtests += $#extensions + 2;
68 #In TLS1.3 there are 3 messages with extensions (and no renegotiations)
69 $numtests += 1 if ($proxy->is_tls13());
71 plan tests => $numtests;
75 for ($loop = 0; $handmessages[$loop][1] != 0; $loop++) {
76 next if (($handmessages[$loop][1] & $handtype) == 0);
77 if (scalar @{$proxy->message_list} > $nextmess) {
78 $message = ${$proxy->message_list}[$nextmess];
83 if (!defined $message) {
84 fail("Message type check. Got nothing, expected "
85 .$handmessages[$loop][0]);
88 ok($message->mt == $handmessages[$loop][0],
89 "Message type check. Got ".$message->mt
90 .", expected ".$handmessages[$loop][0]);
93 next if ($message->mt() != TLSProxy::Message::MT_CLIENT_HELLO
94 && $message->mt() != TLSProxy::Message::MT_SERVER_HELLO
96 TLSProxy::Message::MT_ENCRYPTED_EXTENSIONS);
98 if ($message->mt() == TLSProxy::Message::MT_CLIENT_HELLO) {
99 #Add renegotiate extension we will expect if renegotiating
100 $exttype |= RENEGOTIATE_CLI_EXTENSION if ($clienthelloseen);
101 $clienthelloseen = 1;
103 #Now check that we saw the extensions we expected
104 my $msgexts = $message->extension_data();
106 for (my $extloop = 0, $extcount = 0; $extensions[$extloop][2] != 0;
108 next if ($message->mt() != $extensions[$extloop][0]);
109 ok (($extensions[$extloop][2] & $exttype) == 0
110 || defined ($msgexts->{$extensions[$extloop][1]}),
111 "Extension presence check (Message: ".$message->mt()
112 ." Extension: ".($extensions[$extloop][2] & $exttype).", "
114 $extcount++ if (($extensions[$extloop][2] & $exttype) != 0);
116 ok($extcount == keys %$msgexts, "Extensions count mismatch ("
117 .$extcount.", ".(keys %$msgexts)