Mercurial > hg > nginx-tests
annotate stream_ssl_variables.t @ 1571:1b4ceab9cb1c
Tests: fixed ssl_certificate.t with LibreSSL client.
Net::SSLeay::connect() that manages TLS handshake could return unexpected
error when receiving server alert, as seen in server certificate tests if
it could not been selected. Typically, it returns the expected error -1,
but with certain libssl implementations it can be 0, as explained below.
The error is propagated from libssl's SSL_connect(), which is usually -1.
In modern OpenSSL versions, it is the default error code used in the state
machine returned when something went wrong with parsing TLS message header.
In versions up to OpenSSL 1.0.2, with SSLv23_method() used by default, -1
is the only error code in the ssl_connect() method implementation which is
used as well if receiving alert while parsing ServerHello. BoringSSL also
seems to return -1. But it is not so with LibreSSL that returns zero.
Previously, tests failed with client built with LibreSSL with SSLv3 removed.
Here, the error is propagated directly from ssl_read_bytes() method, which
is always implemented as ssl3_read_bytes() in all TLS methods. It could be
also seen with OpenSSL up to 1.0.2 with non-default methods explicitly set.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Fri, 29 May 2020 23:10:20 +0300 |
parents | 144c6ce732e4 |
children | f3ba4c74de31 |
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 ] |
1488
dbce8fb5f5f8
Tests: align with OpenSSL security level 2.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1448
diff
changeset
|
76 default_bits = 2048 |
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 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
|
116 ($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
|
117 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
|
118 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
967
diff
changeset
|
119 ($s, $ssl) = get_ssl_socket(port(8082)); |
967
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
120 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
|
121 |
1447
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 |
967
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
124 ############################################################################### |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
125 |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
126 sub get_ssl_socket { |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
127 my ($port, $ses, $name) = @_; |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
128 my $s; |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
129 |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
130 my $dest_ip = inet_aton('127.0.0.1'); |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
131 my $dest_serv_params = sockaddr_in($port, $dest_ip); |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
132 |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
133 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
|
134 connect($s, $dest_serv_params) or die "connect: $!"; |
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 $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
|
137 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
|
138 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
|
139 Net::SSLeay::set_session($ssl, $ses) if defined $ses; |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
140 Net::SSLeay::set_fd($ssl, fileno($s)); |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
141 Net::SSLeay::connect($ssl) or die("ssl connect"); |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
142 return ($s, $ssl); |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
143 } |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
144 |
eb111c5f7556
Tests: stream ssl tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
145 ############################################################################### |