Mercurial > hg > nginx-tests
comparison ssl_certificate_perl.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 | 144c6ce732e4 |
children | 58951cf933e1 |
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; | |
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; |
112 Net::SSLeay::dump_peer_certificate($ssl); | 110 Net::SSLeay::dump_peer_certificate($ssl); |
113 } | 111 } |
114 | 112 |
115 sub get_ssl_socket { | 113 sub get_ssl_socket { |
116 my ($host, $port) = @_; | 114 my ($host, $port) = @_; |
117 my $s; | |
118 | 115 |
119 my $dest_ip = inet_aton('127.0.0.1'); | 116 my $s = IO::Socket::INET->new('127.0.0.1:' . port($port)); |
120 $port = port($port); | |
121 my $dest_serv_params = sockaddr_in($port, $dest_ip); | |
122 | |
123 socket($s, &AF_INET, &SOCK_STREAM, 0) or die "socket: $!"; | |
124 connect($s, $dest_serv_params) or die "connect: $!"; | |
125 | |
126 my $ctx = Net::SSLeay::CTX_new() or die("Failed to create SSL_CTX $!"); | 117 my $ctx = Net::SSLeay::CTX_new() or die("Failed to create SSL_CTX $!"); |
127 my $ssl = Net::SSLeay::new($ctx) or die("Failed to create SSL $!"); | 118 my $ssl = Net::SSLeay::new($ctx) or die("Failed to create SSL $!"); |
128 Net::SSLeay::set_tlsext_host_name($ssl, $host); | 119 Net::SSLeay::set_tlsext_host_name($ssl, $host); |
129 Net::SSLeay::set_fd($ssl, fileno($s)); | 120 Net::SSLeay::set_fd($ssl, fileno($s)); |
130 Net::SSLeay::connect($ssl) or die("ssl connect"); | 121 Net::SSLeay::connect($ssl) or die("ssl connect"); |