feat: improve performance of getting validated cert chain from libcrypto#5622
Merged
CarolYeh910 merged 2 commits intoaws:mainfrom Nov 29, 2025
Merged
feat: improve performance of getting validated cert chain from libcrypto#5622CarolYeh910 merged 2 commits intoaws:mainfrom
CarolYeh910 merged 2 commits intoaws:mainfrom
Conversation
maddeleine
approved these changes
Nov 19, 2025
jouho
approved these changes
Nov 19, 2025
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.
Goal
This is used to get the cert chain to perform the cert intent validation, which means there's basically no performance cost to adding this validation.
Why
The scope of the certificate intent validation will include all certificates in the chain of trust, except for the trust anchor. In order to ensure that the trust anchor and any extraneous certificates are omitted from the validation, the chain of trust constructed by the libcrypto will be used as the source of the certificates to validate.
Currently, we get the constructed chain of trust from the X509_STORE_CTX_get1_chain() API. This API is inefficient because it allocates a new X509 stack and copies all of the certificates from the internal X509_STORE_CTX stack to it. On the other hand, the X509_STORE_CTX_get0_chain() API is more efficient, since it returns a pointer to the internal X509_STORE_CTX stack. However, this API is not available in OpenSSL 1.0.2.
Since the cert intent validation will be performed every time s2n-tls validates a certificate chain, it'd be better to use the more efficient API whenever it's available.
How
X509_STORE_CTX_get0_chain()API is available.s2n_validated_cert_chainto store the pointer to the validated cert chain.s2n_x509_validator_get_validated_cert_chain()that calls the get0_chain API when it's available, but falls back to using the get1_chain API for OpenSSL 1.0.2.s2n_x509_validator_get_validated_cert_chain().Testing
This change does not affect existing behaviors. CI should pass.
I also added a unit test for this getter to make sure the freeing is properly implemented.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.