Skip to content

NIFI-16622 Adjusted SocketUtils to create SSLSocket after Socket connect - #11959

Merged
pvillard31 merged 1 commit into
apache:mainfrom
exceptionfactory:NIFI-16622
Nov 20, 2026
Merged

pvillard31 merged 1 commit into
apache:mainfrom
exceptionfactory:NIFI-16622

Conversation

@exceptionfactory

Copy link
Copy Markdown
Contributor

Summary

NIFI-16622 Changes SocketUtils.createSocket() to create an SSLSocket after connecting the initial standard Socket. This approach supports alternative Security Providers such as Bouncy Castle that need the hostname during creation for hostname verification.

Tracking

Please complete the following tracking steps prior to pull request creation.

Issue Tracking

Pull Request Tracking

  • Pull Request title starts with Apache NiFi Jira issue number, such as NIFI-00000
  • Pull Request commit message starts with Apache NiFi Jira issue number, as such NIFI-00000
  • Pull request contains commits signed with a registered key indicating Verified status

Pull Request Formatting

  • Pull Request based on current revision of the main branch
  • Pull Request refers to a feature branch with one commit containing changes

Verification

Please indicate the verification steps performed prior to pull request creation.

Build

  • Build completed using ./mvnw clean install -P contrib-check
    • JDK 21
    • JDK 25

Licensing

  • New dependencies are compatible with the Apache License 2.0 according to the License Policy
  • New dependencies are documented in applicable LICENSE and NOTICE files

Documentation

  • Documentation formatting appears as expected in rendered files

- Resolves potential hostname verification issues with separate creation and connect handling
} else {
// Create SSLSocket after successful connection to support hostname verification
final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
final SSLSocket sslSocket = (SSLSocket) sslSocketFactory.createSocket(socket, address.getHostName(), address.getPort(), true);

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.

Should we close the connected socket if creating or configuring the SSLSocket throws, like the connect block does with closeQuietly?

@pvillard31 pvillard31 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.

My comment can be done as a follow up if needed.

@pvillard31
pvillard31 merged commit dd4336e into apache:main Nov 20, 2026
11 of 13 checks passed
@exceptionfactory

Copy link
Copy Markdown
Contributor Author

Thanks for reviewing and merging @pvillard31.

Regarding exception handling and closeQuietly(), I evaluated the behavior along with current callers and it does not look like a concern for standard operation, since the TLS handshake occurs after the method returns the socket. However, with the goal of avoid future unexpected behavior, I opened a follow on PR #11961 to add the try-catch with a unit test asserting expected handling.

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