177177# 2017-01-03 Created check_config function to list all obvious config issues (2.02)
178178# 2017-01-10 force renew if FORCE_RENEWAL file exists (2.03)
179179# 2017-01-12 added drill, dig or host as alternatives to nslookup (2.04)
180+ # 2017-01-18 bugfix issue #227 - error deleting csr if doesn't exist
181+ # 2017-01-18 issue #228 check private key and account key are different (2.05)
182+ # 2017-01-21 issue #231 mingw bugfix and typos in debug messages (2.06)
183+ # 2017-01-29 issue #232 use neutral locale for date formatting (2.07)
184+ # 2017-01-30 issue #243 compatibility with bash 3.0 (2.08)
185+ # 2017-01-30 issue #243 additional compatibility with bash 3.0 (2.09)
186+ # 2017-02-18 add OCSP Must-Staple to the domain csr generation (2.10)
180187# ----------------------------------------------------------------------------------------
181188
182189PROGNAME=${0##*/ }
183- VERSION=" 2.04 "
190+ VERSION=" 2.10 "
184191
185192# defaults
186193ACCOUNT_KEY_LENGTH=4096
@@ -212,6 +219,7 @@ REUSE_PRIVATE_KEY="true"
212219SERVER_TYPE=" https"
213220SKIP_HTTP_TOKEN_CHECK=" false"
214221SSLCONF=" $( openssl version -d 2> /dev/null| cut -d\" -f2) /openssl.cnf"
222+ OCSP_MUST_STAPLE=" false"
215223TEMP_UPGRADE_FILE=" "
216224TOKEN_USER_ID=" "
217225USE_SINGLE_ACL=" false"
@@ -229,6 +237,7 @@ _UPGRADE=0
229237_UPGRADE_CHECK=1
230238_USE_DEBUG=0
231239config_errors=" false"
240+ LANG=C
232241
233242# store copy of original command in case of upgrading script and re-running
234243ORIGCMD=" $0 $* "
@@ -312,14 +321,24 @@ check_config() { # check the config files for all obvious errors
312321 debug " checking config"
313322
314323 # check keys
315- if [[ ! " $ACCOUNT_KEY_TYPE " =~ ^(rsa| prime256v1| secp384r1| secp521r1)$ ]]; then
316- info " ${DOMAIN} : invalid ACCOUNT_KEY_TYPE"
317- config_errors=true
318- fi
319- if [[ ! " $PRIVATE_KEY_ALG " =~ ^(rsa| prime256v1| secp384r1| secp521r1)$ ]]; then
320- info " ${DOMAIN} : invalid PRIVATE_KEY_ALG"
324+ case " $ACCOUNT_KEY_TYPE " in
325+ rsa|prime256v1|secp384r1|secp521r1)
326+ debug " checked ACCOUNT_KEY_TYPE " ;;
327+ * )
328+ info " ${DOMAIN} : invalid ACCOUNT_KEY_TYPE - $ACCOUNT_KEY_TYPE "
329+ config_errors=true ;;
330+ esac
331+ if [[ " $ACCOUNT_KEY " == " $DOMAIN_DIR /${DOMAIN} .key" ]]; then
332+ info " ${DOMAIN} : ACCOUNT_KEY and domain key ( $DOMAIN_DIR /${DOMAIN} .key ) must be different"
321333 config_errors=true
322334 fi
335+ case " $PRIVATE_KEY_ALG " in
336+ rsa|prime256v1|secp384r1|secp521r1)
337+ debug " checked PRIVATE_KEY_ALG " ;;
338+ * )
339+ info " ${DOMAIN} : invalid PRIVATE_KEY_ALG - $PRIVATE_KEY_ALG "
340+ config_errors=true ;;
341+ esac
323342 if [[ " $DUAL_RSA_ECDSA " == " true" ]] && [[ " $PRIVATE_KEY_ALG " == " rsa" ]]; then
324343 info " ${DOMAIN} : PRIVATE_KEY_ALG not set to an EC type and DUAL_RSA_ECDSA=\" true\" "
325344 config_errors=true
@@ -437,7 +456,7 @@ check_getssl_upgrade() { # check if a more recent version of code is available a
437456 declare -a getssl_versions
438457 shopt -s nullglob
439458 for getssl_version in $0 .v* ; do
440- getssl_versions+=( $getssl_version )
459+ getssl_versions[ ${ # getssl_versions[@]} ]= " $getssl_version "
441460 done
442461 shopt -u nullglob
443462 # Explicitly sort the getssl_versions array to make sure
@@ -603,6 +622,11 @@ create_csr() { # create a csr using a given key (if it doesn't already exist)
603622 tmp_conf=$( mktemp)
604623 cat " $SSLCONF " > " $tmp_conf "
605624 printf " [SAN]\n%s" " $SANLIST " >> " $tmp_conf "
625+ # add OCSP Must-Staple to the domain csr
626+ # if openssl version >= 1.1.0 one can also use "tlsfeature = status_request"
627+ if [[ " $OCSP_MUST_STAPLE " == " true" ]]; then
628+ printf " \n1.3.6.1.5.5.7.1.24 = DER:30:03:02:01:05" >> " $tmp_conf "
629+ fi
606630 openssl req -new -sha256 -key " $csr_key " -subj " $CSR_SUBJECT " -reqexts SAN -config " $tmp_conf " > " $csr_file "
607631 rm -f " $tmp_conf "
608632 fi
@@ -612,13 +636,13 @@ create_key() { # create a domain key (if it doesn't already exist)
612636 key_type=$1 # domain key type
613637 key_loc=$2 # domain key location
614638 key_len=$3 # domain key length - for rsa keys.
615- # check if domain key exists, if not then create it.
639+ # check if key exists, if not then create it.
616640 if [[ -s " $key_loc " ]]; then
617641 debug " domain key exists at $key_loc - skipping generation"
618642 # ideally need to check validity of domain key
619643 else
620644 umask 077
621- info " creating domain key - $key_loc "
645+ info " creating key - $key_loc "
622646 case " $key_type " in
623647 rsa)
624648 openssl genrsa " $key_len " > " $key_loc " ;;
@@ -629,7 +653,9 @@ create_key() { # create a domain key (if it doesn't already exist)
629653 esac
630654 umask " $ORIG_UMASK "
631655 # remove csr on generation of new domain key
632- rm -f " ${key_loc::- 4} .csr"
656+ if [[ -e " ${key_loc::- 4} .csr" ]]; then
657+ rm -f " ${key_loc::- 4} .csr"
658+ fi
633659 fi
634660}
635661
@@ -835,7 +861,7 @@ get_os() { # function to get the current Operating System
835861 os=" mac"
836862 elif [[ ${uname_res: 0: 6} == " CYGWIN" ]]; then
837863 os=" cygwin"
838- elif [[ ${uname_res: 0: 6 } == " MINGW" ]]; then
864+ elif [[ ${uname_res: 0: 5 } == " MINGW" ]]; then
839865 os=" mingw"
840866 else
841867 os=" unknown"
@@ -1137,9 +1163,9 @@ send_signed_request() { # Sends a request to the ACME server, signed with your p
11371163
11381164 # Send header + extended header + payload + signature to the acme-server
11391165 body=" {\" header\" : ${header} ,"
1140- body+= " \" protected\" : \" ${protected64} \" ,"
1141- body+= " \" payload\" : \" ${payload64} \" ,"
1142- body+= " \" signature\" : \" ${signed64} \" }"
1166+ body= " ${body} \" protected\" : \" ${protected64} \" ,"
1167+ body= " ${body} \" payload\" : \" ${payload64} \" ,"
1168+ body= " ${body} \" signature\" : \" ${signed64} \" }"
11431169 debug " header, payload and signature = $body "
11441170
11451171 code=" 500"
@@ -1409,6 +1435,11 @@ done
14091435# Get the current OS, so the correct functions can be used for that OS. (sets the variable os)
14101436get_os
14111437
1438+ # check if "recent" version of bash.
1439+ # if [[ "${BASH_VERSINFO[0]}${BASH_VERSINFO[1]}" -lt 42 ]]; then
1440+ # info "this script is designed for bash v4.2 or later - earlier version may give errors"
1441+ # fi
1442+
14121443# check if required applications are included
14131444
14141445requires which
@@ -1472,6 +1503,9 @@ DOMAIN_DIR="$DOMAIN_STORAGE/$DOMAIN"
14721503CERT_FILE=" $DOMAIN_DIR /${DOMAIN} .crt"
14731504CA_CERT=" $DOMAIN_DIR /chain.crt"
14741505TEMP_DIR=" $DOMAIN_DIR /tmp"
1506+ if [[ " $os " == " mingw" ]]; then
1507+ CSR_SUBJECT=" //"
1508+ fi
14751509
14761510# Set the OPENSSL_CONF environment variable so openssl knows which config to use
14771511export OPENSSL_CONF=$SSLCONF
16891723# end of .... if there is an existing certificate file, check details.
16901724
16911725if [[ ! -t 0 ]] && [[ " $PREVENT_NON_INTERACTIVE_RENEWAL " = " true" ]]; then
1692- errmsg=" $DOMAIN due for renewal, "
1693- errmsg+= " but not completed due to PREVENT_NON_INTERACTIVE_RENEWAL=true in config"
1726+ errmsg=" $DOMAIN due for renewal,"
1727+ errmsg= " ${errmsg} but not completed due to PREVENT_NON_INTERACTIVE_RENEWAL=true in config"
16941728 error_exit " $errmsg "
16951729fi
16961730
0 commit comments