Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting up ability for user to set SSL Validity period. #25

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ LABEL \
vendor="devilbox" \
license="MIT"


###
### Build arguments
###
Expand Down
5 changes: 3 additions & 2 deletions data/create-vhost.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ VHOST_TPL="${4}"
CA_KEY="${5}"
CA_CRT="${6}"
GENERATE_SSL="${7}"
VERBOSE="${8:-}"
SSL_VALIDITY="${8}"
VERBOSE="${9:-}"

if [ "${GENERATE_SSL}" = "1" ]; then
if [ ! -d "/etc/httpd/cert/mass" ]; then
Expand All @@ -23,7 +24,7 @@ if [ "${GENERATE_SSL}" = "1" ]; then
_out_key="/etc/httpd/cert/mass/${VHOST_NAME}${VHOST_TLD}.key"
_out_csr="/etc/httpd/cert/mass/${VHOST_NAME}${VHOST_TLD}.csr"
_out_crt="/etc/httpd/cert/mass/${VHOST_NAME}${VHOST_TLD}.crt"
if ! cert-gen -v -c DE -s Berlin -l Berlin -o Devilbox -u Devilbox -n "${_domain}" -e "${_email}" -a "${_domains}" "${CA_KEY}" "${CA_CRT}" "${_out_key}" "${_out_csr}" "${_out_crt}"; then
if ! cert-gen -v -c DE -s Berlin -l Berlin -o Devilbox -u Devilbox -n "${_domain}" -e "${_email}" -a "${_domains}" -d "${SSL_VALIDITY}" "${CA_KEY}" "${CA_CRT}" "${_out_key}" "${_out_csr}" "${_out_crt}"; then
echo "[FAILED] Failed to add SSL certificate for ${VHOST_NAME}${VHOST_TLD}"
exit 1
fi
Expand Down
20 changes: 18 additions & 2 deletions data/docker-entrypoint.d/08-cert-gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ cert_gen_generate_ca() {
local crt="${2}"
local verbose="${3}"
local debug="${4}"
local def_days="${5:-}"

# Create directories
if [ ! -d "$( dirname "${key}" )" ]; then
Expand All @@ -33,9 +34,16 @@ cert_gen_generate_ca() {
verbose=""
fi

# user defined custom days
if [ -z "${def_days}" ]; then
def_days="820"
else
def_days="${5}"
fi

# Generate CA if it does not exist yet
if [ ! -f "${key}" ] || [ ! -f "${crt}" ]; then
run "ca-gen ${verbose} -c DE -s Berlin -l Berlin -o Devilbox -u Devilbox -n 'Devilbox Root CA' -e 'cytopia@devilbox.org' ${key} ${crt}" "${DEBUG_LEVEL}"
run "ca-gen ${verbose} -c DE -s Berlin -l Berlin -o Devilbox -u Devilbox -n 'Devilbox Root CA' -e 'cytopia@devilbox.org' -d ${def_days} ${key} ${crt}" "${DEBUG_LEVEL}"
fi
}

Expand All @@ -54,6 +62,7 @@ cert_gen_generate_cert() {
local domains="${8}"
local verbose="${9}"
local debug="${10}"
local def_days="${11:-}"

# If not enabled, skip SSL certificate eneration
if [ "${enable}" != "1" ]; then
Expand Down Expand Up @@ -83,6 +92,13 @@ cert_gen_generate_cert() {
verbose=""
fi

# user defined custom days
if [ -z "${def_days}" ]; then
def_days="820"
else
def_days="${11}"
fi

# Get domain name and alt_names
cn=
alt_names=
Expand All @@ -98,5 +114,5 @@ cert_gen_generate_cert() {
done
alt_names="$( echo "${alt_names}" | xargs )" # tim

run "cert-gen ${verbose} -c DE -s Berlin -l Berlin -o Devilbox -u Devilbox -n '${cn}' -e 'admin@${cn}' -a '${alt_names}' ${ca_key} ${ca_crt} ${key} ${csr} ${crt}" "${debug}"
run "cert-gen ${verbose} -c DE -s Berlin -l Berlin -o Devilbox -u Devilbox -n '${cn}' -e 'admin@${cn}' -a '${alt_names}' -d ${def_days} ${ca_key} ${ca_crt} ${key} ${csr} ${crt}" "${debug}"
}
14 changes: 11 additions & 3 deletions data/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ DEBUG_RUNTIME="$( env_get "DEBUG_RUNTIME" "0" )"
log "info" "Runtime debug: ${DEBUG_RUNTIME}" "${DEBUG_LEVEL}"


###
### Does user have custom SSL validity settings?
###
MAIN_VHOST_SSL_VALIDITY_PERIOD="$( env_get "MAIN_VHOST_SSL_VALIDITY_PERIOD" "803" )"
log "info" "SSL Generation Validity period: ${MAIN_VHOST_SSL_VALIDITY_PERIOD}" "${DEBUG_LEVEL}"


###
### Change uid/gid
###
Expand Down Expand Up @@ -201,7 +208,7 @@ vhost_gen_mass_vhost_tld \
###
### Create Certificate Signing request
###
cert_gen_generate_ca "${CA_KEY}" "${CA_CRT}" "${DEBUG_RUNTIME}" "${DEBUG_LEVEL}"
cert_gen_generate_ca "${CA_KEY}" "${CA_CRT}" "${DEBUG_RUNTIME}" "${DEBUG_LEVEL}" "${MAIN_VHOST_SSL_VALIDITY_PERIOD}"


###
Expand All @@ -217,7 +224,8 @@ cert_gen_generate_cert \
"/etc/httpd/cert/main/localhost.crt" \
"${MAIN_VHOST_SSL_CN}" \
"${DEBUG_RUNTIME}" \
"${DEBUG_LEVEL}"
"${DEBUG_LEVEL}" \
"${MAIN_VHOST_SSL_VALIDITY_PERIOD}"



Expand All @@ -244,7 +252,7 @@ if [ "${MASS_VHOST_ENABLE}" -eq "1" ]; then
fi

# Create watcherd sub commands
watcherd_add="create-vhost.sh '%%p' '%%n' '${MASS_VHOST_TLD}' '%%p/${MASS_VHOST_TPL}/' '${CA_KEY}' '${CA_CRT}' '1' '${verbose}'"
watcherd_add="create-vhost.sh '%%p' '%%n' '${MASS_VHOST_TLD}' '%%p/${MASS_VHOST_TPL}/' '${CA_KEY}' '${CA_CRT}' '1' '${MAIN_VHOST_SSL_VALIDITY_PERIOD}' '${verbose}'"
watcherd_del="rm /etc/httpd/vhost.d/%%n.conf"
watcherd_tri="${HTTPD_RELOAD}"

Expand Down