feat(certgen/tls): allow to download cfssl bundles

This commit is contained in:
oscar 2022-08-11 21:53:53 +12:00
parent bd80d1213f
commit c666bdedd1

View File

@ -2,7 +2,13 @@
set -eu set -eu
read -p "Specify the output path: " OUTPUT_PATH ERROR_COLOR='\033[0;31m';
HIGHLIGHT_COLOR='\033[0;32m';
INPUT_COLOR='\033[0;33m';
NO_COLOR='\033[0m';
read -p "$(echo -e ${INPUT_COLOR}Specify the output path: ${NO_COLOR})" OUTPUT_PATH
if [ -z "$OUTPUT_PATH" ]; then if [ -z "$OUTPUT_PATH" ]; then
OUTPUT_PATH="$(pwd)/output" OUTPUT_PATH="$(pwd)/output"
@ -13,26 +19,51 @@ if [ -z "$OUTPUT_PATH" ]; then
fi fi
if [[ ! -e "$OUTPUT_PATH" ]]; then if [[ ! -e "$OUTPUT_PATH" ]]; then
printf "$OUTPUT_PATH doesn't exist" printf "${ERROR_COLOR}${OUTPUT_PATH} doesn't exist.\n";
exit; exit;
fi fi
read -p "Specify the path where the cfssl and cfssljson are placed: " TOOL_PATH read -p "Do you have cfssl installed?(y/n): " is_cfssl_installed
CFSSLEXE=${TOOL_PATH}/cfssl CFSSLEXE=${OUTPUT_PATH}/cfssl
CFSSLJSONEXE=${TOOL_PATH}/cfssljson CFSSLJSONEXE=${OUTPUT_PATH}/cfssljson
echo ${CFSSLEXE} if [[ "${is_cfssl_installed}" == "y" || "${is_cfssl_installed}" == "Y" ]]; then
if [ ! -e "$CFSSLEXE" ]; then read -p "Specify the path where the cfssl and cfssljson are placed: " TOOL_PATH
printf "no cfssl found"
CFSSLEXE=${TOOL_PATH}/cfssl
CFSSLJSONEXE=${TOOL_PATH}/cfssljson
printf "${HIGHLIGHT_COLOR}Your cfssl binary path is ${CFSSLEXE}${NO_COLOR}\n"
if [ ! -e "$CFSSLEXE" ]; then
printf "${ERROR_COLOR}no cfssl found.\n";
exit;
fi
if [ ! -e "$CFSSLJSONEXE" ]; then
printf "${ERROR_COLOR}no cfssljson found.\n";
exit;
fi
else
# Download the cfssl for users
read -p "Specify your platform(darwin/linux/windows): " PLATFORM
if [ -Z "$PLATFORM" ]; then
printf "${ERROR_COLOR}Platform must be provided.\n";
exit; exit;
fi fi
if [ ! -e "$CFSSLJSONEXE" ]; then printf "${HIGHLIGHT_COLOR}Only amd64 is supported${NO_COLOR}\n"
printf "no cfssljson found"
exit;
fi
wget "https://github.com/cloudflare/cfssl/releases/download/v1.6.1/cfssl_1.6.1_${PLATFORM}_amd64" -O "${OUTPUT_PATH}/cfssl"
chmod +x "${OUTPUT_PATH}/cfssl"
wget "https://github.com/cloudflare/cfssl/releases/download/v1.6.1/cfssljson_1.6.1_${PLATFORM}_amd64" -O "${OUTPUT_PATH}/cfssljson"
chmod +x "${OUTPUT_PATH}/cfssljson"
printf "${HIGHLIGHT_COLOR}Download the cfssl bundle successfully.${NO_COLOR}\n"
fi
cd $OUTPUT_PATH cd $OUTPUT_PATH
@ -49,7 +80,6 @@ cat <<EOF >> ${CONFIG_CFSSL_JSON}
} }
} }
} }
EOF EOF
read -p "Give a name to the certificate: " CERT_NAME read -p "Give a name to the certificate: " CERT_NAME
@ -57,4 +87,6 @@ read -p "Give a name to the certificate: " CERT_NAME
read -p "Input the hostname(example.org,127.0.0.1): " CERT_HOSTNAME read -p "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=ldap-ca.pem -ca-key=ldap-ca-key.pem -config=${CONFIG_CFSSL_JSON} \
-hostname="${CERT_HOSTNAME}" - | ${CFSSLJSONEXE} -bare ${CERT_NAME} -hostname="${CERT_HOSTNAME}" - | ${CFSSLJSONEXE} -bare ${CERT_NAME}
printf "${HIGHLIGHT_COLOR}The custom TLS certificates are successfully generated in the path ${OUTPUT_PATH}.${NO_COLOR}\n"