Skip to content

docs: ML-KEM key exchange with Bouncy Castle and Conscrypt - #2040

Open
pjfanning wants to merge 3 commits into
apache:mainfrom
pjfanning:bouncycastle-ml-kem
Open

pjfanning wants to merge 3 commits into
apache:mainfrom
pjfanning:bouncycastle-ml-kem

Conversation

@pjfanning

@pjfanning pjfanning commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Motivation

A hybrid ML-KEM key exchange for TLS 1.3 (RFC 10024) protects recorded traffic against later decryption by a quantum computer. Whether the Pekko HTTP server and client can use one depends on the JSSE provider of the Java runtime: JDK 27 supports the hybrid groups (JEP 527) and some vendors ship them in update releases of earlier JDKs, but many runtimes, including the project's JDK 17 baseline, do not.

Pekko HTTP already accepts the SSLContext or SSLEngine of any provider, so users on such runtimes need documentation, not a new module. This PR originally added a pekko-http-bouncycastle module; it is now docs and tested examples only.

Modification

  • New "ML-KEM key exchange" section in server-https-support.md, with a pointer from client-https-support.md. It covers:
    • when a runtime needs another JSSE provider
    • the two policies, preferring ML-KEM and requiring it
    • how the order of the named groups works: BCJSSE servers follow the client's order unless setUseNamedGroupsOrder(true) is set, and a client only offers
    • that a group list does not restrict the TLS version
    • the pitfalls of each provider (key managers and EC keys, SAN-only host name matching, provider configuration, Conscrypt's trust managers and its limits on JDK 17)
  • Complete examples that users can copy, in Scala and Java, for Bouncy Castle (BouncyCastleTls) and Conscrypt (ConscryptTls), plus usage examples that bind a server and send a request.
  • The examples live in the docs test sources and run as tests. Bouncy Castle 1.87 (bcprov, bctls, bcpkix) and Conscrypt 2.10.0 are test dependencies of the docs project only; their versions are shown in the docs through Paradox properties.

No module, public API, runtime dependency or default changes.

Result

Users can serve and call HTTPS over an ML-KEM key exchange on JDK 17 or later, for HTTP/1.1 and HTTP/2, by copying a documented and tested example.

Tests

  • sbt "docs/Test/testOnly docs.http.scaladsl.MlKemTlsExamplesSpec docs.http.javadsl.MlKemTlsExamplesDocTest": 47 passed (Scala 2.13, JDK 17). MlKemTlsExamplesSpec runs the same cases against the Scala and the Java example:
    • each ML-KEM group on its own, asserting TLS 1.3
    • the negotiated group, read from a Conscrypt client: X25519MLKEM768, and the server's order winning over the client's
    • handshake failure when only one side allows ML-KEM groups (both directions, HTTP/1.1 and HTTP/2)
    • TLS 1.2 peers of the JDK's own provider: accepted when preferring ML-KEM, refused when requiring it
    • host name verification, and that no provider is registered with java.security.Security
    • the Conscrypt examples: HTTP/1.1 and HTTP/2 over TLS 1.3, X25519MLKEM768 by default, interoperation with a Bouncy Castle client that requires ML-KEM
  • sbt docs/paradox: passed.
  • scalafmt, docs/javafmtAll and docs/headerCheckAll run.
  • Not run locally, left to CI: Scala 3 build, other modules' tests.

References

None - follows the ML-KEM recommendation proposed in #1409

pjfanning added a commit to pjfanning/pekko-http that referenced this pull request Dec 3, 2026
Motivation:
New public APIs should state the version they first appear in.

Modification:
Add @SInCE 2.1.0 to BouncyCastleConnectionContext and each of its public
members, in the scaladsl and the javadsl.

Result:
The API docs show when the module's APIs were added.

Tests:
- Not run - scaladoc only; scalafmt run on the changed files

References:
Refs apache#2040
@pjfanning
pjfanning force-pushed the bouncycastle-ml-kem branch from a2f774c to 76a2c7e Compare December 3, 2026 10:21
@He-Pin

He-Pin commented Dec 3, 2026

Copy link
Copy Markdown
Member

Thanks, and user can use https://github.com/google/conscrypt/ for performance

@He-Pin He-Pin added this to the 2.1.0 milestone Dec 3, 2026

@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.

Review at 76a2c7e: the optional BCJSSE direction is useful, but please make its TLS policy guarantees match what it configures and confirm the ASF release gate. Relevant standards: RFC 10024, RFC 9525 and RFC 9113 §9.2.

engine match {
case bcEngine: BCSSLEngine =>
val params = bcEngine.getParameters
params.setNamedGroups(namedGroups)

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.

Setting the list is not enough to make this a server preference. BCJSSE 1.87 defaults to peer order unless local named-group ordering is enabled (ContextData). The current tests prove that the server can use a hybrid group when that is the only common option, not that its preference wins under shared alternatives. Please either set the server-side ordering explicitly and test the negotiated policy, or document the server value as an allowlist with provider/peer negotiation policy, rather than promising hybrid-first selection.

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 0937ba5. Server contexts now call BCSSLParameters.setUseNamedGroupsOrder(true), so the server selects the first group of its own list that the client supports.

Tests added in BouncyCastleConnectionContextSpec, using a Conscrypt 2.10 client (test dependency) because it reports the negotiated group and BCJSSE does not:

  • the default server negotiates X25519MLKEM768 with it
  • a server configured with x25519, X25519MLKEM768 negotiates x25519, although the client prefers the hybrid. Without the ordering change this test fails with "x25519mlkem768" did not equal "x25519".


SSLContext clientSslContext =
BouncyCastleConnectionContext.createSSLContext(null, null, trustStore);
// only connects to servers that support ML-KEM

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 narrow this example's “only connects” promise to TLS 1.3, or expose and test an explicit TLS-1.3-only policy for strict ML-KEM use. The factory configures named groups on a generic TLS context without pinning the TLS version; RFC 10024 defines these groups for TLS 1.3. In the positive integration test, please also assert the negotiated TLS version (and group if the provider exposes it), not just the HTTP status.

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 0937ba5, by adding the explicit policy rather than only narrowing the comment.

  • New httpsServerRequiringMlKem / httpsClientRequiringMlKem in both DSLs only enable TLS 1.3 and only allow the ML-KEM groups. The docs example now uses httpsClientRequiringMlKem.
  • The scaladoc of the named-group overloads says that the list does not restrict the TLS version and that a TLS 1.2 connection never uses a hybrid group.
  • Tests: the positive cases assert TLSv1.3 (the Java test reads it from the server's SSL session), the negotiated group is asserted through a Conscrypt client, and TLS 1.2-only JDK peers are accepted by the default contexts and refused by the RequiringMlKem ones, in both directions.


* Create the `SSLContext` with `BouncyCastleConnectionContext.createSSLContext`. Bouncy Castle cannot use every key
that a key manager of the JDK's own TLS provider selects, and an `SSLContext` of another provider is rejected.
* Bouncy Castle only matches a host name against the subject alternative names of a certificate. A certificate that

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 qualify SAN-only identity checking as the BCJSSE default, consistent with RFC 9525. Provider 1.87 also documents an optional legacy compatibility setting, which this adapter does not override. Passing provider instances explicitly avoids registration but does not make provider policy independent of process configuration.

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.

Reworded in 0937ba5. The docs now say that matching subject alternative names only is the Bouncy Castle default, in line with RFC 9525, and that Bouncy Castle documents a system property restoring the legacy behaviour which this module does not set or override. The neighbouring bullet, and the scaladoc, now say that not registering the providers does not make their policy independent of the process configuration: they still read the system and security properties Bouncy Castle documents.

Comment thread build.sbt Outdated
.dependsOn(http, httpCore, httpTestkit % "test")
.enablePlugins(BootstrapGenjavadoc)

lazy val httpBouncyCastle = project("http-bouncycastle")

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.

Before merging, could the PMC confirm whether this new module is covered by the ASF cryptography process, including the export/source listing, notification and user-facing notice where applicable? This is separate from the dependency license: the guidance also covers software designed to use a third-party crypto API, even if the library is not bundled.

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.

Pekko HTTP does not ship cryptography code in this module. Bouncy Castle does, and it is an ordinary dependency that is not bundled in our artifacts. The module only passes named-group and protocol settings to a JSSE provider, in the same way the rest of Pekko HTTP already drives the JDK's TLS through SSLContext and SSLEngine.

## ML-KEM key exchange with Bouncy Castle

A hybrid ML-KEM key exchange for TLS 1.3, such as `X25519MLKEM768`, protects recorded traffic against being decrypted
later by a quantum computer. The JDK's own TLS implementation supports it from JDK 27. On older JDKs, the

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.

Could we phrase this in terms of runtime/JSSE capability rather than JDK major version? Oracle JDK 25.0.5 already ships all three hybrid TLS 1.3 groups (JDK-8314323). This module is useful when the runtime's JSSE provider does not offer these groups (including the project's JDK 17 baseline), but is not needed solely for hybrid key exchange on every pre-27 JDK. Please align the PR motivation with the guide.

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.

Reworded in 0937ba5, and the PR description is updated to match. The section is now "ML-KEM key exchange" and starts from the capability of the runtime's JSSE provider: JDK 27 supports the hybrid groups, some vendors ship them in update releases of earlier JDKs, and if the runtime has them the plain ConnectionContext factories are all that is needed. The module is described as an option where the runtime does not offer them, including the JDK 17 baseline.

@He-Pin

He-Pin commented Dec 3, 2026

Copy link
Copy Markdown
Member

Follow-up checklist for #2040

Please address these points in the next revision. The inline threads have the code locations; this checklist separates behavior, tests, and release work.

  • Make server group selection match the API contract. A list of enabled groups is not the same as a server-preference policy. BCJSSE 1.87 normally follows peer order. Either enforce and document the server's hybrid-first preference, or describe the default as enabling both families without promising which one wins. RFC 10024 §4 defines the hybrid groups; RFC 8446 §§4.2.7–4.2.8 defines group and key-share negotiation, not a requirement to prefer ML-KEM.
  • Make strict mode actually hybrid-only. The strict Java and Scala entry points should explicitly require TLS 1.3 or reject incompatible protocol settings, so a successful negotiation cannot be mistaken for a hybrid one simply because the configured group list contains only hybrid groups. Exercise the real Pekko HTTPS/HTTP2 path: assert the negotiated TLS version and selected group for a peer supporting both group families, verify the documented classic-only fallback in permissive mode, and verify that strict mode rejects a classic-only peer for the expected reason. An engine configuration assertion or a generic failed future is not sufficient. Netty 4.2's TLS context builder is a useful reference for keeping protocol configuration independent from ALPN; it is not the normative source for the group policy.
  • Qualify identity and runtime support in the guide. RFC 9525 §2 specifies SAN-based service identity rather than Common Name matching. Distinguish the provider default from a guarantee enforced by this API, keep identity verification enabled, and show the expected result with test certificates. Also describe availability in terms of the runtime's JSSE capabilities: Oracle JDK 25.0.5 already includes TLS 1.3 hybrid key exchange.
  • Confirm the ASF release step with the PMC. Please record whether the new optional crypto-provider integration needs any updates under the ASF cryptography process. This is separate from dependency licensing and whether the provider is bundled.

When ready, please link the new commit and the focused handshake results, with the protocol and group actually observed.

pjfanning added a commit to pjfanning/pekko-http that referenced this pull request Dec 3, 2026
Motivation:
Review of apache#2040 found that the module promised more than it configured.
BCJSSE selects the key exchange group by the client's order unless local
ordering is enabled, so the server did not prefer ML-KEM. The named
groups do not restrict the TLS version, so "only ML-KEM" was not a
guarantee. The docs also tied the need for the module to the JDK major
version rather than to what the runtime's TLS provider supports.

Modification:
- Server contexts enable BCJSSE's local named-group ordering, so the
  server selects the first group of its list that the client supports.
- Add httpsServerRequiringMlKem and httpsClientRequiringMlKem to both
  DSLs. They only enable TLS 1.3 and only allow the ML-KEM groups.
- Scaladoc states that a named-group list does not restrict the TLS
  version.
- Tests assert the negotiated TLS version, and the negotiated group
  through a Conscrypt client (test dependency), which reports it. Add
  tests for TLS 1.2 peers against the default and the strict contexts.
  The Java test reads the TLS version from the server's SSL session.
- Docs: describe the need by JSSE capability, describe the two policies,
  qualify SAN-only host name matching as the BCJSSE default, note that
  provider policy still follows process configuration, and add a
  Conscrypt section.

Result:
A server context prefers ML-KEM over a client's own ordering, and an
application can require TLS 1.3 with ML-KEM on either side.

Tests:
- sbt "http-bouncycastle/Test/testOnly
  org.apache.pekko.http.bouncycastle.scaladsl.BouncyCastleConnectionContextSpec
  org.apache.pekko.http.bouncycastle.javadsl.BouncyCastleConnectionContextTest":
  20 passed (Scala 2.13, JDK 17)
- The server-order test fails without the ordering change:
  "x25519mlkem768" did not equal "x25519"
- scalafmt, javafmtAll and headerCheckAll run for the module
- Scala 3, the docs build and other modules are left to CI

References:
Refs apache#2040
@pjfanning

Copy link
Copy Markdown
Member Author

Thanks. Conscrypt needs no code on our side: I ran the Pekko HTTP server and client over a Conscrypt 2.10 SSLContext with the existing ConnectionContext.httpsServer / httpsClient, and they negotiated X25519MLKEM768 on JDK 17 for HTTP/1.1 and HTTP/2.

0937ba5 adds a Conscrypt section to the HTTPS docs with what a user needs to know: use Conscrypt's own TrustManagerFactory on the client (TLS 1.3 handshakes fail with the JDK's trust managers), host names are matched against subject alternative names only, and the named groups of an SSLEngine can only be changed through SSLParameters.setNamedGroups, which needs JDK 20 or later. The module's tests now also use a Conscrypt client against the Bouncy Castle server.

@pjfanning

Copy link
Copy Markdown
Member Author

@He-Pin I'm completely reworking this and dropping the new module. The updated PR will just be docs and test code referenced by the docs with worked examples based on Bouncycastle and Conscrypt.

pjfanning added a commit to pjfanning/pekko-http that referenced this pull request Dec 3, 2026
Motivation:
A hybrid ML-KEM key exchange for TLS 1.3 (RFC 10024) protects recorded
traffic against later decryption by a quantum computer. Whether Pekko
HTTP can use one depends on the JSSE provider of the Java runtime, and
many runtimes, including the JDK 17 baseline, do not support it. Pekko
HTTP accepts the SSLContext or SSLEngine of any provider, so this needs
documentation, not a module.

Modification:
- Add an "ML-KEM key exchange" section to the server HTTPS page, with a
  pointer from the client HTTPS page. It covers when a runtime needs
  another provider, how the order of the named groups works on the
  server and the client, why a group list does not restrict the TLS
  version, and the pitfalls of each provider.
- Add complete Scala and Java examples for Bouncy Castle (BCJSSE) and
  Conscrypt that users can copy, with usage examples.
- Run the examples as tests in the docs project. Bouncy Castle 1.87 and
  Conscrypt 2.10.0 are test dependencies of the docs project only.

Result:
Users can serve and call HTTPS over an ML-KEM key exchange on JDK 17 or
later by copying a documented example. Pekko HTTP gains no module, API
or runtime dependency.

Tests:
- sbt "docs/Test/testOnly docs.http.scaladsl.MlKemTlsExamplesSpec
  docs.http.javadsl.MlKemTlsExamplesDocTest": 47 passed (Scala 2.13,
  JDK 17)
