Skip to content

Commit

Permalink
add silent options
Browse files Browse the repository at this point in the history
  • Loading branch information
paulczar committed Jul 21, 2017
1 parent 3488381 commit ad38455
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions generate-certs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#!/bin/bash

if [[ -z $SILENT ]]; then
echo "----------------------------"
echo "| OMGWTFSSL Cert Generator |"
echo "----------------------------"
echo
fi

export CA_KEY=${CA_KEY-"ca-key.pem"}
export CA_CERT=${CA_CERT-"ca.pem"}
Expand All @@ -21,21 +23,19 @@ export SSL_SUBJECT=${SSL_SUBJECT:-"example.com"}
export SSL_DNS=${SSL_DNS}
export SSL_IP=${SSL_IP}

export DEBUG=${DEBUG:=1}

echo "--> Certificate Authority"
[[ -z $SILENT ]] && echo "--> Certificate Authority"

if [[ -e ./${CA_KEY} ]]; then
echo "====> Using existing CA Key ${CA_KEY}"
[[ -z $SILENT ]] && echo "====> Using existing CA Key ${CA_KEY}"
else
echo "====> Generating new CA key ${CA_KEY}"
[[ -z $SILENT ]] && echo "====> Generating new CA key ${CA_KEY}"
openssl genrsa -out ${CA_KEY} ${SSL_SIZE} > /dev/null
fi

if [[ -e ./${CA_CERT} ]]; then
echo "====> Using existing CA Certificate ${CA_CERT}"
[[ -z $SILENT ]] && echo "====> Using existing CA Certificate ${CA_CERT}"
else
echo "====> Generating new CA Certificate ${CA_CERT}"
[[ -z $SILENT ]] && echo "====> Generating new CA Certificate ${CA_CERT}"
openssl req -x509 -new -nodes -key ${CA_KEY} -days ${CA_EXPIRE} -out ${CA_CERT} -subj "/CN=${CA_SUBJECT}" > /dev/null || exit 1
fi

Expand Down Expand Up @@ -72,16 +72,17 @@ EOM
fi
fi

echo "====> Generating new SSL KEY ${SSL_KEY}"
[[ -z $SILENT ]] && echo "====> Generating new SSL KEY ${SSL_KEY}"
openssl genrsa -out ${SSL_KEY} ${SSL_SIZE} > /dev/null || exit 1

echo "====> Generating new SSL CSR ${SSL_CSR}"
[[ -z $SILENT ]] && echo "====> Generating new SSL CSR ${SSL_CSR}"
openssl req -new -key ${SSL_KEY} -out ${SSL_CSR} -subj "/CN=${SSL_SUBJECT}" -config ${SSL_CONFIG} > /dev/null || exit 1

echo "====> Generating new SSL CERT ${SSL_CERT}"
[[ -z $SILENT ]] && echo "====> Generating new SSL CERT ${SSL_CERT}"
openssl x509 -req -in ${SSL_CSR} -CA ${CA_CERT} -CAkey ${CA_KEY} -CAcreateserial -out ${SSL_CERT} \
-days ${SSL_EXPIRE} -extensions v3_req -extfile ${SSL_CONFIG} > /dev/null || exit 1

if [[ -z $SILENT ]]; then
echo "====> Complete"
echo "keys can be found in volume mapped to $(pwd)"
echo
Expand All @@ -102,3 +103,4 @@ echo
echo "ssl_cert: |"
cat $SSL_CERT | sed 's/^/ /'
echo
fi

0 comments on commit ad38455

Please sign in to comment.