Skip to content

feat: named-groups setting for remoting TLS and ML-KEM examples - #3843

Open
pjfanning wants to merge 2 commits into
apache:mainfrom
pjfanning:remote-ml-kem-named-groups
Open

pjfanning wants to merge 2 commits into
apache:mainfrom
pjfanning:remote-ml-kem-named-groups

Conversation

@pjfanning

Copy link
Copy Markdown
Member

Motivation

A hybrid ML-KEM key exchange for TLS 1.3 (such as X25519MLKEM768) protects recorded traffic between nodes against later decryption by a quantum computer. The TLS providers of Pekko Remote had no way to choose the named groups of the key exchange, so a node could not prefer or require ML-KEM. There was also no guidance for Java runtimes whose TLS implementation does not support the hybrid groups, which includes many JDK 17 builds.

Modification

  • New named-groups setting (default [], the defaults of the Java runtime) for:
    • pekko.remote.artery.ssl.config-ssl-engine
    • pekko.remote.artery.ssl.rotating-keys-engine
    • pekko.remote.classic.netty.ssl.security
  • The setting is applied with SSLParameters.setNamedGroups. That method needs JDK 20, so it is looked up with a MethodHandle (NamedGroupsSupport, internal). A node with the setting does not start on earlier versions, so it cannot silently run with other groups.
  • New "ML-KEM key exchange" sections in remote-security.md (Artery) and remoting.md (classic): the prefer and require policies, rolling upgrades, and the pitfalls of each option.
  • Complete SSLEngineProvider examples for Bouncy Castle and Conscrypt, in Scala and Java, for Artery and classic remoting. They live in the docs test sources and run as tests.
  • Bouncy Castle 1.87 (bcprov, bctls, MIT-style licence) and Conscrypt 2.10.0 (Apache 2.0) are test dependencies of docs only. Their versions are shown in the docs through Paradox properties.

The deprecation status of classic remoting is unchanged. No runtime dependency or default changes.

Result

Nodes can prefer or require an ML-KEM key exchange by configuration on Java runtimes that support it (JDK 27, and update releases of some earlier versions), and by copying a documented and tested example on others, from JDK 17.

Tests

  • remote/Test/testOnly NamedGroupsSpec, ClassicRemotingWithNamedGroupsSpec, TlsTcpWithNamedGroupsSpec, TlsTcpWithRotatingKeysSSLEngineAndNamedGroupsSpec:
    • JDK 17: 11 passed, 21 pending (they need setNamedGroups); covers the failure to start with named-groups set
    • JDK 25 (Temurin 25.0.5, which supports X25519MLKEM768): 29 passed, 3 pending; covers group order, common and disjoint groups, unsupported names, and ML-KEM only, preferred and required, for all three providers
  • docs/Test/testOnly docs.remoting.MlKemTlsDocSpec jdocs.remoting.MlKemTlsDocTest: 41 passed on JDK 17. The spec runs the same cases against the Scala and the Java examples: each ML-KEM group, the negotiated group read from a Conscrypt peer, the accepting side's order, refusal of peers without ML-KEM, interoperation with the JDK's provider, and message delivery over Artery and classic remoting.
  • remote/headerCheckAll, docs/headerCheckAll, docs/javafmtCheckAll, scalafmt, remote/mimaReportBinaryIssues, docs/paradox, git diff --check: passed.
  • Not run locally: the one-line assertion added to RemoteConfigSpec (compiled only), sbt validatePullRequest, the Scala 3 build and other modules' tests. Left to CI.

References

None - follows apache/pekko-http#2040

Motivation:
A hybrid ML-KEM key exchange for TLS 1.3 protects recorded traffic between
nodes against later decryption by a quantum computer. The TLS providers of
Pekko Remote had no way to choose the named groups of the key exchange, so a
node could not prefer or require ML-KEM, and there was no guidance for Java
runtimes whose TLS implementation does not support the hybrid groups.

Modification:
- Add a named-groups setting to the Artery ConfigSSLEngineProvider and
  RotatingKeysSSLEngineProvider and to the classic ConfigSSLEngineProvider.
  It is applied with SSLParameters.setNamedGroups, which is looked up with a
  MethodHandle because it needs JDK 20. A node with the setting does not
  start on earlier versions.
- Document ML-KEM key exchange for Artery and classic remoting, with tested
  SSLEngineProvider examples for Bouncy Castle and Conscrypt in Scala and
  Java. Bouncy Castle and Conscrypt are test dependencies of docs only.

Result:
Nodes can prefer or require an ML-KEM key exchange by configuration on Java
runtimes that support it, and by copying a documented example on others.

Tests:
- remote NamedGroupsSpec, ClassicRemotingWithNamedGroupsSpec,
  TlsTcpWithNamedGroupsSpec, TlsTcpWithRotatingKeysSSLEngineAndNamedGroupsSpec:
  passed on JDK 17 (11 passed, 21 pending) and JDK 25 (29 passed, 3 pending)
