2016-04-22 19:21:51 +08:00
|
|
|
#! /usr/bin/env perl
|
|
|
|
# Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
|
|
|
|
#
|
2018-12-06 20:05:25 +08:00
|
|
|
# Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-04-22 19:21:51 +08:00
|
|
|
# this file except in compliance with the License. You can obtain a copy
|
|
|
|
# in the file LICENSE in the source distribution or at
|
|
|
|
# https://www.openssl.org/source/license.html
|
|
|
|
|
2015-04-20 04:24:17 +08:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use POSIX;
|
2016-02-22 04:54:30 +08:00
|
|
|
use File::Path 2.00 qw/rmtree/;
|
2016-01-30 08:05:33 +08:00
|
|
|
use OpenSSL::Test qw/:DEFAULT cmdstr srctop_file/;
|
2017-03-03 01:27:17 +08:00
|
|
|
use OpenSSL::Test::Utils;
|
2015-04-20 04:24:17 +08:00
|
|
|
|
|
|
|
setup("test_ca");
|
|
|
|
|
2016-04-01 21:09:28 +08:00
|
|
|
$ENV{OPENSSL} = cmdstr(app(["openssl"]), display => 1);
|
2016-01-30 08:05:33 +08:00
|
|
|
my $std_openssl_cnf =
|
|
|
|
srctop_file("apps", $^O eq "VMS" ? "openssl-vms.cnf" : "openssl.cnf");
|
2015-04-20 04:24:17 +08:00
|
|
|
|
2016-02-22 04:54:30 +08:00
|
|
|
rmtree("demoCA", { safe => 0 });
|
2015-04-20 04:24:17 +08:00
|
|
|
|
2019-06-05 14:46:48 +08:00
|
|
|
plan tests => 6;
|
2015-04-20 04:24:17 +08:00
|
|
|
SKIP: {
|
2016-05-25 21:03:08 +08:00
|
|
|
$ENV{OPENSSL_CONFIG} = '-config "'.srctop_file("test", "CAss.cnf").'"';
|
2017-03-03 01:26:26 +08:00
|
|
|
skip "failed creating CA structure", 4
|
2016-03-30 01:38:30 +08:00
|
|
|
if !ok(run(perlapp(["CA.pl","-newca"], stdin => undef)),
|
2015-04-20 04:24:17 +08:00
|
|
|
'creating CA structure');
|
|
|
|
|
2016-05-25 21:03:08 +08:00
|
|
|
$ENV{OPENSSL_CONFIG} = '-config "'.srctop_file("test", "Uss.cnf").'"';
|
2017-03-03 01:26:26 +08:00
|
|
|
skip "failed creating new certificate request", 3
|
2016-03-30 01:38:30 +08:00
|
|
|
if !ok(run(perlapp(["CA.pl","-newreq"])),
|
2016-10-12 05:52:09 +08:00
|
|
|
'creating certificate request');
|
2015-04-20 04:24:17 +08:00
|
|
|
|
2017-08-17 03:49:25 +08:00
|
|
|
$ENV{OPENSSL_CONFIG} = '-rand_serial -config "'.$std_openssl_cnf.'"';
|
2017-03-03 01:26:26 +08:00
|
|
|
skip "failed to sign certificate request", 2
|
2016-03-30 01:38:30 +08:00
|
|
|
if !is(yes(cmdstr(perlapp(["CA.pl", "-sign"]))), 0,
|
2015-04-20 04:24:17 +08:00
|
|
|
'signing certificate request');
|
|
|
|
|
2016-03-30 01:38:30 +08:00
|
|
|
ok(run(perlapp(["CA.pl", "-verify", "newcert.pem"])),
|
2016-10-12 05:52:09 +08:00
|
|
|
'verifying new certificate');
|
2016-03-11 04:26:34 +08:00
|
|
|
|
2017-03-03 01:27:17 +08:00
|
|
|
skip "CT not configured, can't use -precert", 1
|
|
|
|
if disabled("ct");
|
|
|
|
|
2017-08-03 05:28:34 +08:00
|
|
|
$ENV{OPENSSL_CONFIG} = '-config "'.srctop_file("test", "Uss.cnf").'"';
|
2017-01-14 03:06:03 +08:00
|
|
|
ok(run(perlapp(["CA.pl", "-precert"], stderr => undef)),
|
2016-03-11 04:26:34 +08:00
|
|
|
'creating new pre-certificate');
|
2015-04-20 04:24:17 +08:00
|
|
|
}
|
|
|
|
|
2019-06-05 14:46:48 +08:00
|
|
|
SKIP: {
|
|
|
|
skip "SM2 is not supported by this OpenSSL build", 1
|
|
|
|
if disabled("sm2");
|
|
|
|
|
|
|
|
is(yes(cmdstr(app(["openssl", "ca", "-config",
|
|
|
|
srctop_file("test", "CAss.cnf"),
|
|
|
|
"-in", srctop_file("test", "certs", "sm2-csr.pem"),
|
|
|
|
"-out", "sm2-test.crt",
|
2020-03-11 06:10:29 +08:00
|
|
|
"-sigopt", "distid:1234567812345678",
|
|
|
|
"-vfyopt", "distid:1234567812345678",
|
2019-06-05 14:46:48 +08:00
|
|
|
"-md", "sm3",
|
|
|
|
"-cert", srctop_file("test", "certs", "sm2-root.crt"),
|
|
|
|
"-keyfile", srctop_file("test", "certs", "sm2-root.key")]))),
|
|
|
|
0,
|
|
|
|
"Signing SM2 certificate request");
|
|
|
|
}
|
2015-04-20 04:24:17 +08:00
|
|
|
|
|
|
|
sub yes {
|
2016-01-13 22:16:41 +08:00
|
|
|
my $cntr = 10;
|
2015-04-20 04:24:17 +08:00
|
|
|
open(PIPE, "|-", join(" ",@_));
|
|
|
|
local $SIG{PIPE} = "IGNORE";
|
2016-01-13 22:16:41 +08:00
|
|
|
1 while $cntr-- > 0 && print PIPE "y\n";
|
2015-04-20 04:24:17 +08:00
|
|
|
close PIPE;
|
|
|
|
return 0;
|
|
|
|
}
|
2016-01-30 08:05:33 +08:00
|
|
|
|