Skip to content

Refactored logic for determining SSL inputs - #1607

Merged
rjrudin merged 1 commit into
developfrom
feature/ssl-cleanup
Oct 2, 2023
Merged

Refactored logic for determining SSL inputs#1607
rjrudin merged 1 commit into
developfrom
feature/ssl-cleanup

Conversation

@rjrudin

@rjrudin rjrudin commented Oct 2, 2023

Copy link
Copy Markdown
Contributor

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.

*/
private SSLInputs buildSSLInputs(String authType) {
SSLContext sslContext = null;
X509TrustManager userTrustManager = getTrustManager();

Copy link
Copy Markdown
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
Copy Markdown
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

@BillFarber BillFarber left a comment

Copy link
Copy Markdown
Contributor

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