2 # Copyright 2015-2020 The OpenSSL Project Authors. All Rights Reserved.
4 # Licensed under the Apache License 2.0 (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
14 use File::Path 2.00 qw/rmtree/;
15 use OpenSSL::Test qw/:DEFAULT cmdstr srctop_file/;
16 use OpenSSL::Test::Utils;
20 $ENV{OPENSSL} = cmdstr(app(["openssl"]), display => 1);
22 my $cnf = '"' . srctop_file("test","ca-and-certs.cnf") . '"';;
23 my $std_openssl_cnf = '"'
24 . srctop_file("apps", $^O eq "VMS" ? "openssl-vms.cnf" : "openssl.cnf")
27 rmtree("demoCA", { safe => 0 });
31 $ENV{OPENSSL_CONFIG} = '-config ' . $cnf;
32 skip "failed creating CA structure", 4
33 if !ok(run(perlapp(["CA.pl","-newca"], stdin => undef)),
34 'creating CA structure');
36 $ENV{OPENSSL_CONFIG} = '-config ' . $cnf;
37 skip "failed creating new certificate request", 3
38 if !ok(run(perlapp(["CA.pl","-newreq",
39 '-extra-req', '-outform DER -section userreq'])),
40 'creating certificate request');
41 $ENV{OPENSSL_CONFIG} = '-rand_serial -inform DER -config '.$std_openssl_cnf;
42 skip "failed to sign certificate request", 2
43 if !is(yes(cmdstr(perlapp(["CA.pl", "-sign"]))), 0,
44 'signing certificate request');
46 ok(run(perlapp(["CA.pl", "-verify", "newcert.pem"])),
47 'verifying new certificate');
49 skip "CT not configured, can't use -precert", 1
52 $ENV{OPENSSL_CONFIG} = '-config ' . $cnf;
53 ok(run(perlapp(["CA.pl", "-precert", '-extra-req', '-section userreq'], stderr => undef)),
54 'creating new pre-certificate');
58 skip "SM2 is not supported by this OpenSSL build", 1
61 is(yes(cmdstr(app(["openssl", "ca", "-config",
63 "-in", srctop_file("test", "certs", "sm2-csr.pem"),
64 "-out", "sm2-test.crt",
65 "-sigopt", "distid:1234567812345678",
66 "-vfyopt", "distid:1234567812345678",
68 "-cert", srctop_file("test", "certs", "sm2-root.crt"),
69 "-keyfile", srctop_file("test", "certs", "sm2-root.key")]))),
71 "Signing SM2 certificate request");
76 open(PIPE, "|-", join(" ",@_));
77 local $SIG{PIPE} = "IGNORE";
78 1 while $cntr-- > 0 && print PIPE "y\n";