From be384a6f033a7c862b95e86f28feca5d42d9fc58 Mon Sep 17 00:00:00 2001 From: Johannes Zellner Date: Thu, 31 Jul 2014 11:15:01 -0700 Subject: [PATCH] Generate self signed certs based on hostname during bootstrap --- scripts/bootstrap.sh | 13 +++-- scripts/generate_certificate.sh | 99 +++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+), 6 deletions(-) create mode 100644 scripts/generate_certificate.sh diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh index d04abf0ab..32bf94d70 100644 --- a/scripts/bootstrap.sh +++ b/scripts/bootstrap.sh @@ -21,13 +21,14 @@ cat > /etc/yellowtent.json < -# tar xf cert.tar +tar xf cert.tar echo "==== Sudoers file for app removal ====" diff --git a/scripts/generate_certificate.sh b/scripts/generate_certificate.sh new file mode 100644 index 000000000..f8cb56f05 --- /dev/null +++ b/scripts/generate_certificate.sh @@ -0,0 +1,99 @@ +#!/bin/bash + +# C = US +# ST = California +# L = San Francisco +# O = Selfhost +# OU = Cloudron +# CN = *.nebulon.cloudron.com +# emailAddress = cert@selfhost.io + +if [[ $# < 7 ]]; then + echo "Not enough arguments"; + exit 1; +fi + +ARG_C=$1; +ARG_ST=$2; +ARG_L=$3; +ARG_O=$4; +ARG_OU=$5; +ARG_CN=$6; +ARG_EMAIL=$7; + +CONFIG_FILE=cert.config; +OUT_TAR=cert.tar; + +CERT_OUT_DIR=/tmp/$ARG_CN; + +if [[ -z "$8" ]]; then + echo "No output dir specified, use default $CERT_OUT_DIR"; +else + echo "Using output dir $8"; + CERT_OUT_DIR=$8; +fi + +echo ""; +echo "==================================="; +echo " Generating certifcate:"; +echo " C: $ARG_C"; +echo " ST: $ARG_ST"; +echo " L: $ARG_L"; +echo " O: $ARG_O"; +echo " OU: $ARG_OU"; +echo " CN: $ARG_CN"; +echo " EMAIL: $ARG_EMAIL"; +echo "==================================="; +echo ""; + +# ensure out dir +mkdir -p $CERT_OUT_DIR; + +# cd into out dir +cd $CERT_OUT_DIR; + +# clean out dir +rm host.*; +rm $CONFIG_FILE; + +# generate config file +cat > $CONFIG_FILE < host.key; + +openssl req -new -out host.csr -key host.key -config $CONFIG_FILE +openssl x509 -req -days 3650 -in host.csr -signkey host.key -out host.cert -extensions v3_req -extfile $CONFIG_FILE +openssl x509 -noout -fingerprint -text < host.cert > host.info; +cat host.cert host.key > host.pem; + +# create the cert.tar +tar -cf $OUT_TAR host.cert host.info host.key host.pem + +echo "Done."; \ No newline at end of file