Cleanup on exit in Test-https-*.px

* tests/Test-https-*.px: Cleanup on exit
This commit is contained in:
Tim Rühsen 2017-05-09 16:58:33 +02:00
parent 4669ba5e0c
commit 2894a37189
5 changed files with 71 additions and 12 deletions

View File

@ -6,8 +6,10 @@ use POSIX;
use Socket;
use WgetFeature qw(https ssl/openssl);
use SSLTest;
use File::Remove 'remove';
###############################################################################
my @tempfiles;
# code, msg, headers, content
my %urls = (
@ -54,17 +56,20 @@ unless (inet_ntoa($addr) =~ "127.0.0.1")
}
# Create certindex
push (@tempfiles, "$cdir/certindex");
open CERTID, ">", "$cdir/certindex" or
warn "Cannot overwrite file $cdir/certindex";
close CERTID;
# Create certserial
push (@tempfiles, "$cdir/certserial");
open CERTSN, ">", "$cdir/certserial" or
warn "Cannot overwrite file $cdir/certserial";
print CERTSN "1122";
close CERTSN;
# Create crlnumber
push (@tempfiles, "$cdir/crlnumber");
open CRLN, ">", "$cdir/crlnumber" or
warn "Cannot overwrite file $cdir/crlnumber";
print CRLN "1122";
@ -172,3 +177,8 @@ else
exit -1;
}
# vim: et ts=4 sw=4
END {
print "remove(@tempfiles);";
remove(@tempfiles);
}

View File

@ -5,8 +5,10 @@ use warnings;
use Socket;
use WgetFeature qw(https);
use SSLTest;
use File::Remove 'remove';
###############################################################################
my @tempfiles;
# code, msg, headers, content
my %urls = (
@ -53,19 +55,25 @@ unless (inet_ntoa($addr) =~ "127.0.0.1")
}
# Create certindex
open CERTID, ">", "$cdir/certindex" or
warn "Cannot overwrite file $cdir/certindex";
my $certindex = "$cdir/certindex";
push (@tempfiles, $certindex);
open CERTID, ">", $certindex or
warn "Cannot overwrite file $certindex";
close CERTID;
# Create certserial
open CERTSN, ">", "$cdir/certserial" or
warn "Cannot overwrite file $cdir/certserial";
my $certserial = "$cdir/certserial";
push (@tempfiles, $certserial);
open CERTSN, ">", $certserial or
warn "Cannot overwrite file $certserial";
print CERTSN "1122";
close CERTSN;
# Create crlnumber
open CRLN, ">", "$cdir/crlnumber" or
warn "Cannot overwrite file $cdir/crlnumber";
my $crlnumber = "$cdir/crlnumber";
push (@tempfiles, $crlnumber);
open CRLN, ">", $crlnumber or
warn "Cannot overwrite file $crlnumber";
close CRLN;
my $caconf = "$srcdir/certs/rootca.conf";
@ -73,9 +81,11 @@ my $cacrt = "$srcdir/certs/test-ca-cert.pem";
my $cakey = "$srcdir/certs/test-ca-key.pem";
# Prepare server certificate
my $servercrt = "$cdir/tmpserver1.crt";
my $serverkey = "$cdir/tmpserver1.key";
my $servercsr = "$cdir/tmpserver.csr";
my $servercrt = "$cdir/tmpserver$$.crt";
my $serverkey = "$cdir/tmpserver$$.key";
my $servercsr = "$cdir/tmpserver$$.csr";
push (@tempfiles, , $servercrt, $serverkey, $servercsr);
my $serversubj = "/C=US/ST=CA/L=Server Mystery Spot/O=Serv/CN=".
"$testhostname/emailAddress=servertester";
my $servercmd = "openssl genrsa -out $serverkey 4096 && openssl req -new".
@ -98,6 +108,7 @@ unless(-e $servercrt && -e $serverkey && $servercheck == 1)
my $clientcert = "$cdir/client.crt";
my $clientkey = "$cdir/client.key";
my $clientcsr = "$cdir/client.csr";
push (@tempfiles, , $clientcert, $clientkey, $clientcsr);
my $clientsubj = "/C=US/ST=CA/L=Client Mystery Spot/O=Client/CN=".
"Client Tester/emailAddress=clienttester";
my $clientcertcmd = "openssl genrsa -out $clientkey 4096 &&".
@ -167,3 +178,8 @@ my $retryssl = SSLTest->new(cmdline => $cmdline,
sslport => $port);
exit $retryssl->run();
# vim: et ts=4 sw=4
END {
print "remove(@tempfiles);\n";
remove(@tempfiles);
}

View File