- docs MlKemTlsDocSpec and MlKemTlsDocTest: 41 passed on JDK 17
- headerCheckAll, javafmtCheckAll, scalafmt, remote/mimaReportBinaryIssues,
  docs/paradox: passed

References:
None - follows apache/pekko-http#2040

@He-Pin He-Pin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the named-group configuration, JSSE provider examples, and handshake tests at d25f0ee. The issues below need a follow-up before approval.

case Some(handle) =>
val params = engine.getSSLParameters
handle.invokeWithArguments(params, namedGroups.toArray)
engine.setSSLParameters(params)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Policy enforcement depends on the active JSSE provider. The MethodHandle check proves the JDK setter exists, not that the engine obtained from SSLContext.getInstance honors it. The JSSE API explicitly allows providers to ignore this setting. Please either limit the documented requirement guarantee to providers that enforce named groups (and clearly distinguish this from the pre-JDK-20 startup check), or add a reliable fail-closed provider check if the setting is meant to enforce policy universally. Reading configured parameters back is not a negotiated-group assertion.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 61f9506 by scoping the guarantee, with no behaviour change. The docs now say the list is passed to the TLS implementation with SSLParameters.setNamedGroups and that the guarantee is what that implementation does with it; the prefer/require description is stated for SunJSSE, the provider these classes use unless another is registered ahead of it. Two bullets were added: the pre-JDK-20 startup check is only about the Java API, and a JSSE provider may ignore the setting, so a different registered provider has to be checked with a classical-only peer before relying on it to require ML-KEM. reference.conf and the NamedGroupsSupport scaladoc say the same. "Require" stays tied to protocol = "TLSv1.3". The pre-JDK-20 error and the empty-list path are unchanged. No test added for this one: the existing NamedGroupsSpec cases that back the SunJSSE claim are the handshake ones (ML-KEM-only peers connect, a classical-only peer is refused in both directions), not the parameter readback.

It gives you two policies:

* **Prefer ML-KEM.** List the ML-KEM group first and classical groups after it. ML-KEM is used whenever the peer
supports it, and a peer without ML-KEM can still connect with a classical key exchange.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make this a preference, not a negotiation guarantee. RFC 9846 §§4.3.7–4.3.8 distinguish supported groups from the actual key shares offered. SunJSSE can use an acceptable offered share without requesting a share for another mutually supported group. A peer supporting ML-KEM is therefore not sufficient on its own. Adjust the rolling-upgrade text too, and keep the documented BCJSSE server-order behavior scoped to BCJSSE.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 61f9506. "Prefer" is now described as a preference and not a guarantee, with a bullet explaining that the connecting node sends key shares for the first groups of its list and the accepting node may use one of them even when both support a group it lists earlier (RFC 9846 section 4.3.8). The opening paragraph says nodes offer ML-KEM to each other, and the rolling-upgrade steps no longer claim that preferring nodes use ML-KEM with each other; only the require step is stated as a guarantee. The setUseNamedGroupsOrder bullet now says the behaviour and the call are specific to Bouncy Castle. In the tests, the cases that claim which group won already use the negotiated group reported by a Conscrypt peer (MlKemTlsDocSpec: X25519MLKEM768 with a preferring BC node, and x25519 when the accepting BC node lists it first); the SunJSSE cases only assert success or failure of the handshake.

Copy this class into your project:

Scala
: @@snip [MlKemTls.scala](/docs/src/test/scala/docs/remoting/MlKemTls.scala) { #conscrypt }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Scala example is not standalone as rendered. The #conscrypt fragment in MlKemTls.scala includes the Conscrypt import but not Config, Files, KeyStore, or the javax SSL types; those shared imports appear only in #bouncy-castle. The whole-file test sees them and cannot catch this. Please make the rendered fragments self-contained, including the classic wrapper imports, and show the actual Scala/Java Conscrypt provider wrappers or link to their complete source. A compile check of the extracted examples would cover this.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 61f9506. MlKemTls.scala is split into one file per class (BouncyCastleEngines, ConscryptEngines, and the Artery and classic provider for each), and each file is one snippet that starts at its own imports, so the rendered fragment is the whole compilation unit that the build compiles. The Conscrypt provider wrappers are now rendered too, Scala and Java: for Artery in remote-security.md and for classic remoting in remoting.md, next to the Bouncy Castle ones. MlKemTlsDocSpec runs against these classes (41 passed on JDK 17) and docs/paradox passes.


// SSLParameters.getNamedGroups was added in JDK 20, like setNamedGroups
def namedGroupsOf(params: SSLParameters): List[String] =
classOf[SSLParameters].getMethod("getNamedGroups").invoke(params).asInstanceOf[Array[String]].toList

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Treat missing provider capability separately from a missing Java API. getNamedGroups() is nullable per the JSSE API. Here .toList can throw when probing getSupportedSSLParameters, before runtimeSupportsMlKem can skip the provider-specific cases. Please make that probe null-safe and keep the explicit positive handshake assertion on providers expected to support the selected group.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 61f9506. namedGroupsOf in NamedGroupsSpec now maps a null getNamedGroups() to an empty list, so a provider that does not tell its groups makes runtimeSupportsMlKem false and the ML-KEM cases pending, without throwing. The positive assertion is kept: where the runtime lists X25519MLKEM768, peers that only allow that group must complete the handshake. Re-ran NamedGroupsSpec on JDK 17 (6 passed, 21 pending as they need JDK 20+); the JDK 20+ path of this probe is left to CI.

}

