70-test_tls13messages.t 9.6 KB
Newer Older
1 2 3 4 5 6 7 8 9
#! /usr/bin/env perl
# Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
#
# Licensed under the OpenSSL license (the "License").  You may not use
# this file except in compliance with the License.  You can obtain a copy
# in the file LICENSE in the source distribution or at
# https://www.openssl.org/source/license.html

use strict;
10
use OpenSSL::Test qw/:DEFAULT cmdstr srctop_file srctop_dir bldtop_dir/;
11
use OpenSSL::Test::Utils;
M
Matt Caswell 已提交
12
use File::Temp qw(tempfile);
13
use TLSProxy::Proxy;
14
use checkhandshake qw(checkhandshake @handmessages @extensions);
15

16 17
my $test_name = "test_tls13messages";
setup($test_name);
18

19 20 21 22 23 24 25 26 27 28 29 30 31
plan skip_all => "TLSProxy isn't usable on $^O"
    if $^O =~ /^(VMS|MSWin32)$/;

plan skip_all => "$test_name needs the dynamic engine feature enabled"
    if disabled("engine") || disabled("dynamic-engine");

plan skip_all => "$test_name needs the sock feature enabled"
    if disabled("sock");

plan skip_all => "$test_name needs TLSv1.3 enabled"
    if disabled("tls1_3");

$ENV{OPENSSL_ia32cap} = '~0x200000200000000';
M
Matt Caswell 已提交
32
$ENV{CTLOG_FILE} = srctop_file("test", "ct", "log_list.conf");
33 34


35 36
@handmessages = (
    [TLSProxy::Message::MT_CLIENT_HELLO,
37
        checkhandshake::ALL_HANDSHAKES],
38
    [TLSProxy::Message::MT_SERVER_HELLO,
39
        checkhandshake::ALL_HANDSHAKES],
40
    [TLSProxy::Message::MT_ENCRYPTED_EXTENSIONS,
41
        checkhandshake::ALL_HANDSHAKES],
42
    [TLSProxy::Message::MT_CERTIFICATE_REQUEST,
43
        checkhandshake::CLIENT_AUTH_HANDSHAKE],
44
    [TLSProxy::Message::MT_CERTIFICATE,
45
        checkhandshake::ALL_HANDSHAKES & ~checkhandshake::RESUME_HANDSHAKE],
46 47
    [TLSProxy::Message::MT_CERTIFICATE_VERIFY,
        checkhandshake::ALL_HANDSHAKES & ~checkhandshake::RESUME_HANDSHAKE],
48
    [TLSProxy::Message::MT_FINISHED,
49
        checkhandshake::ALL_HANDSHAKES],
50
    [TLSProxy::Message::MT_CERTIFICATE,
51
        checkhandshake::CLIENT_AUTH_HANDSHAKE],
52
    [TLSProxy::Message::MT_CERTIFICATE_VERIFY,
53
        checkhandshake::CLIENT_AUTH_HANDSHAKE],
54
    [TLSProxy::Message::MT_FINISHED,
55
        checkhandshake::ALL_HANDSHAKES],
56 57 58
    [0, 0]
);

59 60
@extensions = (
    [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SERVER_NAME,
61
        checkhandshake::SERVER_NAME_CLI_EXTENSION],
62
    [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_STATUS_REQUEST,
63
        checkhandshake::STATUS_REQUEST_CLI_EXTENSION],
64
    [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SUPPORTED_GROUPS,
65
        checkhandshake::DEFAULT_EXTENSIONS],
66
    [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_EC_POINT_FORMATS,
67
        checkhandshake::DEFAULT_EXTENSIONS],
68
    [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SIG_ALGS,
69
        checkhandshake::DEFAULT_EXTENSIONS],
70
    [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_ALPN,
71
        checkhandshake::ALPN_CLI_EXTENSION],
72
    [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SCT,
73
        checkhandshake::SCT_CLI_EXTENSION],
74
    [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_ENCRYPT_THEN_MAC,
75
        checkhandshake::DEFAULT_EXTENSIONS],
76
    [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_EXTENDED_MASTER_SECRET,
77
        checkhandshake::DEFAULT_EXTENSIONS],
78
    [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SESSION_TICKET,
79
        checkhandshake::DEFAULT_EXTENSIONS],
80
    [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_KEY_SHARE,
81
        checkhandshake::DEFAULT_EXTENSIONS],
82
    [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SUPPORTED_VERSIONS,
83
        checkhandshake::DEFAULT_EXTENSIONS],
84 85

    [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_KEY_SHARE,
86
        checkhandshake::DEFAULT_EXTENSIONS],
87 88

    [TLSProxy::Message::MT_ENCRYPTED_EXTENSIONS, TLSProxy::Message::EXT_SERVER_NAME,
89
        checkhandshake::SERVER_NAME_SRV_EXTENSION],
90
    [TLSProxy::Message::MT_ENCRYPTED_EXTENSIONS, TLSProxy::Message::EXT_ALPN,
91
        checkhandshake::ALPN_SRV_EXTENSION],
92 93 94 95

    [TLSProxy::Message::MT_CERTIFICATE, TLSProxy::Message::EXT_STATUS_REQUEST,
        checkhandshake::STATUS_REQUEST_SRV_EXTENSION],

M
Matt Caswell 已提交
96 97 98
    [0,0,0]
);

