> ## Documentation Index
> Fetch the complete documentation index at: https://chatcli.edilsonfreitas.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Post-Quantum Cryptography

> How ChatCLI protects data, connections, releases, plugins and tokens against a future quantum computer: the CNSA 2.0 algorithms it uses (ML-KEM, ML-DSA-87, SHA-512, AES-256), what changed from earlier versions, what migrates on its own, and what is still classical and why.

A large quantum computer breaks the public-key algorithms most software relies on today: RSA, elliptic-curve key exchange and elliptic-curve signatures. Symmetric encryption and hashes survive, provided the key and the digest are large enough. Traffic recorded now can be decrypted later, so the key exchange has to be replaced before such a computer exists, not after.

ChatCLI uses the algorithms of the [CNSA 2.0](https://media.defense.gov/2022/Sep/07/2003071834/-1/-1/0/CSA_CNSA_2.0_ALGORITHMS_.PDF) suite everywhere it chooses the algorithm itself. This page is the map: one section per place cryptography is used, with what protects it, what you have to do (usually nothing) and what stays classical.

## At a glance

| Where | Algorithm | What you do |
| - | - | - |
| Data on disk | AES-256-GCM, a key per payload, HKDF-SHA512 | nothing: older data is migrated |
| TLS key exchange | hybrid ML-KEM (FIPS 203) with a classical curve, whenever the other side supports it | nothing by default; set `CHATCLI_TLS_PQ` to make it mandatory |
| Release signatures (`chatcli update`) | Ed25519 **and** ML-DSA-87 (FIPS 204), both required, over SHA-512 checksums | nothing |
| Plugin signatures | Ed25519 **and** ML-DSA-87, both required | publishers: `chatcli plugin keygen --upgrade` |
| Server JWT | ML-DSA-87 or RS256 with public keys; HS512 or HS256 with a shared secret | optional: `chatcli jwt keygen` and issue ML-DSA-87 tokens |
| Audit trail | SHA-512 hash chain | nothing: existing trails keep verifying |
| Workspace trust | SHA-512 fingerprint | nothing: trusted workspaces stay trusted |
| Own webhooks | HMAC-SHA512 beside HMAC-SHA256 | optional: verify the SHA-512 header |

Two principles hold in every row:

* **Hybrid, not replacement.** Where a post-quantum algorithm is added, the classical one stays beside it and both must hold. ML-KEM and ML-DSA are young; a flaw found in either one does not weaken ChatCLI below what it had before.
* **Transparent migration.** Data, keys, signatures and trails created by earlier versions keep working. Nothing is rewritten in a way that could strand it, and nothing asks you to convert it by hand.

## Data on disk

Everything ChatCLI seals under `~/.chatcli` uses AES-256-GCM. Each file and each journal line is sealed under **its own key**, derived with HKDF-SHA512 from the data secret and a random 32-byte salt stored with the payload. A passphrase in `CHATCLI_ENCRYPTION_KEY` shorter than 32 characters is stretched with Argon2id and PBKDF2-HMAC-SHA512 together.

Stored data uses no public-key cryptography, so there is no key exchange to replace here: its exposure to a quantum computer is the key size and the hash, and both are at the top of the suite.

Stores written by earlier versions still open and are rewritten in the new format on their own. Your recovery key did not change. See [Encryption at Rest](https://chatcli.edilsonfreitas.com/security/encryption-at-rest.md) for the migration and the downgrade path.

## TLS

Every TLS connection ChatCLI makes or accepts negotiates a **hybrid key exchange**, a classical curve combined with ML-KEM, whenever the other side supports one. That covers the client and server (`chatcli connect`, `chatcli server`), the Kubernetes operator, the health probe, and outbound calls to LLM providers, webhooks and SMTP.

`CHATCLI_TLS_PQ` decides what happens when the other side does not support one:

| Value | Between ChatCLI components (client, server, operator, health probe) | To other services (LLM providers, webhooks, SMTP) |
| - | - | - |
| `prefer` (default) | hybrid when available, classical otherwise | hybrid when available, classical otherwise |
| `require` | classical key exchange refused | as `prefer` |
| `cnsa` | only `SecP384r1MLKEM1024`: ML-KEM-1024, the CNSA 2.0 parameter set, with P-384 | as `prefer` |
| `require-all` | as `require` | classical key exchange refused |
| `cnsa-all` | as `cnsa` | classical key exchange refused |

The variable is read by the CLI, the server and the operator. In Kubernetes it is `security.tlsPostQuantum` in both Helm charts and `spec.server.security.tlsPostQuantum` on an Instance.

> [accordion] Rolling out a strict mode
>
> One end is enough. A server on `cnsa` and a client on the default negotiate ML-KEM-1024, and so does the reverse, because ChatCLI clients and the operator already offer every group. Set the mode on the server first, confirm, then set it on the clients that should refuse a server without it.
>
> A strict mode applies to whatever terminates TLS. An ingress, a mesh sidecar or a load balancer in front of the server must support the groups the mode demands, or connections through it are refused.

> [accordion] A strict mode has no plaintext
>
> A strict mode demands a post-quantum key exchange, and a plaintext connection has none. Under any mode other than `prefer`:
>
> * the server refuses to start without a certificate;
> * the operator refuses to start unless its REST API has TLS (`security.apiTLS.*`);
> * a client refuses `CHATCLI_ALLOW_INSECURE=true`;
> * the health probe refuses to run without the server certificate.

> [accordion] Checking what was negotiated
>
> ```bash theme={"system"}
> chatcli healthcheck -addr server.example.com:50051 -tls-cert server.crt -show-tls
> ```
>
> ```text theme={"system"}
> TLS: TLS 1.3, key exchange SecP384r1MLKEM1024 (post-quantum hybrid), cipher TLS_AES_128_GCM_SHA256
> server.example.com:50051 is serving.
> ```
>
> `/config security` shows the mode in effect in the current session.

> [accordion] An invalid value
>
> A value that does not parse is an error at server and operator startup. In the CLI it is reported on screen and the strictest mode applies, so a typo never weakens a session.

> [!NOTE]
>
> Certificates are still signed with classical algorithms: public certificate authorities and the TLS ecosystem do not issue post-quantum certificates yet. A classical certificate protects against impersonation today, which a future quantum computer cannot undo after the fact. The hybrid key exchange is what protects recorded traffic against being decrypted later. The TLS 1.3 record cipher is chosen by the Go TLS stack and cannot be pinned.

## Releases

`chatcli update` authenticates a release with a **hybrid signature**: Ed25519 and ML-DSA-87 over the same statement, both required. The statement names what is signed, its purpose and the key pair, so a signature cannot be replayed for something else and one half cannot be combined with another key.

| Asset | What it is |
| - | - |
| `checksums-sha512.txt` | SHA-512 of every release asset |
| `checksums-sha512.txt.sig` | the hybrid signature over that file |
| `checksums.txt`, `checksums.txt.sig` | SHA-256 and Ed25519, still published for binaries released before the hybrid signature and for manual checks |

The updater verifies the hybrid signature against the key pair embedded in the binary, then the SHA-512 of the download. It refuses a release with only one valid half, with the earlier format alone, or without the new assets. An older binary updates once through the Ed25519 assets and verifies every update after that with the hybrid signature. See [Auto-update](https://chatcli.edilsonfreitas.com/start/auto-update.md).

Container images are signed with Cosign and Homebrew verifies SHA-256: those are the mechanisms of their ecosystems and are unchanged.

## Plugins

Plugin signing keys are hybrid as well, for tool plugins and provider plugins alike.

```bash theme={"system"}
# A new publisher key
chatcli plugin keygen --output ./keys

# An existing Ed25519 key: add the ML-DSA-87 half and keep the key
chatcli plugin keygen --upgrade --output ./keys
```

* A hybrid key accepts only a signature with both halves. Removing the ML-DSA-87 half or presenting the earlier format does not verify.
* A signature file still begins with the Ed25519 signature, so a plugin signed today installs on ChatCLI versions from before the change.
* A classical key fingerprint reads `SHA256:…`; a hybrid one reads `SHA512:…`. `chatcli plugin verify` and `chatcli plugin trust list` say which kind a plugin or key is.
* When a publisher upgrades, an installation that pinned the earlier fingerprint accepts the hybrid successor without asking, because the key it already trusts signed for the pair. The pin moves to the hybrid fingerprint and does not go back.
* Keys and signatures from before the change keep working.

See [Plugin System](https://chatcli.edilsonfreitas.com/extensions/plugin-system.md).

## Server tokens (JWT)

The key material you configure decides which algorithms the server accepts, never the token:

| Material | Accepted |
| - | - |
| ML-DSA-87 public keys in `CHATCLI_JWT_PUBLIC_KEY` | `ML-DSA-87` |
| RSA public keys in `CHATCLI_JWT_PUBLIC_KEY` | `RS256` |
| Both kinds in the same file | both, each against its own keys |
| Shared secret in `CHATCLI_JWT_SECRET` | `HS512` and `HS256` |

RS256 is the part a quantum computer breaks. Identity providers do not issue ML-DSA-87 tokens yet, so ChatCLI can issue them itself:

```bash theme={"system"}
chatcli jwt keygen --output ./jwt
export CHATCLI_JWT_PUBLIC_KEY=./jwt/jwt-signing.pub      # on the server

chatcli jwt sign --key ./jwt/jwt-signing.key --subject alice --role user --ttl 8h
```

To move without a cutover, put the RSA public key and the ML-DSA-87 public key in the same file: tokens of both kinds are accepted until the last RS256 token expires. A shared secret needs nothing: it already accepts HS512, and `chatcli jwt sign --secret-env CHATCLI_JWT_SECRET --subject alice` issues one. See [Server Mode](https://chatcli.edilsonfreitas.com/server/server-mode.md).

## Integrity hashes

Where ChatCLI picks a hash to protect integrity, it is SHA-512:

* **Audit trail.** Each entry is chained to the previous one with SHA-512. Entries written with SHA-256 by earlier versions keep verifying, and a trail moves over at the first entry a current version appends. `/config security verify-audit` reports how many entries use each hash.
* **Workspace trust.** `chatcli trust` records a SHA-512 fingerprint of the files that can run code or change the security posture. A workspace trusted earlier stays trusted while those files are unchanged.
* **Webhooks.** The gateway webhook sends `X-ChatCLI-Signature-512` beside `X-ChatCLI-Signature`, and the operator webhook channel sends `X-Signature-512` beside `X-Signature-256`. The SHA-256 headers are unchanged for receivers that check them. See [Webhook](https://chatcli.edilsonfreitas.com/gateway/webhook.md).

## What is still classical, and why

| What | Why |
| - | - |
| TLS certificates | Public CAs do not issue post-quantum certificates yet. The key exchange, which is what recorded traffic depends on, is hybrid. |
| Slack and WhatsApp webhook verification, OAuth PKCE, AWS SigV4 | The platform on the other side defines the algorithm. |
| Cosign image signatures, Homebrew checksums | The mechanisms of those ecosystems. |
| The recovery key derivation (HKDF-SHA256 from the root secret) | Changing it would change every recovery key already saved off the machine. Every key that seals data is derived from it with HKDF-SHA512. |
| SHA-256 digests of the speech model archives ChatCLI downloads | They are the digests the publisher releases, so they stay comparable with the source. |

## Hardening checklist

For a deployment that must refuse anything classical between its own components:

* [ ] `CHATCLI_TLS_PQ=cnsa` on the server (`security.tlsPostQuantum: cnsa` in the chart, `spec.server.security.tlsPostQuantum: cnsa` on an Instance), with TLS enabled.
* [ ] The same on the operator, with TLS on its REST API.
* [ ] Whatever terminates TLS in front of them supports `SecP384r1MLKEM1024`.
* [ ] `chatcli healthcheck -show-tls` reports `SecP384r1MLKEM1024 (post-quantum hybrid)`.
* [ ] JWT verification configured with ML-DSA-87 public keys only, or a shared secret with issuers on HS512.
* [ ] Plugin publishers moved to hybrid keys (`chatcli plugin trust list` shows no key that is Ed25519 alone).
* [ ] `/config security verify-audit` reports every entry in SHA-512 for new trails.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.