"negotiate X25519MLKEM768 with a peer that supports it" in {
negotiatedGroup(conscrypt(), bouncyCastle(PreferMlKemGroups)) should ===("x25519mlkem768")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep Java-only BC coverage runnable without Conscrypt’s native library. These BC negotiation checks use a Conscrypt peer, and the Conscrypt block also loads it unconditionally. The 2.10.0 provider exposes isAvailable() because native support is platform-dependent. Please isolate or capability-gate all Conscrypt-dependent cases, including these mixed-provider checks, while still requiring them on supported CI targets and leaving BC-only cases active.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 61f9506. Every case in MlKemTlsDocSpec that needs Conscrypt, including the two Bouncy Castle cases that use a Conscrypt peer to read the negotiated group, now starts with requireConscrypt(). It checks Conscrypt.isAvailable: on a platform that conscrypt-openjdk-uber has no native library for the case is cancelled, and on the platforms it has one for (Linux and macOS on x86_64 and aarch64, Windows on x86_64) the case fails, so CI still requires them. The Bouncy Castle only cases, including delivery over Artery and classic remoting, and the Java test do not touch Conscrypt and stay active. Re-ran the spec on JDK 17 on macOS aarch64: 41 passed, none cancelled.

@He-Pin

He-Pin commented Dec 3, 2026

Copy link
Copy Markdown
Member

Follow-up checklist for the next revision

Review scope: d25f0ee. The configuration wiring for the built-in Artery, rotating-key and classic TLS providers, and the empty-list compatibility path, look reasonable. I would hold approval until the following are addressed.

  1. Provider enforcement: distinguish the presence of the JDK 20+ API from the active provider enforcing the configured groups. Scope “require ML-KEM” to a provider that enforces the list and to TLS 1.3. Keep the pre-JDK-20 error and the empty-list behavior. If broader enforcement is intended, verify it rather than treating the Java setter or a parameter readback as proof.
  2. Preference and rollout: make “prefer” conditional on the peer’s offered key shares and provider selection. Keep the verified BCJSSE local-order example separate. When a test or deployment claim depends on which group won, use the negotiated group (or the ServerHello) as the oracle. See RFC 9846 §§4.3.7–4.3.8 and RFC 10024 §4. Netty’s native option is useful implementation precedent, not a guarantee for classic remoting’s JSSE engine.
  3. Copyable examples: give the rendered Scala Conscrypt and classic fragments their own imports and link or render the corresponding Java/Scala provider wrappers. Verify the extracted examples, not just the combined source file.
  4. Capability-aware tests and native portability: handle a provider returning no named-group capability. Isolate native Conscrypt cases, including those used as a BC oracle, on platforms where the pinned artifact cannot load; keep BC-only cases active, and require the native cases on supported test targets.

This review checked the source and existing test oracles; it did not rerun the PR’s test suite. No default, public API, or runtime dependency change is needed merely to resolve these review points.

Motivation:
Review of the named-groups setting and the ML-KEM examples found that the
docs promised more than the setting can guarantee, that the rendered Scala
examples did not carry their own imports, and that tests assumed provider
capabilities that are optional.

Modification:
- Docs: named-groups is enforced by the JSSE provider, which may ignore it;
  the pre-JDK-20 check is only about the Java API. "Prefer" is a preference
  that depends on the key shares of the connecting node, and the rolling
  upgrade text no longer claims ML-KEM between preferring nodes. The
  setUseNamedGroupsOrder behaviour is scoped to Bouncy Castle.
- Split the Scala examples into one file per class, each with its own
  imports, and render the Conscrypt provider wrappers for Artery and classic
  remoting in Scala and Java.
- NamedGroupsSpec: treat a null getNamedGroups as no capability.
- MlKemTlsDocSpec: gate every case that needs Conscrypt on
  Conscrypt.isAvailable. They are cancelled where the artifact has no native
  library and fail where it has one and cannot load it. Bouncy Castle only
  cases stay active.

Result:
The documented guarantees match what the providers enforce, and each
rendered example compiles on its own.

Tests:
- remote NamedGroupsSpec: passed on JDK 17 (6 passed, 21 pending)
- docs MlKemTlsDocSpec and MlKemTlsDocTest: 41 passed on JDK 17
- docs/javafmtAll, scalafmt, headerCheckAll, docs/paradox: passed

References:
Refs apache#3843
@pjfanning
pjfanning requested a review from He-Pin December 5, 2026 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants