2015-04-19 20:24:17 +00:00
|
|
|
#! /usr/bin/perl
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use POSIX;
|
2015-04-28 18:39:09 +00:00
|
|
|
use File::Path 2.00 qw/remove_tree/;
|
2016-01-26 14:01:00 +00:00
|
|
|
use OpenSSL::Test qw/:DEFAULT cmdstr top_file/;
|
2015-04-19 20:24:17 +00:00
|
|
|
|
|
|
|
setup("test_ca");
|
|
|
|
|
|
|
|
$ENV{OPENSSL} = cmdstr(app(["openssl"]));
|
2016-01-13 14:16:41 +00:00
|
|
|
my $std_openssl_cnf = $^O eq "VMS"
|
|
|
|
? top_file("apps", "openssl-vms.cnf") : top_file("apps", "openssl.cnf");
|
2015-04-19 20:24:17 +00:00
|
|
|
|
|
|
|
remove_tree("demoCA", { safe => 0 });
|
|
|
|
|
|
|
|
plan tests => 4;
|
|
|
|
SKIP: {
|
2015-10-27 19:11:48 +00:00
|
|
|
$ENV{OPENSSL_CONFIG} = "-config ".top_file("test", "CAss.cnf");
|
2015-04-19 20:24:17 +00:00
|
|
|
skip "failed creating CA structure", 3
|
2016-01-26 14:01:00 +00:00
|
|
|
if !ok(run(perlapp(["CA.pl","-newca"], stdin => undef, stderr => undef)),
|
2015-04-19 20:24:17 +00:00
|
|
|
'creating CA structure');
|
|
|
|
|
2015-10-27 19:11:48 +00:00
|
|
|
$ENV{OPENSSL_CONFIG} = "-config ".top_file("test", "Uss.cnf");
|
2015-04-19 20:24:17 +00:00
|
|
|
skip "failed creating new certificate request", 2
|
2016-01-26 14:01:00 +00:00
|
|
|
if !ok(run(perlapp(["CA.pl","-newreq"], stderr => undef)),
|
|
|
|
'creating CA structure');
|
2015-04-19 20:24:17 +00:00
|
|
|
|
2015-10-27 19:11:48 +00:00
|
|
|
$ENV{OPENSSL_CONFIG} = "-config ".$std_openssl_cnf;
|
2015-04-19 20:24:17 +00:00
|
|
|
skip "failed to sign certificate request", 1
|
2016-01-26 14:01:00 +00:00
|
|
|
if !is(yes(cmdstr(perlapp(["CA.pl", "-sign"], stderr => undef))), 0,
|
2015-04-19 20:24:17 +00:00
|
|
|
'signing certificate request');
|
|
|
|
|
2016-01-26 14:01:00 +00:00
|
|
|
ok(run(perlapp(["CA.pl", "-verify", "newcert.pem"], stderr => undef)),
|
2015-04-19 20:24:17 +00:00
|
|
|
'verifying new certificate');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
remove_tree("demoCA", { safe => 0 });
|
|
|
|
unlink "newcert.pem", "newreq.pem";
|
|
|
|
|
|
|
|
|
|
|
|
sub yes {
|
2016-01-13 14:16:41 +00:00
|
|
|
my $cntr = 10;
|
2015-04-19 20:24:17 +00:00
|
|
|
open(PIPE, "|-", join(" ",@_));
|
|
|
|
local $SIG{PIPE} = "IGNORE";
|
2016-01-13 14:16:41 +00:00
|
|
|
1 while $cntr-- > 0 && print PIPE "y\n";
|
2015-04-19 20:24:17 +00:00
|
|
|
close PIPE;
|
|
|
|
return 0;
|
|
|
|
}
|