211211# 2020-02-12 Fix for DUAL_RSA_ECDSA not working with ACMEv2 (#334, #474, #502)
212212# 2020-02-12 Fix #424 - Sporadic "error in EC signing couldn't get R from ..." (2.18)
213213# 2020-02-12 Fix "Registration key already in use" (2.19)
214+ # 2020-02-13 Fix bug with copying to all locations when creating RSA and ECDSA certs (2.20)
214215# ----------------------------------------------------------------------------------------
215216
216217PROGNAME=${0##*/ }
217- VERSION=" 2.19 "
218+ VERSION=" 2.20 "
218219
219220# defaults
220221ACCOUNT_KEY_LENGTH=4096
@@ -549,8 +550,12 @@ copy_file_to_location() { # copies a file, using scp, sftp or ftp if required.
549550 cert=$1 # descriptive name, just used for display
550551 from=$2 # current file location
551552 to=$3 # location to move file to.
553+ suffix=$4 # (optional) optional suffix for DUAL_RSA_ECDSA, i.e. save to private.key becomes save to private.ec.key
552554 IFS=\; read -r -a copy_locations <<< " $3"
553555 for to in " ${copy_locations[@]} " ; do
556+ if [[ -n " $suffix " ]]; then
557+ to=" ${to% .* } .${suffix} .${to##* .} "
558+ fi
554559 info " copying $cert to $to "
555560 if [[ " ${to: 0: 4} " == " ssh:" ]] ; then
556561 debug " using scp -q $SCP_OPTS $from ${to: 4} "
@@ -1823,6 +1828,9 @@ sign_string() { # sign a string with a given key and algorithm and return urlbas
18231828 elif [[ " ${signed: 4: 4} " == " 0231" ]]; then # sha384 which needs trimming
18241829 R=$( echo " $signed " | cut -c 11-106)
18251830 part2=$( echo " $signed " | cut -c 107-)
1831+ elif [[ " ${signed: 6: 4} " == " 0240" ]]; then # sha512 which needs padding
1832+ R=$( echo -n 00; echo " $signed " | cut -c 9-138)
1833+ part2=$( echo " $signed " | cut -c 141-)
18261834 elif [[ " ${signed: 6: 4} " == " 0241" ]]; then # sha512 which needs padding
18271835 R=$( echo -n 00; echo " $signed " | cut -c 11-140)
18281836 part2=$( echo " $signed " | cut -c 141-)
@@ -1846,6 +1854,8 @@ sign_string() { # sign a string with a given key and algorithm and return urlbas
18461854 S=$( echo " $part2 " | cut -c 5-100)
18471855 elif [[ " ${part2: 0: 4} " == " 0231" ]]; then # sha384
18481856 S=$( echo " $part2 " | cut -c 7-102)
1857+ elif [[ " ${part2: 0: 4} " == " 0240" ]]; then # sha512 with padding
1858+ S=$( echo -n 00; echo " $part2 " | cut -c 5-)
18491859 elif [[ " ${part2: 0: 4} " == " 0241" ]]; then # sha512 with padding
18501860 S=$( echo -n 00; echo " $part2 " | cut -c 5-)
18511861 elif [[ " ${part2: 0: 4} " == " 0242" ]]; then # sha512
@@ -2545,17 +2555,20 @@ if [[ "$DUAL_RSA_ECDSA" == "true" ]]; then
25452555 if [[ -n " $DOMAIN_CERT_LOCATION " ]]; then
25462556 copy_file_to_location " ec domain certificate" \
25472557 " ${CERT_FILE% .* } .ec.crt" \
2548- " ${DOMAIN_CERT_LOCATION% .* } .ec.crt"
2558+ " ${DOMAIN_CERT_LOCATION} " \
2559+ " ec"
25492560 fi
25502561 if [[ -n " $DOMAIN_KEY_LOCATION " ]]; then
2551- copy_file_to_location " ec private key" \
2552- " $DOMAIN_DIR /${DOMAIN} .ec.key" \
2553- " ${DOMAIN_KEY_LOCATION% .* } .ec.key"
2562+ copy_file_to_location " ec private key" \
2563+ " $DOMAIN_DIR /${DOMAIN} .ec.key" \
2564+ " ${DOMAIN_KEY_LOCATION} " \
2565+ " ec"
25542566 fi
25552567 if [[ -n " $CA_CERT_LOCATION " ]]; then
2556- copy_file_to_location " ec CA certificate" \
2557- " ${CA_CERT% .* } .ec.crt" \
2558- " ${CA_CERT_LOCATION% .* } .ec.crt"
2568+ copy_file_to_location " ec CA certificate" \
2569+ " ${CA_CERT% .* } .ec.crt" \
2570+ " ${CA_CERT_LOCATION% .* } .crt" \
2571+ " ec"
25592572 fi
25602573fi
25612574
@@ -2570,7 +2583,7 @@ if [[ -n "$DOMAIN_CHAIN_LOCATION" ]]; then
25702583 copy_file_to_location " full chain" " $TEMP_DIR /${DOMAIN} _chain.pem" " $to_location "
25712584 if [[ " $DUAL_RSA_ECDSA " == " true" ]]; then
25722585 cat " ${CERT_FILE% .* } .ec.crt" " ${CA_CERT% .* } .ec.crt" > " $TEMP_DIR /${DOMAIN} _chain.pem.ec"
2573- copy_file_to_location " full chain" " $TEMP_DIR /${DOMAIN} _chain.pem.ec" " ${to_location% . * } .ec. ${to_location ##* .} "
2586+ copy_file_to_location " full chain" " $TEMP_DIR /${DOMAIN} _chain.pem.ec" " ${to_location} " " ec "
25742587 fi
25752588fi
25762589# if DOMAIN_KEY_CERT_LOCATION is not blank, then create and copy file.
@@ -2583,8 +2596,8 @@ if [[ -n "$DOMAIN_KEY_CERT_LOCATION" ]]; then
25832596 cat " $DOMAIN_DIR /${DOMAIN} .key" " $CERT_FILE " > " $TEMP_DIR /${DOMAIN} _K_C.pem"
25842597 copy_file_to_location " private key and domain cert pem" " $TEMP_DIR /${DOMAIN} _K_C.pem" " $to_location "
25852598 if [[ " $DUAL_RSA_ECDSA " == " true" ]]; then
2586- cat " $DOMAIN_DIR /${DOMAIN} .ec.key" " ${CERT_FILE% .* } .ec.crt" > " $TEMP_DIR /${DOMAIN} _K_C.pem.ec"
2587- copy_file_to_location " private ec key and domain cert pem" " $TEMP_DIR /${DOMAIN} _K_C.pem.ec" " ${to_location% . * } .ec. ${to_location ##* .} "
2599+ cat " $DOMAIN_DIR /${DOMAIN} .ec.key" " ${CERT_FILE% .* } .ec.crt" > " $TEMP_DIR /${DOMAIN} _K_C.pem.ec"
2600+ copy_file_to_location " private ec key and domain cert pem" " $TEMP_DIR /${DOMAIN} _K_C.pem.ec" " ${to_location} " " ec "
25882601 fi
25892602fi
25902603# if DOMAIN_PEM_LOCATION is not blank, then create and copy file.
@@ -2598,7 +2611,7 @@ if [[ -n "$DOMAIN_PEM_LOCATION" ]]; then
25982611 copy_file_to_location " full key, cert and chain pem" " $TEMP_DIR /${DOMAIN} .pem" " $to_location "
25992612 if [[ " $DUAL_RSA_ECDSA " == " true" ]]; then
26002613 cat " $DOMAIN_DIR /${DOMAIN} .ec.key" " ${CERT_FILE% .* } .ec.crt" " ${CA_CERT% .* } .ec.crt" > " $TEMP_DIR /${DOMAIN} .pem.ec"
2601- copy_file_to_location " full ec key, cert and chain pem" " $TEMP_DIR /${DOMAIN} .pem.ec" " ${to_location% . * } .ec. ${to_location ##* .} "
2614+ copy_file_to_location " full ec key, cert and chain pem" " $TEMP_DIR /${DOMAIN} .pem.ec" " ${to_location} " " ec "
26022615 fi
26032616fi
26042617# end of copying certs.
0 commit comments