80-test_ca.t 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #! /usr/bin/env perl
  2. # Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
  3. #
  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
  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 => 6;
  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. SKIP: {
  42. skip "SM2 is not supported by this OpenSSL build", 1
  43. if disabled("sm2");
  44. is(yes(cmdstr(app(["openssl", "ca", "-config",
  45. srctop_file("test", "CAss.cnf"),
  46. "-in", srctop_file("test", "certs", "sm2-csr.pem"),
  47. "-out", "sm2-test.crt",
  48. "-sigopt", "sm2_id:1234567812345678",
  49. "-sm2-id", "1234567812345678",
  50. "-md", "sm3",
  51. "-cert", srctop_file("test", "certs", "sm2-root.crt"),
  52. "-keyfile", srctop_file("test", "certs", "sm2-root.key")]))),
  53. 0,
  54. "Signing SM2 certificate request");
  55. }
  56. rmtree("demoCA", { safe => 0 });
  57. unlink "newcert.pem", "newreq.pem", "newkey.pem", "sm2-test.crt";
  58. sub yes {
  59. my $cntr = 10;
  60. open(PIPE, "|-", join(" ",@_));
  61. local $SIG{PIPE} = "IGNORE";
  62. 1 while $cntr-- > 0 && print PIPE "y\n";
  63. close PIPE;
  64. return 0;
  65. }