| 1 |
#!/usr/bin/env perl |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
use Socket; |
| 6 |
use WgetFeature qw(https); |
| 7 |
use SSLTest; |
| 8 |
|
| 9 |
############################################################################### |
| 10 |
|
| 11 |
# code, msg, headers, content |
| 12 |
my %urls = ( |
| 13 |
'/somefile.txt' => { |
| 14 |
code => "200", |
| 15 |
msg => "Dontcare", |
| 16 |
headers => { |
| 17 |
"Content-type" => "text/plain", |
| 18 |
}, |
| 19 |
content => "blabla", |
| 20 |
}, |
| 21 |
); |
| 22 |
|
| 23 |
my $srcdir; |
| 24 |
if (@ARGV) { |
| 25 |
$srcdir = shift @ARGV; |
| 26 |
} elsif (defined $ENV{srcdir}) { |
| 27 |
$srcdir = $ENV{srcdir}; |
| 28 |
} |
| 29 |
$srcdir = Cwd::abs_path("$srcdir"); |
| 30 |
|
| 31 |
# HOSTALIASES env variable allows us to create hosts file alias. |
| 32 |
my $testhostname = "WgetTestingServer"; |
| 33 |
$ENV{'HOSTALIASES'} = "$srcdir/certs/wgethosts"; |
| 34 |
|
| 35 |
my $addr = gethostbyname($testhostname); |
| 36 |
unless ($addr) |
| 37 |
{ |
| 38 |
warn "Failed to resolve $testhostname, using $srcdir/certs/wgethosts\n"; |
| 39 |
exit 77; |
| 40 |
} |
| 41 |
unless (inet_ntoa($addr) =~ "127.0.0.1") |
| 42 |
{ |
| 43 |
warn "Unexpected IP for localhost: ".inet_ntoa($addr)."\n"; |
| 44 |
exit 77; |
| 45 |
} |
| 46 |
|
| 47 |
my $cacrt = "$srcdir/certs/test-ca-cert.pem"; |
| 48 |
|
| 49 |
# Use a revoked certificate |
| 50 |
my $servercrt = "$srcdir/certs/server-cert.pem"; |
| 51 |
my $serverkey = "$srcdir/certs/server-key.pem"; |
| 52 |
|
| 53 |
# Try Wget using SSL first without --no-check-certificate. Expect Success. |
| 54 |
my $port = 32443; |
| 55 |
my $cmdline = $WgetTest::WGETPATH . " --ca-certificate=$cacrt". |
| 56 |
" https://$testhostname:$port/somefile.txt"; |
| 57 |
my $expected_error_code = 0; |
| 58 |
my %existing_files = ( |
| 59 |
); |
| 60 |
|
| 61 |
my %expected_downloaded_files = ( |
| 62 |
'somefile.txt' => { |
| 63 |
content => "blabla", |
| 64 |
}, |
| 65 |
); |
| 66 |
|
| 67 |
my $sslsock = SSLTest->new(cmdline => $cmdline, |
| 68 |
input => \%urls, |
| 69 |
errcode => $expected_error_code, |
| 70 |
existing => \%existing_files, |
| 71 |
output => \%expected_downloaded_files, |
| 72 |
certfile => $servercrt, |
| 73 |
keyfile => $serverkey, |
| 74 |
lhostname => $testhostname, |
| 75 |
sslport => $port); |
| 76 |
if ($sslsock->run() != 0) |
| 77 |
{ |
| 78 |
exit -1; |
| 79 |
} |
| 80 |
|
| 81 |
# Revoke the certificate |
| 82 |
my $crlfile = "$srcdir/certs/revoked-crl.pem"; |
| 83 |
|
| 84 |
# Retry the test with CRL. Expect Failure. |
| 85 |
$port = 23443; |
| 86 |
$cmdline = $WgetTest::WGETPATH . " --crl-file=$crlfile ". |
| 87 |
" --ca-certificate=$cacrt". |
| 88 |
" https://$testhostname:$port/somefile.txt"; |
| 89 |
|
| 90 |
$expected_error_code = 5; |
| 91 |
|
| 92 |
my $retryssl = SSLTest->new(cmdline => $cmdline, |
| 93 |
input => \%urls, |
| 94 |
errcode => $expected_error_code, |
| 95 |
existing => \%existing_files, |
| 96 |
certfile => $servercrt, |
| 97 |
keyfile => $serverkey, |
| 98 |
lhostname => $testhostname, |
| 99 |
sslport => $port); |
| 100 |
exit $retryssl->run(); |
| 101 |
# vim: et ts=4 sw=4 |