/usr/share/doc/libcrypt-ssleay-perl/examples/net-ssl-test is in libcrypt-ssleay-perl 0.58-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | #!/usr/bin/perl
use strict;
use vars qw($opt_p $opt_n $opt_bench $opt_debug $opt_version
$opt_v $opt_help
$opt_cert $opt_key $opt_cafile $opt_cadir
);
use lib qw(lib);
use Net::SSL;
use File::Basename;
use Benchmark;
use Getopt::Long;
&GetOptions ('p:s' => \$opt_p,
'proxy:s' => \$opt_p,
'bench:n' => \$opt_bench,
'd' => \$opt_debug,
'version:i' => \$opt_version,
'v:i' => \$opt_version,
'h' => \$opt_help,
'help' => \$opt_help,
'cert:s' => \$opt_cert,
'key:s' => \$opt_key,
'CAfile:s' => \$opt_cafile,
'CAdir:s' => \$opt_cadir,
);
my $basename = &File::Basename::basename($0);
# define sub first, in case you are reading the source :)
sub help {
print <<HELP;
Usage: $basename [-d] [-b=NNN] [-h] [-p proxy_name:port] [-CAfile=FILE] [GET|HEAD] [ssl_server_name] [port]
-d Debug mode
-b Benchmark NNN times, good test for memory leaks
-h This help message
-p Proxy server, via CONNECT method, localhost:80 format
-cert client certificate file
-key private key file
-CAfile CA certificates file, use certs/ca-bundle.crt for primary root certs
method defaults to HEAD
ssl_server_name defaults to www.nodeworks.com
port defaults to 443
These are equivalent:
./net_ssl_test
./net_ssl_test HEAD www.nodeworks.com 443
This might be how you debug your proxy:
./net_ssl_test -d -p http://proxy_name:80 www.nodeworks.com
Note http:// on proxy hostname is stripped off, and is
meaningless to Crypt::SSLeay.
HELP
;
exit;
}
if($opt_help) {
&help;
};
if($opt_debug) {
eval "use LWP::Debug qw(+)";
}
my $method = (@ARGV && $ARGV[0] =~ /^[A-Z]+$/) ? shift : "HEAD";
my($host, $port, $path);
if($opt_bench) {
$host = shift || die("need host, run like ./$basename HEAD yourhost.com.foo");
} else {
$host = shift || "www.nodeworks.com";
}
if($host =~ m|^(https://)?([^/:]+)(:(\d+))?(/.*)?$|) {
($host, $port, $path) = ($2, $4, $5);
}
$port ||= shift || 443;
$path ||= '/';
if($opt_n) {
$ENV{NO_PROXY} = $opt_n;
}
$ENV{HTTPS_PROXY} = $opt_p;
$ENV{HTTPS_CERT_FILE} = $opt_cert;
$ENV{HTTPS_KEY_FILE} = $opt_key;
$opt_cafile && ( $ENV{HTTPS_CA_FILE} = $opt_cafile );
$opt_cadir && ( $ENV{HTTPS_CA_DIR} = $opt_cadir );
if($opt_version) {
grep($opt_version eq $_, '2', '3', '23')
|| die("$opt_version must be one of 2, 3, or 23");
$ENV{HTTPS_VERSION} = $opt_version;
}
unless(eval { &ssl_connect() }) {
print <<OUT;
== FAILED TO CONNECT ==
Error: $@
If you need to use a proxy, please pass it in as an argument like
./net_ssl_test -p 127.0.0.1:8080
which sets \$ENV{HTTPS_PROXY} for you.
OUT
;
}
if($opt_bench) {
timethis($opt_bench, sub { &ssl_connect() });
}
sub ssl_connect {
my $sock = Net::SSL->new(
PeerAddr => $host,
PeerPort => $port,
SSL_Debug => $opt_debug,
Timeout => 15,
);
$sock || ($@ ||= "no Net::SSL connection established");
my $error = $@;
$error && die("Can't connect to $host:$port; $error; $!");
my $out;
$out .= "WEB SITE : $host:$port\n";
$out .= "CIPHER : ".$sock->get_cipher."\n";
my $cert = $sock->get_peer_certificate;
$out .= "CERT SUBJECT : ".$cert->subject_name."\n";
$out .= "CERTIFIED BY : ".$cert->issuer_name."\n";
$out .= "CERT NOT BEFORE: ".$cert->not_before."\n";
$out .= "CERT NOT AFTER : ".$cert->not_after."\n";
$out .= "\n";
$sock->print("$method $path HTTP/1.0\n\n");
print $out;
$out = '';
my $buf = '';
while ($sock->read($buf, 1024)) {
$out .= $buf;
}
unless($opt_bench) {
print $out;
}
1;
}
|