This is an automated email from the ASF dual-hosted git repository.

pvillard31 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git


The following commit(s) were added to refs/heads/main by this push:
     new dd4336eb15f NIFI-16622 Adjusted SocketUtils to create SSLSocket after 
Socket connect (#11959)
dd4336eb15f is described below

commit dd4336eb15f73d70f4588fa69b2c999583c1c857
Author: David Handermann <[email protected]>
AuthorDate: Fri Nov 20 13:53:47 2026 -0600

    NIFI-16622 Adjusted SocketUtils to create SSLSocket after Socket connect 
(#11959)
    
    - Resolves potential hostname verification issues with separate creation 
and connect handling
---
 .../org/apache/nifi/io/socket/SocketUtils.java     | 41 +++++++++++-----------
 1 file changed, 21 insertions(+), 20 deletions(-)

diff --git 
a/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/io/socket/SocketUtils.java
 
b/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/io/socket/SocketUtils.java
index 522959b6b2e..23e6e39e646 100644
--- 
a/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/io/socket/SocketUtils.java
+++ 
b/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/io/socket/SocketUtils.java
@@ -31,6 +31,7 @@ import javax.net.ssl.SSLException;
 import javax.net.ssl.SSLParameters;
 import javax.net.ssl.SSLServerSocket;
 import javax.net.ssl.SSLSocket;
+import javax.net.ssl.SSLSocketFactory;
 
 public final class SocketUtils {
 
@@ -53,25 +54,7 @@ public final class SocketUtils {
             throw new IllegalArgumentException("Configuration may not be 
null.");
         }
 
-        final Socket socket;
-
-        final SSLContext sslContext = config.getSslContext();
-        if (sslContext == null) {
-            socket = new Socket();
-        } else {
-            /* This would ideally be refactored to a shared create method but 
Socket and ServerSocket
-             * do not share a common interface; Socket is effectively "client 
socket" in this context
-             */
-            Socket tempSocket = sslContext.getSocketFactory().createSocket();
-            final SSLSocket sslSocket = (SSLSocket) tempSocket;
-            // Set Preferred TLS Protocol Versions
-            
sslSocket.setEnabledProtocols(TlsPlatform.getPreferredProtocols().toArray(new 
String[0]));
-            final SSLParameters sslParameters = sslSocket.getSSLParameters();
-            
sslParameters.setEndpointIdentificationAlgorithm(TLS_ENDPOINT_IDENTIFICATION_ALGORITHM);
-            sslSocket.setSSLParameters(sslParameters);
-
-            socket = sslSocket;
-        }
+        final Socket socket = new Socket();
 
         if (config.getSocketTimeout() != null) {
             socket.setSoTimeout(config.getSocketTimeout());
@@ -116,7 +99,25 @@ public final class SocketUtils {
             throw e;
         }
 
-        return socket;
+        final Socket connectedSocket;
+
+        final SSLContext sslContext = config.getSslContext();
+        if (sslContext == null) {
+            connectedSocket = socket;
+        } 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);
+
+            
sslSocket.setEnabledProtocols(TlsPlatform.getPreferredProtocols().toArray(new 
String[0]));
+            final SSLParameters sslParameters = sslSocket.getSSLParameters();
+            
sslParameters.setEndpointIdentificationAlgorithm(TLS_ENDPOINT_IDENTIFICATION_ALGORITHM);
+            sslSocket.setSSLParameters(sslParameters);
+
+            connectedSocket = sslSocket;
+        }
+
+        return connectedSocket;
     }
 
     /**

Reply via email to