annotate stream_ssl_variables.t @ 1477:8b122b35703b

Tests: fixed session reuse tests in ssl_certificate.t with TLSv1.3. Previously, session data was retrieved too early, before server passed application data, which usually means NewSessionTicket is not yet sent. The fix is to ask server for application data, then retrieve a session.
author Sergey Kandaurov <pluknet@nginx.com>
date Mon, 20 May 2019 16:00:40 +0300
parents c1b969fc7a23
children dbce8fb5f5f8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
967
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
2
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
3 # (C) Sergey Kandaurov
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
4 # (C) Nginx, Inc.
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
5
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
6 # Tests for stream ssl module with variables.
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
7
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
8 ###############################################################################
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
9
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
10 use warnings;
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
11 use strict;
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
12
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
13 use Test::More;
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
14
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
15 use Socket;
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
16
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
17 BEGIN { use FindBin; chdir($FindBin::Bin); }
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
18
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
19 use lib 'lib';
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
20 use Test::Nginx;
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
21 use Test::Nginx::Stream qw/ stream /;
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
22
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
23 ###############################################################################
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
24
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
25 select STDERR; $| = 1;
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
26 select STDOUT; $| = 1;
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
27
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
28 eval {
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
29 require Net::SSLeay;
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
30 Net::SSLeay::load_error_strings();
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
31 Net::SSLeay::SSLeay_add_ssl_algorithms();
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
32 Net::SSLeay::randomize();
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
33 };
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
34 plan(skip_all => 'Net::SSLeay not installed') if $@;
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
35
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
36 eval {
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
37 my $ctx = Net::SSLeay::CTX_new() or die;
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
38 my $ssl = Net::SSLeay::new($ctx) or die;
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
39 Net::SSLeay::set_tlsext_host_name($ssl, 'example.org') == 1 or die;
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
40 };
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
41 plan(skip_all => 'Net::SSLeay with OpenSSL SNI support required') if $@;
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
42
1447
e1c64ee44212 Tests: added $ssl_server_name tests with SSL session reuse.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
43 my $t = Test::Nginx->new()->has(qw/stream stream_ssl stream_return/)
967
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
44 ->has_daemon('openssl');
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
45
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
46 $t->write_file_expand('nginx.conf', <<'EOF');
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
47
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
48 %%TEST_GLOBALS%%
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
49
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
50 daemon off;
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
51
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
52 events {
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
53 }
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
54
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
55 stream {
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
56 ssl_certificate_key localhost.key;
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
57 ssl_certificate localhost.crt;
1447
e1c64ee44212 Tests: added $ssl_server_name tests with SSL session reuse.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
58 ssl_session_cache builtin;
967
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
59
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
60 server {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 967
diff changeset
61 listen 127.0.0.1:8080;
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 967
diff changeset
62 listen 127.0.0.1:8081 ssl;
967
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
63 return $ssl_session_reused:$ssl_session_id:$ssl_cipher:$ssl_protocol;
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
64 }
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
65
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
66 server {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 967
diff changeset
67 listen 127.0.0.1:8082 ssl;
967
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
68 return $ssl_server_name;
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
69 }
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
70 }
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
71
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
72 EOF
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
73
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
74 $t->write_file('openssl.conf', <<EOF);
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
75 [ req ]
1116
8ef51dbb5d69 Tests: reduced OpenSSL default key length to 1024.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1032
diff changeset
76 default_bits = 1024
967
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
77 encrypt_key = no
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
78 distinguished_name = req_distinguished_name
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
79 [ req_distinguished_name ]
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
80 EOF
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
81
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
82 my $d = $t->testdir();
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
83
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
84 foreach my $name ('localhost') {
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
85 system('openssl req -x509 -new '
1220
0af58b78df35 Tests: removed single quotes from system() calls.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1116
diff changeset
86 . "-config $d/openssl.conf -subj /CN=$name/ "
0af58b78df35 Tests: removed single quotes from system() calls.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1116
diff changeset
87 . "-out $d/$name.crt -keyout $d/$name.key "
967
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
88 . ">>$d/openssl.out 2>&1") == 0
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
89 or die "Can't create certificate for $name: $!\n";
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
90 }
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
91
1447
e1c64ee44212 Tests: added $ssl_server_name tests with SSL session reuse.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
92 $t->run()->plan(6);
967
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
93
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
94 ###############################################################################
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
95
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
96 my ($s, $ssl);
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
97
1235
3fc6817cd84a Tests: explicit peer port in stream tests now required.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1220
diff changeset
98 is(stream('127.0.0.1:' . port(8080))->read(), ':::', 'no ssl');
967
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
99
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 967
diff changeset
100 ($s, $ssl) = get_ssl_socket(port(8081));
967
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
101 like(Net::SSLeay::read($ssl), qr/^\.:(\w{64})?:[\w-]+:(TLS|SSL)v(\d|\.)+$/,
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
102 'ssl variables');
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
103
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
104 my $ses = Net::SSLeay::get_session($ssl);
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 967
diff changeset
105 ($s, $ssl) = get_ssl_socket(port(8081), $ses);
967
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
106 like(Net::SSLeay::read($ssl), qr/^r:\w{64}:[\w-]+:(TLS|SSL)v(\d|\.)+$/,
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
107 'ssl variables - session reused');
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
108
1447
e1c64ee44212 Tests: added $ssl_server_name tests with SSL session reuse.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
109 SKIP: {
e1c64ee44212 Tests: added $ssl_server_name tests with SSL session reuse.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
110 skip 'no sni', 3 unless $t->has_module('sni');
e1c64ee44212 Tests: added $ssl_server_name tests with SSL session reuse.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
111
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 967
diff changeset
112 ($s, $ssl) = get_ssl_socket(port(8082), undef, 'example.com');
967
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
113 is(Net::SSLeay::ssl_read_all($ssl), 'example.com', 'ssl server name');
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
114
1447
e1c64ee44212 Tests: added $ssl_server_name tests with SSL session reuse.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
115 TODO: {
e1c64ee44212 Tests: added $ssl_server_name tests with SSL session reuse.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
116 local $TODO = 'not yet' if $t->has_module('OpenSSL (1.1.1|3)')
e1c64ee44212 Tests: added $ssl_server_name tests with SSL session reuse.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
117 && !$t->has_version('1.15.10');
e1c64ee44212 Tests: added $ssl_server_name tests with SSL session reuse.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
118
e1c64ee44212 Tests: added $ssl_server_name tests with SSL session reuse.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
119 my $ses = Net::SSLeay::get_session($ssl);
1448
c1b969fc7a23 Tests: preserving original SNI in a resumption handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1447
diff changeset
120 ($s, $ssl) = get_ssl_socket(port(8082), $ses, 'example.com');
1447
e1c64ee44212 Tests: added $ssl_server_name tests with SSL session reuse.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
121 is(Net::SSLeay::ssl_read_all($ssl), 'example.com', 'ssl server name - reused');
e1c64ee44212 Tests: added $ssl_server_name tests with SSL session reuse.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
122
e1c64ee44212 Tests: added $ssl_server_name tests with SSL session reuse.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
123 }
e1c64ee44212 Tests: added $ssl_server_name tests with SSL session reuse.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
124
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 967
diff changeset
125 ($s, $ssl) = get_ssl_socket(port(8082));
967
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
126 is(Net::SSLeay::ssl_read_all($ssl), '', 'ssl server name empty');
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
127
1447
e1c64ee44212 Tests: added $ssl_server_name tests with SSL session reuse.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
128 }
e1c64ee44212 Tests: added $ssl_server_name tests with SSL session reuse.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
129
967
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
130 ###############################################################################
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
131
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
132 sub get_ssl_socket {
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
133 my ($port, $ses, $name) = @_;
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
134 my $s;
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
135
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
136 my $dest_ip = inet_aton('127.0.0.1');
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
137 my $dest_serv_params = sockaddr_in($port, $dest_ip);
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
138
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
139 socket($s, &AF_INET, &SOCK_STREAM, 0) or die "socket: $!";
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
140 connect($s, $dest_serv_params) or die "connect: $!";
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
141
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
142 my $ctx = Net::SSLeay::CTX_new() or die("Failed to create SSL_CTX $!");
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
143 my $ssl = Net::SSLeay::new($ctx) or die("Failed to create SSL $!");
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
144 Net::SSLeay::set_tlsext_host_name($ssl, $name) if defined $name;
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
145 Net::SSLeay::set_session($ssl, $ses) if defined $ses;
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
146 Net::SSLeay::set_fd($ssl, fileno($s));
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
147 Net::SSLeay::connect($ssl) or die("ssl connect");
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
148 return ($s, $ssl);
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
149 }
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
150
eb111c5f7556 Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
151 ###############################################################################