Mercurial > hg > nginx-tests
comparison 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 | 436d0ffc2ea3 |
children | da52525f49d1 |
comparison
equal
deleted
inserted
replaced
1620:166461f0bd4b | 1621:fd440d324700 |
---|---|
10 use warnings; | 10 use warnings; |
11 use strict; | 11 use strict; |
12 | 12 |
13 use Test::More; | 13 use Test::More; |
14 | 14 |
15 use Socket qw/ :DEFAULT CRLF /; | 15 use Socket qw/ CRLF /; |
16 | 16 |
17 BEGIN { use FindBin; chdir($FindBin::Bin); } | 17 BEGIN { use FindBin; chdir($FindBin::Bin); } |
18 | 18 |
19 use lib 'lib'; | 19 use lib 'lib'; |
20 use Test::Nginx; | 20 use Test::Nginx; |
212 Net::SSLeay::dump_peer_certificate($ssl); | 212 Net::SSLeay::dump_peer_certificate($ssl); |
213 } | 213 } |
214 | 214 |
215 sub get_ssl_socket { | 215 sub get_ssl_socket { |
216 my ($host, $port, $ses) = @_; | 216 my ($host, $port, $ses) = @_; |
217 my $s; | 217 |
218 | 218 my $s = IO::Socket::INET->new('127.0.0.1:' . port($port)); |
219 my $dest_ip = inet_aton('127.0.0.1'); | |
220 $port = port($port); | |
221 my $dest_serv_params = sockaddr_in($port, $dest_ip); | |
222 | |
223 socket($s, &AF_INET, &SOCK_STREAM, 0) or die "socket: $!"; | |
224 connect($s, $dest_serv_params) or die "connect: $!"; | |
225 | |
226 my $ctx = Net::SSLeay::CTX_new() or die("Failed to create SSL_CTX $!"); | 219 my $ctx = Net::SSLeay::CTX_new() or die("Failed to create SSL_CTX $!"); |
227 my $ssl = Net::SSLeay::new($ctx) or die("Failed to create SSL $!"); | 220 my $ssl = Net::SSLeay::new($ctx) or die("Failed to create SSL $!"); |
228 Net::SSLeay::set_tlsext_host_name($ssl, $host); | 221 Net::SSLeay::set_tlsext_host_name($ssl, $host); |
229 Net::SSLeay::set_session($ssl, $ses) if defined $ses; | 222 Net::SSLeay::set_session($ssl, $ses) if defined $ses; |
230 Net::SSLeay::set_fd($ssl, fileno($s)); | 223 Net::SSLeay::set_fd($ssl, fileno($s)); |