- sbt docs/paradox: passed
- scalafmt, docs/javafmtAll and docs/headerCheckAll run
- Scala 3 and the other modules are left to CI

References:
Refs apache#2040, apache#1409
@pjfanning
pjfanning force-pushed the bouncycastle-ml-kem branch from 0937ba5 to c93dd31 Compare December 3, 2026 11:03
@pjfanning pjfanning changed the title feat: add pekko-http-bouncycastle module for ML-KEM key exchange docs: ML-KEM key exchange with Bouncy Castle and Conscrypt Dec 3, 2026
@pjfanning

Copy link
Copy Markdown
Member Author

Change of direction in c93dd31: the pekko-http-bouncycastle module is removed and this PR is now documentation with tested examples.

Pekko HTTP already accepts the SSLContext or SSLEngine of any JSSE provider, and the module was a thin wrapper around about 30 lines of provider setup. That is the same situation as Conscrypt, which needed no code from us. So both providers are now covered the same way:

  • complete BouncyCastleTls and ConscryptTls examples in Scala and Java that users can copy, with usage examples
  • the examples run as tests in the docs project (47 tests), with Bouncy Castle and Conscrypt as test dependencies of that project only
  • the docs keep everything from the review: the capability-based framing, the prefer and require policies, how group order works on server and client (including setUseNamedGroupsOrder), that a group list does not restrict the TLS version, and the SAN and provider-configuration notes

The earlier review points still apply to the examples and are covered by the same tests. Pekko HTTP gains no module, public API or runtime dependency, and THREAT_MODEL.md is no longer touched.

@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.

Re-reviewed the docs-only revision. Moving the providers to the documentation test classpath, pinning TLS 1.3 for strict BCJSSE, and checking actual group preference address the main design concerns from the earlier revision. The remaining issues below are about what the examples and their negative checks establish.

* Like Bouncy Castle, Conscrypt only matches a host name against the subject alternative names of a certificate.
* This example prefers ML-KEM and does not require it: a peer that only offers classical groups still connects.
To change the named groups of an `SSLEngine`, Conscrypt relies on `SSLParameters.setNamedGroups`, which needs
JDK 20 or later. On older JDKs you get the default groups of Conscrypt and cannot refuse peers without ML-KEM.

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.

This conflates the JDK's per-engine SSLParameters API with what the provider can enforce. In Conscrypt 2.10.0's NativeSsl initialization, the provider consults the process-wide jdk.tls.namedGroups property when no per-engine override was supplied; that branch is not gated on JDK 20. Please say that the example uses provider defaults and cannot set a per-engine policy through the standard Java API on JDK 17. The process-level setting is a distinct deployment scope and should not be described as impossible.

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.

You're right, corrected in 6c6d9ec. I confirmed it with Conscrypt 2.10.0 on JDK 17: with -Djdk.tls.namedGroups=x25519 a default engine pair negotiates X25519 instead of X25519MLKEM768.

