diff --git a/AGENTS.md b/AGENTS.md index 706596f..f28c2f7 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -133,6 +133,7 @@ startup; a mismatch fails the boot. Tests run the same migrations against in-mem | `docs/ARCHITECTURE.md` | request flow, routing, metering fields | | `docs/CONFIGURATION.md` | every environment variable and profile | | `docs/OPERATIONS.md` | admin API, metrics, migrations, alerts | +| `docs/CRYPTO.md` | cryptographic inventory, TLS posture, PQC gaps | | `docs/LIMITS.md` | design notes and known gaps | | `docs/TESTING.md` | test suites and the mock upstream | | `docs/ROADMAP.md` | delivered work and the open stories | @@ -294,6 +295,12 @@ is a guess, not a commitment — re-tag when reality disagrees. provider-reported usage. - **`usage_estimated=true`** means the provider returned no `usage` block and the counts were inferred from text length. Never present those as observed. +- **JSSE on Java 21 has no hybrid key exchange, and a bad `jdk.tls.namedGroups` kills all + TLS.** ML-KEM exists as a JCA primitive (`Security.getAlgorithms("KEM")`) but + `X25519MLKEM768` reaches JSSE only in Java 27 (JEP 527). Setting `jdk.tls.namedGroups` + to a group the JVM does not know throws `ExceptionInInitializerError` at + `SSLContext.getDefault()`, so every outbound call fails — never set it speculatively. + `GET /admin/crypto-posture` reports the live group list. - **The demo key is unlimited** and is created when the key table is empty. Set `GATEWAY_BOOTSTRAP_DEMO_KEY=false` anywhere real. - **`tools/smoke_test.py` needs a clean DB** for the demo-key path; otherwise it creates diff --git "a/bruno/07 \302\267 Admin \342\200\224 reporting/Crypto posture.bru" "b/bruno/07 \302\267 Admin \342\200\224 reporting/Crypto posture.bru" new file mode 100644 index 0000000..243ca3b --- /dev/null +++ "b/bruno/07 \302\267 Admin \342\200\224 reporting/Crypto posture.bru" @@ -0,0 +1,14 @@ +meta { + name: Crypto posture + type: http + seq: 4 +} + +get { + url: {{baseUrl}}/admin/crypto-posture + auth: none +} + +headers { + X-Admin-Token: {{adminToken}} +} diff --git a/changelog/v0.2.24.md b/changelog/v0.2.24.md new file mode 100644 index 0000000..31528a5 --- /dev/null +++ b/changelog/v0.2.24.md @@ -0,0 +1,21 @@ +# v0.2.24 + +A cryptographic inventory for the post-quantum transition, reported at runtime. + +## Added + +- `GET /admin/crypto-posture` reports the JVM's enabled TLS protocols, the key-exchange + groups JSSE supports, whether any of them is a post-quantum hybrid, and which NIST PQC + primitives (ML-KEM, ML-DSA) are installed. Read scope is enough; it exposes no + credential. +- `docs/CRYPTO.md` inventories every cryptographic dependency with its quantum status, + covers inbound and outbound TLS, and records the open items. + +## Notes + +- On Java 21 the endpoint reports `hybrid_key_exchange=false`: ML-KEM exists as a JCA + primitive but JSSE cannot negotiate a hybrid group until Java 27 (JEP 527). Outbound + provider traffic is therefore classical ECDHE for now; the endpoint exists so that gap + is visible instead of assumed. +- Symmetric primitives (AES-256-GCM, SHA-256, HMAC, PBKDF2) are unchanged: they are not + broken by quantum search, and replacing them would be work with negative value. diff --git a/docs/API.md b/docs/API.md index 9d9551d..08df974 100644 --- a/docs/API.md +++ b/docs/API.md @@ -468,6 +468,30 @@ most 500 points. The series is one query over `usage_records` for the whole wind bucketed in Java (`AdminReportingService`), not one query per point; `p95_latency_ms` covers successful calls only. Omitting `bucket` leaves the response exactly as before. +### Crypto posture + +`GET /admin/crypto-posture` — read-only inventory of the running JVM: enabled TLS +protocols, the key-exchange groups JSSE supports, whether any of them is a post-quantum +hybrid, and which PQC primitives (`ML-KEM`, `ML-DSA`) are installed. Read scope is +enough; it exposes no credential. See [CRYPTO.md](CRYPTO.md) for what each field means +and the current gaps. + +```json +{ + "java_version": "21.0.13.1", + "tls": { + "enabled_protocols": ["TLSv1.3", "TLSv1.2"], + "supported_named_groups": ["x25519", "secp256r1", "secp384r1", "secp521r1", "x448", "..."], + "hybrid_key_exchange": false, + "hybrid_groups": [], + "tls12_enabled": true + }, + "pqc": {"ml_kem": true, "ml_dsa": true, "kem_algorithms": ["ML-KEM", "ML-KEM-512", "..."]}, + "warnings": ["JSSE offers no post-quantum key exchange: every outbound TLS connection uses classical ECDHE. ..."], + "reference": "docs/CRYPTO.md" +} +``` + --- ### Gemini extensions diff --git a/docs/CRYPTO.md b/docs/CRYPTO.md new file mode 100644 index 0000000..e47268e --- /dev/null +++ b/docs/CRYPTO.md @@ -0,0 +1,116 @@ +# Cryptographic inventory + +Where Path uses cryptography, what breaks under a quantum adversary, and what is left to +do. This is the "inventory your cryptographic dependencies" step of the NSA advisory +[*Immediate Actions to Push Toward Post-Quantum*](https://media.defense.gov/2026/Dec/01/2004039413/-1/-1/0/CSA_Immediate_Actions_Push_Toward_PQC.PDF) +(2 Dec 2026), written for this codebase rather than for a national security system. + +The advisory creates no obligation for a commercial gateway and states that the recent +disclosures are **not an immediate, widespread threat**. The part that applies here is +harvest-now-decrypt-later: prompts and completions in transit are worth recording today +if the key exchange can be broken later. + +Maintainers: update this file when a JVM, proxy or provider changes, and re-read +`GET /admin/crypto-posture` (below) after any such bump. + +## Summary + +| Layer | Primitive | Quantum status | +|---|---|---| +| Provider keys, mail password, Vertex key at rest | AES-256-GCM (`SecretCipher`) | Safe. Grover halves the margin, 256-bit stays ~128-bit. | +| Admin passwords | PBKDF2-HMAC-SHA256, 210k iterations (`PasswordHasher`) | Safe. Symmetric. | +| Client keys and admin sessions at rest | SHA-256 hash of a high-entropy random secret (`ApiKeyService`, `AdminAuthService`) | Safe. No public-key operation. | +| OAuth state | HMAC-SHA256 (`GithubOAuthService`) | Safe. Symmetric. | +| Google service-account assertion (Vertex) | RSASSA-PKCS1-v1_5 / SHA-256, RS256 (`VertexTokenService`) | **Vulnerable signature**, but Google's key and contract. Not ours to change. | +| Outbound TLS to providers, webhooks, SMTP | TLS 1.3, ECDHE x25519 / P-256 | **Vulnerable key exchange.** JSSE on Java 21 cannot offer a hybrid group. | +| Inbound TLS (browser → gateway) | Terminated by Traefik or Cloudflare, never by the JVM | Depends on the edge. See below. | +| Console (`path-admin`) | Browser TLS; token in `sessionStorage`, in-memory cache | Depends on the edge. Chrome 131+, Firefox 132+ and Safari 26 already offer hybrid. | +| Postgres, Valkey | Plaintext on the container network in the shipped compose files | Not a PQC issue; a network-trust issue. | + +### What is *not* vulnerable + +Symmetric primitives (AES, SHA-2, HMAC, PBKDF2) are not broken by Shor's algorithm, only +weakened by Grover's quadratic speed-up. Do not "migrate" them: replacing AES-256-GCM or +PBKDF2-HMAC-SHA256 would be work with negative value. The migration is public-key only: +key establishment and signatures. + +## Outbound TLS is the real gap + +Verified on the JDK this project builds with (Temurin 21.0.13.1): + +``` +KEM algs = [ML-KEM-768, ML-KEM-1024, ML-KEM, ML-KEM-512, DHKEM] +default TLS named groups = [x25519, secp256r1, secp384r1, secp521r1, x448, ffdhe…] +-Djdk.tls.namedGroups=X25519MLKEM768 + -> IllegalArgumentException: contains no supported named groups +``` + +So ML-KEM is installed as a JCA primitive, but **JSSE has no hybrid key exchange**. Every +`java.net.http.HttpClient` call in `UpstreamClient` negotiates classical ECDHE. That is +the one finding in this document that matters: provider traffic is the sensitive traffic. + +Hybrid TLS in JSSE arrives with JEP 527 (Java 27). It is the default there, so +`UpstreamClient` needs no code change once the build moves; the groups list becomes +`[X25519MLKEM768, …]` automatically. Do not hand-roll RFC 10024 in this repository, and +do not set `jdk.tls.namedGroups` to a group the JVM does not know: JSSE fails to +initialise and every outbound connection dies. + +The provider side is usually ready: most LLM endpoints sit behind a CDN that already +offers hybrid key exchange (Cloudflare has on TLS 1.3 zones since 2022). A client that +cannot offer the group simply keeps using X25519. + +## Inbound TLS + +The JVM never terminates TLS; the proxy does. Nothing in `path-gateway` can add PQC to +that hop, so the posture is whatever the edge runs: + +| Edge | Hybrid key exchange | +|---|---| +| Cloudflare in front (as in `deploy/dokploy/compose.yml`) | Yes, for every TLS 1.3 zone. Origin pull is a separate setting. | +| Traefik | 3.4.2+ (Go 1.24 defaults to `X25519MLKEM768`). Earlier builds fall back to classical. | +| nginx / nginx-ingress | Any build linked against OpenSSL 3.5+, which offers the group by default. | +| Kubernetes API server, kubelet | Go 1.24+, so hybrid by default; not on the request path. | + +Verify the edge, not the code: + +```bash +openssl s_client -connect path.example.com:443 -groups X25519MLKEM768 -brief io.github.an1ndra path-parent - 0.2.23 + 0.2.24 ../pom.xml diff --git a/path-gateway/src/main/java/com/anindra/path/admin/AdminController.java b/path-gateway/src/main/java/com/anindra/path/admin/AdminController.java index e4b5036..a9f010a 100644 --- a/path-gateway/src/main/java/com/anindra/path/admin/AdminController.java +++ b/path-gateway/src/main/java/com/anindra/path/admin/AdminController.java @@ -26,6 +26,7 @@ public class AdminController { private final MailSettingsService mailSettingsService; private final SystemPromptService systemPromptService; private final DailyDigestService digest; + private final CryptoPostureService cryptoPosture; private final com.anindra.path.config.GatewayProperties props; // ------------------------------------------------------------- providers @@ -244,6 +245,15 @@ public Map settings(jakarta.servlet.http.HttpServletRequest requ return out; } + /** + * Cryptographic inventory of the running JVM (see docs/CRYPTO.md). Read-only, and read + * scope is enough: it exposes no credential, only which algorithms this build can use. + */ + @GetMapping("/crypto-posture") + public Map 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