Skip to content

Commit b115c47

Browse files
Fix --days flag to properly calculate renewal time with --valid-to
When using --valid-to with --days, the renewal time was incorrectly set to 1 day before certificate expiry instead of respecting the user's --days value. This fix ensures that: - Renewal is scheduled at 'issuance + days' as intended - Falls back to 1 day before expiry only if cert expires before renewal - Matches the behavior when --valid-to is not specified Example: With --valid-to '+47d' --days 42: - Before: Renewal at day 46 (1 day before expiry) - After: Renewal at day 42 (as specified)
1 parent a5754e9 commit b115c47

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

acme.sh

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5386,26 +5386,41 @@ $_authorizations_map"
53865386
_cleardomainconf Le_ForceNewDomainKey
53875387
fi
53885388
if [ "$_notAfter" ]; then
5389-
Le_NextRenewTime=$(_date2time "$_notAfter")
5389+
Le_CertExpireTime=$(_date2time "$_notAfter")
53905390
Le_NextRenewTimeStr="$_notAfter"
53915391
if [ "$_valid_to" ] && ! _startswith "$_valid_to" "+"; then
53925392
_info "The domain is set to be valid until: $_valid_to"
53935393
_info "It cannot be renewed automatically"
53945394
_info "See: $_VALIDITY_WIKI"
5395+
Le_NextRenewTime="$Le_CertExpireTime"
53955396
else
5396-
_now=$(_time)
5397-
_debug2 "_now" "$_now"
5398-
_lifetime=$(_math $Le_NextRenewTime - $_now)
5399-
_debug2 "_lifetime" "$_lifetime"
5400-
if [ $_lifetime -gt 86400 ]; then
5401-
#if lifetime is logner than one day, it will renew one day before
5402-
Le_NextRenewTime=$(_math $Le_NextRenewTime - 86400)
5403-
Le_NextRenewTimeStr=$(_time2str "$Le_NextRenewTime")
5397+
# Calculate renewal time based on user's --days setting first
5398+
Le_UserRenewTime=$(_math "$Le_CertCreateTime" + "$Le_RenewalDays" \* 24 \* 60 \* 60)
5399+
_debug2 "Le_UserRenewTime" "$Le_UserRenewTime"
5400+
_debug2 "Le_CertExpireTime" "$Le_CertExpireTime"
5401+
5402+
# Check if user's renewal time is after certificate expiration
5403+
if [ "$Le_UserRenewTime" -ge "$Le_CertExpireTime" ]; then
5404+
# User's setting would renew after expiration, use fallback logic
5405+
_now=$(_time)
5406+
_debug2 "_now" "$_now"
5407+
_lifetime=$(_math $Le_CertExpireTime - $_now)
5408+
_debug2 "_lifetime" "$_lifetime"
5409+
if [ $_lifetime -gt 86400 ]; then
5410+
#if lifetime is longer than one day, it will renew one day before
5411+
Le_NextRenewTime=$(_math $Le_CertExpireTime - 86400)
5412+
_info "Certificate expires in less than $Le_RenewalDays days, setting renewal to 1 day before expiration"
5413+
else
5414+
#if lifetime is less than 24 hours, it will renew one hour before
5415+
Le_NextRenewTime=$(_math $Le_CertExpireTime - 3600)
5416+
_info "Certificate expires in less than 24 hours, setting renewal to 1 hour before expiration"
5417+
fi
54045418
else
5405-
#if lifetime is less than 24 hours, it will renew one hour before
5406-
Le_NextRenewTime=$(_math $Le_NextRenewTime - 3600)
5407-
Le_NextRenewTimeStr=$(_time2str "$Le_NextRenewTime")
5419+
# User's setting is valid, use it
5420+
Le_NextRenewTime="$Le_UserRenewTime"
5421+
_info "Using user-specified renewal time: $Le_RenewalDays days after issuance"
54085422
fi
5423+
Le_NextRenewTimeStr=$(_time2str "$Le_NextRenewTime")
54095424
fi
54105425
else
54115426
Le_NextRenewTime=$(_math "$Le_CertCreateTime" + "$Le_RenewalDays" \* 24 \* 60 \* 60)

0 commit comments

Comments
 (0)