Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ if(GTest_FOUND)
tests/unit/AuthCodecTest.cpp
tests/unit/HotRodURITest.cpp
tests/unit/SaslAuthenticatorTest.cpp
tests/unit/TlsConnectionTest.cpp
)

target_link_libraries(unit_tests
Expand All @@ -104,6 +105,12 @@ if(GTest_FOUND)
GTest::gtest_main
)

# TlsConnectionTest reads PEM fixtures by absolute path (no working-dir
# assumption); the server side links OpenSSL directly.
target_compile_definitions(unit_tests PRIVATE
TLS_FIXTURE_DIR="${CMAKE_CURRENT_SOURCE_DIR}/tests/fixtures/tls")
target_link_libraries(unit_tests PRIVATE OpenSSL::SSL OpenSSL::Crypto)

add_test(NAME UnitTests COMMAND unit_tests)

# Copy test scripts and configs to build directory
Expand Down Expand Up @@ -331,6 +338,18 @@ if(GTest_FOUND)
# Note: NOT gtest_main - we provide our own main()
)

# Server-authenticated TLS integration tests (TLS-enabled single server, #18)
add_executable(tls_integration_tests
tests/integration/TlsIntegrationTest.cpp
)

target_link_libraries(tls_integration_tests
PRIVATE
hotrod-client
GTest::gtest
# Note: NOT gtest_main - we provide our own main()
)

