perl: Separate compile-time environment from runtime environment
[openssl.git] / apps / CA.pl.in
index 52a97d7345034cb5b0b7ba0f8d3cf6209d9ddb81..3187e473d236f5d1e2ba0ec83c6b52b332cf2544 100644 (file)
@@ -1,4 +1,11 @@
-#!{- $config{perl} -}
+#!{- $config{hashbangperl} -}
+# Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
+#
+# 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
 #
@@ -16,7 +23,7 @@ if(defined $ENV{'OPENSSL'}) {
 
 my $verbose = 1;
 
-my $OPENSSL_CONFIG = $ENV{"OPENSSL_CONFIG"};
+my $OPENSSL_CONFIG = $ENV{"OPENSSL_CONFIG"} || "";
 my $DAYS = "-days 365";
 my $CADAYS = "-days 1095";     # 3 years
 my $REQ = "$openssl req $OPENSSL_CONFIG";
@@ -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 {