2 # Written by Stephen Henson for the OpenSSL project.
3 # ====================================================================
4 # Copyright (c) 1998-2015 The OpenSSL Project. All rights reserved.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
13 # 2. Redistributions in binary form must reproduce the above copyright
14 # notice, this list of conditions and the following disclaimer in
15 # the documentation and/or other materials provided with the
18 # 3. All advertising materials mentioning features or use of this
19 # software must display the following acknowledgment:
20 # "This product includes software developed by the OpenSSL Project
21 # for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23 # 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
24 # endorse or promote products derived from this software without
25 # prior written permission. For written permission, please contact
26 # openssl-core@openssl.org.
28 # 5. Products derived from this software may not be called "OpenSSL"
29 # nor may "OpenSSL" appear in their names without prior written
30 # permission of the OpenSSL Project.
32 # 6. Redistributions of any form whatsoever must retain the following
34 # "This product includes software developed by the OpenSSL Project
35 # for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37 # THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
38 # EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
39 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
40 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
41 # ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
43 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
44 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
45 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
46 # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
47 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
48 # OF THE POSSIBILITY OF SUCH DAMAGE.
49 # ====================================================================
51 # This product includes cryptographic software written by Eric Young
52 # (eay@cryptsoft.com). This product includes software written by Tim
53 # Hudson (tjh@cryptsoft.com).
56 use OpenSSL::Test qw/:DEFAULT cmdstr srctop_file bldtop_dir/;
57 use OpenSSL::Test::Utils;
59 use File::Temp qw(tempfile);
61 my $test_name = "test_tlsextms";
64 plan skip_all => "TLSProxy isn't usable on $^O"
67 plan skip_all => "$test_name needs the dynamic engine feature enabled"
68 if disabled("engine") || disabled("dynamic-engine");
70 $ENV{OPENSSL_ENGINES} = bldtop_dir("engines");
71 $ENV{OPENSSL_ia32cap} = '~0x200000200000000';
73 sub checkmessages($$$$$);
83 my $proxy = TLSProxy::Proxy->new(
85 cmdstr(app(["openssl"])),
86 srctop_file("apps", "server.pem"),
87 (!$ENV{HARNESS_ACTIVE} || $ENV{HARNESS_VERBOSE})
92 #Test 1: By default server and client should send extended master secret
94 #Expected result: ClientHello extension seen; ServerHello extension seen
99 checkmessages(1, "Default extended master secret test", 1, 1, 1);
101 #Test 2: If client omits extended master secret extension, server should too.
102 #Expected result: ClientHello extension not seen; ServerHello extension not seen
108 checkmessages(2, "No client extension extended master secret test", 0, 0, 1);
110 # Test 3: same as 1 but with session tickets disabled.
111 # Expected result: same as test 1.
114 $proxy->clientflags("-no_ticket");
117 checkmessages(3, "No ticket extended master secret test", 1, 1, 1);
119 # Test 4: same as 2 but with session tickets disabled.
120 # Expected result: same as test 2.
123 $proxy->clientflags("-no_ticket");
126 checkmessages(2, "No ticket, no client extension extended master secret test", 0, 0, 1);
128 #Test 5: Session resumption extended master secret test
130 #Expected result: ClientHello extension seen; ServerHello extension seen
131 # Abbreviated handshake
135 (my $fh, my $session) = tempfile();
136 $proxy->serverconnects(2);
137 $proxy->clientflags("-sess_out ".$session);
140 $proxy->clientflags("-sess_in ".$session);
141 $proxy->clientstart();
142 checkmessages(5, "Session resumption extended master secret test", 1, 1, 0);
144 #Test 6: Session resumption extended master secret test original session
145 # omits extension. Server must not resume session.
146 #Expected result: ClientHello extension seen; ServerHello extension seen
151 ($fh, $session) = tempfile();
152 $proxy->serverconnects(2);
153 $proxy->clientflags("-sess_out ".$session);
156 $proxy->clientflags("-sess_in ".$session);
158 $proxy->clientstart();
159 checkmessages(6, "Session resumption extended master secret test", 1, 1, 1);
161 #Test 7: Session resumption extended master secret test resumed session
162 # omits client extension. Server must abort connection.
163 #Expected result: aborted connection.
167 ($fh, $session) = tempfile();
168 $proxy->serverconnects(2);
169 $proxy->clientflags("-sess_out ".$session);
172 $proxy->clientflags("-sess_in ".$session);
174 $proxy->clientstart();
175 ok(TLSProxy::Message->fail(), "Client inconsistent session resumption");
177 #Test 8: Session resumption extended master secret test resumed session
178 # omits server extension. Client must abort connection.
179 #Expected result: aborted connection.
183 ($fh, $session) = tempfile();
184 $proxy->serverconnects(2);
185 $proxy->clientflags("-sess_out ".$session);
188 $proxy->clientflags("-sess_in ".$session);
190 $proxy->clientstart();
191 ok(TLSProxy::Message->fail(), "Server inconsistent session resumption 1");
193 #Test 9: Session resumption extended master secret test initial session
194 # omits server extension. Client must abort connection.
195 #Expected result: aborted connection.
199 ($fh, $session) = tempfile();
200 $proxy->serverconnects(2);
201 $proxy->clientflags("-sess_out ".$session);
204 $proxy->clientflags("-sess_in ".$session);
206 $proxy->clientstart();
207 ok(TLSProxy::Message->fail(), "Server inconsistent session resumption 2");
213 foreach my $message (@{$proxy->message_list}) {
214 if ($crmextms && $message->mt == TLSProxy::Message::MT_CLIENT_HELLO) {
215 $message->delete_extension(TLSProxy::Message::EXT_EXTENDED_MASTER_SECRET);
218 if ($srmextms && $message->mt == TLSProxy::Message::MT_SERVER_HELLO) {
219 $message->delete_extension(TLSProxy::Message::EXT_EXTENDED_MASTER_SECRET);
225 sub checkmessages($$$$$)
227 my ($testno, $testname, $testcextms, $testsextms, $testhand) = @_;
229 subtest $testname => sub {
231 foreach my $message (@{$proxy->message_list}) {
232 if ($message->mt == TLSProxy::Message::MT_CLIENT_HELLO
233 || $message->mt == TLSProxy::Message::MT_SERVER_HELLO) {
234 #Get the extensions data
235 my %extensions = %{$message->extension_data};
237 $extensions{TLSProxy::Message::EXT_EXTENDED_MASTER_SECRET}) {
238 if ($message->mt == TLSProxy::Message::MT_CLIENT_HELLO) {
244 } elsif ($message->mt == TLSProxy::Message::MT_CLIENT_KEY_EXCHANGE) {
245 #Must be doing a full handshake
252 ok(TLSProxy::Message->success, "Handshake");
254 ok($testcextms == $cextms,
255 "ClientHello extension extended master secret check");
256 ok($testsextms == $sextms,
257 "ServerHello extension extended master secret check");
258 ok($testhand == $fullhand,
259 "Extended master secret full handshake check");
266 ($crmextms, $srmextms) = @_;