Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions bruno/07 · Admin — reporting/Crypto posture.bru
Original file line number Diff line number Diff line change
@@ -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}}
}
21 changes: 21 additions & 0 deletions changelog/v0.2.24.md
Original file line number Diff line number Diff line change
@@ -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.
24 changes: 24 additions & 0 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
116 changes: 116 additions & 0 deletions docs/CRYPTO.md
Original file line number Diff line number Diff line change
@@ -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 </dev/null
# look for "Negotiated TLS1.3 group: X25519MLKEM768"
```

## Checking the running process

```bash
curl -s -H "X-Admin-Token: $GATEWAY_ADMIN_TOKEN" \
https://path.example.com/admin/crypto-posture | jq
```

The endpoint is read-only and read scope is enough. Fields:

| Field | Meaning |
|---|---|
| `tls.enabled_protocols` | Protocols the default `SSLContext` enables (expected `TLSv1.3`, `TLSv1.2`). |
| `tls.supported_named_groups` | Key-exchange groups JSSE can use. No `…MLKEM…` entry means classical only. |
| `tls.hybrid_key_exchange` | True only when a hybrid group is in that list. |
| `tls.named_groups_property` | Present when `jdk.tls.namedGroups` overrides the defaults. |
| `pqc.ml_kem`, `pqc.ml_dsa` | Whether the JVM installs the NIST PQC primitives. |
| `warnings` | Actionable gaps, including the JEP 527 message on Java 21. |

## Plan

| Item | Status | Action |
|---|---|---|
| Inventory and live posture | Done | This file and `/admin/crypto-posture`. |
| Egress key exchange | **Open** | Blocked on a JVM with JEP 527 (Java 27) or a JSSE provider that implements RFC 10024. Re-check `tls.hybrid_key_exchange` after every JDK bump. |
| Edge key exchange | Deployment task | Confirm Traefik ≥ 3.4.2 or nginx + OpenSSL 3.5; test with `openssl s_client`. |
| PQ certificates and signatures | Wait | No publicly trusted CA issues them; Chrome is pursuing Merkle Tree Certificates. Nothing to implement. |
| Vertex JWT (RS256) | External | Google would have to accept and issue a PQ signature. |
| Release artifact signing | Optional | Not used today; if added, prefer ML-DSA-capable tooling. |
| Cryptographic agility | Covered | Ciphertexts carry a `v1:` prefix and the master key rotates (`/admin/rotate-master-key`), so an at-rest algorithm can change without a rewrite. |

## Re-verify after

- a JDK or Spring Boot major bump — expect `tls.hybrid_key_exchange` to flip to `true` on Java 27;
- a proxy upgrade — rerun the `openssl s_client` check;
- a new provider integration — confirm its endpoint supports TLS 1.3 and, where offered, the hybrid group;
- any change to `SecretCipher`, `PasswordHasher` or token hashing — update the summary table.
2 changes: 1 addition & 1 deletion path-gateway/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>io.github.an1ndra</groupId>
<artifactId>path-parent</artifactId>
<version>0.2.23</version>
<version>0.2.24</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -244,6 +245,15 @@ public Map<String, Object> 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<String, Object> cryptoPosture() {
return cryptoPosture.snapshot();
}

// --------------------------------------------------------------- aliases

@com.fasterxml.jackson.databind.annotation.JsonNaming(
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
*
* <p>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.
*
* <p>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<String> HYBRID_GROUPS = List.of(
"X25519MLKEM768", "SecP256r1MLKEM768", "SecP384r1MLKEM1024");

public Map<String, Object> snapshot() {
Map<String, Object> 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<String> protocols = List.of();
List<String> 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<String> hybrid = new ArrayList<>();
for (String group : groups) {
for (String candidate : HYBRID_GROUPS) {
if (candidate.equalsIgnoreCase(group)) {
hybrid.add(candidate);
}
}
}

Map<String, Object> 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<String> kems = new TreeSet<>(Security.getAlgorithms("KEM"));
Set<String> 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<String, Object> pqc = new LinkedHashMap<>();
pqc.put("kem_algorithms", kems);
pqc.put("ml_kem", mlKem);
pqc.put("ml_dsa", mlDsa);
out.put("pqc", pqc);

List<String> 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<String> 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;
}
}
13 changes: 13 additions & 0 deletions path-gateway/src/test/java/com/anindra/path/GatewayApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
Loading
Loading