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