Allow renew time relative to the expiration date

You can now set a negative value for days, that will be subtracted from
the expiration date of the generated certificate.
pull/4457/head
Alexander Sulfrian 2 years ago
parent 7fe06adcfd
commit 4d9d59ae6a

@ -990,6 +990,12 @@ _checkcert() {
fi fi
} }
#file
_enddate() {
_cf="$1"
${ACME_OPENSSL_BIN:-openssl} x509 -noout -enddate -in "$_cf" | cut -d = -f 2
}
#Usage: hashalg [outputhex] #Usage: hashalg [outputhex]
#Output Base64-encoded digest #Output Base64-encoded digest
_digest() { _digest() {
@ -1791,6 +1797,25 @@ _date2time() {
return 1 return 1
} }
#support the output format of openssl -enddate:
# Apr 01 08:10:33 2022 GMT to 1641283833
_ssldate2time() {
#Linux
if date -u -d "$1" +"%s" 2>/dev/null; then
return
fi
#Solaris
if gdate -u -d "$1" +"%s" 2>/dev/null; then
return
fi
#Mac/BSD
if date -j -f "%b %d %T %Y %Z" "$1" +"%s" 2>/dev/null; then
return
fi
_err "Can not parse _date2time $1"
return 1
}
_utc_date() { _utc_date() {
date -u "+%Y-%m-%d %H:%M:%S" date -u "+%Y-%m-%d %H:%M:%S"
} }
@ -5248,7 +5273,7 @@ $_authorizations_map"
Le_CertCreateTimeStr=$(_time2str "$Le_CertCreateTime") Le_CertCreateTimeStr=$(_time2str "$Le_CertCreateTime")
_savedomainconf "Le_CertCreateTimeStr" "$Le_CertCreateTimeStr" _savedomainconf "Le_CertCreateTimeStr" "$Le_CertCreateTimeStr"
if [ -z "$Le_RenewalDays" ] || [ "$Le_RenewalDays" -lt "0" ]; then if [ -z "$Le_RenewalDays" ]; then
Le_RenewalDays="$DEFAULT_RENEW" Le_RenewalDays="$DEFAULT_RENEW"
else else
_savedomainconf "Le_RenewalDays" "$Le_RenewalDays" _savedomainconf "Le_RenewalDays" "$Le_RenewalDays"
@ -5307,6 +5332,11 @@ $_authorizations_map"
Le_NextRenewTimeStr=$(_time2str "$Le_NextRenewTime") Le_NextRenewTimeStr=$(_time2str "$Le_NextRenewTime")
fi fi
fi fi
elif [ "$Le_RenewalDays" -lt "0" ]; then
_enddate=$(_enddate "$CERT_PATH")
_endtime=$(_ssldate2time "$_enddate")
Le_NextRenewTime=$(_math "$_endtime" + "$Le_RenewalDays" \* 24 \* 60 \* 60)
Le_NextRenewTimeStr=$(_time2str "$Le_NextRenewTime")
else else
Le_NextRenewTime=$(_math "$Le_CertCreateTime" + "$Le_RenewalDays" \* 24 \* 60 \* 60) Le_NextRenewTime=$(_math "$Le_CertCreateTime" + "$Le_RenewalDays" \* 24 \* 60 \* 60)
Le_NextRenewTime=$(_math "$Le_NextRenewTime" - 86400) Le_NextRenewTime=$(_math "$Le_NextRenewTime" - 86400)

Loading…
Cancel
Save