@ -5,8 +5,10 @@ use warnings;
use Socket;
use WgetFeature qw(https);
use SSLTest;
use File::Remove 'remove';
###############################################################################
my @tempfiles;
# code, msg, headers, content
my %urls = (
@ -53,17 +55,20 @@ unless (inet_ntoa($addr) =~ "127.0.0.1")
}
# Create certindex
push (@tempfiles, "$cdir/certindex");
open CERTID, ">", "$cdir/certindex" or
warn "Cannot overwrite file $cdir/certindex";
close CERTID;
# Create certserial
push (@tempfiles, "$cdir/certserial");
open CERTSN, ">", "$cdir/certserial" or
warn "Cannot overwrite file $cdir/certserial";
print CERTSN "1122";
close CERTSN;
# Create crlnumber
push (@tempfiles, "$cdir/crlnumber");
open CRLN, ">", "$cdir/crlnumber" or
warn "Cannot overwrite file $cdir/crlnumber";
print CRLN "1122";
@ -74,9 +79,10 @@ my $cacrt = "$srcdir/certs/test-ca-cert.pem";
my $cakey = "$srcdir/certs/test-ca-key.pem";
# Prepare server certificate
my $servercrt = "$cdir/tmpserver2.crt";
my $serverkey = "$cdir/tmpserver2.key";
my $servercsr = "$cdir/tmpserver.csr";
my $servercrt = "$cdir/tmpserver$$.crt";
my $serverkey = "$cdir/tmpserver$$.key";
my $servercsr = "$cdir/tmpserver$$.csr";
push (@tempfiles, $servercrt, $serverkey, $servercsr);
my $serversubj = "/C=US/ST=CA/L=Server Mystery Spot/O=Serv/CN=".
"$testhostname/emailAddress=servertester";
my $servercmd = "openssl genrsa -out $serverkey 4096 && openssl req -new".
@ -126,6 +132,7 @@ if ($sslsock->run() != 0)
# Revoke the certificate
my $crlfile = "$cdir/servercrl.pem";
push (@tempfiles, $crlfile);
my $revokecmd = "openssl ca -config $caconf -revoke $servercrt &&
openssl ca -config $caconf -gencrl -keyfile $cakey ".
"-cert $cacrt -out $crlfile";
@ -167,3 +174,8 @@ else
exit 0;
}
# vim: et ts=4 sw=4
END {
print "remove(@tempfiles);\n";
remove(@tempfiles);
}

View File

@ -5,8 +5,10 @@ use warnings;
use Socket;
use WgetFeature qw(https);
use SSLTest;
use File::Remove 'remove';
###############################################################################
my @tempfiles;
# code, msg, headers, content
my %urls = (
@ -55,6 +57,7 @@ unless (inet_ntoa($addr) =~ "127.0.0.1")
# Prepare self-signed certificates
my $certfile="$cdir/tmpsscert.pem";
my $keyfile="$cdir/tmpsskey.pem";
push (@tempfiles, $certfile, $keyfile);
my $certsubj="/C=US/ST=CA/L=Mystery Spot/O=Dis/CN=$testhostname/emailAddress=tester";
my $sscertcmd="openssl req -x509 -nodes -newkey rsa:4096 -keyout $keyfile ".
" -out $certfile -days 365 -subj \"$certsubj\"";
@ -117,3 +120,8 @@ my $retryssl = SSLTest->new(cmdline => $cmdline,
sslport => $port);
exit $retryssl->run();
# vim: et ts=4 sw=4
END {
print "remove(@tempfiles);\n";
remove(@tempfiles);
}

View File

@ -5,8 +5,10 @@ use warnings;
use Socket;
use WgetFeature qw(https);
use SSLTest;
use File::Remove 'remove';
###############################################################################
my @tempfiles;
# code, msg, headers, content
my %urls = (
@ -53,17 +55,20 @@ unless (inet_ntoa($addr) =~ "127.0.0.1")
}
# Create certindex
push (@tempfiles, "$cdir/certindex");
open CERTID, ">", "$cdir/certindex" or
warn "Cannot overwrite file $cdir/certindex";
close CERTID;
# Create certserial
push (@tempfiles, "$cdir/certserial");
open CERTSN, ">", "$cdir/certserial" or
warn "Cannot overwrite file $cdir/certserial";
print CERTSN "1122";
close CERTSN;
# Create crlnumber
push (@tempfiles, "$cdir/crlnumber");
open CRLN, ">", "$cdir/crlnumber" or
warn "Cannot overwrite file $cdir/crlnumber";
close CRLN;
@ -73,6 +78,7 @@ my $caconf = "$srcdir/certs/rootca.conf";
my $icrtfile = "$cdir/interca.crt";
my $ikeyfile = "$cdir/interca.key";
my $icsrfile = "$cdir/interca.csr";
push (@tempfiles, $icrtfile, $ikeyfile, $icsrfile);
my $icasubj = "/C=US/ST=CA/L=Intermediate Mystery Spot/O=Int/CN=".
"ica-$testhostname/emailAddress=icatester";
my $icacmd = "openssl genrsa -out $ikeyfile 4096 && openssl req -new".
@ -92,6 +98,7 @@ unless(-e $icrtfile && -e $ikeyfile && $icacheck == 1)
}
# Now create web of trust - Root CA + Intermediate CA
push (@tempfiles, "$cdir/wotca.pem");
open WOT, ">", "$cdir/wotca.pem" or
die "Cannot overwrite file $cdir/wotca";
open ICA, "<", $icrtfile or die "Cannot read file $icrtfile";
@ -116,6 +123,7 @@ my $icaconf = "$srcdir/certs/interca.conf";
my $usrcrt = "$cdir/user.crt";
my $usrkey = "$cdir/user.key";
my $usrcsr = "$cdir/user.csr";
push (@tempfiles, $usrcrt, $usrkey, $usrcsr);
my $usrsubj = "/C=US/ST=CA/L=User Mystery Spot/O=Int/CN=$testhostname/".
"emailAddress=usertester";
my $usrcmd = "openssl genrsa -out $usrkey 4096 && ".
@ -179,3 +187,8 @@ my $retryssl = SSLTest->new(cmdline => $cmdline,
sslport => $port);
exit $retryssl->run();
# vim: et ts=4 sw=4
END {
print "remove(@tempfiles);\n";
remove(@tempfiles);
}