From 0b8cf633ee360e02fedd0ba57b396895567d6793 Mon Sep 17 00:00:00 2001 From: Aidan Hahn Date: Sat, 1 Jun 2019 13:25:32 -0700 Subject: [PATCH] refactored certs-gen to work with default values when read is not effective --- certs-gen.sh | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/certs-gen.sh b/certs-gen.sh index 74abc7c..2845f7c 100755 --- a/certs-gen.sh +++ b/certs-gen.sh @@ -1,9 +1,17 @@ #!/bin/sh - pwd -read -p "Enter Server CN (localhost or address): " SRVNAME -read -p "Enter Client CN (localhost or address): " CLTNAME + +# get CNs +read -p "Enter Server CN (default: localhost): " SRVNAME +read -p "Enter Client CN (default: localhost): " CLTNAME +if [ -z "$SRVNAME" ]; then + SRVNAME=localhost +fi + +if [ -z "$CLTNAME" ]; then + CLTNAME=localhost +fi SERVER_CA_CN=jobserv-server-ca SERVER_PATH=resources/server @@ -25,6 +33,16 @@ rm -rf staging # Get passwords for CAs read -p "Enter Server CA Passphrase: " SRVCAPASS read -p "Enter Client CA Passphrase: " CLTCAPASS +if [ -z "$SRVCAPASS" ]; then + SRVCAPASS=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 13) + echo "[*] Server CA Password is: " $SRVCAPASS +fi + +if [ -z "$CLTCAPASS" ]; then + CLTCAPASS=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 13) + echo "[*] Client CA Password is: " $CLTCAPASS +fi + # Generate CA Keys echo "[+] Generating Server CA Key" openssl genrsa -passout pass:$SRVCAPASS -aes256 -out $SERVER_PATH/ca.key 4096