November 30, 2026

Is my TLS connection really post-quantum? Asking the JDK 28 API

Hybrid post-quantum TLS fails open by design: an old peer, a middlebox or one system property quietly keeps you classical. JDK 28 finally lets the application ask which key exchange group was negotiated. This post shows how to read it, count it and alert on it.

In my previous article I showed that upgrading to Java 27 (but now to Java 25 as well, thanks to the backport) is enough to get hybrid post-quantum key exchange in TLS 1.3. At the end of the first demo there was a sentence I wasn’t happy with: the SSLSession API does not tell you which named group was chosen, so to find out you have to read javax.net.debug logs. That is fine for a blog post, but it is not a way to run a fleet. JDK 28 closes that gap, and this article is about using it.

The log-reading problem

Look again at what the client printed in the first article:

200 Hello over TLSv1.3 / TLS_AES_256_GCM_SHA384

That line is identical whether the key exchange was X25519MLKEM768 or plain x25519. The cipher suite only describes the symmetric part of the session.

This matters because hybrid TLS fails open by design. “Failing open” means that when a protection can’t be applied, the system carries on without it instead of refusing the connection (the opposite, “failing closed”, is what we triggered on purpose in chapter three of the first article). If the server doesn’t know the hybrid group, TLS 1.3 quietly picks the next group in the list, and everything keeps working. That is the right behavior for compatibility, because otherwise upgrading one side would break every connection to a peer that hasn’t upgraded yet. But it means a regression is invisible. An old JDK somewhere in the path, a proxy that mangles the larger ClientHello, or a leftover -Djdk.tls.namedGroups in a start script: none of them produce an error. They just keep you classical, and your recorded traffic exposed to “harvest now, decrypt later”.

So the question for this article is: how do I prove, from inside the application and in production, that the handshake was post-quantum, without turning on -Djavax.net.debug?

What Java 28 adds

The change is JDK-8388519, “Add APIs to get supported and negotiated named groups”, integrated for Java 28. It is an API addition with a CSR, not a JEP, and there is a release note filed as JDK-8394308. It adds two things:

  • ExtendedSSLSession.getNamedGroup() returns the key exchange group negotiated for the session.
  • getSupportedNamedGroups() on SSLEngine, SSLSocket and SSLServerSocket returns the groups the provider is able to use.

getSupportedNamedGroups() is easy to confuse with something we already had, so here are the three different questions you can now ask:

QuestionAPIMeaning
What could be used?getSupportedNamedGroups()Everything the provider implements
What is configured?SSLParameters.getNamedGroups()What this peer will offer or accept
What happened?ExtendedSSLSession.getNamedGroup()The group that produced this session’s keys

Only the third one is evidence. Both new methods have default implementations that throw UnsupportedOperationException, and SunJSSE overrides them. Keep that in mind, because third-party providers may not.

There is also a motivation behind the API. JDK-8389911 complains that SSLParameters.setNamedGroups() silently drops groups the provider doesn’t support, leaving no way to notice a downgrade. That is the same “fails open” problem seen from the configuration side.

Everything below was run on a JDK 28 early-access build, which you can download from jdk.java.net/28. JDK 28 is scheduled for March 2027, so check the behavior again on the GA build.

Setting the stage

I’m reusing the server and client from the first article, so nothing about the setup changes. The new code is a few lines added to each, plus one small helper class that I show in chapter three. You need JDK 28 (an early-access build at the time of writing), and everything still runs with java File.java, no build tool needed.

Chapter one: the one-line answer

On the client side, HttpClient hands back the session of the connection that served the response. In JDK 28 that session is an ExtendedSSLSession, so the cast works:

response.sslSession().ifPresent(s -> {
    String group = ((ExtendedSSLSession) s).getNamedGroup();
    System.out.println(s.getProtocol() + " / " + s.getCipherSuite() + " / group=" + group);
});

On the server side, HttpsExchange.getSSLSession() returns a session that supports the same call:

SSLSession session = ((HttpsExchange) exchange).getSSLSession();
String group = ((ExtendedSSLSession) session).getNamedGroup();

Run the client against the server with default settings:

200 TLSv1.3 / TLS_AES_256_GCM_SHA384 / group=X25519MLKEM768

Now the experiment from the first article. A server that only knows classical groups, and a client with the defaults:

java -Djdk.tls.namedGroups=x25519,secp256r1 PqcObserveServer.java
java PqcObserveClient.java
200 TLSv1.3 / TLS_AES_256_GCM_SHA384 / group=x25519

The request succeeds, the cipher suite is the same, and nothing is logged. But now the application can see the downgrade. This is the silent fallback, made visible.

One more data point: with -Djdk.tls.client.protocols=TLSv1.2 the group is x25519 as well. TLS 1.2 can’t negotiate a hybrid group, so a TLS 1.2 session will never report one.

Chapter two: supported, configured and negotiated

Let’s look at the first two rows of the table above. This snippet prints the groups the provider supports, and marks the ones enabled by default:

SSLSocket socket = (SSLSocket) ctx.getSocketFactory().createSocket();
List<String> enabled = Arrays.asList(socket.getSSLParameters().getNamedGroups());
for (String group : socket.getSupportedNamedGroups()) {
    System.out.println((enabled.contains(group) ? "[x] " : "[ ] ") + group);
}

On my machine it lists 25 groups and only 9 are enabled:

[x] X25519MLKEM768
[x] x25519
[x] secp256r1
[x] secp384r1
[x] secp521r1
[x] x448
[x] ffdhe2048
[x] ffdhe3072
[x] ffdhe4096
[ ] sect233k1
...
[ ] SecP256r1MLKEM768
[ ] SecP384r1MLKEM1024

The two other hybrid groups from JEP-527 are implemented by the provider, but off by default. Of the three hybrids, only X25519MLKEM768 is on, which is worth knowing before you assume that “supports hybrid” means all of them.

The configuration side is the trap. SSLParameters.setNamedGroups() happily accepts a name the provider doesn’t know, and getNamedGroups() echoes it back, so reading the configuration proves nothing about what the handshake will do. I tried MLKEM768, a group name from the TLS registry that is not a hybrid and that SunJSSE doesn’t list, and it was accepted without complaint. Only the negotiated group tells you the truth.

What getSupportedNamedGroups() is good for is a startup check. If your policy says a service must be able to do hybrid key exchange, fail fast when the provider can’t:

if (!Arrays.asList(socket.getSupportedNamedGroups()).contains("X25519MLKEM768")) {
    throw new IllegalStateException("This JVM cannot negotiate X25519MLKEM768");
}

That catches the “someone deployed this on an old runtime” case before the first request, instead of after a year of silent classical traffic.

Chapter three: turning it into a metric

Printing a line is not observability. What we want is a counter we can scrape, chart and alert on. A raw group name is a poor thing to alert on, so the helper normalizes it into a small set of labels, and counts the result. I used a ConcurrentHashMap<String, LongAdder> so the demo has no dependencies:

import javax.net.ssl.ExtendedSSLSession;
import javax.net.ssl.SSLSession;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.LongAdder;

public final class NamedGroupTelemetry {

    private static final Map<String, LongAdder> COUNTERS = new ConcurrentHashMap<>();

    /** hybrid-pqc, classical, none (nothing negotiated) or unsupported (provider can't tell). */
    public static String kind(String group) {
        if (group == null) {
            return "none";
        }
        if (group.equals("unsupported")) {
            return "unsupported";
        }
        return group.contains("MLKEM") ? "hybrid-pqc" : "classical";
    }

    public static String namedGroup(SSLSession session) {
        if (session instanceof ExtendedSSLSession extended) {
            try {
                return extended.getNamedGroup();
            } catch (UnsupportedOperationException e) {
                // providers that don't implement the JDK 28 API
            }
        }
        return "unsupported";
    }

    public static void record(String source, SSLSession session) {
        count(source, session.getProtocol(), namedGroup(session));
    }

    public static void count(String source, String protocol, String group) {
        String key = "tls.handshakes{source=%s, protocol=%s, group=%s, kind=%s}"
                .formatted(source, protocol, group == null ? "none" : group, kind(group));
        COUNTERS.computeIfAbsent(key, k -> new LongAdder()).increment();
    }

    public static void dump() {
        COUNTERS.entrySet().stream()
                .sorted(Map.Entry.comparingByKey())
                .forEach(e -> System.out.println(e.getKey() + " = " + e.getValue().sum()));
    }
}

There are two details here that the happy path hides. getNamedGroup() can legitimately return null, which the spec defines as no group negotiated (or the handshake not complete), so that gets its own value, none. And a provider that doesn’t implement the method throws UnsupportedOperationException. That is a different situation from “nothing negotiated”, so it becomes unsupported.

With Micrometer the body of count() becomes one line, and the same tags map one to one to OpenTelemetry attributes:

registry.counter("tls.handshakes",
        "protocol", protocol, "group", group, "kind", kind(group)).increment();

I call it from the client after each request, and from the server inside the HttpHandler. Then the client sends three requests through the same HttpClient. This is what the server counters look like afterwards:

tls.handshakes{source=server-request, protocol=TLSv1.3, group=X25519MLKEM768, kind=hybrid-pqc} = 3

Three requests, three increments, and this is the problem. A request is not a handshake. The HttpClient keeps the connection alive, so the three requests shared one handshake and one set of keys. A counter in the handler measures traffic, not key exchanges. If one client of a hundred is stuck on x25519 but sends 90% of the requests, the request-weighted ratio will paint a very wrong picture of your PQC adoption. What we need is one count per handshake.

Chapter four: one event per handshake from JFR

