80-test_ca.t 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. use strict;
  9. use warnings;
  10. use POSIX;
  11. use File::Path 2.00 qw/rmtree/;
  12. use OpenSSL::Test qw/:DEFAULT cmdstr srctop_file/;
  13. use OpenSSL::Test::Utils;
  14. setup("test_ca");
  15. $ENV{OPENSSL} = cmdstr(app(["openssl"]), display => 1);
  16. my $std_openssl_cnf =
  17. srctop_file("apps", $^O eq "VMS" ? "openssl-vms.cnf" : "openssl.cnf");
  18. rmtree("demoCA", { safe => 0 });
  19. plan tests => 5;
  20. SKIP: {
  21. $ENV{OPENSSL_CONFIG} = '-config "'.srctop_file("test", "CAss.cnf").'"';
  22. skip "failed creating CA structure", 4
  23. if !ok(run(perlapp(["CA.pl","-newca"], stdin => undef)),
  24. 'creating CA structure');
  25. $ENV{OPENSSL_CONFIG} = '-config "'.srctop_file("test", "Uss.cnf").'"';
  26. skip "failed creating new certificate request", 3
  27. if !ok(run(perlapp(["CA.pl","-newreq"])),
  28. 'creating certificate request');
  29. $ENV{OPENSSL_CONFIG} = '-rand_serial -config "'.$std_openssl_cnf.'"';
  30. skip "failed to sign certificate request", 2
  31. if !is(yes(cmdstr(perlapp(["CA.pl", "-sign"]))), 0,
  32. 'signing certificate request');
  33. ok(run(perlapp(["CA.pl", "-verify", "newcert.pem"])),
  34. 'verifying new certificate');
  35. skip "CT not configured, can't use -precert", 1
  36. if disabled("ct");
  37. $ENV{OPENSSL_CONFIG} = '-config "'.srctop_file("test", "Uss.cnf").'"';
  38. ok(run(perlapp(["CA.pl", "-precert"], stderr => undef)),
  39. 'creating new pre-certificate');
  40. }
  41. rmtree("demoCA", { safe => 0 });
  42. unlink "newcert.pem", "newreq.pem", "newkey.pem";
  43. sub yes {
  44. my $cntr = 10;
  45. open(PIPE, "|-", join(" ",@_));
  46. local $SIG{PIPE} = "IGNORE";
  47. 1 while $cntr-- > 0 && print PIPE "y\n";
  48. close PIPE;
  49. return 0;
  50. }