Fix: Honor --days flag for short-lived certificates#6572
Open
hselomein wants to merge 2 commits intoacmesh-official:devfrom
Open
Fix: Honor --days flag for short-lived certificates#6572hselomein wants to merge 2 commits intoacmesh-official:devfrom
hselomein wants to merge 2 commits intoacmesh-official:devfrom
Conversation
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)
1e785a6 to
b115c47
Compare
Author
Update: Simplified Fix Based on TestingWhat ChangedAfter real-world testing, I discovered the original fix had an issue and have simplified the approach: Original PR approach:
Updated approach (current):
Bug Found During TestingThe original fix still had a logic issue. When testing with
The problem was in how the renewal time was being calculated and compared. The original code was still falling back to "1 day before expiry" even when the user's The Corrected FixNow the logic is much simpler and matches what happens when # Calculate renewal time based on user's --days setting
Le_UserRenewTime=$(_math "$Le_CertCreateTime" + "$Le_RenewalDays" \* 24 \* 60 \* 60)
# Check if this would be after certificate expiration
if [ "$Le_UserRenewTime" -ge "$Le_CertExpireTime" ]; then
# User's setting would renew after expiration, use fallback
Le_NextRenewTime=$(_math $Le_CertExpireTime - 86400)
_info "Certificate expires in less than $Le_RenewalDays days, setting renewal to 1 day before expiration"
else
# User's setting is valid, use it
Le_NextRenewTime="$Le_UserRenewTime"
_info "Using user-specified renewal time: $Le_RenewalDays days after issuance"
fi |
|
Here is another solution: #4457 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix --days flag to properly calculate renewal time with --valid-to
Summary
When using
--valid-towith--days, the renewal time was incorrectly set to 1 day before certificate expiry instead of respecting the user's--daysvalue. This fix ensures renewal is scheduled at the specified number of days after issuance, as intended.Background & Business Need
Our institution is proactively preparing for the industry-wide transition to shorter certificate lifetimes ahead of the 2029 deadline. We've moved to 47-day certificates now to:
Original Problem
The
--daysflag in acme.sh was being ignored for short-lived certificates:--days 60worked as expected--daysvalue was ignored, renewal defaulted to 1 day before expirationRoot Cause: The renewal calculation logic had separate code paths where short-lived certificates (when
_notAfteris set) ignoredLe_RenewalDaysand used hardcoded fallback logic instead of respecting user preferences.Update: Simplified Approach
After real-world testing, I simplified the fix:
Removed:
Reasoning:
The Solution
Modified the renewal calculation logic to match the behavior when
--valid-tois NOT used:Le_UserRenewTimeasLe_CertCreateTime + Le_RenewalDays * 86400Le_CertExpireTimeto validate renewal time is before expiry