davsclaus commented on code in PR #31066:
URL: https://github.com/apache/camel/pull/31066#discussion_r4726310125


##########
core/camel-api/src/main/java/org/apache/camel/support/jsse/SSLContextClientParameters.java:
##########
@@ -54,6 +60,37 @@ public void setSniHostName(String sniHostName) {
         this.sniHostNames.add(sniHostName);
     }
 
+    /**
+     * Returns the endpoint identification algorithm that client sockets use 
to check that the certificate of the server
+     * matches the host they connect to, or {@code null} if it is not set.
+     */
+    public @Nullable String getEndpointIdentificationAlgorithm() {
+        return endpointIdentificationAlgorithm;
+    }
+
+    /**
+     * Sets the endpoint identification algorithm, such as {@code HTTPS} or 
{@code LDAPS}, that the client uses to check
+     * that the certificate of the server matches the host it connects to 
(host name verification). It is applied to the
+     * {@code SSLSocket} instances that the {@code SSLSocketFactory} of the 
context creates, which are client sockets.
+     * Unset by default, which keeps the behavior of the JDK: no host name 
verification.
+     * <p>
+     * The JDK checks the host that the socket was created with, so a socket 
that is created without one, and connected
+     * afterwards, fails the handshake. An {@code SSLEngine} starts in server 
mode and is switched to client mode by the

Review Comment:
   The JDK takes the peer host from the `InetSocketAddress` on `connect()`, so 
`createSocket()` followed by `connect(new InetSocketAddress("localhost", 
port))` passes with `HTTPS`. I checked this on JDK 25 with `localhost.p12`. 
What fails is connecting by IP address. Suggested wording (the formatter 
reflows it):
   
   ```suggestion
        * The JDK checks the host name that the socket connects to: the host 
given to {@code createSocket}, or the host of
        * the {@code InetSocketAddress} given to {@code connect}. Connecting to 
an IP address, or to an {@code InetAddress}
        * without a host name, fails the handshake unless the certificate lists 
that address. An {@code SSLEngine} starts
        * in server mode and is switched to client mode by the
   ```



##########
core/camel-api/src/main/java/org/apache/camel/support/jsse/SSLContextClientParameters.java:
##########
@@ -54,6 +60,37 @@ public void setSniHostName(String sniHostName) {
         this.sniHostNames.add(sniHostName);
     }
 
+    /**
+     * Returns the endpoint identification algorithm that client sockets use 
to check that the certificate of the server
+     * matches the host they connect to, or {@code null} if it is not set.

Review Comment:
   New public method in `core/camel-api`, so it needs `@since 4.24` (CLAUDE.md, 
"Javadoc `@since` tags"):
   
   ```suggestion
        *
        * @since 4.24
        */
   ```



##########
core/camel-api/src/main/java/org/apache/camel/support/jsse/SSLContextClientParameters.java:
##########
@@ -54,6 +60,37 @@ public void setSniHostName(String sniHostName) {
         this.sniHostNames.add(sniHostName);
     }
 
+    /**
+     * Returns the endpoint identification algorithm that client sockets use 
to check that the certificate of the server
+     * matches the host they connect to, or {@code null} if it is not set.
+     */
+    public @Nullable String getEndpointIdentificationAlgorithm() {
+        return endpointIdentificationAlgorithm;
+    }
+
+    /**
+     * Sets the endpoint identification algorithm, such as {@code HTTPS} or 
{@code LDAPS}, that the client uses to check
+     * that the certificate of the server matches the host it connects to 
(host name verification). It is applied to the
+     * {@code SSLSocket} instances that the {@code SSLSocketFactory} of the 
context creates, which are client sockets.
+     * Unset by default, which keeps the behavior of the JDK: no host name 
verification.
+     * <p>
+     * The JDK checks the host that the socket was created with, so a socket 
that is created without one, and connected
+     * afterwards, fails the handshake. An {@code SSLEngine} starts in server 
mode and is switched to client mode by the
+     * component, so this setting is not applied to engines: a component that 
uses an {@code SSLEngine} applies it to
+     * the {@code SSLParameters} of the engine once it is in client mode, as 
for its own host name verification option.
+     *
+     * @param endpointIdentificationAlgorithm the algorithm, or {@code null} 
to not verify the host name

Review Comment:
   Same as for the getter, `@since` as the last tag:
   
   ```suggestion
        * @param endpointIdentificationAlgorithm the algorithm, or {@code null} 
to not verify the host name
        * @since 4.24
   ```



##########
docs/user-manual/modules/ROOT/pages/camel-configuration-utilities.adoc:
##########
@@ -360,6 +361,17 @@ SSLContextClientParameters contains the following elements:
 sniHostNames::
 Contains a list of sniHostName elements which provides a list
 of SNIHostNames to be used for SSL.
+endpointIdentificationAlgorithm::
+This optional property turns on host name verification for the client
+sockets that the `SSLSocketFactory` of the context creates: with `HTTPS`
+(or `LDAPS`), the handshake fails unless the certificate of the server
+matches the host that the socket connects to. It is unset by default,
+which keeps the behavior of the JDK: no host name verification. It may
+use a property placeholder. The JDK checks the host that the socket was
+created with, so a socket created without one fails the handshake. It is

Review Comment:
   Same point as in the Javadoc: a socket created without a host and connected 
later picks up the host from the `InetSocketAddress`. Connecting by IP address 
is what fails.
   
   ```suggestion
   use a property placeholder. The JDK checks the host name that the socket
   connects to (the host given to `createSocket`, or of the `InetSocketAddress`
   given to `connect`), so connecting by IP address fails the handshake unless
   the certificate lists that address. It is
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to