The JDK already has an event that fires once per TLS handshake: jdk.TLSHandshake. It is disabled by default, and in JDK 28 it gets a namedGroup field (JDK-8301626). Let’s turn it on for the client, with the server running as before. You enable the event the same way on any JVM, including your own services:

java -XX:StartFlightRecording:filename=client.jfr,jdk.TLSHandshake#enabled=true,jdk.TLSHandshake#stackTrace=false PqcObserveClient.java
jfr print --events jdk.TLSHandshake client.jfr
jdk.TLSHandshake {
  peerHost = "localhost"
  peerPort = 8443
  protocolVersion = "TLSv1.3"
  cipherSuite = "TLS_AES_256_GCM_SHA384"
  namedGroup = "X25519MLKEM768"
  certificateId = 2427077556
  eventThread = "HttpClient-1-Worker-0" (javaThreadId = 84)
}

The client sent three requests and there is one event. That confirms the point from the previous chapter: only the first request did a handshake. Starting the server with the same options gives you the matching event on its side.

You don’t need a file and jfr print to use this. JFR can stream events to the same JVM, and that is enough to feed the counter without touching a single HTTP handler:

import jdk.jfr.consumer.RecordingStream;

public final class JfrHandshakeCounter {

    public static RecordingStream start(String source) {
        RecordingStream stream = new RecordingStream();
        stream.enable("jdk.TLSHandshake").withoutStackTrace();
        stream.onEvent("jdk.TLSHandshake", event ->
                NamedGroupTelemetry.count(source, event.getString("protocolVersion"),
                        event.getString("namedGroup")));
        stream.startAsync();
        return stream;
    }
}

The server calls JfrHandshakeCounter.start("server-handshake") once at startup, and the client calls JfrHandshakeCounter.start("client-handshake"). The stream owns a thread, so close it (stream.close()) when the program is done, or it will keep the JVM alive.

After the same three requests, the counters for the client and the server look like this (the -request lines are the ones from the previous chapter):

tls.handshakes{source=client-handshake, protocol=TLSv1.3, group=X25519MLKEM768, kind=hybrid-pqc} = 1
tls.handshakes{source=client-request,   protocol=TLSv1.3, group=X25519MLKEM768, kind=hybrid-pqc} = 3
tls.handshakes{source=server-handshake, protocol=TLSv1.3, group=X25519MLKEM768, kind=hybrid-pqc} = 1
tls.handshakes{source=server-request,   protocol=TLSv1.3, group=X25519MLKEM768, kind=hybrid-pqc} = 3

One handshake, three requests, on both sides. This is the number that belongs on a dashboard.

The JFR route has another advantage: it works for anything built on SSLEngine or SSLSocket in that JVM. Netty, Vert.x and the Kafka clients and brokers do their TLS through SSLEngine, so there is no place where you could easily hook getNamedGroup() yourself, and the event covers them all. stackTrace=false keeps the cost of each event small, and handshakes are rare compared with requests, but I haven’t measured the overhead, so measure it before enabling this on a hot path.

What to put on the dashboard

With a per-handshake counter tagged with kind, three panels are enough:

  1. PQC adoption ratio: hybrid-pqc handshakes divided by all handshakes. This is the headline number.
  2. Fallback alert: alert when classical handshakes appear where you expect none, or when the ratio drops. A drop from 100% is far more suspicious than a slow climb.
  3. Who is still classical: break the counter down by peer or by service. The aggregate tells you that something is wrong, and the breakdown tells you which service is still on an old JDK.

The fallback alert is also how you would discover the middlebox problem I mentioned in the first article. A proxy that chokes on the larger ClientHello shows up as a group of clients that never get hybrid, and you’d want to hear about that before a security review does.

You may also want handshake latency by group, since the hybrid key shares are bigger. I haven’t measured it, so I won’t make a claim about the cost. On localhost the network doesn’t get in the way, which makes any number misleading anyway.

What this does and does not tell you

Before declaring victory:

  • It reports the key exchange only. Authentication is untouched, and our certificates are still elliptic curve keys. A hybrid group means the recorded traffic is protected, and nothing else about your PKI changed.
  • It is the local provider’s view. SunJSSE implements the API, but other providers may throw UnsupportedOperationException, which is why unsupported is a label of its own.
  • TLS 1.2 never reports a hybrid group. Hybrid groups exist only in TLS 1.3, so legacy protocol versions will always show up as classical.
  • It is a Java 28 API. On 25 and 27 you can’t call getNamedGroup(). The JFR field has backport requests open for 25u and 27u, but I didn’t verify that any update release includes it yet, so until then you are left with log parsing there.

The takeaway

The first article ended with the idea that the JDK made the migration to post-quantum TLS cheap. This one is the other half: it makes the migration checkable. With one method, getNamedGroup(), and one JFR event, “we upgraded the JDK” becomes “98% of our handshakes are hybrid, and these two services are not”. Hybrid TLS is designed to keep working when it can’t do its job, and that is exactly why it needs a number next to it.