-
Notifications
You must be signed in to change notification settings - Fork 712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: pem parsing detection of last cert errors #4908
Merged
Merged
Conversation
This file contains 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
goatgoose
reviewed
Nov 20, 2024
goatgoose
approved these changes
Nov 21, 2024
jmayclin
approved these changes
Nov 22, 2024
github-merge-queue
bot
removed this pull request from the merge queue due to no response for status checks
Dec 10, 2024
github-merge-queue
bot
removed this pull request from the merge queue due to failed status checks
Dec 10, 2024
github-merge-queue
bot
removed this pull request from the merge queue due to no response for status checks
Dec 11, 2024
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.
Release Summary:
Fixed a bug in certificate pem parsing. We now correctly reject certificate chains where the last certificate is unexpectedly significantly truncated (for example, missing the final "-- END CERTIFICATE --" marker).
Resolved issues:
resolves #4788
Description of changes:
Before, certificate parsing ignored errors unless there was unread data left in the stuffer after the failure. That meant any error due to missing data in the last certificate was ignored. My new tests are a good visual representation of what errors were previously ignored.
I modified the parsing logic to require that certificate parsing always succeed. Instead of attempting to parse the next certificate and then deciding how to handle any failures, we now first check for the delimiter characters ("--") and assert that parsing will succeed if the characters are present. If the characters aren't present, then there are no more certificates in the pem file (although there might be whitespace / comments / other garbage, but we also skipped over those before). Basically, we now treat any error that occurs after we find the delimiter characters as a real error, regardless of the state of the stuffer or chain.
The pem parsing code is also used for CRLs, private keys, and DH params, but all those parsing methods assume only one certificate in the pem and treat all errors as failures (although private key parsing does act on those errors).
Call-outs:
I also cleaned up memory management in the parsing method using DEFER_CLEANUP. It makes the diff harder to read, but it's not a large diff. But let me know if the diff is too hard to read and I should move the memory cleanup to another PR.
Testing:
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.