This repository was archived by the owner on May 28, 2018. It is now read-only.
#3293 Pre-load default ssl socket factory in HttpUrlConnector#3738
Open
kevinconaway wants to merge 1 commit intojavaee:masterfrom
Open
#3293 Pre-load default ssl socket factory in HttpUrlConnector#3738kevinconaway wants to merge 1 commit intojavaee:masterfrom
kevinconaway wants to merge 1 commit intojavaee:masterfrom
Conversation
…y() to avoid a race condition in HttpUrlConnector#secureConnection
Author
|
@pavelbucek are you the correct person to review this? |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
@mpotociar @petrbouda this PR is a potential fix for #3293
From my understanding of the current code, the logic for using a custom SSL socket factory is:
HttpsUrlConnectionreturned by theConnectionFactoryalready has a customSSLSocketFactoryset on it, do nothingSSLContextin the client config.Currently, the first check is done via:
The issue with this code is that
HttpsURLConnection.getDefaultSSLSocketFactory()is not thread safe. The implementation looks like:If there are concurrent requests, one of them may end up creating a separate
SSLSocketFactorythat is not the default. The comparison check above fails and the request ends up using the default SSL context instead of the provided one.The fix in this PR is to call
HttpsURLConnection.getDefaultSSLSocketFactory()in a static initializer block for the class so that the default SSLContext is present when the comparison is made inHttpUrlConnector#secureConnectorI'm open to feedback on alternate approaches to resolving this.