Mercurial > hg > nginx-tests
annotate stream_ssl_variables.t @ 1619:436d0ffc2ea3
Tests: correctly shutdown ssl for reproducible session reuse tests.
Previously, session reuse tests in stream_ssl_certificate.t were prone
to testing errors, since the client doesn't write any application data
before closing a connection, which is done so to pass tests on win32.
In this case, the server may happened to get an unexpected eof meaning
that it will abandon that session. This is specific to stream testing
pattern, changes to ssl_certificate.t are applied too for consistency.
This is also specific to SSL_R_UNEXPECTED_EOF_WHILE_READING, which is
implemented in OpenSSL 3.0.0.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Mon, 23 Nov 2020 22:46:06 +0000 |
parents | f3ba4c74de31 |
children | fd440d324700 |
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 { |
1609
f3ba4c74de31
Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents:
1535
diff
changeset
|
56 %%TEST_GLOBALS_STREAM%% |
f3ba4c74de31
Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents:
1535
diff
changeset
|
57 |
967
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 ssl_certificate_key localhost.key; |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 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
|
60 ssl_session_cache builtin; |
967
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
967
diff
changeset
|
63 listen 127.0.0.1:8080; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
967
diff
changeset
|
64 listen 127.0.0.1:8081 ssl; |
967
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 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
|
66 } |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
967
diff
changeset
|
69 listen 127.0.0.1:8082 ssl; |
967
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 return $ssl_server_name; |
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 } |
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 EOF |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 $t->write_file('openssl.conf', <<EOF); |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 [ req ] |
1488
dbce8fb5f5f8
Tests: align with OpenSSL security level 2.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1448
diff
changeset
|
78 default_bits = 2048 |
967
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 encrypt_key = no |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 distinguished_name = req_distinguished_name |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 [ req_distinguished_name ] |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 EOF |
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 my $d = $t->testdir(); |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 foreach my $name ('localhost') { |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 system('openssl req -x509 -new ' |
1220
0af58b78df35
Tests: removed single quotes from system() calls.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1116
diff
changeset
|
88 . "-config $d/openssl.conf -subj /CN=$name/ " |
0af58b78df35
Tests: removed single quotes from system() calls.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1116
diff
changeset
|
89 . "-out $d/$name.crt -keyout $d/$name.key " |
967
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 . ">>$d/openssl.out 2>&1") == 0 |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 or die "Can't create certificate for $name: $!\n"; |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 } |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
93 |
1447
e1c64ee44212
Tests: added $ssl_server_name tests with SSL session reuse.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
94 $t->run()->plan(6); |
967
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 ############################################################################### |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
97 |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
98 my ($s, $ssl); |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
99 |
1235
3fc6817cd84a
Tests: explicit peer port in stream tests now required.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1220
diff
changeset
|
100 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
|
101 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
967
diff
changeset
|
102 ($s, $ssl) = get_ssl_socket(port(8081)); |
967
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
103 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
|
104 'ssl variables'); |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
105 |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
106 my $ses = Net::SSLeay::get_session($ssl); |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
967
diff
changeset
|
107 ($s, $ssl) = get_ssl_socket(port(8081), $ses); |
967
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
108 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
|
109 'ssl variables - session reused'); |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
110 |
1447
e1c64ee44212
Tests: added $ssl_server_name tests with SSL session reuse.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
111 SKIP: { |
e1c64ee44212
Tests: added $ssl_server_name tests with SSL session reuse.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
112 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
|
113 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
967
diff
changeset
|
114 ($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
|
115 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
|
116 |
1447
e1c64ee44212
Tests: added $ssl_server_name tests with SSL session reuse.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
117 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
|
118 ($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
|
119 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
|
120 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
967
diff
changeset
|
121 ($s, $ssl) = get_ssl_socket(port(8082)); |
967
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
122 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
|
123 |
1447
e1c64ee44212
Tests: added $ssl_server_name tests with SSL session reuse.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
124 } |
e1c64ee44212
Tests: added $ssl_server_name tests with SSL session reuse.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
125 |
967
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
126 ############################################################################### |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
127 |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
128 sub get_ssl_socket { |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
129 my ($port, $ses, $name) = @_; |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
130 my $s; |
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 my $dest_ip = inet_aton('127.0.0.1'); |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
133 my $dest_serv_params = sockaddr_in($port, $dest_ip); |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
134 |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
135 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
|
136 connect($s, $dest_serv_params) or die "connect: $!"; |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
137 |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
138 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
|
139 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
|
140 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
|
141 Net::SSLeay::set_session($ssl, $ses) if defined $ses; |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
142 Net::SSLeay::set_fd($ssl, fileno($s)); |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
143 Net::SSLeay::connect($ssl) or die("ssl connect"); |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
144 return ($s, $ssl); |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
145 } |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
146 |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
147 ############################################################################### |