cryptoPosture() {
+ return cryptoPosture.snapshot();
+ }
+
// --------------------------------------------------------------- aliases
@com.fasterxml.jackson.databind.annotation.JsonNaming(
diff --git a/path-gateway/src/main/java/com/anindra/path/admin/CryptoPostureService.java b/path-gateway/src/main/java/com/anindra/path/admin/CryptoPostureService.java
new file mode 100644
index 0000000..63bc061
--- /dev/null
+++ b/path-gateway/src/main/java/com/anindra/path/admin/CryptoPostureService.java
@@ -0,0 +1,117 @@
+package com.anindra.path.admin;
+
+import org.springframework.stereotype.Service;
+
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLParameters;
+import java.security.Security;
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+
+/**
+ * Read-only snapshot of the cryptographic posture of the running JVM.
+ *
+ * This is the machine-readable half of the inventory in {@code docs/CRYPTO.md}: what
+ * TLS the JVM can negotiate, whether it can offer a post-quantum key exchange, and which
+ * PQC primitives are installed. Nothing here changes behaviour; it exists so an operator
+ * can see the gap instead of discovering it during an audit.
+ *
+ *
The honest answer on Java 21 is that JSSE offers no hybrid group: ML-KEM is present
+ * as a JCA primitive, but TLS key establishment stays classical until a JVM implements
+ * RFC 10024 (JEP 527, Java 27). The warnings say so explicitly.
+ */
+@Service
+public class CryptoPostureService {
+
+ /** Hybrid key-exchange groups from RFC 10024 and its siblings, in preference order. */
+ private static final List HYBRID_GROUPS = List.of(
+ "X25519MLKEM768", "SecP256r1MLKEM768", "SecP384r1MLKEM1024");
+
+ public Map snapshot() {
+ Map out = new LinkedHashMap<>();
+ out.put("java_version", System.getProperty("java.version"));
+ out.put("java_vendor", System.getProperty("java.vendor"));
+ out.put("checked_at", Instant.now().toString());
+
+ String namedGroupsProperty = System.getProperty("jdk.tls.namedGroups");
+ List protocols = List.of();
+ List groups = List.of();
+ boolean tlsReadable = true;
+ try {
+ SSLParameters defaults = SSLContext.getDefault().getDefaultSSLParameters();
+ protocols = List.of(defaults.getProtocols());
+ groups = List.of(SSLContext.getDefault().getSupportedSSLParameters().getNamedGroups());
+ } catch (RuntimeException | java.security.NoSuchAlgorithmException | LinkageError e) {
+ // An invalid jdk.tls.namedGroups override fails JSSE initialisation with
+ // ExceptionInInitializerError. Report it instead of failing the admin call.
+ tlsReadable = false;
+ }
+
+ List hybrid = new ArrayList<>();
+ for (String group : groups) {
+ for (String candidate : HYBRID_GROUPS) {
+ if (candidate.equalsIgnoreCase(group)) {
+ hybrid.add(candidate);
+ }
+ }
+ }
+
+ Map tls = new LinkedHashMap<>();
+ tls.put("enabled_protocols", protocols);
+ tls.put("supported_named_groups", groups);
+ tls.put("hybrid_key_exchange", !hybrid.isEmpty());
+ tls.put("hybrid_groups", hybrid);
+ tls.put("tls12_enabled", protocols.contains("TLSv1.2"));
+ if (namedGroupsProperty != null && !namedGroupsProperty.isBlank()) {
+ tls.put("named_groups_property", namedGroupsProperty);
+ }
+ out.put("tls", tls);
+
+ Set kems = new TreeSet<>(Security.getAlgorithms("KEM"));
+ Set signatures = new TreeSet<>(Security.getAlgorithms("Signature"));
+ boolean mlKem = kems.stream().anyMatch(a -> a.toUpperCase(Locale.ROOT).startsWith("ML-KEM"));
+ boolean mlDsa = signatures.stream().anyMatch(a -> a.toUpperCase(Locale.ROOT).startsWith("ML-DSA"));
+
+ Map pqc = new LinkedHashMap<>();
+ pqc.put("kem_algorithms", kems);
+ pqc.put("ml_kem", mlKem);
+ pqc.put("ml_dsa", mlDsa);
+ out.put("pqc", pqc);
+
+ List warnings = new ArrayList<>();
+ if (!tlsReadable) {
+ warnings.add("JSSE could not be initialised; check jdk.tls.namedGroups. "
+ + "Without TLS this process cannot reach an https upstream.");
+ }
+ if (hybrid.isEmpty()) {
+ warnings.add("JSSE offers no post-quantum key exchange: every outbound TLS "
+ + "connection uses classical ECDHE. Hybrid X25519MLKEM768 needs a JVM "
+ + "that implements RFC 10024 (JEP 527, Java 27+).");
+ }
+ if (protocols.contains("TLSv1.2")) {
+ warnings.add("TLS 1.2 is still enabled by the default SSL context and the "
+ + "gateway does not pin a minimum, so a peer can select it. The "
+ + "advisory targets TLS 1.3.");
+ }
+ if (!mlKem) {
+ warnings.add("The JVM has no ML-KEM implementation; post-quantum key "
+ + "establishment is unavailable even with a capable peer.");
+ }
+ out.put("warnings", warnings);
+
+ List notes = new ArrayList<>();
+ notes.add("Authentication is still classical: no publicly trusted CA issues "
+ + "post-quantum certificates, so RSA/ECDSA certificate signatures remain.");
+ notes.add("At-rest and hashing primitives (AES-256-GCM, SHA-256, HMAC-SHA256, "
+ + "PBKDF2-HMAC-SHA256) are symmetric and not broken by quantum search.");
+ out.put("notes", notes);
+ out.put("reference", "docs/CRYPTO.md");
+ return out;
+ }
+}
diff --git a/path-gateway/src/test/java/com/anindra/path/GatewayApiTest.java b/path-gateway/src/test/java/com/anindra/path/GatewayApiTest.java
index 67827bc..d814849 100644
--- a/path-gateway/src/test/java/com/anindra/path/GatewayApiTest.java
+++ b/path-gateway/src/test/java/com/anindra/path/GatewayApiTest.java
@@ -228,6 +228,19 @@ void adminSettingsReportsTheTokenScopesAndSubject() throws Exception {
.andExpect(jsonPath("$.can_write").value(true));
}
+ @Test
+ void cryptoPostureIsReadableWithAReadScopedToken() throws Exception {
+ // The inventory is what a read-only auditor needs, so read scope must suffice.
+ String readOnly = tenancy.createToken("posture-viewer", "read").plaintext();
+ mvc.perform(get("/admin/crypto-posture").header("X-Admin-Token", readOnly))
+ .andExpect(status().isOk())
+ .andExpect(jsonPath("$.tls.enabled_protocols").isArray())
+ .andExpect(jsonPath("$.tls.hybrid_key_exchange").isBoolean())
+ .andExpect(jsonPath("$.pqc.ml_kem").isBoolean())
+ .andExpect(jsonPath("$.warnings").isArray())
+ .andExpect(jsonPath("$.reference").value("docs/CRYPTO.md"));
+ }
+
@Test
void systemPromptIsEditableThroughTheAdminApi() throws Exception {
mvc.perform(get("/admin/system-prompt").header("X-Admin-Token", "test-admin"))
diff --git a/path-gateway/src/test/java/com/anindra/path/admin/CryptoPostureServiceTest.java b/path-gateway/src/test/java/com/anindra/path/admin/CryptoPostureServiceTest.java
new file mode 100644
index 0000000..aef8975
--- /dev/null
+++ b/path-gateway/src/test/java/com/anindra/path/admin/CryptoPostureServiceTest.java
@@ -0,0 +1,60 @@
+package com.anindra.path.admin;
+
+import org.junit.jupiter.api.Test;
+
+import javax.net.ssl.SSLContext;
+import java.security.Security;
+import java.time.Instant;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatCode;
+
+/**
+ * The posture endpoint is an audit aid, so the test guards the invariants an auditor
+ * would check: it must not throw on an exotic JVM, and it must never claim hybrid TLS
+ * when the JVM's own supported group list does not contain a hybrid group.
+ */
+class CryptoPostureServiceTest {
+
+ private final CryptoPostureService posture = new CryptoPostureService();
+
+ @Test
+ @SuppressWarnings("unchecked")
+ void snapshotReportsTlsAndPqcWithoutFailing() {
+ Map out = posture.snapshot();
+
+ assertThat(out).containsKeys("java_version", "tls", "pqc", "warnings", "notes", "reference");
+ assertThat(out.get("reference")).isEqualTo("docs/CRYPTO.md");
+ assertThatCode(() -> Instant.parse((String) out.get("checked_at"))).doesNotThrowAnyException();
+
+ Map tls = (Map) out.get("tls");
+ List groups = (List) tls.get("supported_named_groups");
+ boolean anyHybrid = groups.stream().anyMatch(g -> g.toUpperCase(Locale.ROOT).contains("MLKEM"));
+ assertThat(tls.get("hybrid_key_exchange")).isEqualTo(anyHybrid);
+
+ Map pqc = (Map) out.get("pqc");
+ boolean kemInstalled = Security.getAlgorithms("KEM").stream()
+ .anyMatch(a -> a.toUpperCase(Locale.ROOT).startsWith("ML-KEM"));
+ assertThat(pqc.get("ml_kem")).isEqualTo(kemInstalled);
+
+ List warnings = (List) out.get("warnings");
+ if (!anyHybrid) {
+ assertThat(warnings).anyMatch(w -> w.contains("JEP 527"));
+ }
+ }
+
+ @Test
+ @SuppressWarnings("unchecked")
+ void supportedGroupsAreReadableOnThisJvm() throws Exception {
+ // A guard for the probe itself: getSupportedSSLParameters is the only public API
+ // that reveals whether JSSE knows a hybrid group.
+ Set groups = Set.copyOf(List.of(
+ SSLContext.getDefault().getSupportedSSLParameters().getNamedGroups()));
+ assertThat(groups).isNotEmpty();
+ assertThat(posture.snapshot()).isNotNull();
+ }
+}
diff --git a/path-spring-ai/pom.xml b/path-spring-ai/pom.xml
index 8b79273..ba533b9 100644
--- a/path-spring-ai/pom.xml
+++ b/path-spring-ai/pom.xml
@@ -7,7 +7,7 @@
io.github.an1ndra
path-parent
- 0.2.23
+ 0.2.24
../pom.xml
diff --git a/pom.xml b/pom.xml
index a3e4656..16680c8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -13,7 +13,7 @@
io.github.an1ndra
path-parent
- 0.2.23
+ 0.2.24
pom
path-parent
Build parent for Path, the provider-agnostic LLM gateway, and its Spring AI adapter