Skip to content

Refactored logic for determining SSL inputs #1607

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

Merged
merged 1 commit into from
Oct 2, 2023
Merged

Conversation

rjrudin
Copy link
Contributor

@rjrudin rjrudin commented Oct 2, 2023

I was looking at this while analyzing support for 2-way SSL and I couldn't really understand what I wrote. So I refactored in the following way:

  1. All construction for SSLContext/TrustManager is in buildSSLInputs.
  2. There are 4 approaches, each clearly identified and implemented in its own method.
  3. I moved the tests I use for verifying SSL support to a "test.ssl" package (no changes to the tests themselves).

This may actually fix a bug but I'm not certain. The bug would have been that "newCertificateAuthContext" was called before all the SSL-input logic had occurred, meaning that e.g. "default" as an sslProtocol value would not have impacted certificate authentication.

* @return
*/
private SSLInputs buildSSLInputs(String authType) {
SSLContext sslContext = null;
X509TrustManager userTrustManager = getTrustManager();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where all the changes start. This method should be a lot easier to understand now.

return (X509TrustManager) getDefaultTrustManagers()[0];
X509TrustManager trustManager = (X509TrustManager) getDefaultTrustManagers()[0];
Logger logger = LoggerFactory.getLogger(SSLUtil.class);
if (logger.isDebugEnabled() && trustManager.getAcceptedIssuers() != null) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved this logging here as it's useful to see for debugging purposes regardless of when this method is called.

I was looking at this while analyzing support for 2-way SSL and I couldn't really understand what I wrote. So I refactored in the following way:

1. All construction for SSLContext/TrustManager is in buildSSLInputs.
2. There are 4 approaches, each clearly identified and implemented in its own method.
3. I moved the tests I use for verifying SSL support to a "test.ssl" package (no changes to the tests themselves).

This may actually fix a bug but I'm not certain. The bug would have been that "newCertificateAuthContext" was called before all the SSL-input logic had occurred, meaning that e.g. "default" as an sslProtocol value would not have impacted certificate authentication.
@rjrudin rjrudin force-pushed the feature/ssl-cleanup branch from 4d5206b to 3b73a4a Compare October 2, 2023 16:31
Copy link
Contributor

@BillFarber BillFarber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rjrudin rjrudin merged commit f849cf4 into develop Oct 2, 2023
@rjrudin rjrudin deleted the feature/ssl-cleanup branch October 2, 2023 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants