From 7c576eae4ce464b1075dbf4881dd8ab80142b529 Mon Sep 17 00:00:00 2001 From: oscar Date: Fri, 12 Aug 2022 19:44:54 +1200 Subject: [PATCH] feat(certgen/tls): allow to customize the ca certifcate name --- custom_tls_cert_gen/generate-custom-tls.sh | 26 ++++++---------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/custom_tls_cert_gen/generate-custom-tls.sh b/custom_tls_cert_gen/generate-custom-tls.sh index 3a9cf7d..c6a6aa0 100755 --- a/custom_tls_cert_gen/generate-custom-tls.sh +++ b/custom_tls_cert_gen/generate-custom-tls.sh @@ -2,23 +2,7 @@ set -eu -ERROR_COLOR='\033[0;31m'; -HIGHLIGHT_COLOR='\033[0;32m'; -INPUT_COLOR='\033[0;33m'; -NO_COLOR='\033[0m'; - - -function print_highlight() { - printf "${HIGHLIGHT_COLOR}$1${NO_COLOR}\n" -} - -function print_error() { - printf "${ERROR_COLOR}$1${NO_COLOR}\n" -} - -function input() { - read -p "$(echo -e ${INPUT_COLOR}$1 ${NO_COLOR})" $2 -} +source ../utils/common.sh input "Specify the output path:" OUTPUT_PATH @@ -35,6 +19,8 @@ if [[ ! -e "$OUTPUT_PATH" ]]; then exit; fi +rm -rvf "$OUTPUT_PATH/*" + input "Do you have cfssl installed?(y/n): " is_cfssl_installed CFSSLEXE=${OUTPUT_PATH}/cfssl @@ -81,7 +67,9 @@ cd $OUTPUT_PATH input "Give a name to the CA certificate: " CA_CERT_NAME -${CFSSLEXE} print-defaults csr | ${CFSSLEXE} gencert -initca - | ${CFSSLJSONEXE} -bare ${CA_CERT_NAME}-ca +CA_CERT_NAME=${CA_CERT_NAME}-ca + +${CFSSLEXE} print-defaults csr | ${CFSSLEXE} gencert -initca - | ${CFSSLJSONEXE} -bare ${CA_CERT_NAME} CONFIG_CFSSL_JSON=${OUTPUT_PATH}/cfssl.json @@ -100,7 +88,7 @@ input "Give a name to the certificate: " CERT_NAME input "Input the hostname(example.org,127.0.0.1): " CERT_HOSTNAME -echo '{}' | ${CFSSLEXE} gencert -ca=ldap-ca.pem -ca-key=ldap-ca-key.pem -config=${CONFIG_CFSSL_JSON} \ +echo '{}' | ${CFSSLEXE} gencert -ca=${CA_CERT_NAME}.pem -ca-key=${CA_CERT_NAME}-key.pem -config=${CONFIG_CFSSL_JSON} \ -hostname="${CERT_HOSTNAME}" - | ${CFSSLJSONEXE} -bare ${CERT_NAME} print_highlight "The custom TLS certificates are successfully generated in the path ${OUTPUT_PATH}."