The docs now make two separate statements: the example uses Conscrypt's default groups and cannot set a policy for a single SSLEngine on JDK 17, because SSLParameters.setNamedGroups needs JDK 20; and Conscrypt reads the jdk.tls.namedGroups system property on any JDK when an engine has no groups of its own, which is a process-wide deployment setting that the other JSSE providers read too.

try
// the certificate is issued for localhost only
Http().singleRequest(HttpRequest(uri = s"https://127.0.0.1:${binding.localAddress.getPort}/"),
connectionContext = requiringClient).failed.futureValue

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.

This can pass without reaching hostname verification. The listener binds to localhost, while the client dials 127.0.0.1; on a system where the bind resolves to ::1, connection refusal satisfies failed.futureValue as well. The Conscrypt case below has the same shape. Please keep the TCP address fixed, demonstrate a successful handshake on the same listener with the matching reference identity, then vary only the reference identity and assert a certificate/endpoint-verification failure rather than an arbitrary failed request. This is the identity check in RFC 9525, separate from trust and transport.

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 6c6d9ec, for the Bouncy Castle and the Conscrypt cases.

  • Every listener in the spec now binds to 127.0.0.1, and the client dials that address through a ClientTransport, so the TCP address is fixed and only the reference identity varies.
  • verifiesHostName uses one listener: a request checked against localhost completes over TLS 1.3, then the same client against other.example must fail with a CertificateException in the cause chain whose message is about the subject alternative names. A refused connection or any other failure no longer passes.

}

