This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 02bd7fdd7590 CAMEL-28013: camel-netty, camel-netty-http - Apply the
endpointIdentificationAlgorithm of the client parameters to client engines
(#31221)
02bd7fdd7590 is described below
commit 02bd7fdd7590ac46cbfa6cd3950fb57d68dfa238
Author: Ayush Kulshreshtha <[email protected]>
AuthorDate: Wed Dec 2 17:57:58 2026 +0530
CAMEL-28013: camel-netty, camel-netty-http - Apply the
endpointIdentificationAlgorithm of the client parameters to client engines
(#31221)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
.../camel/catalog/components/netty-http.json | 4 +-
.../org/apache/camel/catalog/components/netty.json | 4 +-
.../apache/camel/catalog/docs/netty-component.adoc | 6 +
.../camel/catalog/docs/netty-http-component.adoc | 6 +
.../camel/component/netty/http/netty-http.json | 4 +-
.../src/main/docs/netty-http-component.adoc | 6 +
.../netty/http/HttpClientInitializerFactory.java | 11 +-
...HttpSSLEndpointIdentificationAlgorithmTest.java | 140 +++++++++++
.../org/apache/camel/component/netty/netty.json | 4 +-
.../camel-netty/src/main/docs/netty-component.adoc | 6 +
.../netty/DefaultClientInitializerFactory.java | 17 +-
.../netty/DefaultServerInitializerFactory.java | 17 +-
.../camel/component/netty/NettyConfiguration.java | 7 +-
.../component/netty/ssl/SSLEngineFactory.java | 21 ++
...nsumerClientModeEndpointIdentificationTest.java | 258 +++++++++++++++++++++
...ettySSLEndpointIdentificationAlgorithmTest.java | 156 +++++++++++++
...SSLEngineFactoryEndpointIdentificationTest.java | 94 ++++++++
.../dsl/NettyComponentBuilderFactory.java | 4 +-
.../dsl/NettyHttpComponentBuilderFactory.java | 4 +-
.../endpoint/dsl/NettyEndpointBuilderFactory.java | 24 +-
.../dsl/NettyHttpEndpointBuilderFactory.java | 24 +-
21 files changed, 783 insertions(+), 34 deletions(-)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/netty-http.json
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/netty-http.json
index 27c658265c11..6c63a4e06be5 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/netty-http.json
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/netty-http.json
@@ -91,7 +91,7 @@
"encoding": { "index": 63, "kind": "property", "displayName": "Encoding",
"group": "codec", "label": "codec", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": false, "configurationClass":
"org.apache.camel.component.netty.NettyConfiguration", "configurationField":
"configuration", "description": "The charset (such as UTF-8 or ISO-8859-1) of
the String codec that Camel installs (the textline codec or the default St [...]
"textline": { "index": 64, "kind": "property", "displayName": "Textline",
"group": "codec", "label": "codec", "required": false, "type": "boolean",
"javaType": "boolean", "deprecated": false, "autowired": false, "secret":
false, "defaultValue": false, "configurationClass":
"org.apache.camel.component.netty.NettyConfiguration", "configurationField":
"configuration", "description": "Whether to use the text line codec when no
encoders and decoders are set: each message is a line of text [...]
"enabledProtocols": { "index": 65, "kind": "property", "displayName":
"Enabled Protocols", "group": "security", "label": "security", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": "TLSv1.2,TLSv1.3",
"configurationClass": "org.apache.camel.component.netty.NettyConfiguration",
"configurationField": "configuration", "description": "The SSL\/TLS protocols
to enable, as a comma-separated list. [...]
- "hostnameVerification": { "index": 66, "kind": "property", "displayName":
"Hostname Verification", "group": "security", "label": "common,security",
"required": false, "type": "boolean", "javaType": "boolean", "deprecated":
false, "autowired": false, "secret": false, "security": "insecure:ssl",
"insecureValue": "false", "defaultValue": false, "configurationClass":
"org.apache.camel.component.netty.NettyConfiguration", "configurationField":
"configuration", "description": "To enable\/d [...]
+ "hostnameVerification": { "index": 66, "kind": "property", "displayName":
"Hostname Verification", "group": "security", "label": "common,security",
"required": false, "type": "boolean", "javaType": "boolean", "deprecated":
false, "autowired": false, "secret": false, "security": "insecure:ssl",
"insecureValue": "false", "defaultValue": false, "configurationClass":
"org.apache.camel.component.netty.NettyConfiguration", "configurationField":
"configuration", "description": "To enable ho [...]
"keyStoreFormat": { "index": 67, "kind": "property", "displayName": "Key
Store Format", "group": "security", "label": "security", "required": false,
"type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.netty.NettyConfiguration", "configurationField":
"configuration", "description": "The type of the keystore and the truststore,
such as JKS or PKCS12. Defaults to JKS if not set." },
"keyStoreResource": { "index": 68, "kind": "property", "displayName": "Key
Store Resource", "group": "security", "label": "security", "required": false,
"type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "supportFileReference": true,
"configurationClass": "org.apache.camel.component.netty.NettyConfiguration",
"configurationField": "configuration", "description": "The keystore with the
key and certificate of this endpoint, used [...]
"needClientAuth": { "index": 69, "kind": "property", "displayName": "Need
Client Auth", "group": "security", "label": "consumer,security", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false,
"configurationClass": "org.apache.camel.component.netty.NettyConfiguration",
"configurationField": "configuration", "description": "Configures whether the
server needs client authentication when using SSL." },
@@ -221,7 +221,7 @@
"encoders": { "index": 74, "kind": "parameter", "displayName": "Encoders",
"group": "codec", "label": "codec", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": false, "configurationClass":
"org.apache.camel.component.netty.http.NettyHttpConfiguration",
"configurationField": "configuration", "description": "The encoders (Netty
ChannelHandler) to add to the channel pipeline, as a comma-separated list of
references t [...]
"deserializationFilter": { "index": 75, "kind": "parameter",
"displayName": "Deserialization Filter", "group": "security", "label":
"advanced,security", "required": false, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"configurationClass":
"org.apache.camel.component.netty.http.NettyHttpConfiguration",
"configurationField": "configuration", "description": "Sets an
ObjectInputFilter pattern (jdk.serialFilter syntax) applied [...]
"enabledProtocols": { "index": 76, "kind": "parameter", "displayName":
"Enabled Protocols", "group": "security", "label": "security", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": "TLSv1.2,TLSv1.3",
"configurationClass":
"org.apache.camel.component.netty.http.NettyHttpConfiguration",
"configurationField": "configuration", "description": "The SSL\/TLS protocols
to enable, as a comma-separa [...]
- "hostnameVerification": { "index": 77, "kind": "parameter", "displayName":
"Hostname Verification", "group": "security", "label": "common,security",
"required": false, "type": "boolean", "javaType": "boolean", "deprecated":
false, "autowired": false, "secret": false, "security": "insecure:ssl",
"insecureValue": "false", "defaultValue": false, "configurationClass":
"org.apache.camel.component.netty.http.NettyHttpConfiguration",
"configurationField": "configuration", "description": "To [...]
+ "hostnameVerification": { "index": 77, "kind": "parameter", "displayName":
"Hostname Verification", "group": "security", "label": "common,security",
"required": false, "type": "boolean", "javaType": "boolean", "deprecated":
false, "autowired": false, "secret": false, "security": "insecure:ssl",
"insecureValue": "false", "defaultValue": false, "configurationClass":
"org.apache.camel.component.netty.http.NettyHttpConfiguration",
"configurationField": "configuration", "description": "To [...]
"keyStoreFormat": { "index": 78, "kind": "parameter", "displayName": "Key
Store Format", "group": "security", "label": "security", "required": false,
"type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.netty.http.NettyHttpConfiguration",
"configurationField": "configuration", "description": "The type of the keystore
and the truststore, such as JKS or PKCS12. Defaults to JKS if no [...]
"keyStoreResource": { "index": 79, "kind": "parameter", "displayName":
"Key Store Resource", "group": "security", "label": "security", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "supportFileReference": true,
"configurationClass":
"org.apache.camel.component.netty.http.NettyHttpConfiguration",
"configurationField": "configuration", "description": "The keystore with the
key and certificate of this endpo [...]
"needClientAuth": { "index": 80, "kind": "parameter", "displayName": "Need
Client Auth", "group": "security", "label": "consumer,security", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false,
"configurationClass":
"org.apache.camel.component.netty.http.NettyHttpConfiguration",
"configurationField": "configuration", "description": "Configures whether the
server needs client authentication when us [...]
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/netty.json
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/netty.json
index 1a3133b51f10..568d2514d569 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/netty.json
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/netty.json
@@ -88,7 +88,7 @@
"encoding": { "index": 61, "kind": "property", "displayName": "Encoding",
"group": "codec", "label": "codec", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": false, "configurationClass":
"org.apache.camel.component.netty.NettyConfiguration", "configurationField":
"configuration", "description": "The charset (such as UTF-8 or ISO-8859-1) of
the String codec that Camel installs (the textline codec or the default St [...]
"textline": { "index": 62, "kind": "property", "displayName": "Textline",
"group": "codec", "label": "codec", "required": false, "type": "boolean",
"javaType": "boolean", "deprecated": false, "autowired": false, "secret":
false, "defaultValue": false, "configurationClass":
"org.apache.camel.component.netty.NettyConfiguration", "configurationField":
"configuration", "description": "Whether to use the text line codec when no
encoders and decoders are set: each message is a line of text [...]
"enabledProtocols": { "index": 63, "kind": "property", "displayName":
"Enabled Protocols", "group": "security", "label": "security", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": "TLSv1.2,TLSv1.3",
"configurationClass": "org.apache.camel.component.netty.NettyConfiguration",
"configurationField": "configuration", "description": "The SSL\/TLS protocols
to enable, as a comma-separated list. [...]
- "hostnameVerification": { "index": 64, "kind": "property", "displayName":
"Hostname Verification", "group": "security", "label": "common,security",
"required": false, "type": "boolean", "javaType": "boolean", "deprecated":
false, "autowired": false, "secret": false, "security": "insecure:ssl",
"insecureValue": "false", "defaultValue": false, "configurationClass":
"org.apache.camel.component.netty.NettyConfiguration", "configurationField":
"configuration", "description": "To enable\/d [...]
+ "hostnameVerification": { "index": 64, "kind": "property", "displayName":
"Hostname Verification", "group": "security", "label": "common,security",
"required": false, "type": "boolean", "javaType": "boolean", "deprecated":
false, "autowired": false, "secret": false, "security": "insecure:ssl",
"insecureValue": "false", "defaultValue": false, "configurationClass":
"org.apache.camel.component.netty.NettyConfiguration", "configurationField":
"configuration", "description": "To enable ho [...]
"keyStoreFormat": { "index": 65, "kind": "property", "displayName": "Key
Store Format", "group": "security", "label": "security", "required": false,
"type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.netty.NettyConfiguration", "configurationField":
"configuration", "description": "The type of the keystore and the truststore,
such as JKS or PKCS12. Defaults to JKS if not set." },
"keyStoreResource": { "index": 66, "kind": "property", "displayName": "Key
Store Resource", "group": "security", "label": "security", "required": false,
"type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "supportFileReference": true,
"configurationClass": "org.apache.camel.component.netty.NettyConfiguration",
"configurationField": "configuration", "description": "The keystore with the
key and certificate of this endpoint, used [...]
"needClientAuth": { "index": 67, "kind": "property", "displayName": "Need
Client Auth", "group": "security", "label": "consumer,security", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false,
"configurationClass": "org.apache.camel.component.netty.NettyConfiguration",
"configurationField": "configuration", "description": "Configures whether the
server needs client authentication when using SSL." },
@@ -189,7 +189,7 @@
"encoding": { "index": 64, "kind": "parameter", "displayName": "Encoding",
"group": "codec", "label": "codec", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": false, "configurationClass":
"org.apache.camel.component.netty.NettyConfiguration", "configurationField":
"configuration", "description": "The charset (such as UTF-8 or ISO-8859-1) of
the String codec that Camel installs (the textline codec or the default S [...]
"textline": { "index": 65, "kind": "parameter", "displayName": "Textline",
"group": "codec", "label": "codec", "required": false, "type": "boolean",
"javaType": "boolean", "deprecated": false, "autowired": false, "secret":
false, "defaultValue": false, "configurationClass":
"org.apache.camel.component.netty.NettyConfiguration", "configurationField":
"configuration", "description": "Whether to use the text line codec when no
encoders and decoders are set: each message is a line of tex [...]
"enabledProtocols": { "index": 66, "kind": "parameter", "displayName":
"Enabled Protocols", "group": "security", "label": "security", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": "TLSv1.2,TLSv1.3",
"configurationClass": "org.apache.camel.component.netty.NettyConfiguration",
"configurationField": "configuration", "description": "The SSL\/TLS protocols
to enable, as a comma-separated list. [...]
- "hostnameVerification": { "index": 67, "kind": "parameter", "displayName":
"Hostname Verification", "group": "security", "label": "common,security",
"required": false, "type": "boolean", "javaType": "boolean", "deprecated":
false, "autowired": false, "secret": false, "security": "insecure:ssl",
"insecureValue": "false", "defaultValue": false, "configurationClass":
"org.apache.camel.component.netty.NettyConfiguration", "configurationField":
"configuration", "description": "To enable\/ [...]
+ "hostnameVerification": { "index": 67, "kind": "parameter", "displayName":
"Hostname Verification", "group": "security", "label": "common,security",
"required": false, "type": "boolean", "javaType": "boolean", "deprecated":
false, "autowired": false, "secret": false, "security": "insecure:ssl",
"insecureValue": "false", "defaultValue": false, "configurationClass":
"org.apache.camel.component.netty.NettyConfiguration", "configurationField":
"configuration", "description": "To enable h [...]
"keyStoreFormat": { "index": 68, "kind": "parameter", "displayName": "Key
Store Format", "group": "security", "label": "security", "required": false,
"type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.netty.NettyConfiguration", "configurationField":
"configuration", "description": "The type of the keystore and the truststore,
such as JKS or PKCS12. Defaults to JKS if not set." },
"keyStoreResource": { "index": 69, "kind": "parameter", "displayName":
"Key Store Resource", "group": "security", "label": "security", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "supportFileReference": true,
"configurationClass": "org.apache.camel.component.netty.NettyConfiguration",
"configurationField": "configuration", "description": "The keystore with the
key and certificate of this endpoint, used [...]
"needClientAuth": { "index": 70, "kind": "parameter", "displayName": "Need
Client Auth", "group": "security", "label": "consumer,security", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false,
"configurationClass": "org.apache.camel.component.netty.NettyConfiguration",
"configurationField": "configuration", "description": "Configures whether the
server needs client authentication when using SSL." },
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/netty-component.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/netty-component.adoc
index 452876197d01..84941b87209a 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/netty-component.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/netty-component.adoc
@@ -702,6 +702,12 @@ A certificate that does not match makes the producer or
consumer fail with an
`No subject alternative DNS name matching ... found` for a host name).
Enabling the option also makes the JDK send the
host as an SNI server name.
+Host name verification is also enabled, without `hostnameVerification`, when
the client parameters of the
+`sslContextParameters` set an `endpointIdentificationAlgorithm`, such as
`HTTPS` or `LDAPS` (see
+xref:manual::camel-configuration-utilities.adoc[the JSSE Configuration
Utility]). This includes the global SSL
+configuration that the endpoint uses with
`useGlobalSslContextParameters=true`. When `hostnameVerification=true` is set
+as well, it takes precedence and the algorithm is `HTTPS`.
+
The option applies to the client side only. On a consumer that acts as a
server it is ignored, because the JDK does not
support host name verification on that side of a handshake: asked to do it
anyway, it rejects the client certificate
with `Endpoint Identification Algorithm HTTPS is not supported on the server
side`.
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/netty-http-component.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/netty-http-component.adoc
index 98daaa0147f1..6183cdefb95d 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/netty-http-component.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/netty-http-component.adoc
@@ -189,6 +189,12 @@ matches the host it connects to, with the same rules as an
HTTPS client: a conne
certificate that lists that address as a subject alternative name of its own.
A certificate that does not match makes
the call fail with an `SSLHandshakeException`.
+Host name verification is also enabled, without `hostnameVerification`, when
the client parameters of the
+`sslContextParameters` set an `endpointIdentificationAlgorithm`, such as
`HTTPS` (see
+xref:manual::camel-configuration-utilities.adoc[the JSSE Configuration
Utility]). This includes the global SSL
+configuration that the endpoint uses with
`useGlobalSslContextParameters=true`. When `hostnameVerification=true` is set
+as well, it takes precedence and the algorithm is `HTTPS`.
+
The option applies to the producer only. On a consumer it is ignored, because
the JDK does not support host name
verification on the server side of a handshake. To control which clients may
connect to a consumer, use client
authentication (`needClientAuth=true`) with a trust store that holds only the
certificates you accept.
diff --git
a/components/camel-netty-http/src/generated/resources/META-INF/org/apache/camel/component/netty/http/netty-http.json
b/components/camel-netty-http/src/generated/resources/META-INF/org/apache/camel/component/netty/http/netty-http.json
index 27c658265c11..6c63a4e06be5 100644
---
a/components/camel-netty-http/src/generated/resources/META-INF/org/apache/camel/component/netty/http/netty-http.json
+++
b/components/camel-netty-http/src/generated/resources/META-INF/org/apache/camel/component/netty/http/netty-http.json
@@ -91,7 +91,7 @@
"encoding": { "index": 63, "kind": "property", "displayName": "Encoding",
"group": "codec", "label": "codec", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": false, "configurationClass":
"org.apache.camel.component.netty.NettyConfiguration", "configurationField":
"configuration", "description": "The charset (such as UTF-8 or ISO-8859-1) of
the String codec that Camel installs (the textline codec or the default St [...]
"textline": { "index": 64, "kind": "property", "displayName": "Textline",
"group": "codec", "label": "codec", "required": false, "type": "boolean",
"javaType": "boolean", "deprecated": false, "autowired": false, "secret":
false, "defaultValue": false, "configurationClass":
"org.apache.camel.component.netty.NettyConfiguration", "configurationField":
"configuration", "description": "Whether to use the text line codec when no
encoders and decoders are set: each message is a line of text [...]
"enabledProtocols": { "index": 65, "kind": "property", "displayName":
"Enabled Protocols", "group": "security", "label": "security", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": "TLSv1.2,TLSv1.3",
"configurationClass": "org.apache.camel.component.netty.NettyConfiguration",
"configurationField": "configuration", "description": "The SSL\/TLS protocols
to enable, as a comma-separated list. [...]
- "hostnameVerification": { "index": 66, "kind": "property", "displayName":
"Hostname Verification", "group": "security", "label": "common,security",
"required": false, "type": "boolean", "javaType": "boolean", "deprecated":
false, "autowired": false, "secret": false, "security": "insecure:ssl",
"insecureValue": "false", "defaultValue": false, "configurationClass":
"org.apache.camel.component.netty.NettyConfiguration", "configurationField":
"configuration", "description": "To enable\/d [...]
+ "hostnameVerification": { "index": 66, "kind": "property", "displayName":
"Hostname Verification", "group": "security", "label": "common,security",
"required": false, "type": "boolean", "javaType": "boolean", "deprecated":
false, "autowired": false, "secret": false, "security": "insecure:ssl",
"insecureValue": "false", "defaultValue": false, "configurationClass":
"org.apache.camel.component.netty.NettyConfiguration", "configurationField":
"configuration", "description": "To enable ho [...]
"keyStoreFormat": { "index": 67, "kind": "property", "displayName": "Key
Store Format", "group": "security", "label": "security", "required": false,
"type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.netty.NettyConfiguration", "configurationField":
"configuration", "description": "The type of the keystore and the truststore,
such as JKS or PKCS12. Defaults to JKS if not set." },
"keyStoreResource": { "index": 68, "kind": "property", "displayName": "Key
Store Resource", "group": "security", "label": "security", "required": false,
"type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "supportFileReference": true,
"configurationClass": "org.apache.camel.component.netty.NettyConfiguration",
"configurationField": "configuration", "description": "The keystore with the
key and certificate of this endpoint, used [...]
"needClientAuth": { "index": 69, "kind": "property", "displayName": "Need
Client Auth", "group": "security", "label": "consumer,security", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false,
"configurationClass": "org.apache.camel.component.netty.NettyConfiguration",
"configurationField": "configuration", "description": "Configures whether the
server needs client authentication when using SSL." },
@@ -221,7 +221,7 @@
"encoders": { "index": 74, "kind": "parameter", "displayName": "Encoders",
"group": "codec", "label": "codec", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": false, "configurationClass":
"org.apache.camel.component.netty.http.NettyHttpConfiguration",
"configurationField": "configuration", "description": "The encoders (Netty
ChannelHandler) to add to the channel pipeline, as a comma-separated list of
references t [...]
"deserializationFilter": { "index": 75, "kind": "parameter",
"displayName": "Deserialization Filter", "group": "security", "label":
"advanced,security", "required": false, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"configurationClass":
"org.apache.camel.component.netty.http.NettyHttpConfiguration",
"configurationField": "configuration", "description": "Sets an
ObjectInputFilter pattern (jdk.serialFilter syntax) applied [...]
"enabledProtocols": { "index": 76, "kind": "parameter", "displayName":
"Enabled Protocols", "group": "security", "label": "security", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": "TLSv1.2,TLSv1.3",
"configurationClass":
"org.apache.camel.component.netty.http.NettyHttpConfiguration",
"configurationField": "configuration", "description": "The SSL\/TLS protocols
to enable, as a comma-separa [...]
- "hostnameVerification": { "index": 77, "kind": "parameter", "displayName":
"Hostname Verification", "group": "security", "label": "common,security",
"required": false, "type": "boolean", "javaType": "boolean", "deprecated":
false, "autowired": false, "secret": false, "security": "insecure:ssl",
"insecureValue": "false", "defaultValue": false, "configurationClass":
"org.apache.camel.component.netty.http.NettyHttpConfiguration",
"configurationField": "configuration", "description": "To [...]
+ "hostnameVerification": { "index": 77, "kind": "parameter", "displayName":
"Hostname Verification", "group": "security", "label": "common,security",
"required": false, "type": "boolean", "javaType": "boolean", "deprecated":
false, "autowired": false, "secret": false, "security": "insecure:ssl",
"insecureValue": "false", "defaultValue": false, "configurationClass":
"org.apache.camel.component.netty.http.NettyHttpConfiguration",
"configurationField": "configuration", "description": "To [...]
"keyStoreFormat": { "index": 78, "kind": "parameter", "displayName": "Key
Store Format", "group": "security", "label": "security", "required": false,
"type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.netty.http.NettyHttpConfiguration",
"configurationField": "configuration", "description": "The type of the keystore
and the truststore, such as JKS or PKCS12. Defaults to JKS if no [...]
"keyStoreResource": { "index": 79, "kind": "parameter", "displayName":
"Key Store Resource", "group": "security", "label": "security", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "supportFileReference": true,
"configurationClass":
"org.apache.camel.component.netty.http.NettyHttpConfiguration",
"configurationField": "configuration", "description": "The keystore with the
key and certificate of this endpo [...]
"needClientAuth": { "index": 80, "kind": "parameter", "displayName": "Need
Client Auth", "group": "security", "label": "consumer,security", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false,
"configurationClass":
"org.apache.camel.component.netty.http.NettyHttpConfiguration",
"configurationField": "configuration", "description": "Configures whether the
server needs client authentication when us [...]
diff --git
a/components/camel-netty-http/src/main/docs/netty-http-component.adoc
b/components/camel-netty-http/src/main/docs/netty-http-component.adoc
index 98daaa0147f1..6183cdefb95d 100644
--- a/components/camel-netty-http/src/main/docs/netty-http-component.adoc
+++ b/components/camel-netty-http/src/main/docs/netty-http-component.adoc
@@ -189,6 +189,12 @@ matches the host it connects to, with the same rules as an
HTTPS client: a conne
certificate that lists that address as a subject alternative name of its own.
A certificate that does not match makes
the call fail with an `SSLHandshakeException`.
+Host name verification is also enabled, without `hostnameVerification`, when
the client parameters of the
+`sslContextParameters` set an `endpointIdentificationAlgorithm`, such as
`HTTPS` (see
+xref:manual::camel-configuration-utilities.adoc[the JSSE Configuration
Utility]). This includes the global SSL
+configuration that the endpoint uses with
`useGlobalSslContextParameters=true`. When `hostnameVerification=true` is set
+as well, it takes precedence and the algorithm is `HTTPS`.
+
The option applies to the producer only. On a consumer it is ignored, because
the JDK does not support host name
verification on the server side of a handshake. To control which clients may
connect to a consumer, use client
authentication (`needClientAuth=true`) with a trust store that holds only the
certificates you accept.
diff --git
a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpClientInitializerFactory.java
b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpClientInitializerFactory.java
index ea24bfe9ca0b..4bd29497cb52 100644
---
a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpClientInitializerFactory.java
+++
b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpClientInitializerFactory.java
@@ -56,6 +56,7 @@ public class HttpClientInitializerFactory extends
ClientInitializerFactory {
private NettyHttpProducer producer;
private SSLContext sslContext;
private List<SNIServerName> sniServerNames;
+ private String endpointIdentificationAlgorithm;
public HttpClientInitializerFactory() {
// default constructor needed
@@ -65,6 +66,12 @@ public class HttpClientInitializerFactory extends
ClientInitializerFactory {
this.producer = nettyProducer;
try {
this.sslContext = createSSLContext(producer);
+ if (sslContext != null) {
+ this.endpointIdentificationAlgorithm
+ =
SSLEngineFactory.getClientEndpointIdentificationAlgorithm(producer.getContext(),
+
producer.getConfiguration().isHostnameVerification(),
+
producer.getConfiguration().getSslContextParameters());
+ }
} catch (Exception e) {
throw RuntimeCamelException.wrapRuntimeCamelException(e);
}
@@ -177,8 +184,8 @@ public class HttpClientInitializerFactory extends
ClientInitializerFactory {
SSLParameters sslParameters = engine.getSSLParameters();
sslParameters
.setServerNames(sniServerNames != null ? sniServerNames :
List.of(new SNIHostName(uri.getHost())));
- if (producer.getConfiguration().isHostnameVerification()) {
- sslParameters.setEndpointIdentificationAlgorithm("HTTPS");
+ if (endpointIdentificationAlgorithm != null) {
+
sslParameters.setEndpointIdentificationAlgorithm(endpointIdentificationAlgorithm);
}
engine.setSSLParameters(sslParameters);
if (producer.getConfiguration().getSslContextParameters() == null)
{
diff --git
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpSSLEndpointIdentificationAlgorithmTest.java
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpSSLEndpointIdentificationAlgorithmTest.java
new file mode 100644
index 000000000000..e6fc97bdd7e6
--- /dev/null
+++
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpSSLEndpointIdentificationAlgorithmTest.java
@@ -0,0 +1,140 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.netty.http;
+
+import javax.net.ssl.SSLHandshakeException;
+
+import org.apache.camel.BindToRegistry;
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.support.jsse.KeyManagersParameters;
+import org.apache.camel.support.jsse.KeyStoreParameters;
+import org.apache.camel.support.jsse.SSLContextClientParameters;
+import org.apache.camel.support.jsse.SSLContextParameters;
+import org.apache.camel.support.jsse.TrustManagersParameters;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.DisabledIfSystemProperty;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * The producer checks that the certificate of the server matches the host it
connects to when the client parameters of
+ * the {@code sslContextParameters} set an {@code
endpointIdentificationAlgorithm}, without
+ * {@code hostnameVerification}.
+ * <p/>
+ * localhost.p12 lists only DNS:localhost as subject alternative name, so it
matches "localhost" but not "127.0.0.1",
+ * which both reach the same consumer. The consumer uses the same parameters:
the algorithm applies to client engines
+ * only.
+ */
+@DisabledIfSystemProperty(named = "java.vendor", matches = ".*ibm.*")
+public class NettyHttpSSLEndpointIdentificationAlgorithmTest extends
BaseNettyTestSupport {
+
+ @BindToRegistry("sslContextParameters")
+ public SSLContextParameters loadSSLContextParameters() {
+ SSLContextParameters answer = createSSLContextParameters();
+ SSLContextClientParameters clientParameters = new
SSLContextClientParameters();
+ clientParameters.setEndpointIdentificationAlgorithm("HTTPS");
+ answer.setClientParameters(clientParameters);
+ return answer;
+ }
+
+ @BindToRegistry("noEndpointIdentification")
+ public SSLContextParameters loadSSLContextParametersWithoutAlgorithm() {
+ return createSSLContextParameters();
+ }
+
+ private static SSLContextParameters createSSLContextParameters() {
+ KeyStoreParameters ksp = new KeyStoreParameters();
+ ksp.setResource("jsse/localhost.p12");
+ ksp.setPassword("changeit");
+
+ KeyManagersParameters kmp = new KeyManagersParameters();
+ kmp.setKeyPassword("changeit");
+ kmp.setKeyStore(ksp);
+
+ TrustManagersParameters tmp = new TrustManagersParameters();
+ tmp.setKeyStore(ksp);
+
+ SSLContextParameters answer = new SSLContextParameters();
+ answer.setKeyManagers(kmp);
+ answer.setTrustManagers(tmp);
+ return answer;
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+
from("netty-http:https://localhost:{{port}}/hello?sslContextParameters=#sslContextParameters")
+ .transform().constant("Bye World");
+ }
+ };
+ }
+
+ @Test
+ public void testConnectsWhenTheCertificateMatchesTheHost() {
+ String out = template.requestBody(
+
"netty-http:https://localhost:{{port}}/hello?sslContextParameters=#sslContextParameters",
+ "Hello World", String.class);
+
+ assertEquals("Bye World", out);
+ }
+
+ @Test
+ public void testFailsWhenTheCertificateDoesNotMatchTheHost() {
+ CamelExecutionException e = assertThrows(CamelExecutionException.class,
+ () -> template.requestBody(
+
"netty-http:https://127.0.0.1:{{port}}/hello?sslContextParameters=#sslContextParameters",
+ "Hello World", String.class));
+
+ // the handshake was rejected by the host name check, and not, for
example, a connection refused
+ assertNotNull(findCause(e, SSLHandshakeException.class), "expected an
SSLHandshakeException in " + e);
+ String message = rootCause(e).getMessage();
+ assertTrue(message != null && message.contains("No subject alternative
names matching IP address 127.0.0.1"),
+ "the host name check should have rejected the certificate, but
got: " + message);
+ }
+
+ @Test
+ public void
testConnectsToAHostTheCertificateDoesNotListWithoutTheAlgorithm() {
+ String out = template.requestBody(
+
"netty-http:https://127.0.0.1:{{port}}/hello?sslContextParameters=#noEndpointIdentification",
+ "Hello World", String.class);
+
+ assertEquals("Bye World", out);
+ }
+
+ private static Throwable findCause(Throwable t, Class<? extends Throwable>
type) {
+ for (Throwable cause = t; cause != null; cause = cause.getCause()) {
+ if (type.isInstance(cause)) {
+ return cause;
+ }
+ }
+ return null;
+ }
+
+ private static Throwable rootCause(Throwable t) {
+ Throwable answer = t;
+ while (answer.getCause() != null) {
+ answer = answer.getCause();
+ }
+ return answer;
+ }
+}
diff --git
a/components/camel-netty/src/generated/resources/META-INF/org/apache/camel/component/netty/netty.json
b/components/camel-netty/src/generated/resources/META-INF/org/apache/camel/component/netty/netty.json
index 1a3133b51f10..568d2514d569 100644
---
a/components/camel-netty/src/generated/resources/META-INF/org/apache/camel/component/netty/netty.json
+++
b/components/camel-netty/src/generated/resources/META-INF/org/apache/camel/component/netty/netty.json
@@ -88,7 +88,7 @@
"encoding": { "index": 61, "kind": "property", "displayName": "Encoding",
"group": "codec", "label": "codec", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": false, "configurationClass":
"org.apache.camel.component.netty.NettyConfiguration", "configurationField":
"configuration", "description": "The charset (such as UTF-8 or ISO-8859-1) of
the String codec that Camel installs (the textline codec or the default St [...]
"textline": { "index": 62, "kind": "property", "displayName": "Textline",
"group": "codec", "label": "codec", "required": false, "type": "boolean",
"javaType": "boolean", "deprecated": false, "autowired": false, "secret":
false, "defaultValue": false, "configurationClass":
"org.apache.camel.component.netty.NettyConfiguration", "configurationField":
"configuration", "description": "Whether to use the text line codec when no
encoders and decoders are set: each message is a line of text [...]
"enabledProtocols": { "index": 63, "kind": "property", "displayName":
"Enabled Protocols", "group": "security", "label": "security", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": "TLSv1.2,TLSv1.3",
"configurationClass": "org.apache.camel.component.netty.NettyConfiguration",
"configurationField": "configuration", "description": "The SSL\/TLS protocols
to enable, as a comma-separated list. [...]
- "hostnameVerification": { "index": 64, "kind": "property", "displayName":
"Hostname Verification", "group": "security", "label": "common,security",
"required": false, "type": "boolean", "javaType": "boolean", "deprecated":
false, "autowired": false, "secret": false, "security": "insecure:ssl",
"insecureValue": "false", "defaultValue": false, "configurationClass":
"org.apache.camel.component.netty.NettyConfiguration", "configurationField":
"configuration", "description": "To enable\/d [...]
+ "hostnameVerification": { "index": 64, "kind": "property", "displayName":
"Hostname Verification", "group": "security", "label": "common,security",
"required": false, "type": "boolean", "javaType": "boolean", "deprecated":
false, "autowired": false, "secret": false, "security": "insecure:ssl",
"insecureValue": "false", "defaultValue": false, "configurationClass":
"org.apache.camel.component.netty.NettyConfiguration", "configurationField":
"configuration", "description": "To enable ho [...]
"keyStoreFormat": { "index": 65, "kind": "property", "displayName": "Key
Store Format", "group": "security", "label": "security", "required": false,
"type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.netty.NettyConfiguration", "configurationField":
"configuration", "description": "The type of the keystore and the truststore,
such as JKS or PKCS12. Defaults to JKS if not set." },
"keyStoreResource": { "index": 66, "kind": "property", "displayName": "Key
Store Resource", "group": "security", "label": "security", "required": false,
"type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "supportFileReference": true,
"configurationClass": "org.apache.camel.component.netty.NettyConfiguration",
"configurationField": "configuration", "description": "The keystore with the
key and certificate of this endpoint, used [...]
"needClientAuth": { "index": 67, "kind": "property", "displayName": "Need
Client Auth", "group": "security", "label": "consumer,security", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false,
"configurationClass": "org.apache.camel.component.netty.NettyConfiguration",
"configurationField": "configuration", "description": "Configures whether the
server needs client authentication when using SSL." },
@@ -189,7 +189,7 @@
"encoding": { "index": 64, "kind": "parameter", "displayName": "Encoding",
"group": "codec", "label": "codec", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": false, "configurationClass":
"org.apache.camel.component.netty.NettyConfiguration", "configurationField":
"configuration", "description": "The charset (such as UTF-8 or ISO-8859-1) of
the String codec that Camel installs (the textline codec or the default S [...]
"textline": { "index": 65, "kind": "parameter", "displayName": "Textline",
"group": "codec", "label": "codec", "required": false, "type": "boolean",
"javaType": "boolean", "deprecated": false, "autowired": false, "secret":
false, "defaultValue": false, "configurationClass":
"org.apache.camel.component.netty.NettyConfiguration", "configurationField":
"configuration", "description": "Whether to use the text line codec when no
encoders and decoders are set: each message is a line of tex [...]
"enabledProtocols": { "index": 66, "kind": "parameter", "displayName":
"Enabled Protocols", "group": "security", "label": "security", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": "TLSv1.2,TLSv1.3",
"configurationClass": "org.apache.camel.component.netty.NettyConfiguration",
"configurationField": "configuration", "description": "The SSL\/TLS protocols
to enable, as a comma-separated list. [...]
- "hostnameVerification": { "index": 67, "kind": "parameter", "displayName":
"Hostname Verification", "group": "security", "label": "common,security",
"required": false, "type": "boolean", "javaType": "boolean", "deprecated":
false, "autowired": false, "secret": false, "security": "insecure:ssl",
"insecureValue": "false", "defaultValue": false, "configurationClass":
"org.apache.camel.component.netty.NettyConfiguration", "configurationField":
"configuration", "description": "To enable\/ [...]
+ "hostnameVerification": { "index": 67, "kind": "parameter", "displayName":
"Hostname Verification", "group": "security", "label": "common,security",
"required": false, "type": "boolean", "javaType": "boolean", "deprecated":
false, "autowired": false, "secret": false, "security": "insecure:ssl",
"insecureValue": "false", "defaultValue": false, "configurationClass":
"org.apache.camel.component.netty.NettyConfiguration", "configurationField":
"configuration", "description": "To enable h [...]
"keyStoreFormat": { "index": 68, "kind": "parameter", "displayName": "Key
Store Format", "group": "security", "label": "security", "required": false,
"type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.netty.NettyConfiguration", "configurationField":
"configuration", "description": "The type of the keystore and the truststore,
such as JKS or PKCS12. Defaults to JKS if not set." },
"keyStoreResource": { "index": 69, "kind": "parameter", "displayName":
"Key Store Resource", "group": "security", "label": "security", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "supportFileReference": true,
"configurationClass": "org.apache.camel.component.netty.NettyConfiguration",
"configurationField": "configuration", "description": "The keystore with the
key and certificate of this endpoint, used [...]
"needClientAuth": { "index": 70, "kind": "parameter", "displayName": "Need
Client Auth", "group": "security", "label": "consumer,security", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false,
"configurationClass": "org.apache.camel.component.netty.NettyConfiguration",
"configurationField": "configuration", "description": "Configures whether the
server needs client authentication when using SSL." },
diff --git a/components/camel-netty/src/main/docs/netty-component.adoc
b/components/camel-netty/src/main/docs/netty-component.adoc
index 452876197d01..84941b87209a 100644
--- a/components/camel-netty/src/main/docs/netty-component.adoc
+++ b/components/camel-netty/src/main/docs/netty-component.adoc
@@ -702,6 +702,12 @@ A certificate that does not match makes the producer or
consumer fail with an
`No subject alternative DNS name matching ... found` for a host name).
Enabling the option also makes the JDK send the
host as an SNI server name.
+Host name verification is also enabled, without `hostnameVerification`, when
the client parameters of the
+`sslContextParameters` set an `endpointIdentificationAlgorithm`, such as
`HTTPS` or `LDAPS` (see
+xref:manual::camel-configuration-utilities.adoc[the JSSE Configuration
Utility]). This includes the global SSL
+configuration that the endpoint uses with
`useGlobalSslContextParameters=true`. When `hostnameVerification=true` is set
+as well, it takes precedence and the algorithm is `HTTPS`.
+
The option applies to the client side only. On a consumer that acts as a
server it is ignored, because the JDK does not
support host name verification on that side of a handshake: asked to do it
anyway, it rejects the client certificate
with `Endpoint Identification Algorithm HTTPS is not supported on the server
side`.
diff --git
a/components/camel-netty/src/main/java/org/apache/camel/component/netty/DefaultClientInitializerFactory.java
b/components/camel-netty/src/main/java/org/apache/camel/component/netty/DefaultClientInitializerFactory.java
index 05a5c1db6294..ad30b7fe4fbf 100644
---
a/components/camel-netty/src/main/java/org/apache/camel/component/netty/DefaultClientInitializerFactory.java
+++
b/components/camel-netty/src/main/java/org/apache/camel/component/netty/DefaultClientInitializerFactory.java
@@ -40,11 +40,18 @@ public class DefaultClientInitializerFactory extends
ClientInitializerFactory {
private final NettyProducer producer;
private SSLContext sslContext;
+ private String endpointIdentificationAlgorithm;
public DefaultClientInitializerFactory(NettyProducer producer) {
this.producer = producer;
try {
this.sslContext = createSSLContext(producer);
+ if (sslContext != null) {
+ this.endpointIdentificationAlgorithm
+ =
SSLEngineFactory.getClientEndpointIdentificationAlgorithm(producer.getContext(),
+
producer.getConfiguration().isHostnameVerification(),
+
producer.getConfiguration().getSslContextParameters());
+ }
} catch (Exception e) {
throw RuntimeCamelException.wrapRuntimeCamelException(e);
}
@@ -128,7 +135,9 @@ public class DefaultClientInitializerFactory extends
ClientInitializerFactory {
}
/**
- * Creates the client engine, carrying the host and port when host name
verification is enabled.
+ * Creates the client engine, carrying the host and port when host name
verification is enabled, by
+ * {@code hostnameVerification} or by the {@code
endpointIdentificationAlgorithm} of the client parameters of the
+ * {@code sslContextParameters}.
* <p/>
* The JDK reads the name to match from {@code SSLSession.getPeerHost()},
which is only populated when the engine is
* created with the peer. With the no-arg factory method it stays {@code
null} and {@code HostnameChecker.match}
@@ -140,7 +149,7 @@ public class DefaultClientInitializerFactory extends
ClientInitializerFactory {
*/
private SSLEngine createClientSSLEngine() {
NettyConfiguration configuration = producer.getConfiguration();
- if (configuration.isHostnameVerification()) {
+ if (endpointIdentificationAlgorithm != null) {
return sslContext.createSSLEngine(configuration.getHost(),
configuration.getPort());
}
return sslContext.createSSLEngine();
@@ -156,9 +165,9 @@ public class DefaultClientInitializerFactory extends
ClientInitializerFactory {
} else if (sslContext != null) {
SSLEngine engine = createClientSSLEngine();
engine.setUseClientMode(true);
- if (producer.getConfiguration().isHostnameVerification()) {
+ if (endpointIdentificationAlgorithm != null) {
SSLParameters sslParams = engine.getSSLParameters();
- sslParams.setEndpointIdentificationAlgorithm("HTTPS");
+
sslParams.setEndpointIdentificationAlgorithm(endpointIdentificationAlgorithm);
engine.setSSLParameters(sslParams);
}
if (producer.getConfiguration().getSslContextParameters() == null)
{
diff --git
a/components/camel-netty/src/main/java/org/apache/camel/component/netty/DefaultServerInitializerFactory.java
b/components/camel-netty/src/main/java/org/apache/camel/component/netty/DefaultServerInitializerFactory.java
index 12f992222084..f4f3662f625e 100644
---
a/components/camel-netty/src/main/java/org/apache/camel/component/netty/DefaultServerInitializerFactory.java
+++
b/components/camel-netty/src/main/java/org/apache/camel/component/netty/DefaultServerInitializerFactory.java
@@ -40,6 +40,7 @@ public class DefaultServerInitializerFactory extends
ServerInitializerFactory {
private NettyConsumer consumer;
private SSLContext sslContext;
+ private String clientEndpointIdentificationAlgorithm;
public DefaultServerInitializerFactory(NettyConsumer consumer) {
this.consumer = consumer;
@@ -51,6 +52,13 @@ public class DefaultServerInitializerFactory extends
ServerInitializerFactory {
if (sslContext != null) {
LOG.info("Created SslContext {}", sslContext);
+ if (consumer.getConfiguration().isClientMode()) {
+ // in client mode the consumer connects to a server, and
checks its certificate as a producer does
+ this.clientEndpointIdentificationAlgorithm
+ =
SSLEngineFactory.getClientEndpointIdentificationAlgorithm(consumer.getContext(),
+
consumer.getConfiguration().isHostnameVerification(),
+
consumer.getConfiguration().getSslContextParameters());
+ }
}
}
@@ -132,7 +140,8 @@ public class DefaultServerInitializerFactory extends
ServerInitializerFactory {
/**
* Creates the engine, carrying the host and port when this consumer
connects as a client with host name
- * verification enabled.
+ * verification enabled, by {@code hostnameVerification} or by the {@code
endpointIdentificationAlgorithm} of the
+ * client parameters of the {@code sslContextParameters}.
* <p/>
* The JDK reads the name to match from {@code SSLSession.getPeerHost()},
which the no-arg factory method leaves
* {@code null} - and then {@code HostnameChecker.match} throws
@@ -147,7 +156,7 @@ public class DefaultServerInitializerFactory extends
ServerInitializerFactory {
*/
private SSLEngine createServerSSLEngine() {
NettyConfiguration configuration = consumer.getConfiguration();
- if (configuration.isClientMode() &&
configuration.isHostnameVerification()) {
+ if (clientEndpointIdentificationAlgorithm != null) {
return sslContext.createSSLEngine(configuration.getHost(),
configuration.getPort());
}
return sslContext.createSSLEngine();
@@ -168,9 +177,9 @@ public class DefaultServerInitializerFactory extends
ServerInitializerFactory {
// REQUIRE or WANT) when needClientAuth is not enabled
engine.setNeedClientAuth(true);
}
- if (consumer.getConfiguration().isClientMode() &&
consumer.getConfiguration().isHostnameVerification()) {
+ if (clientEndpointIdentificationAlgorithm != null) {
SSLParameters sslParams = engine.getSSLParameters();
- sslParams.setEndpointIdentificationAlgorithm("HTTPS");
+
sslParams.setEndpointIdentificationAlgorithm(clientEndpointIdentificationAlgorithm);
engine.setSSLParameters(sslParams);
}
if (consumer.getConfiguration().getSslContextParameters() == null)
{
diff --git
a/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConfiguration.java
b/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConfiguration.java
index e05e4a8e2a04..32af19b8614d 100644
---
a/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConfiguration.java
+++
b/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConfiguration.java
@@ -93,7 +93,9 @@ public class NettyConfiguration extends
NettyServerBootstrapConfiguration implem
description = "The decoders (Netty ChannelHandler) to add to the
channel pipeline, as a comma-separated list of"
+ " references to beans in the registry, each
prefixed with #.")
private String decoders;
- @UriParam(label = "common,security", description = "To enable/disable
hostname verification on SSLEngine",
+ @UriParam(label = "common,security",
+ description = "To enable hostname verification on the client
SSLEngine. It is also enabled by the"
+ + " endpointIdentificationAlgorithm of the client
parameters of the sslContextParameters.",
security = "insecure:ssl", insecureValue = "false")
private boolean hostnameVerification;
@UriParam(label = "common",
@@ -774,7 +776,8 @@ public class NettyConfiguration extends
NettyServerBootstrapConfiguration implem
}
/**
- * To enable/disable hostname verification on SSLEngine
+ * To enable hostname verification on the client SSLEngine. It is also
enabled by the
+ * endpointIdentificationAlgorithm of the client parameters of the
sslContextParameters.
*/
public void setHostnameVerification(boolean hostnameVerification) {
this.hostnameVerification = hostnameVerification;
diff --git
a/components/camel-netty/src/main/java/org/apache/camel/component/netty/ssl/SSLEngineFactory.java
b/components/camel-netty/src/main/java/org/apache/camel/component/netty/ssl/SSLEngineFactory.java
index 0b7429e9376c..b24dfa5f3ffc 100644
---
a/components/camel-netty/src/main/java/org/apache/camel/component/netty/ssl/SSLEngineFactory.java
+++
b/components/camel-netty/src/main/java/org/apache/camel/component/netty/ssl/SSLEngineFactory.java
@@ -29,6 +29,8 @@ import javax.net.ssl.TrustManagerFactory;
import org.apache.camel.CamelContext;
import org.apache.camel.support.ResourceHelper;
import org.apache.camel.support.jsse.JsseParametersHelper;
+import org.apache.camel.support.jsse.SSLContextClientParameters;
+import org.apache.camel.support.jsse.SSLContextParameters;
import org.apache.camel.util.IOHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -39,6 +41,25 @@ public final class SSLEngineFactory {
private static final String SSL_PROTOCOL = "TLSv1.3";
+ /**
+ * The endpoint identification algorithm for a client engine: {@code
HTTPS} when {@code hostnameVerification} is
+ * enabled, otherwise the {@code endpointIdentificationAlgorithm} of the
client parameters of the
+ * {@code sslContextParameters}, if set, or {@code null} for no host name
verification.
+ * <p/>
+ * An {@code SSLEngine} starts in server mode, so {@code
SSLContextParameters} does not apply the algorithm to the
+ * engines of its context: the client applies it once its engine is in
client mode.
+ */
+ public static String getClientEndpointIdentificationAlgorithm(
+ CamelContext camelContext, boolean hostnameVerification,
SSLContextParameters parameters) {
+ if (hostnameVerification) {
+ return "HTTPS";
+ }
+ SSLContextClientParameters clientParameters = parameters != null ?
parameters.getClientParameters() : null;
+ String algorithm = clientParameters != null ?
clientParameters.getEndpointIdentificationAlgorithm() : null;
+ // the algorithm may use a property placeholder
+ return algorithm != null ?
camelContext.resolvePropertyPlaceholders(algorithm) : null;
+ }
+
public SSLEngineFactory() {
}
diff --git
a/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettySSLConsumerClientModeEndpointIdentificationTest.java
b/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettySSLConsumerClientModeEndpointIdentificationTest.java
new file mode 100644
index 000000000000..daaa152f2bc8
--- /dev/null
+++
b/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettySSLConsumerClientModeEndpointIdentificationTest.java
@@ -0,0 +1,258 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.netty;
+
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.security.KeyStore;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import javax.net.ssl.KeyManagerFactory;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLEngine;
+import javax.net.ssl.TrustManagerFactory;
+
+import io.netty.bootstrap.ServerBootstrap;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelFuture;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelInitializer;
+import io.netty.channel.ChannelPipeline;
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.SimpleChannelInboundHandler;
+import io.netty.channel.nio.NioEventLoopGroup;
+import io.netty.channel.socket.SocketChannel;
+import io.netty.channel.socket.nio.NioServerSocketChannel;
+import io.netty.handler.codec.DelimiterBasedFrameDecoder;
+import io.netty.handler.codec.Delimiters;
+import io.netty.handler.codec.string.StringDecoder;
+import io.netty.handler.codec.string.StringEncoder;
+import io.netty.handler.ssl.SslHandler;
+import org.apache.camel.BindToRegistry;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.support.jsse.KeyStoreParameters;
+import org.apache.camel.support.jsse.SSLContextClientParameters;
+import org.apache.camel.support.jsse.SSLContextParameters;
+import org.apache.camel.support.jsse.TrustManagersParameters;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.DisabledIfSystemProperty;
+import org.junit.jupiter.api.parallel.Isolated;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * A consumer with {@code clientMode=true} connects as a TCP client, so the
{@code endpointIdentificationAlgorithm} of
+ * the client parameters of its {@code sslContextParameters} applies to it as
well, without
+ * {@code hostnameVerification}.
+ * <p/>
+ * The server below presents keystore-localhost.jks, whose only subject
alternative name is DNS:localhost. The consumer
+ * that connects to localhost routes the greeting of the server, and the one
that connects to 127.0.0.1 rejects the
+ * certificate, which the server sees as a failed handshake.
+ */
+@Isolated("Does not seem to run reliably in parallel")
+@DisabledIfSystemProperty(named = "java.vendor", matches = ".*ibm.*")
+class NettySSLConsumerClientModeEndpointIdentificationTest extends
BaseNettyTest {
+
+ private static final Logger LOG =
LoggerFactory.getLogger(NettySSLConsumerClientModeEndpointIdentificationTest.class);
+ private static final String KEYSTORE =
"src/test/resources/keystore-localhost.jks";
+ private static final char[] PASSWORD = "changeit".toCharArray();
+
+ private MyServer server;
+
+ @BindToRegistry("sslContextParameters")
+ public SSLContextParameters loadSSLContextParameters() {
+ KeyStoreParameters ksp = new KeyStoreParameters();
+ ksp.setResource("file:" + KEYSTORE);
+ ksp.setPassword("changeit");
+
+ TrustManagersParameters tmp = new TrustManagersParameters();
+ tmp.setKeyStore(ksp);
+
+ SSLContextClientParameters clientParameters = new
SSLContextClientParameters();
+ clientParameters.setEndpointIdentificationAlgorithm("HTTPS");
+
+ SSLContextParameters answer = new SSLContextParameters();
+ answer.setTrustManagers(tmp);
+ answer.setClientParameters(clientParameters);
+ return answer;
+ }
+
+ @AfterEach
+ void stopServer() {
+ if (server != null) {
+ server.shutdown();
+ }
+ }
+
+ @Test
+ void connectsWhenTheCertificateMatchesTheHost() throws Exception {
+ server = new MyServer(getPort());
+ server.start();
+
+ MockEndpoint receive = context.getEndpoint("mock:receive",
MockEndpoint.class);
+ receive.expectedBodiesReceived("Bye Willem");
+ context.getRouteController().startRoute("localhost");
+ receive.assertIsSatisfied();
+ }
+
+ @Test
+ void failsWhenTheCertificateDoesNotMatchTheHost() throws Exception {
+ server = new MyServer(getPort());
+ server.start();
+
+ MockEndpoint receive = context.getEndpoint("mock:receive",
MockEndpoint.class);
+ receive.expectedMessageCount(0);
+ context.getRouteController().startRoute("ip");
+
+ assertTrue(server.failedHandshake.await(20, TimeUnit.SECONDS),
+ "the consumer should have rejected the certificate, which does
not list 127.0.0.1");
+ receive.assertIsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+
from("netty:tcp://localhost:{{port}}?textline=true&clientMode=true&ssl=true"
+ + "&sslContextParameters=#sslContextParameters")
+ .id("localhost").autoStartup(false)
+ .setBody(simple("Bye ${body}"))
+ .to("mock:receive");
+
+
from("netty:tcp://127.0.0.1:{{port}}?textline=true&clientMode=true&ssl=true"
+ + "&sslContextParameters=#sslContextParameters")
+ .id("ip").autoStartup(false)
+ .setBody(simple("Bye ${body}"))
+ .to("mock:receive");
+ }
+ };
+ }
+
+ private static SSLContext serverSslContext() throws Exception {
+ KeyStore ks = KeyStore.getInstance("JKS");
+ try (InputStream in = new FileInputStream(KEYSTORE)) {
+ ks.load(in, PASSWORD);
+ }
+ KeyManagerFactory kmf =
KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
+ kmf.init(ks, PASSWORD);
+ TrustManagerFactory tmf =
TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
+ tmf.init(ks);
+
+ SSLContext answer = SSLContext.getInstance("TLS");
+ answer.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
+ return answer;
+ }
+
+ /** Greets whoever connects, and counts down when a client rejects the
handshake. */
+ private static final class MyServer {
+
+ private final int port;
+ private final CountDownLatch failedHandshake = new CountDownLatch(1);
+ private Channel channel;
+ private EventLoopGroup bossGroup;
+ private EventLoopGroup workerGroup;
+
+ MyServer(int port) {
+ this.port = port;
+ }
+
+ void start() throws Exception {
+ bossGroup = new NioEventLoopGroup(1);
+ workerGroup = new NioEventLoopGroup();
+
+ ServerBootstrap bootstrap = new ServerBootstrap();
+ bootstrap.group(bossGroup, workerGroup)
+ .channel(NioServerSocketChannel.class)
+ .childHandler(new ServerInitializer(failedHandshake));
+
+ ChannelFuture cf = bootstrap.bind(port).sync();
+ channel = cf.channel();
+ }
+
+ void shutdown() {
+ if (channel != null) {
+ channel.close();
+ }
+ if (bossGroup != null) {
+ bossGroup.shutdownGracefully();
+ }
+ if (workerGroup != null) {
+ workerGroup.shutdownGracefully();
+ }
+ }
+ }
+
+ private static final class ServerHandler extends
SimpleChannelInboundHandler<String> {
+
+ @Override
+ public void channelActive(ChannelHandlerContext ctx) {
+ ctx.write("Willem\r\n");
+ ctx.flush();
+ }
+
+ @Override
+ public void exceptionCaught(ChannelHandlerContext ctx, Throwable
cause) {
+ LOG.debug("Exception caught: {}", cause.getMessage());
+ ctx.close();
+ }
+
+ @Override
+ protected void channelRead0(ChannelHandlerContext ctx, String msg) {
+ // the consumer is the one that routes, the server only greets
+ }
+ }
+
+ private static final class ServerInitializer extends
ChannelInitializer<SocketChannel> {
+
+ private final SSLContext sslContext;
+ private final CountDownLatch failedHandshake;
+
+ ServerInitializer(CountDownLatch failedHandshake) {
+ this.failedHandshake = failedHandshake;
+ try {
+ sslContext = serverSslContext();
+ } catch (Exception e) {
+ throw new IllegalStateException("Could not create the server
SSLContext", e);
+ }
+ }
+
+ @Override
+ public void initChannel(SocketChannel ch) {
+ SSLEngine engine = sslContext.createSSLEngine();
+ engine.setUseClientMode(false);
+ SslHandler sslHandler = new SslHandler(engine);
+ sslHandler.handshakeFuture().addListener(future -> {
+ if (!future.isSuccess()) {
+ failedHandshake.countDown();
+ }
+ });
+
+ ChannelPipeline pipeline = ch.pipeline();
+ pipeline.addLast("ssl", sslHandler);
+ pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192,
Delimiters.lineDelimiter()));
+ pipeline.addLast("decoder", new StringDecoder());
+ pipeline.addLast("encoder", new StringEncoder());
+ pipeline.addLast("handler", new ServerHandler());
+ }
+ }
+}
diff --git
a/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettySSLEndpointIdentificationAlgorithmTest.java
b/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettySSLEndpointIdentificationAlgorithmTest.java
new file mode 100644
index 000000000000..ba9564ab2548
--- /dev/null
+++
b/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettySSLEndpointIdentificationAlgorithmTest.java
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.netty;
+
+import java.util.Properties;
+
+import javax.net.ssl.SSLHandshakeException;
+
+import org.apache.camel.BindToRegistry;
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.support.jsse.KeyManagersParameters;
+import org.apache.camel.support.jsse.KeyStoreParameters;
+import org.apache.camel.support.jsse.SSLContextClientParameters;
+import org.apache.camel.support.jsse.SSLContextParameters;
+import org.apache.camel.support.jsse.TrustManagersParameters;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.DisabledIfSystemProperty;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * The producer checks that the certificate of the server matches the host it
connects to when the client parameters of
+ * the {@code sslContextParameters} set an {@code
endpointIdentificationAlgorithm}, without
+ * {@code hostnameVerification}.
+ * <p/>
+ * keystore-localhost.jks lists only DNS:localhost as subject alternative
name, so it matches "localhost" but not
+ * "127.0.0.1" - which both routes below resolve to, so the same consumer
serves them. The consumer uses the same
+ * parameters: the algorithm applies to client engines only.
+ */
+@DisabledIfSystemProperty(named = "java.vendor", matches = ".*ibm.*")
+class NettySSLEndpointIdentificationAlgorithmTest extends BaseNettyTest {
+
+ private static final String REPLY = "Bonjour";
+
+ @Override
+ @BindToRegistry("prop")
+ public Properties loadProperties() {
+ Properties prop = super.loadProperties();
+ prop.setProperty("endpointIdentificationAlgorithm", "HTTPS");
+ return prop;
+ }
+
+ @BindToRegistry("sslContextParameters")
+ public SSLContextParameters loadSSLContextParams() {
+ SSLContextParameters answer = createSSLContextParameters();
+ SSLContextClientParameters clientParameters = new
SSLContextClientParameters();
+ // a property placeholder, resolved by the component
+
clientParameters.setEndpointIdentificationAlgorithm("{{endpointIdentificationAlgorithm}}");
+ answer.setClientParameters(clientParameters);
+ return answer;
+ }
+
+ @BindToRegistry("noEndpointIdentification")
+ public SSLContextParameters loadSSLContextParamsWithoutAlgorithm() {
+ return createSSLContextParameters();
+ }
+
+ private SSLContextParameters createSSLContextParameters() {
+ KeyStoreParameters ksp = new KeyStoreParameters();
+
ksp.setResource(this.getClass().getClassLoader().getResource("keystore-localhost.jks").toString());
+ ksp.setPassword("changeit");
+
+ KeyManagersParameters kmp = new KeyManagersParameters();
+ kmp.setKeyPassword("changeit");
+ kmp.setKeyStore(ksp);
+
+ TrustManagersParameters tmp = new TrustManagersParameters();
+ tmp.setKeyStore(ksp);
+
+ SSLContextParameters sslContextParameters = new SSLContextParameters();
+ sslContextParameters.setKeyManagers(kmp);
+ sslContextParameters.setTrustManagers(tmp);
+ return sslContextParameters;
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+
from("netty:tcp://localhost:{{port}}?sync=true&ssl=true&sslContextParameters=#sslContextParameters")
+ .setBody(constant(REPLY));
+ }
+ };
+ }
+
+ @Test
+ void connectsWhenTheCertificateMatchesTheHost() {
+ String out = template.requestBody(
+
"netty:tcp://localhost:{{port}}?sync=true&ssl=true&sslContextParameters=#sslContextParameters",
+ "Hello", String.class);
+
+ assertEquals(REPLY, out);
+ }
+
+ /**
+ * Without a peer host on the engine the JDK cannot run the check at all
and reports "Hostname or IP address is
+ * undefined", which would make this pass for the wrong reason - so the
message is asserted as well.
+ */
+ @Test
+ void failsWhenTheCertificateDoesNotMatchTheHost() {
+ CamelExecutionException e = assertThrows(CamelExecutionException.class,
+ () -> template.requestBody(
+
"netty:tcp://127.0.0.1:{{port}}?sync=true&ssl=true&sslContextParameters=#sslContextParameters",
+ "Hello", String.class));
+
+ // the handshake was rejected by the host name check, and not, for
example, a connection refused
+ assertNotNull(findCause(e, SSLHandshakeException.class), "expected an
SSLHandshakeException in " + e);
+ String message = rootCause(e).getMessage();
+ assertTrue(message != null && message.contains("No subject alternative
names matching IP address 127.0.0.1"),
+ "the host name check should have rejected the certificate, but
got: " + message);
+ }
+
+ @Test
+ void connectsToAHostTheCertificateDoesNotListWithoutTheAlgorithm() {
+ String out = template.requestBody(
+
"netty:tcp://127.0.0.1:{{port}}?sync=true&ssl=true&sslContextParameters=#noEndpointIdentification",
+ "Hello", String.class);
+
+ assertEquals(REPLY, out);
+ }
+
+ private static Throwable findCause(Throwable t, Class<? extends Throwable>
type) {
+ for (Throwable cause = t; cause != null; cause = cause.getCause()) {
+ if (type.isInstance(cause)) {
+ return cause;
+ }
+ }
+ return null;
+ }
+
+ private static Throwable rootCause(Throwable t) {
+ Throwable answer = t;
+ while (answer.getCause() != null) {
+ answer = answer.getCause();
+ }
+ return answer;
+ }
+}
diff --git
a/components/camel-netty/src/test/java/org/apache/camel/component/netty/ssl/SSLEngineFactoryEndpointIdentificationTest.java
b/components/camel-netty/src/test/java/org/apache/camel/component/netty/ssl/SSLEngineFactoryEndpointIdentificationTest.java
new file mode 100644
index 000000000000..55932879ddfc
--- /dev/null
+++
b/components/camel-netty/src/test/java/org/apache/camel/component/netty/ssl/SSLEngineFactoryEndpointIdentificationTest.java
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.netty.ssl;
+
+import java.util.Properties;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.support.jsse.SSLContextClientParameters;
+import org.apache.camel.support.jsse.SSLContextParameters;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+/**
+ * The algorithm that the producer, and a consumer in client mode, set on
their client engine.
+ */
+class SSLEngineFactoryEndpointIdentificationTest {
+
+ private CamelContext context;
+
+ @BeforeEach
+ void createContext() {
+ context = new DefaultCamelContext();
+ Properties properties = new Properties();
+ properties.setProperty("algorithm", "LDAPS");
+ context.getPropertiesComponent().setInitialProperties(properties);
+ context.start();
+ }
+
+ @AfterEach
+ void stopContext() {
+ context.stop();
+ }
+
+ @Test
+ void noneByDefault() {
+
assertNull(SSLEngineFactory.getClientEndpointIdentificationAlgorithm(context,
false, null));
+
+ SSLContextParameters parameters = new SSLContextParameters();
+
assertNull(SSLEngineFactory.getClientEndpointIdentificationAlgorithm(context,
false, parameters));
+
+ parameters.setClientParameters(new SSLContextClientParameters());
+
assertNull(SSLEngineFactory.getClientEndpointIdentificationAlgorithm(context,
false, parameters));
+ }
+
+ @Test
+ void httpsWithHostnameVerification() {
+ assertEquals("HTTPS",
SSLEngineFactory.getClientEndpointIdentificationAlgorithm(context, true, null));
+ }
+
+ @Test
+ void theAlgorithmOfTheClientParameters() {
+ assertEquals("LDAPS",
SSLEngineFactory.getClientEndpointIdentificationAlgorithm(context, false,
+ parametersWithAlgorithm("LDAPS")));
+ }
+
+ @Test
+ void theAlgorithmOfTheClientParametersMayUseAPlaceholder() {
+ assertEquals("LDAPS",
SSLEngineFactory.getClientEndpointIdentificationAlgorithm(context, false,
+ parametersWithAlgorithm("{{algorithm}}")));
+ }
+
+ @Test
+ void hostnameVerificationTakesPrecedence() {
+ assertEquals("HTTPS",
SSLEngineFactory.getClientEndpointIdentificationAlgorithm(context, true,
+ parametersWithAlgorithm("LDAPS")));
+ }
+
+ private static SSLContextParameters parametersWithAlgorithm(String
algorithm) {
+ SSLContextClientParameters clientParameters = new
SSLContextClientParameters();
+ clientParameters.setEndpointIdentificationAlgorithm(algorithm);
+ SSLContextParameters answer = new SSLContextParameters();
+ answer.setClientParameters(clientParameters);
+ return answer;
+ }
+}
diff --git
a/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/NettyComponentBuilderFactory.java
b/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/NettyComponentBuilderFactory.java
index f0dcac5ee917..0202f371bdec 100644
---
a/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/NettyComponentBuilderFactory.java
+++
b/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/NettyComponentBuilderFactory.java
@@ -1315,7 +1315,9 @@ public interface NettyComponentBuilderFactory {
/**
- * To enable/disable hostname verification on SSLEngine.
+ * To enable hostname verification on the client SSLEngine. It is also
+ * enabled by the endpointIdentificationAlgorithm of the client
+ * parameters of the sslContextParameters.
*
* The option is a: <code>boolean</code> type.
*
diff --git
a/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/NettyHttpComponentBuilderFactory.java
b/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/NettyHttpComponentBuilderFactory.java
index ff9f3b170fe0..24d9c781ce58 100644
---
a/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/NettyHttpComponentBuilderFactory.java
+++
b/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/NettyHttpComponentBuilderFactory.java
@@ -1351,7 +1351,9 @@ public interface NettyHttpComponentBuilderFactory {
/**
- * To enable/disable hostname verification on SSLEngine.
+ * To enable hostname verification on the client SSLEngine. It is also
+ * enabled by the endpointIdentificationAlgorithm of the client
+ * parameters of the sslContextParameters.
*
* The option is a: <code>boolean</code> type.
*
diff --git
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/NettyEndpointBuilderFactory.java
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/NettyEndpointBuilderFactory.java
index 073df3f2151e..2352693a3a07 100644
---
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/NettyEndpointBuilderFactory.java
+++
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/NettyEndpointBuilderFactory.java
@@ -641,7 +641,9 @@ public interface NettyEndpointBuilderFactory {
return this;
}
/**
- * To enable/disable hostname verification on SSLEngine.
+ * To enable hostname verification on the client SSLEngine. It is also
+ * enabled by the endpointIdentificationAlgorithm of the client
+ * parameters of the sslContextParameters.
*
* The option is a: <code>boolean</code> type.
*
@@ -656,7 +658,9 @@ public interface NettyEndpointBuilderFactory {
return this;
}
/**
- * To enable/disable hostname verification on SSLEngine.
+ * To enable hostname verification on the client SSLEngine. It is also
+ * enabled by the endpointIdentificationAlgorithm of the client
+ * parameters of the sslContextParameters.
*
* The option will be converted to a <code>boolean</code> type.
*
@@ -2526,7 +2530,9 @@ public interface NettyEndpointBuilderFactory {
return this;
}
/**
- * To enable/disable hostname verification on SSLEngine.
+ * To enable hostname verification on the client SSLEngine. It is also
+ * enabled by the endpointIdentificationAlgorithm of the client
+ * parameters of the sslContextParameters.
*
* The option is a: <code>boolean</code> type.
*
@@ -2541,7 +2547,9 @@ public interface NettyEndpointBuilderFactory {
return this;
}
/**
- * To enable/disable hostname verification on SSLEngine.
+ * To enable hostname verification on the client SSLEngine. It is also
+ * enabled by the endpointIdentificationAlgorithm of the client
+ * parameters of the sslContextParameters.
*
* The option will be converted to a <code>boolean</code> type.
*
@@ -4277,7 +4285,9 @@ public interface NettyEndpointBuilderFactory {
return this;
}
/**
- * To enable/disable hostname verification on SSLEngine.
+ * To enable hostname verification on the client SSLEngine. It is also
+ * enabled by the endpointIdentificationAlgorithm of the client
+ * parameters of the sslContextParameters.
*
* The option is a: <code>boolean</code> type.
*
@@ -4292,7 +4302,9 @@ public interface NettyEndpointBuilderFactory {
return this;
}
/**
- * To enable/disable hostname verification on SSLEngine.
+ * To enable hostname verification on the client SSLEngine. It is also
+ * enabled by the endpointIdentificationAlgorithm of the client
+ * parameters of the sslContextParameters.
*
* The option will be converted to a <code>boolean</code> type.
*
diff --git
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/NettyHttpEndpointBuilderFactory.java
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/NettyHttpEndpointBuilderFactory.java
index 759634ed95ef..476187b1c718 100644
---
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/NettyHttpEndpointBuilderFactory.java
+++
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/NettyHttpEndpointBuilderFactory.java
@@ -462,7 +462,9 @@ public interface NettyHttpEndpointBuilderFactory {
return this;
}
/**
- * To enable/disable hostname verification on SSLEngine.
+ * To enable hostname verification on the client SSLEngine. It is also
+ * enabled by the endpointIdentificationAlgorithm of the client
+ * parameters of the sslContextParameters.
*
* The option is a: <code>boolean</code> type.
*
@@ -477,7 +479,9 @@ public interface NettyHttpEndpointBuilderFactory {
return this;
}
/**
- * To enable/disable hostname verification on SSLEngine.
+ * To enable hostname verification on the client SSLEngine. It is also
+ * enabled by the endpointIdentificationAlgorithm of the client
+ * parameters of the sslContextParameters.
*
* The option will be converted to a <code>boolean</code> type.
*
@@ -2867,7 +2871,9 @@ public interface NettyHttpEndpointBuilderFactory {
return this;
}
/**
- * To enable/disable hostname verification on SSLEngine.
+ * To enable hostname verification on the client SSLEngine. It is also
+ * enabled by the endpointIdentificationAlgorithm of the client
+ * parameters of the sslContextParameters.
*
* The option is a: <code>boolean</code> type.
*
@@ -2882,7 +2888,9 @@ public interface NettyHttpEndpointBuilderFactory {
return this;
}
/**
- * To enable/disable hostname verification on SSLEngine.
+ * To enable hostname verification on the client SSLEngine. It is also
+ * enabled by the endpointIdentificationAlgorithm of the client
+ * parameters of the sslContextParameters.
*
* The option will be converted to a <code>boolean</code> type.
*
@@ -4575,7 +4583,9 @@ public interface NettyHttpEndpointBuilderFactory {
return this;
}
/**
- * To enable/disable hostname verification on SSLEngine.
+ * To enable hostname verification on the client SSLEngine. It is also
+ * enabled by the endpointIdentificationAlgorithm of the client
+ * parameters of the sslContextParameters.
*
* The option is a: <code>boolean</code> type.
*
@@ -4590,7 +4600,9 @@ public interface NettyHttpEndpointBuilderFactory {
return this;
}
/**
- * To enable/disable hostname verification on SSLEngine.
+ * To enable hostname verification on the client SSLEngine. It is also
+ * enabled by the endpointIdentificationAlgorithm of the client
+ * parameters of the sslContextParameters.
*
* The option will be converted to a <code>boolean</code> type.
*