99 100 101 102 103 104 105 106
my $proxy = TLSProxy::Proxy->new(
    undef,
    cmdstr(app(["openssl"]), display => 1),
    srctop_file("apps", "server.pem"),
    (!$ENV{HARNESS_ACTIVE} || $ENV{HARNESS_VERBOSE})
);

#Test 1: Check we get all the right messages for a default handshake
M
Matt Caswell 已提交
107
(undef, my $session) = tempfile();
108
#$proxy->serverconnects(2);
M
Matt Caswell 已提交
109
$proxy->clientflags("-sess_out ".$session);
110
$proxy->start() or plan skip_all => "Unable to start up Proxy for tests";
M
Matt Caswell 已提交
111
plan tests => 12;
112 113
checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
               checkhandshake::DEFAULT_EXTENSIONS,
114
               "Default handshake test");
115

116
#TODO(TLS1.3): Test temporarily disabled until we implement TLS1.3 resumption
M
Matt Caswell 已提交
117
#Test 2: Resumption handshake
118 119 120 121
#$proxy->clearClient();
#$proxy->clientflags("-sess_in ".$session);
#$proxy->clientstart();
#checkmessages(RESUME_HANDSHAKE, "Resumption handshake test");
M
Matt Caswell 已提交
122 123
unlink $session;

M
Matt Caswell 已提交
124 125 126 127
#Test 3: A status_request handshake (client request only)
$proxy->clear();
$proxy->clientflags("-status");
$proxy->start();
128
checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
M
Matt Caswell 已提交
129 130 131
               checkhandshake::DEFAULT_EXTENSIONS
               | checkhandshake::STATUS_REQUEST_CLI_EXTENSION,
               "status_request handshake test (client)");
M
Matt Caswell 已提交
132 133 134 135 136 137

#Test 4: A status_request handshake (server support only)
$proxy->clear();
$proxy->serverflags("-status_file "
                    .srctop_file("test", "recipes", "ocsp-response.der"));
$proxy->start();
138 139
checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
               checkhandshake::DEFAULT_EXTENSIONS,
M
Matt Caswell 已提交
140
               "status_request handshake test (server)");
M
Matt Caswell 已提交
141 142

#Test 5: A status_request handshake (client and server)
M
Matt Caswell 已提交
143 144 145 146 147 148 149 150
#TODO(TLS1.3): TLS1.3 doesn't actually have CertificateStatus messages. This is
#a temporary test until such time as we do proper TLS1.3 style certificate
#status
$proxy->clear();
$proxy->clientflags("-status");
$proxy->serverflags("-status_file "
                    .srctop_file("test", "recipes", "ocsp-response.der"));
$proxy->start();
151
checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
M
Matt Caswell 已提交
152 153 154 155
               checkhandshake::DEFAULT_EXTENSIONS
               | checkhandshake::STATUS_REQUEST_CLI_EXTENSION
               | checkhandshake::STATUS_REQUEST_SRV_EXTENSION,
               "status_request handshake test");
M
Matt Caswell 已提交
156