"keep the named groups when HTTP/2 configures the engines for ALPN" in {
exchange(server(mlKemGroups), client(ClassicalGroups), http2 = true).failed.futureValue

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 test name says this proves that ALPN preserves each engine's named groups, but any failed request currently passes. A bind/transport error, timeout, unrelated TLS failure or HTTP/2 negotiation error would all look the same here. Please assert a TLS handshake rejection caused by the incompatible policies (allow provider-specific alert wording), and keep a successful, policy-matched HTTP/2 exchange as the control. The positive group-preference check above is good evidence for the positive case; it does not prove the reason for these failures.

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 6c6d9ec.

  • The negative checks no longer accept any failed request. They require an SSLException in the cause chain that names the alert: handshake_failure for incompatible groups and protocol_version for the TLS 1.2 cases. The match is on the alert name only, since BCJSSE, SunJSSE and Conscrypt word their messages differently.
  • The ALPN test now starts with its control: the same server and client factories complete an HTTP/2 exchange over TLS 1.3 when their groups match (ML-KEM on both sides, and classical on both sides), and are then refused with handshake_failure when the groups do not overlap.

pjfanning added a commit to pjfanning/pekko-http that referenced this pull request Dec 3, 2026
Motivation:
Review of apache#2040 found that the negative checks of the ML-KEM examples
passed on any failed request, that the host name check dialled a
different address than the listener was bound to, and that the docs
described Conscrypt's named groups as unchangeable before JDK 20.

Modification:
- Bind every test listener to 127.0.0.1 and dial that address through a
  client transport, so that only the host name the certificate is
  checked against varies.
- The host name test first completes a handshake on the same listener
  with the matching name, then asserts a CertificateException about the
  subject alternative names for another name.
- Group and TLS version mismatches assert a TLS failure that names the
  handshake_failure or protocol_version alert.
- The HTTP/2 ALPN test adds successful exchanges with matching groups as
  its control.
- Docs: the Conscrypt example uses provider defaults and cannot set a
  per-engine policy on JDK 17; jdk.tls.namedGroups is a separate,
  process-wide setting that Conscrypt reads on any JDK.

Result:
The negative tests fail for the reason they name, and the Conscrypt
notes separate the per-engine API from the process-level property.

Tests:
- sbt "docs/Test/testOnly docs.http.scaladsl.MlKemTlsExamplesSpec
  docs.http.javadsl.MlKemTlsExamplesDocTest": 47 passed (Scala 2.13,
  JDK 17)
- sbt docs/paradox: passed
- scalafmt run on the changed file

