Repository navigation
fix: validate duration on certificate regenerate - #1234
Merged
Merged
Conversation
Generate (POST /api/v1/data) rejects a certificate duration outside
1-3650 days, but regenerate (POST /api/v1/certificates/{id}/regenerate)
did not check the `duration` it accepts. Add the same check to
CertificateGenerateRequest.setDuration(), so regenerate now returns the
existing INVALID_DURATION error too. ONE_DAY and TEN_YEARS become
shared constants in CertificateGenerationRequestParameters.
Only a caller-supplied duration is checked. The check is not in the
domain-level CertificateGenerationParameters.validate(): regenerate
builds parameters from the existing certificate and setKeyLength() also
calls validate(), so checking there would break regenerating existing
certificates longer than 3650 days.
Prior context:
- The 1-3650 range was added in 2016 (11a331e) as input validation on
generate, not as a limit on stored certificate lifetimes.
- `credhub set` does not check validity, so imported certificates can
exceed 3650 days.
- Regenerating set certificates is supported, and regenerate keeps the
original duration (0c0d60f, 2017).
No product decision on long-lived imported certificates was found, so
this change leaves them as is. Open question: on regenerate, should they
keep their duration, be capped, or be rejected?
dlinsley
approved these changes
Nov 16, 2026
dlinsley
left a comment
Contributor
There was a problem hiding this comment.
Nice use of the parameterized test!
Setting a 10 year limit for the regeneration duration seems acceptable.
Thanks for the fix!
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.
Generate (POST /api/v1/data) rejects a certificate duration outside 1-3650 days, but regenerate (POST /api/v1/certificates/{id}/regenerate) did not check the
durationit accepts. Add the same check to CertificateGenerateRequest.setDuration(), so regenerate now returns the existing INVALID_DURATION error too. ONE_DAY and TEN_YEARS become shared constants in CertificateGenerationRequestParameters.Only a caller-supplied duration is checked. The check is not in the domain-level CertificateGenerationParameters.validate(): regenerate builds parameters from the existing certificate and setKeyLength() also calls validate(), so checking there would break regenerating existing certificates longer than 3650 days.
Prior context:
credhub setdoes not check validity, so imported certificates can exceed 3650 days.No product decision on long-lived imported certificates was found, so this change leaves them as is. Open question: on regenerate, should they keep their duration, be capped, or be rejected?