perl: Separate compile-time environment from runtime environment
[openssl.git] / apps / CA.pl.in
index 5c8cdd09f29f1a6862d0d9b241c95363ec036a26..3187e473d236f5d1e2ba0ec83c6b52b332cf2544 100644 (file)
@@ -1,8 +1,15 @@
-#!/usr/bin/perl
+#!{- $config{hashbangperl} -}
+# Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
 #
-# Wrapper around the ca to make it easier to use
-# Edit CA.pl.in not CA.pl!
+# Licensed under the OpenSSL license (the "License").  You may not use
+# 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
 
+#
+# Wrapper around the ca to make it easier to use
+#
+# {- join("\n# ", @autowarntext) -}
 
 use strict;
 use warnings;
@@ -16,11 +23,11 @@ if(defined $ENV{'OPENSSL'}) {
 
 my $verbose = 1;
 
-my $SSLEAY_CONFIG = $ENV{"SSLEAY_CONFIG"};
+my $OPENSSL_CONFIG = $ENV{"OPENSSL_CONFIG"} || "";
 my $DAYS = "-days 365";
 my $CADAYS = "-days 1095";     # 3 years
-my $REQ = "$openssl req $SSLEAY_CONFIG";
-my $CA = "$openssl ca $SSLEAY_CONFIG";
+my $REQ = "$openssl req $OPENSSL_CONFIG";
+my $CA = "$openssl ca $OPENSSL_CONFIG";
 my $VERIFY = "$openssl verify";
 my $X509 = "$openssl x509";
 my $PKCS12 = "$openssl pkcs12";
@@ -38,7 +45,7 @@ my $NEWREQ = "newreq.pem";
 my $NEWCERT = "newcert.pem";
 my $NEWP12 = "newcert.p12";
 my $RET = 0;
-my $WHAT = shift @ARGV;
+my $WHAT = shift @ARGV || "";
 my $FILE;
 
 # See if reason for a CRL entry is valid; exit if not.
@@ -89,7 +96,7 @@ sub run
 
 
 if ( $WHAT =~ /^(-\?|-h|-help)$/ ) {
-    print STDERR "usage: CA -newcert|-newreq|-newreq-nodes|-newca|-sign|-verify\n";
+    print STDERR "usage: CA -newcert|-newreq|-newreq-nodes|-newca|-sign|-signcert|-verify\n";
     print STDERR "       CA -pkcs12 [certname]\n";
     print STDERR "       CA -crl|-revoke cert-filename [reason]\n";
     exit 0;
@@ -120,9 +127,9 @@ if ($WHAT eq '-newcert' ) {
     close OUT;
     # ask user for existing CA certificate
     print "CA certificate filename (or enter to create)\n";
-    $FILE = <STDIN>;
-    chop $FILE if $FILE;
-    if ($FILE) {
+    $FILE = "" unless defined($FILE = <STDIN>);
+    $FILE =~ s{\R$}{};
+    if ($FILE ne "") {
         copy_pemfile($FILE,"${CATOP}/private/$CAKEY", "PRIVATE");
         copy_pemfile($FILE,"${CATOP}/$CACERT", "CERTIFICATE");
     } else {
@@ -164,7 +171,7 @@ if ($WHAT eq '-newcert' ) {
     my @files = @ARGV ? @ARGV : ( $NEWCERT );
     my $file;
     foreach $file (@files) {
-        my $status = run("$VERIFY -CAfile ${CATOP}/$CACERT $file");
+        my $status = run("$VERIFY \"-CAfile\" ${CATOP}/$CACERT $file");
         $RET = $status if $status != 0;
     }
 } elsif ($WHAT eq '-crl' ) {