References:
Refs apache#2040
The list of named groups and the `tls13Only` flag give you two policies:

* **Prefer ML-KEM.** With @scala[`PreferMlKemGroups`]@java[`PREFER_ML_KEM_GROUPS`] and `tls13Only` off, ML-KEM is
used whenever the peer supports it. A peer without ML-KEM, or one that only supports TLS 1.2, can still connect

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 preference is not a guarantee in both roles. A client can offer ML-KEM first, but a peer server that also supports it can select a mutually supported classical group. The new negative control for client ordering in MlKemTlsExamplesSpec (the server selects x25519 while the Conscrypt client supports and prefers ML-KEM) demonstrates this distinction.

Could you scope this sentence to the example BCJSSE server using its own order, when TLS 1.3 and a hybrid group are mutually enabled, and state that the preferring client advertises a preference but does not control the selection? Keep “Require ML-KEM” as the explicit guarantee. RFC 8446 §§4.2.7–4.2.8 and RFC 10024 §4 do not require hybrid-first selection.

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 d695265. The "Prefer ML-KEM" bullet is now scoped to the example server: it selects an ML-KEM group when the client offers one that the server has enabled and the connection uses TLS 1.3. It then says that a client with this policy only advertises a preference, that a server supporting ML-KEM may still select a classical group both sides have enabled, and that the policy is not a guarantee. "Require ML-KEM" (TLS 1.3 only, hybrid groups only) is named as the policy to use for the guarantee and is otherwise unchanged.

No test change was needed: select the group by the server's order of preference, not the client's already covers the client side of this (the server selects x25519 while the Conscrypt client prefers ML-KEM), and it passes for the Scala and the Java example.

offers classical groups still connects. The example cannot set a policy for a single `SSLEngine` on JDK 17,
because the standard API for that, `SSLParameters.setNamedGroups`, needs JDK 20 or later.
* Conscrypt also reads the `jdk.tls.namedGroups` system property when an engine has no groups of its own, on any
JDK. That is a setting for the whole process, which the other JSSE providers in it read as well, so it is a

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 scope correction here is useful. Please narrow the last clause: this is a process-wide setting and it can also affect other providers that honor it; there is no portable requirement that every JSSE provider read this property. The fallback when no per-engine override was supplied is confirmed specifically for Conscrypt 2.10.0.

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 d695265. The bullet now says that the tested version of Conscrypt reads jdk.tls.namedGroups when an engine has no groups of its own, that the property is a setting for the whole process, and that it also affects any other JSSE provider in the process that honors it, which providers are not required to do. It starts with "Separately from that API" to keep it apart from the previous bullet about SSLParameters.setNamedGroups on a single engine.

The SAN bullet for Conscrypt is reworded too: it is the default of the tested version, the client example leaves endpoint identification enabled and does not change that default, and a hybrid key exchange does not replace the check because the server is still authenticated by its certificate. Docs only, so no test change.

@He-Pin

He-Pin commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Review checklist at 6c6d9ec

The docs-only approach is a good fit for Pekko’s existing connection contexts: no new published module, default, or provider dependency for applications. The current source addresses the earlier server order, strict TLS, and endpoint-identity concerns; please keep the actual negotiated-group and positive HTTP/2 controls.

  • Bound the prefer-mode claim. The policy of the example BCJSSE server differs from what a client can guarantee. A provider having hybrid support is not the same as the chosen group being enabled and negotiated. Keep strict mode TLS 1.3 plus hybrid groups only. RFC 8446 §§4.2.7–4.2.8, RFC 10024 §4, and RFC 9113 §9.2 cover negotiation and protocol requirements, not a universal preference. Netty 4.2’s TLS builder is a reference for keeping protocol, ALPN, and provider policy distinct.
  • Qualify the Conscrypt property. Explain the scope as process-wide and effects on other providers only if they honor it. Keep the per-engine JDK API limitation separate. Describe SAN-only behavior as the pinned provider’s default; don't change endpoint identification or equate key exchange with certificate authentication (RFC 9525 §2).
  • Record the PMC’s disposition in the existing ASF thread. The removed module and docs-test-only dependencies address the binary distribution concern; the source release can still include the executable examples. Please confirm whether the existing classification, source listing, notification, or README already covers that source, or note what needs to change under the ASF process. This review is not a ruling that a new notification is required.
  • On the final revision, report the exact focused test head and provider/runtime. Keep positive HTTP/1.1 and HTTP/2 exchanges and the separately scoped endpoint-identity assertions. Don’t describe the Scala 3 axis or other OS/provider combinations as verified unless actually run.