M
Matt Caswell 已提交
157
#Test 6: A client auth handshake
M
Matt Caswell 已提交
158 159 160 161
$proxy->clear();
$proxy->clientflags("-cert ".srctop_file("apps", "server.pem"));
$proxy->serverflags("-Verify 5");
$proxy->start();
162 163
checkhandshake($proxy, checkhandshake::CLIENT_AUTH_HANDSHAKE,
               checkhandshake::DEFAULT_EXTENSIONS,
M
Matt Caswell 已提交
164
               "Client auth handshake test");
M
Matt Caswell 已提交
165

M
Matt Caswell 已提交
166 167 168 169
#Test 7: Server name handshake (client request only)
$proxy->clear();
$proxy->clientflags("-servername testhost");
$proxy->start();
170 171 172
checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
               checkhandshake::DEFAULT_EXTENSIONS
               | checkhandshake::SERVER_NAME_CLI_EXTENSION,
M
Matt Caswell 已提交
173
               "Server name handshake test (client)");
M
Matt Caswell 已提交
174 175 176 177 178

#Test 8: Server name handshake (server support only)
$proxy->clear();
$proxy->serverflags("-servername testhost");
$proxy->start();
179 180
checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
               checkhandshake::DEFAULT_EXTENSIONS,
M
Matt Caswell 已提交
181
               "Server name handshake test (server)");
M
Matt Caswell 已提交
182 183 184 185 186 187

#Test 9: Server name handshake (client and server)
$proxy->clear();
$proxy->clientflags("-servername testhost");
$proxy->serverflags("-servername testhost");
$proxy->start();
188
checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
M
Matt Caswell 已提交
189 190 191 192
               checkhandshake::DEFAULT_EXTENSIONS
               | checkhandshake::SERVER_NAME_CLI_EXTENSION
               | checkhandshake::SERVER_NAME_SRV_EXTENSION,
               "Server name handshake test");
M
Matt Caswell 已提交
193 194 195 196 197

#Test 10: ALPN handshake (client request only)
$proxy->clear();
$proxy->clientflags("-alpn test");
$proxy->start();
198 199 200
checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
               checkhandshake::DEFAULT_EXTENSIONS
               | checkhandshake::ALPN_CLI_EXTENSION,
M
Matt Caswell 已提交
201
               "ALPN handshake test (client)");
M
Matt Caswell 已提交
202 203 204 205 206

#Test 11: ALPN handshake (server support only)
$proxy->clear();
$proxy->serverflags("-alpn test");
$proxy->start();
207 208
checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
               checkhandshake::DEFAULT_EXTENSIONS,
M
Matt Caswell 已提交
209
               "ALPN handshake test (server)");
M
Matt Caswell 已提交
210

M
Matt Caswell 已提交
211 212 213 214 215
#Test 12: ALPN handshake (client and server)
$proxy->clear();
$proxy->clientflags("-alpn test");
$proxy->serverflags("-alpn test");
$proxy->start();
216
checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
M
Matt Caswell 已提交
217 218 219 220
               checkhandshake::DEFAULT_EXTENSIONS
               | checkhandshake::ALPN_CLI_EXTENSION
               | checkhandshake::ALPN_SRV_EXTENSION,
               "ALPN handshake test");
M
Matt Caswell 已提交
221 222 223 224 225 226 227 228 229 230 231 232 233 234

#Test 13: SCT handshake (client request only)
#TODO(TLS1.3): This only checks that the client side extension appears. The
#SCT extension is unusual in that we have no built-in server side implementation
#The server side implementation can nomrally be added using the custom
#extensions framework (e.g. by using the "-serverinfo" s_server option). However
#currently we only support <= TLS1.2 for custom extensions because the existing
#framework and API has no knowledge of the TLS1.3 messages
$proxy->clear();
#Note: -ct also sends status_request
$proxy->clientflags("-ct");
$proxy->serverflags("-status_file "
                    .srctop_file("test", "recipes", "ocsp-response.der"));
$proxy->start();
235
checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
M
Matt Caswell 已提交
236 237 238 239 240
               checkhandshake::DEFAULT_EXTENSIONS
               | checkhandshake::SCT_CLI_EXTENSION
               | checkhandshake::STATUS_REQUEST_CLI_EXTENSION
               | checkhandshake::STATUS_REQUEST_SRV_EXTENSION,
               "SCT handshake test");