270270# 2021-07-30 Run tests with -d to catch intermittent failures, Use fork's repo for upgrade tests. (tlhackque) (#692) (2.41)
271271# 2021-08-26 Improve upgrade check & make upgrade do a full install when possible (tlhackque) (#694) (2.42)
272272# 2021-09-02 Fix version compare - cURL v8 may have single digit minor numbers. (tlhackque) (2.43)
273+ # 2021-09-26 Delete key file when key algorithm has changed (makuhama)
273274# ----------------------------------------------------------------------------------------
274275
275276case :$SHELLOPTS : in
@@ -819,11 +820,13 @@ check_getssl_upgrade() { # check if a more recent release is available
819820 if [ " $TEMP_UPGRADE_FILE " == " " ]; then
820821 error_exit " mktemp failed"
821822 fi
822- CODE_LOCATION=$( sed -e" s/master/${release_tag} /" <<< " $CODE_LOCATION" )
823+ CODE_LOCATION=$( sed -e" s/getssl\/master/${release_tag} /" <<< " $CODE_LOCATION" )
824+ # shellcheck disable=SC2086
825+ debug curl ${_NOMETER:- --silent} --user-agent " $CURL_USERAGENT " " $CODE_LOCATION " --output " $TEMP_UPGRADE_FILE "
823826 # shellcheck disable=SC2086
824827 curl ${_NOMETER:- --silent} --user-agent " $CURL_USERAGENT " " $CODE_LOCATION " --output " $TEMP_UPGRADE_FILE "
825-
826828 errcode=$?
829+
827830 if [[ $errcode -eq 60 ]]; then
828831 error_exit " curl needs updating, your version does not support SNI (multiple SSL domains on a single IP)"
829832 elif [[ $errcode -gt 0 ]]; then
@@ -838,11 +841,11 @@ check_getssl_upgrade() { # check if a more recent release is available
838841 fi
839842
840843 if [[ ${_MUTE} -eq 0 ]]; then
841- echo " Updated getssl from v${VERSION} to v ${release_tag} "
844+ echo " Updated getssl from v${VERSION} to ${release_tag} "
842845 echo " The old version remains as ${0} .v${VERSION} and should be removed"
843846 echo " These update notifications can be turned off using the -Q option"
844847 echo " "
845- echo " Updates are; "
848+ echo " Updates are: "
846849 awk " /\(${VERSION} \)$/ {s=1} s; /\(${release_tag} \)$/ || /^# ----/ {s=0}" " $TEMP_UPGRADE_FILE " | awk ' {if(NR>1)print}'
847850 echo " "
848851 fi
@@ -2117,11 +2120,22 @@ json_get() { # get values from json
21172120
21182121obtain_ca_resource_locations ()
21192122{
2123+ CURL_RESPONSE_FILE=" $( mktemp 2> /dev/null || mktemp -t getssl.XXXXXX) "
2124+
21202125 for suffix in " " " /directory" " /dir" ;
21212126 do
21222127 # Obtain CA resource locations
21232128 # shellcheck disable=SC2086
2124- ca_all_loc=$( curl ${_NOMETER} --user-agent " $CURL_USERAGENT " " ${CA}${suffix} " 2> /dev/null)
2129+ ca_all_loc=$( curl ${_NOMETER} --user-agent " $CURL_USERAGENT " " ${CA}${suffix} " 2> $CURL_RESPONSE_FILE )
2130+ errcode=$?
2131+ if [[ $errcode -ne 0 ]]; then
2132+ response=$( cat " $CURL_RESPONSE_FILE " )
2133+ rm " $CURL_RESPONSE_FILE "
2134+ error_exit " ERROR curl \" $CA$suffix \" failed with $errcode and returned:\n$response "
2135+ else
2136+ rm " $CURL_RESPONSE_FILE "
2137+ fi
2138+
21252139 debug " ca_all_loc from ${CA}${suffix} gives $ca_all_loc "
21262140 # APIv1
21272141 URL_new_reg=$( echo " $ca_all_loc " | grep " new-reg" | awk -F' "' ' {print $4}' )
@@ -3146,6 +3160,22 @@ else
31463160fi
31473161debug " created SAN list = $SANLIST "
31483162
3163+ # check if private key alg has changed from RSA to EC (or vice versa)
3164+ if [[ " $DUAL_RSA_ECDSA " == " false" ]] && [[ -s " $DOMAIN_DIR /${DOMAIN} .key" ]]; then
3165+ case " ${PRIVATE_KEY_ALG} " in
3166+ rsa)
3167+ if grep -q -- " -----BEGIN EC PRIVATE KEY-----" " $DOMAIN_DIR /${DOMAIN} .key" ; then
3168+ rm -f " $DOMAIN_DIR /${DOMAIN} .key"
3169+ _FORCE_RENEW=1
3170+ fi ;;
3171+ prime256v1|secp384r1|secp521r1)
3172+ if grep -q -- " -----BEGIN RSA PRIVATE KEY-----" " $DOMAIN_DIR /${DOMAIN} .key" ; then
3173+ rm -f " $DOMAIN_DIR /${DOMAIN} .key"
3174+ _FORCE_RENEW=1
3175+ fi ;;
3176+ esac
3177+ fi
3178+
31493179# if there is an existing certificate file, check details.
31503180if [[ -s " $CERT_FILE " ]]; then
31513181 debug " certificate $CERT_FILE exists"
@@ -3199,20 +3229,6 @@ if [[ "$REUSE_PRIVATE_KEY" != "true" ]]; then
31993229 fi
32003230fi
32013231
3202- # check if private key alg has changed from RSA to EC (or vice versa)
3203- if [[ " $DUAL_RSA_ECDSA " == " false" ]] && [[ -s " $DOMAIN_DIR /${DOMAIN} .key" ]]; then
3204- case " ${PRIVATE_KEY_ALG} " in
3205- rsa)
3206- if grep --silent -- " -----BEGIN EC PRIVATE KEY-----" " $DOMAIN_DIR /${DOMAIN} .key" ; then
3207- rm -f " $DOMAIN_DIR /${DOMAIN} .key"
3208- fi ;;
3209- prime256v1|secp384r1|secp521r1)
3210- if grep --silent -- " -----BEGIN RSA PRIVATE KEY-----" " $DOMAIN_DIR /${DOMAIN} .key" ; then
3211- rm -f " $DOMAIN_DIR /${DOMAIN} .key"
3212- fi ;;
3213- esac
3214- fi
3215-
32163232# create new domain keys if they don't already exist
32173233if [[ " $DUAL_RSA_ECDSA " == " false" ]]; then
32183234 create_key " ${PRIVATE_KEY_ALG} " " $DOMAIN_DIR /${DOMAIN} .key" " $DOMAIN_KEY_LENGTH "
0 commit comments