Source review only here; no approval on this revision.
Build cleanup (non-blocking): Dependencies.scala defines the four example dependencies twice. The docs settings reference Docs.* only. Please drop the unused copies in the general Test object so the documented docs-only boundary is also apparent in the build.

Motivation:
A hybrid ML-KEM key exchange for TLS 1.3 (RFC 10024) protects recorded
traffic against later decryption by a quantum computer. Whether Pekko
HTTP can use one depends on the JSSE provider of the Java runtime, and
many runtimes, including the JDK 17 baseline, do not support it. Pekko
HTTP accepts the SSLContext or SSLEngine of any provider, so this needs
documentation, not a module.

Modification:
- Add an "ML-KEM key exchange" section to the server HTTPS page, with a
  pointer from the client HTTPS page. It covers when a runtime needs
  another provider, how the order of the named groups works on the
  server and the client, why a group list does not restrict the TLS
  version, and the pitfalls of each provider.
- Add complete Scala and Java examples for Bouncy Castle (BCJSSE) and
  Conscrypt that users can copy, with usage examples.
- Run the examples as tests in the docs project. Bouncy Castle 1.87 and
  Conscrypt 2.10.0 are test dependencies of the docs project only.

Result:
Users can serve and call HTTPS over an ML-KEM key exchange on JDK 17 or
later by copying a documented example. Pekko HTTP gains no module, API
or runtime dependency.

Tests:
- sbt "docs/Test/testOnly docs.http.scaladsl.MlKemTlsExamplesSpec
  docs.http.javadsl.MlKemTlsExamplesDocTest": 47 passed (Scala 2.13,
  JDK 17)
- sbt docs/paradox: passed
- scalafmt, docs/javafmtAll and docs/headerCheckAll run
- Scala 3 and the other modules are left to CI

References:
Refs apache#2040, apache#1409
Motivation:
Review of apache#2040 found that the negative checks of the ML-KEM examples
passed on any failed request, that the host name check dialled a
different address than the listener was bound to, and that the docs
described Conscrypt's named groups as unchangeable before JDK 20.

Modification:
- Bind every test listener to 127.0.0.1 and dial that address through a
  client transport, so that only the host name the certificate is
  checked against varies.
- The host name test first completes a handshake on the same listener
  with the matching name, then asserts a CertificateException about the
  subject alternative names for another name.
- Group and TLS version mismatches assert a TLS failure that names the
  handshake_failure or protocol_version alert.
- The HTTP/2 ALPN test adds successful exchanges with matching groups as
  its control.
- Docs: the Conscrypt example uses provider defaults and cannot set a
  per-engine policy on JDK 17; jdk.tls.namedGroups is a separate,
  process-wide setting that Conscrypt reads on any JDK.

Result:
The negative tests fail for the reason they name, and the Conscrypt
notes separate the per-engine API from the process-level property.

Tests:
- sbt "docs/Test/testOnly docs.http.scaladsl.MlKemTlsExamplesSpec
  docs.http.javadsl.MlKemTlsExamplesDocTest": 47 passed (Scala 2.13,
  JDK 17)
- sbt docs/paradox: passed
- scalafmt run on the changed file

References:
Refs apache#2040
Motivation:
Review of the ML-KEM docs found two claims that were wider than what the
examples establish: that the prefer policy uses ML-KEM whenever the peer
supports it, and that every JSSE provider reads jdk.tls.namedGroups.

Modification:
- Scope the prefer policy to the example server selecting by its own
  order under TLS 1.3, and say that a preferring client only advertises
  a preference. Name the require policy as the guarantee.
- Describe jdk.tls.namedGroups as a process-wide setting that affects
  other providers only if they honor it, separate from the per-engine
  SSLParameters API.
- Describe SAN-only host name matching as the default of the tested
  Conscrypt version, which the example leaves unchanged.
- Remove the unused copies of the example dependencies from
  Dependencies.Test, the docs project uses Dependencies.Docs.

Result:
The docs promise only what the examples and their tests show, and the
build shows the example dependencies as docs-only.

Tests:
- sbt "docs/Test/testOnly docs.http.scaladsl.MlKemTlsExamplesSpec docs.http.javadsl.MlKemTlsExamplesDocTest": 47 passed (Scala 2.13, Temurin 17.0.20.1, macOS, Bouncy Castle 1.87, Conscrypt 2.10.0)
- scalafmt --list --mode diff-ref=upstream/main: clean
- git diff --check: clean
- Not run locally, left to CI: docs/paradox, Scala 3 build, other modules

