ktls: improve messaging around freed handshakes #4346
Merged
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.
Description of changes:
A customer integrating with ktls ran into a "NULL pointer encountered" error because they tried to enable ktls after freeing the handshake, which is required to calculate the TLS1.2 keys. I've updated the documentation and added a specific check for "prf_space" so that the caller gets the slightly more helpful "Invalid state, this is the result of invalid use of an API. Check the API documentation for the function that raised this error for more info" error.
Call-outs:
We could theoretically re-allocate and then re-free the memory needed to calculate the TLS1.2 keys, but I don't think that's the right behavior. We should just provide the information the application needs to call the API in a way that doesn't waste memory.
Testing:
I manually verified that prf_space is the only field from the handshake that ktls needs for either TLS1.2 or TLS1.3 by adding the call to s2n_connection_free_handshake, but without s2n_prf_free.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.