# SASL/SCRAM authentication integration tests (auth-enabled single server)
add_executable(auth_integration_tests
tests/integration/AuthIntegrationTest.cpp
Expand Down Expand Up @@ -370,6 +389,7 @@ if(GTest_FOUND)
add_test(NAME PingRetryIntegrationTests COMMAND pingretry_integration_tests)
add_test(NAME MultiSeedIntegrationTests COMMAND multiseed_integration_tests)
add_test(NAME AuthIntegrationTests COMMAND auth_integration_tests)
add_test(NAME TlsIntegrationTests COMMAND tls_integration_tests)

# Set working directory so scripts can be found
set_tests_properties(PingIntegrationTests PROPERTIES
Expand Down Expand Up @@ -452,6 +472,10 @@ if(GTest_FOUND)
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
LABELS "integration;docker;auth"
)
set_tests_properties(TlsIntegrationTests PROPERTIES
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
LABELS "integration;docker;tls"
)

# Fail fast if a suite hangs (e.g. a server/CLI-version regression stalls a
# subprocess) instead of letting one stuck test burn the whole CI job budget.
Expand All @@ -463,7 +487,7 @@ if(GTest_FOUND)
TopologyIntegrationTests
ConcurrentClientsTests HashAwareRoutingIntegrationTests ConcurrentMultiServerTests
RetryViewIntegrationTests PingRetryIntegrationTests MultiSeedIntegrationTests
AuthIntegrationTests
AuthIntegrationTests TlsIntegrationTests
PROPERTIES TIMEOUT 300
)
endif() # NOT WIN32 (integration tests)
Expand Down
38 changes: 27 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,15 @@ coverage breakdown and counts.
- ✅ **SASL/SCRAM authentication** (`setAuthentication(...)`) — end-to-end for the
SCRAM family (`SCRAM-SHA-1`/`SCRAM-SHA-256`/`SCRAM-SHA-512`), applied to every
connection; see [`documentation/topics/security.adoc`](documentation/topics/security.adoc)
- ✅ **Hot Rod URI** (`RemoteCache::fromUri("hotrod://...")`) — build a client from a
connection string (hosts, credentials, `sasl_mechanism`/`client_intelligence`/
`protocol_version` params); `hotrod://` only for now (TLS and more in issue #10)
- ✅ **Hot Rod URI** (`RemoteCache::fromUri("hotrod[s]://...")`) — build a client from
a connection string (hosts, credentials, `sasl_mechanism`/`client_intelligence`/
`protocol_version` params, and the server-auth TLS params below); timeouts and more
in issue #10
- ✅ **Server-authenticated TLS** (`setTls(...)` / `hotrods://`, issue #18) — wraps
every connection in a TLS session (OpenSSL). PEM trust (`ca_file`, empty = system
store), SNI, and host-name validation (default on); min TLS 1.2. URI keys:
`trust_store_file_name` (PEM CA), `sni_host_name`, `ssl_hostname_validation`.
Mutual TLS / keystore formats are deferred (issue #10)
- ✅ **Multi-server seed list** (issue #12) — all hosts in the URI become seed
servers with startup *and* runtime failover (ops fall back to the seed list when
the connected server dies or no topology is known, e.g. in BASIC mode)
Expand Down Expand Up @@ -249,14 +255,23 @@ auto cache = RemoteCache::fromUri(
"my-cache");
cache->connect();

// Supports hotrod:// only. All hosts become seed servers (issue #12): connect()
// tries each in order, and ops fall back to the seed list when the connected
// server dies or no topology is known (e.g. BASIC mode). Credentials
// Supports hotrod:// and hotrods:// (TLS). All hosts become seed servers (issue
// #12): connect() tries each in order, and ops fall back to the seed list when the
// connected server dies or no topology is known (e.g. BASIC mode). Credentials
// enable SCRAM, and sasl_mechanism/client_intelligence/protocol_version (Java
// "4.0"/"4.1" form) are honoured. Userinfo and query values are percent-decoded
// (RFC 3986), so a reserved character in a password is written encoded — e.g. a
// password of p@ss is "...://admin:p%40ss@host". hotrods:// (TLS), timeouts, and
// other parameters throw for now (see issue #10).
// "4.0"/"4.1" form) are honoured. hotrods:// enables server-auth TLS; the
// trust_store_file_name (PEM CA) / sni_host_name / ssl_hostname_validation params
// map to setTls(...). Userinfo and query values are percent-decoded (RFC 3986), so
// a reserved character in a password is written encoded — e.g. a password of p@ss
// is "...://admin:p%40ss@host". Timeouts, mutual TLS, and other parameters throw
// for now (see issue #10).
//
// // TLS from a URI (private CA):
// auto c = RemoteCache::fromUri("hotrods://cache:11222?trust_store_file_name=/etc/pki/ca.pem");
// // or programmatically:
// RemoteCache cache("cache", 11222);
// cache.setTls("/etc/pki/ca.pem"); // ca_file; empty = system trust store
// cache.connect();
```

### Future
Expand All @@ -270,8 +285,9 @@ cache->connect();
`replaceWithVersion`, `removeWithVersion`, `putIfAbsent`, `replace`, `containsKey`
- ✅ **Step 11 — Error handling** (shipped): ERROR response parsing, typed exception,
user-decided retry (keyed + keyless)
- ✅ **Server-authenticated TLS** (shipped, issue #18): `hotrods://` + `setTls(...)`
- **Step 12 — Bulk operations** (next): `GET_ALL`, `PUT_ALL`, `BULK_GET`
- Also: multiplexing benchmarks, TLS/SSL support
- Also: multiplexing benchmarks, mutual TLS (client cert/key, issue #10)

## Project Structure

Expand Down
196 changes: 196 additions & 0 deletions docs/DECISIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1075,3 +1075,199 @@ overclaim until now.
entry) — the `TIMEOUT 300` guard per ctest suite plus `cli.sh -f -` batch mode keep
a server-side change failing fast rather than hanging CI. Verified the full
multi-node suite set green against `:latest` = 16.3.0 on 2026-10-19 after the switch.

## 2026-11-06 — Server-authenticated TLS for `hotrods://` (issue #18, sub-issue of #10)

**What:** first TLS slice. `hotrods://` no longer throws; the client wraps every
connection it opens (seed + topology-discovered) in a TLS session over OpenSSL.
New pure value `TlsConfig` (`include/hotrod/TlsConfig.h`); `RemoteCache::setTls(...)`
mirrors `setAuthentication` and is pushed to each `MultiplexedConnection` →
`Connection` at the same two build sites as auth/protocol/intelligence. The
handshake lives in `Connection::startTls()` (`src/transport/Connection.cpp`):
`TLS_client_method`, min TLS 1.2, trust anchors from a PEM `ca_file` (empty =
`SSL_CTX_set_default_verify_paths`, the system store), `SSL_VERIFY_PEER` always,
SNI via `SSL_set_tlsext_host_name`, host-name match via `SSL_set1_host`. `send`/
`receive` route through `SSL_write`/`SSL_read` when a session is live.

**Scope decisions (settled with the maintainer before coding):**
- **Server-auth only this slice.** Mutual TLS (client cert/key) is deferred.
- **PEM, not Java keystores.** This is an OpenSSL-native client; JKS/PKCS12 +
type/alias/store-password make no sense here. We deliberately diverge from the
Java `SslConfiguration` surface. Note the semantic reuse: the URI key
`trust_store_file_name` (a keystore in Java) is interpreted here as a **PEM CA
file**; `trust_store_type` is not accepted (PEM is implied). Java itself supports
`trust_store_type=pem`, so this isn't alien to Infinispan.
- **URI = option C.** `hotrods://` enables TLS with defaults; the URI additionally
recognizes exactly the three Java-named keys that map onto `TlsConfig`
(`trust_store_file_name`→`ca_file`, `sni_host_name`→`sni_host`,
`ssl_hostname_validation`→`hostname_validation`). Every settable `TlsConfig`
field is reachable both programmatically and from the URI; nothing more. The
other recognized Java TLS keys (`use_ssl`, `key_store_*`, `*_store_type`,
`*_password`, `key_alias`, `ssl_protocol`/`ciphers`/`named_groups`/`provider`/
`context`) are rejected with "not supported yet (… deferred; issue #10)" rather
than silently ignored — preserving the parser's fail-fast contract. TLS params on
a plain `hotrod://` URI are a hard error ("require the hotrods:// scheme").

**Behavioral calls:**
- **Min TLS 1.2** (`SSL_CTX_set_min_proto_version`).
- **SNI skipped for literal IPs** (RFC 6066) — and such a name is not host-validated
as a DNS name either (`isLiteralIp` guards both). To dial a loopback IP but still
verify a name, set `sni_host` to the DNS name (what the unit test does).
- **`hostname_validation=false` disables only the host-name match, not chain
verification** — chain verification is unconditional. Matches Java's
`hostnameValidation` semantics.
- **Quiet shutdown on teardown.** `Connection::close()` sets
`SSL_set_quiet_shutdown` before `SSL_shutdown`, so teardown never writes a
close_notify. Writing it to an already-dead peer raises SIGPIPE/EPIPE, which with
the default disposition kills the process for no benefit. (The in-process test
server also installs `SIG_IGN` for SIGPIPE, since its echo thread writes on close.)

**OpenSSL::SSL link is now live.** Supersedes the 2026-10-09 "Aside": `CMakeLists.txt`
already linked `OpenSSL::SSL` as dead weight next to libcrypto; the handshake code
now uses it (`SSL_*`), so the link is no longer dead. The entry's "folded into the
TLS work" prediction holds.

**Tests:** `tests/unit/TlsConnectionTest.cpp` drives the real handshake against an
in-process OpenSSL echo server (loopback, ephemeral port) presenting a PEM leaf
(SAN=`test.local`) signed by a test CA — fixtures in `tests/fixtures/tls/`
(36500-day validity; path injected via the `TLS_FIXTURE_DIR` compile definition).
Cases: trusted-CA + matching name → handshake + encrypted round-trip; untrusted CA
→ throw; name mismatch with validation on → throw, with validation off → succeed.
POSIX-only (like the integration suites); the cross-platform URI-level parsing is in
`HotRodURITest.cpp`. Full unit suite green (260 tests), stable across repeated runs.

**Integration test (Docker):** `tests/integration/TlsIntegrationTest.cpp` +
`scripts/start_infinispan_tls.sh` + `test-configs/infinispan-tls.xml` run the full
parse→connect→PUT/GET chain over `hotrods://` against a real TLS-enabled Infinispan
(Hot Rod endpoint with a PKCS12 server identity, no SASL). Server cert
`test-configs/tls/server.p12` (alias `server`, SAN DNS:localhost / IP:127.0.0.1,
password `password`); client trusts `test-configs/tls/ca.pem`. Cases: programmatic
`setTls` round-trip, `hotrods://?trust_store_file_name=` round-trip, untrusted
anchor (empty CA → system store) rejected, host-name mismatch rejected / accepted
with validation off. Label `integration;docker;tls`, `TIMEOUT 300`. Two gotchas hit
while wiring it: the mounted keystore must be world-readable (the in-container user
can't read a 0600 `:ro` mount → `FileNotFoundException: … (Permission denied)`), and
`keystore-password` is deprecated in favor of `password` on the `<keystore>` element.

**SIGPIPE on a dropped TLS connection — fixed at the library, per-connection.**
The first integration run was killed by SIGPIPE (exit 141): a client-side write onto
a closed TLS peer raises SIGPIPE, whose default disposition terminates the process.
We checked the authoritative Java client — it has *no* SIGPIPE handling because the
**JVM** sets `SIGPIPE` to `SIG_IGN` process-wide at startup; a broken connection then
surfaces as an `IOException`. That is a *runtime* (process-owner) decision. Our C++
client is a **guest** linked into someone else's process and has no business flipping
process-global signal disposition — a global `SIG_IGN` would, e.g., break a
well-behaved CLI tool that relies on SIGPIPE for shell-pipeline semantics. So instead
of mirroring the JVM's global flip, we suppress SIGPIPE **per connection**, confining
the effect to our own sockets (option 2):
- Plain `send()` uses `MSG_NOSIGNAL` on Linux (`HOTROD_SEND_FLAGS`).
- macOS/BSD set the socket option `SO_NOSIGPIPE` after `socket()` — socket-level, so
it also covers OpenSSL's writes on that fd.
- Linux's TLS path routes all OpenSSL socket I/O through a **custom `BIO`**
(`sigpipeSafeBioMethod` in `Connection.cpp`) whose write uses `MSG_NOSIGNAL`. One
mechanism covers every OpenSSL write — `SSL_write`, plus the writes
`SSL_connect`/`SSL_read` trigger internally (handshake, renegotiation, TLS 1.3
post-handshake). The BIO never closes the fd (Connection owns it); `SSL_set_bio`
takes ownership and frees it in `SSL_free`. Windows has no SIGPIPE, so it keeps the
default `SSL_set_fd` BIO.

Net: observably identical to Java (dropped connection → our thrown exception, process
survives), but with a *narrower blast radius* than the JVM — we never touch the app's
global signal disposition. The integration test's `main()` deliberately does **not**
install `SIG_IGN`, so it genuinely proves the library is self-sufficient (exit 0, not
141). The unit test still installs `SIG_IGN`, but only to guard its in-process echo
*server* thread (harness code doing raw `SSL_write`/`SSL_shutdown`), not the client.
`close()` additionally uses quiet shutdown so teardown performs no close_notify write
at all.

**Deferred (unchanged, issue #10):** mutual TLS / client cert+key, Java keystore
formats, cipher/protocol/provider tuning, `connect_timeout`/`socket_timeout`,
non-SCRAM SASL, `protocol_version=AUTO`/3.x.

## 2026-11-09 — Integration tests force `--pull always` (stale `:latest` cache, not an API change)

**What:** The integration suites bring up `quay.io/infinispan/server:latest`. Every
cluster-dependent suite (Topology, HashAwareRouting, ConcurrentMultiServer,
RetryView, PingRetry, MultiSeed) suddenly failed — first `"Failed to start
cluster"`, and once the cluster did start, `"Resource not found"` from the REST
helpers (`getServerClusterSize`, `getPrimaryOwnerForKey`, `RestAPIHelper`). The
fix: pin the *pull behavior*, not the API — `pull_policy: always` on all four
nodes in `test-configs/docker-compose-cluster.yml`, and `docker run -d --pull
always` in `scripts/start_infinispan_{noauth,auth,tls}.sh`.

**Why it matters / how it was found:** The tests query the server over the REST
`v3` API (`/rest/v3/cluster/_distribution`, `/rest/v3/caches/{c}/...`). That API
is correct for current server builds. The failures were **environmental**: Docker
only pulls `:latest` when the tag is absent locally, so an 8-month-old cached
`:latest` (Feb 2026, id `43285deb7485`) — which predates `rest/v3` and 404s on it
— kept being reused, even though newer tags (`16.3`, id `fa22dddecda4`,
2026-10-20) were present under other names. The REST probes counted 0 members /
returned 404, so clusters "never formed" and owner lookups came back empty.
Confirmed by probing both images directly: cached `:latest` → `rest/v3` 404;
`16.3` → `rest/v3` 200. A manual `docker pull …:latest` (now resolves to the 16.3
build) turned the suite green; the pull-policy change makes that automatic so a
stale local cache can never again silently run an old server. CI (no cache) was
unaffected, which is why this only bit local runs.

**Dead end (not shipped):** first mis-diagnosed as an API removal and rewrote the
test helpers + cluster scripts from `rest/v3` to `rest/v2 ?action=`. Reverted in
full once the 16.3 probe showed `rest/v3` still present — the API was never the
problem. Test code stays on `rest/v3`.

**Gotcha for next time:** `scripts/` and `test-configs/` are copied into the build
dir by `file(COPY …)` at **configure** time (`CMakeLists.txt`), and integration
tests run from `${CMAKE_BINARY_DIR}` using those copies. After editing a script
or compose file, re-run `cmake -S . -B build` (a *reconfigure*, not `cmake
--build`) or the test keeps executing the stale build copy.

## 2026-11-09 — TLS host validation uses X509_VERIFY_PARAM (SSL_set1_host deprecated in OpenSSL 4.0)

**What:** The Fedora CI job failed to build `src/transport/Connection.cpp`:
`SSL_set1_host` is deprecated as of OpenSSL 4.0 and the build uses
`-Werror=deprecated-declarations`. Ubuntu and Windows (older OpenSSL) built fine,
so this was CI-only on Fedora's bleeding-edge OpenSSL. Fix: drop the deprecated
`SSL_set_hostflags` / `SSL_set1_host` convenience wrappers in `startTls()` and
configure the SSL's verification params directly:
`X509_VERIFY_PARAM_set_hostflags(SSL_get0_param(ssl), …)` and
`X509_VERIFY_PARAM_set1_host(SSL_get0_param(ssl), host, 0)`.

**Why it matters:** The `SSL_set1_host` family are thin aliases over the
`X509_VERIFY_PARAM_*` functions, so behaviour is byte-for-byte identical on every
OpenSSL version, and the param API exists since OpenSSL 1.1.0 — the change builds
clean on 1.1.0 through 4.0 with `-Werror=deprecated-declarations`. Verified
locally against OpenSSL 3.5.9 (compiles) and confirmed the replacement against the
OpenSSL 4.0 docs. (Cannot reproduce the 4.0 deprecation locally — local Fedora
ships 3.5.9 where the symbol is not yet deprecated — but the fix references no
deprecated symbol, which is what the 4.0 build needs.)

**Watch out (not yet an issue):** OpenSSL 4.1 additionally drops the common-name
fallback entirely (RFC 9525 — SAN-only matching). Our test certs/validation
already rely on SANs, so no action needed now, but keep it in mind if a future
runner moves to 4.1.

## 2026-11-09 — TLS test certs: committed fixtures + a generator to reproduce them

**What:** The TLS suites use certificate fixtures that were hand-made with
`openssl` and committed as opaque blobs in the #18 commits (`f28a911` added the
unit set `tests/fixtures/tls/{ca,otherca,server}.pem` + `server.key`; `7d39cfa`
added the integration set `test-configs/tls/{ca.pem,server.p12}`). There was **no
script** to regenerate them — the "how" lived only in prose. Added
`scripts/gen-test-certs.sh` which reproduces both sets.

**Why it matters:** The fixtures carry ~100-year validity so they never expire and
normally need no touching, but any change (a new SAN, different key type, mutual-TLS
client certs for #10, rotation) previously meant reverse-engineering the chain. The
generator documents it as runnable code: self-signed roots via stock `req -x509`
(critical `CA:TRUE` + SKI/AKI), leaves carrying only the SAN, RSA-2048/SHA-256.
Unit set: `CN=Test Root CA` + leaf `CN=test.local` SAN `DNS:test.local`, plus an
unrelated `CN=Other Root CA` for the untrusted-anchor test. Integration set:
`CN=Integration Test CA` + `CN=localhost` leaf (SAN `DNS:localhost,IP:127.0.0.1`)
exported to `server.p12` (alias `server`, password `password`).

**Note:** Output is NOT byte-identical to the committed files (fresh random
keys/serials/timestamps) — the committed set is left as-is; the script is only run
when the fixtures must actually change, and the regenerated files must then be
`git add`ed deliberately. CA private keys are not written to the tree (not part of
the committed fixtures); each run regenerates the whole chain together. Output dirs
overridable via `UNIT_DIR`/`INT_DIR` env vars (used to self-test without clobbering
the committed set).
Loading
Loading