References:
Refs apache#2040
@pjfanning
pjfanning force-pushed the bouncycastle-ml-kem branch from 6c6d9ec to d695265 Compare December 5, 2026 22:04
@pjfanning

Copy link
Copy Markdown
Member Author

Update for the checklist at 6c6d9ec6, in d695265 (branch rebased onto the current main):

  • Prefer-mode claim and Conscrypt property: reworded, details in the two inline threads.
  • Build cleanup: the unused copies of the four example dependencies are removed from Dependencies.Test. Only Dependencies.Docs defines them now.
  • ASF cryptography process: not changed by this commit, still open in the existing thread.

Focused test run at d695265:

  • sbt "docs/Test/testOnly docs.http.scaladsl.MlKemTlsExamplesSpec docs.http.javadsl.MlKemTlsExamplesDocTest": 47 passed, 0 failed.
  • Runtime: Temurin 17.0.20.1 on macOS (aarch64), Scala 2.13. Providers: Bouncy Castle 1.87 (BCJSSE) and Conscrypt 2.10.0, with SunJSSE of that JDK as the TLS 1.2 peer.
  • Still covered: positive HTTP/1.1 and HTTP/2 exchanges over TLS 1.3 for both providers, the negotiated group (X25519MLKEM768, and x25519 when the server lists it first), and the host name checks on a fixed listener.
  • Not run locally: Scala 3, other JDKs, other operating systems, docs/paradox. These are left to CI, which runs JDK 17 on Linux.

@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.

The latest server/client preference and Conscrypt property-scope edits address my earlier points. Two narrower issues remain: the native-JSSE guidance overstates when defaults are sufficient, and the Conscrypt HTTP/2 test does not observe the negotiated group.

Whether you need to do anything depends on the TLS implementation (the JSSE provider) of your Java runtime, not only
on its major version. JDK 27 supports the hybrid groups and prefers `X25519MLKEM768` by default
([JEP 527](https://openjdk.org/jeps/527)), and some vendors ship the same support in update releases of earlier JDKs.
If your runtime supports them, the plain `ConnectionContext.httpsServer` and `ConnectionContext.httpsClient` are all

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.

Could we distinguish ‘the provider implements these groups’ from ‘these groups are enabled by the effective TLS policy’? A runtime can support ML-KEM and still have it excluded from the enabled groups, or negotiate a classical group with a peer. The plain ConnectionContext overloads inherit provider policy; they do not enable or require ML-KEM. Please say when the plain overloads are sufficient (TLS 1.3 and a hybrid group enabled with a compatible peer), and point users who need a guarantee to explicit provider policy and verification of the negotiated group.


"complete HTTP/1.1 and HTTP/2 requests over TLS 1.3" in {
exchange(server, client).futureValue shouldEqual Exchange("HTTP/1.1", "TLSv1.3")
exchange(server, client, http2 = true).futureValue shouldEqual Exchange("HTTP/2.0", "TLSv1.3")

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.

This checks HTTP/2 and TLS 1.3, but both can succeed with classical X25519. The group probe at groupNegotiatedWith currently uses exchange with its default http2 = false, so it only observes the HTTP/1.1 path. Can we also assert the negotiated group on the actual HTTP/2 connection under Conscrypt defaults, using the engine from that connection (or a controlled hybrid-only peer)? Please keep the existing endpoint-identity and HTTP/2 assertions.

@He-Pin

He-Pin commented Dec 6, 2026

Copy link
Copy Markdown
Member

Two follow-ups on d6952657 before approval:

  1. Clarify the default JSSE path. The plain Pekko HTTPS contexts use the provider's effective configuration. Implementing a hybrid group, enabling it, and actually negotiating it are three different things. Say when the plain contexts are enough; if a hybrid group is mandatory, refer to explicit provider policy and check the negotiated group. No new Pekko API or default is needed.
  2. Verify the Conscrypt group over HTTP/2. Keep the actual Pekko HTTP/2 exchange and assert X25519MLKEM768 on its engine, or prove it with a peer that only accepts that group. HTTP/2 + TLSv1.3 alone also passes with classical X25519; the current group probe is HTTP/1.1 only. Keep the hostname verification and the existing fallback/strict controls.

References: RFC 9846 §§4.3.7–4.3.8 separates supported groups from the selected key share, RFC 10024 §4 defines the hybrid shares, and RFC 7301 §3 defines ALPN, which selects the application protocol, not a key-exchange group. Netty 4.2's SSL builder similarly treats TLS provider and application-protocol configuration separately. RFC 9525 endpoint identity checks should remain unchanged. The provider-order and process-wide property edits in this head address the earlier feedback.

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