Mercurial > hg > nginx-tests
comparison stream_ssl_certificate.t @ 1621:fd440d324700
Tests: simplified get_ssl_socket() functions that use Net::SSLeay.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Tue, 24 Nov 2020 00:43:56 +0000 |
parents | 166461f0bd4b |
children | da52525f49d1 |
comparison
equal
deleted
inserted
replaced
1620:166461f0bd4b | 1621:fd440d324700 |
---|---|
9 | 9 |
10 use warnings; | 10 use warnings; |
11 use strict; | 11 use strict; |
12 | 12 |
13 use Test::More; | 13 use Test::More; |
14 | |
15 use Socket qw/ :DEFAULT CRLF /; | |
16 | 14 |
17 BEGIN { use FindBin; chdir($FindBin::Bin); } | 15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
18 | 16 |
19 use lib 'lib'; | 17 use lib 'lib'; |
20 use Test::Nginx; | 18 use Test::Nginx; |
190 Net::SSLeay::dump_peer_certificate($ssl); | 188 Net::SSLeay::dump_peer_certificate($ssl); |
191 } | 189 } |
192 | 190 |
193 sub get_ssl_socket { | 191 sub get_ssl_socket { |
194 my ($host, $port, $ses) = @_; | 192 my ($host, $port, $ses) = @_; |
195 my $s; | 193 |
196 | 194 my $s = IO::Socket::INET->new('127.0.0.1:' . port($port)); |
197 my $dest_ip = inet_aton('127.0.0.1'); | |
198 $port = port($port); | |
199 my $dest_serv_params = sockaddr_in($port, $dest_ip); | |
200 | |
201 socket($s, &AF_INET, &SOCK_STREAM, 0) or die "socket: $!"; | |
202 connect($s, $dest_serv_params) or die "connect: $!"; | |
203 | |
204 my $ctx = Net::SSLeay::CTX_new() or die("Failed to create SSL_CTX $!"); | 195 my $ctx = Net::SSLeay::CTX_new() or die("Failed to create SSL_CTX $!"); |
205 my $ssl = Net::SSLeay::new($ctx) or die("Failed to create SSL $!"); | 196 my $ssl = Net::SSLeay::new($ctx) or die("Failed to create SSL $!"); |
206 Net::SSLeay::set_tlsext_host_name($ssl, $host); | 197 Net::SSLeay::set_tlsext_host_name($ssl, $host); |
207 Net::SSLeay::set_session($ssl, $ses) if defined $ses; | 198 Net::SSLeay::set_session($ssl, $ses) if defined $ses; |
208 Net::SSLeay::set_fd($ssl, fileno($s)); | 199 Net::SSLeay::set_fd($ssl, fileno($s)); |