Repository navigation
CAMEL-27206: camel-nats - check the host name in the certificate of the NATS server when TLS is used - #30349
CAMEL-27206: camel-nats - check the host name in the certificate of the NATS server when TLS is used#30349davsclaus wants to merge 2 commits into
Conversation
…he NATS server when TLS is used jnats checks the certificate of the server against the trust store, but not that it was issued for the host it connects to. A new hostnameVerification option (default true, like camel-smpp, camel-mina and camel-mllp) wraps the SSLContext so its sockets check the host name, and uses the happy eyeballs mode of jnats, which keeps the host name for TLS instead of replacing it by an IP address. opentls:// is left as is. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🐫 Apache Camel Committers, please review the following items:
|
gnodet-bot
left a comment
There was a problem hiding this comment.
Review: CAMEL-27206 — camel-nats TLS hostname verification
This is a well-crafted security hardening PR. The HostnameVerifyingSSLContext decorator pattern is correct and consistent with the approach used in camel-smpp, camel-mina, and camel-mllp.
What looks good
- Decorator pattern —
HostnameVerifyingSSLContext extends SSLContextwith anSSLContextSpidelegate is the right approach. All socket factories are overridden, and theSSLServerSocketFactoryis intentionally not wrapped (server-side verification is irrelevant for a client). engineInit()correctness — theSSLContextpassed by jnats is already initialized before the wrap occurs (afterbuilder.build()), so theengineInitno-op is correct.createSocket()no-arg — hostname verification runs during the TLS handshake (viasetEndpointIdentificationAlgorithm("HTTPS")), not at socket creation time. The no-arg factory override is a correctness non-issue.@UriParamdescription — Camel generates the description from the setter Javadoc; the annotation without adescriptionattribute is intentional and correct.- Test design — the control matrix (127.0.0.1 fails, localhost succeeds, 127.0.0.1 with flag=false succeeds) validates the core behavior correctly.
- Upgrade guide — the entry correctly covers the
tls://scheme andsecure=truescenarios.
Observation (non-blocking)
isTrustAll() applies globally when any server uses opentls://
private boolean isTrustAll() {
String servers = getConfiguration().getServers();
return servers != null && servers.toLowerCase(Locale.ROOT).contains("opentls://");
}If a user configures a mixed list of servers (e.g. "tls://host1:4222,opentls://host2:4222"), isTrustAll() returns true, disabling hostname verification for all servers in the list — including the tls:// ones. This is a low-severity edge case: mixing opentls:// with tls:// is an unusual configuration, and opentls:// already implies trusting any certificate, so the security posture of the connection set as a whole is already compromised. Worth documenting in the upgrade guide or a code comment for future maintainers.
LTS / Backport
This PR addresses a security vulnerability (TLS hostname verification bypass → MITM attack vector). It qualifies for LTS backport consideration. Please ensure a backport to the active LTS branch is tracked.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
✅ Generated files are up to dateAn earlier CI run reported uncommitted generated changes; the latest run no longer does. |
gnodet-bot
left a comment
There was a problem hiding this comment.
Following up on my earlier review — the regen commit is correct.
The new Regen commit adds "component:nats" to the hostnameVerification owners map in SecurityUtils.java. This is the expected output of code generation when a new hostnameVerification parameter annotated @UriParam(label = "security", enums = "true,false", security = "insecure:ssl") is added to a component — no manual action needed.
The prior non-blocking observation about isTrustAll() applying globally when mixed tls:// + opentls:// server lists are used still stands as a low-severity edge case worth documenting, but does not block this PR.
LGTM.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
|
🧪 CI tested the following changed modules:
🔬 Scalpel shadow comparison — Scalpel: 594 of 729 tested, 23 compile-only — current: 594 all testedMaveniverse Scalpel detected 594 affected modules (current approach: 594). Skip-tests mode would test 594 modules (6 direct + 592 downstream), skip tests for 23 (generated code, meta-modules) Modules Scalpel would test (594)
Modules with tests skipped (23)
Build reactor — dependencies compiled but only changed modules were tested (6 modules, 55.1s total)Total reactor time: 55.1s
Top 20 slowest modules:
|
CAMEL-27206
When camel-nats connects with TLS (
secure=true, or atls://server address), jnats checks the certificate of the server against the trust store, but not that the certificate was issued for the host it connects to.Changes
hostnameVerificationoption (defaulttrue, markedinsecure:sslwhenfalse), as camel-smpp, camel-mina and camel-mllp have.SSLContextthat jnats gets is wrapped (HostnameVerifyingSSLContext), so its sockets and engines set the endpoint identification algorithmHTTPS.noResolveHostnames()isResolveToFirstin jnats 2.26, and still resolves). With the check on, the options useHostnameResolveMode.HappyEyeballs, which connects to the fastest IP address of the host name and keeps the name for TLS. (Unresolveddid not connect in the test.)opentls://addresses, which ask jnats to trust any certificate, are left as they are.Tests
NatsHostnameVerificationTest: a local server sends the INFO line of a NATS server that requires TLS and does the handshake with a certificate forlocalhostonly: connecting to127.0.0.1fails, connecting tolocalhostsucceeds, andhostnameVerification=falseaccepts it for127.0.0.1.Claude Code on behalf of Claus Ibsen
🤖 Generated with Claude Code