]> git.ipfire.org Git - thirdparty/openssl.git/blame - test/recipes/80-test_ca.t
Documentation for the -precert flag for "openssl req"
[thirdparty/openssl.git] / test / recipes / 80-test_ca.t
CommitLineData
596d6b7e
RS
1#! /usr/bin/env perl
2# Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
3#
4# Licensed under the OpenSSL license (the "License"). You may not use
5# this file except in compliance with the License. You can obtain a copy
6# in the file LICENSE in the source distribution or at
7# https://www.openssl.org/source/license.html
8
88b8a527
RL
9
10use strict;
11use warnings;
12
13use POSIX;
e9fd82f6 14use File::Path 2.00 qw/rmtree/;
42e0ccdf 15use OpenSSL::Test qw/:DEFAULT cmdstr srctop_file/;
88b8a527
RL
16
17setup("test_ca");
18
25c78440 19$ENV{OPENSSL} = cmdstr(app(["openssl"]), display => 1);
42e0ccdf
RL
20my $std_openssl_cnf =
21 srctop_file("apps", $^O eq "VMS" ? "openssl-vms.cnf" : "openssl.cnf");
88b8a527 22
e9fd82f6 23rmtree("demoCA", { safe => 0 });
88b8a527 24
caee75d2 25plan tests => 5;
88b8a527 26 SKIP: {
ac1a998d 27 $ENV{OPENSSL_CONFIG} = '-config "'.srctop_file("test", "CAss.cnf").'"';
88b8a527 28 skip "failed creating CA structure", 3
7d9b2d53 29 if !ok(run(perlapp(["CA.pl","-newca"], stdin => undef)),
88b8a527
RL
30 'creating CA structure');
31
ac1a998d 32 $ENV{OPENSSL_CONFIG} = '-config "'.srctop_file("test", "Uss.cnf").'"';
88b8a527 33 skip "failed creating new certificate request", 2
7d9b2d53 34 if !ok(run(perlapp(["CA.pl","-newreq"])),
32804b04 35 'creating certificate request');
88b8a527 36
ac1a998d 37 $ENV{OPENSSL_CONFIG} = '-config "'.$std_openssl_cnf.'"';
88b8a527 38 skip "failed to sign certificate request", 1
7d9b2d53 39 if !is(yes(cmdstr(perlapp(["CA.pl", "-sign"]))), 0,
88b8a527
RL
40 'signing certificate request');
41
7d9b2d53 42 ok(run(perlapp(["CA.pl", "-verify", "newcert.pem"])),
32804b04 43 'verifying new certificate');
caee75d2
RP
44
45 $ENV{OPENSSL_CONFIG} = "-config ".srctop_file("test", "Uss.cnf");
46 ok(run(perlapp(["CA.pl", "-newprecert"], stderr => undef)),
47 'creating new pre-certificate');
88b8a527
RL
48}
49
50
e9fd82f6 51rmtree("demoCA", { safe => 0 });
c9d24373 52unlink "newcert.pem", "newreq.pem", "newkey.pem";
88b8a527
RL
53
54
55sub yes {
4034c38b 56 my $cntr = 10;
88b8a527
RL
57 open(PIPE, "|-", join(" ",@_));
58 local $SIG{PIPE} = "IGNORE";
4034c38b 59 1 while $cntr-- > 0 && print PIPE "y\n";
88b8a527
RL
60 close PIPE;
61 return 0;
62}
42e0ccdf 63