Fix bug in SslContext private key reading fall-back path#12746
Merged
normanmaurer merged 1 commit intonetty:4.1from Aug 27, 2022
Merged
Fix bug in SslContext private key reading fall-back path#12746normanmaurer merged 1 commit intonetty:4.1from
normanmaurer merged 1 commit intonetty:4.1from
Conversation
Motivation: We first try to read private keys with BouncyCastle, and then fall back to our own code if that fails. It could be the case, that BouncyCastle read some data before it failed, and in that case we need to make sure that our fallback code gets to read the key data from the original stream position - not whatever position caused a failure in BouncyCastle. Modification: Use the mark and reset methods of InputStream to reset the key stream position, if BouncyCastle cannot read a key. If the provided input stream does not already support marking, then we wrap it in a BufferedInputStream which does. We allow up to 1 MiB of data to be buffered for this purpose. If the key is bigger than this, and BouncyCastle reads more than this before failing, then resetting will throw an exception so we don't get silent failures. Result: Fixed private key fallback code path. Fixes netty#12745
normanmaurer
approved these changes
Aug 27, 2022
normanmaurer
pushed a commit
that referenced
this pull request
Aug 27, 2022
Motivation: We first try to read private keys with BouncyCastle, and then fall back to our own code if that fails. It could be the case, that BouncyCastle read some data before it failed, and in that case we need to make sure that our fallback code gets to read the key data from the original stream position - not whatever position caused a failure in BouncyCastle. Modification: Use the mark and reset methods of InputStream to reset the key stream position, if BouncyCastle cannot read a key. If the provided input stream does not already support marking, then we wrap it in a BufferedInputStream which does. We allow up to 1 MiB of data to be buffered for this purpose. If the key is bigger than this, and BouncyCastle reads more than this before failing, then resetting will throw an exception so we don't get silent failures. Result: Fixed private key fallback code path. Fixes #12745
This was referenced Sep 6, 2022
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.
Motivation:
We first try to read private keys with BouncyCastle, and then fall back to our own code if that fails.
It could be the case, that BouncyCastle read some data before it failed, and in that case we need to make sure that our fallback code gets to read the key data from the original stream position - not whatever position caused a failure in BouncyCastle.
Modification:
Use the mark and reset methods of InputStream to reset the key stream position, if BouncyCastle cannot read a key.
If the provided input stream does not already support marking, then we wrap it in a BufferedInputStream which does.
We allow up to 1 MiB of data to be buffered for this purpose.
If the key is bigger than this, and BouncyCastle reads more than this before failing, then resetting will throw an exception so we don't get silent failures.
Result:
Fixed private key fallback code path.
Fixes #12745