# PQ Shift: proving a change

A change counts only with evidence. "I edited the config" is not evidence. This file lists the four kinds of proof and when each is enough.

`PROVEN` needs **P1 plus P2** for config and endpoints, or **P1 plus P3/P4** for code. Anything less stays `CHANGED, NOT PROVEN HERE` and says what is missing.

## P1: re-scan and diff

Repeat the before scan with the same paths, options and ignore rules: if `pq/before.json` was made without `--runtime`, leave it out here too. The check refuses to compare two different scans (`FAIL  incomplete or different after coverage`). Check read errors and coverage, and inspect the changed code or configuration. A changed evidence line can give a finding a new ID.

```sh
python pqshift.py scan . --runtime --json pq/after.json
python pqshift.py report pq/after.json --diff pq/before.json --expect-closed F-3a9c1e7b02,F-77d0c2a913
```

Exit `0` means every listed id is closed and no new high or critical finding appeared. Paste the summary line into the report:

```
diff  closed 10 | remaining 128 | new 0 | post-quantum added 3
```

- `closed`: findings from the before file that are gone.
- `new`: classic findings that were not there before. It should be 0.
- `post-quantum added`: hybrids and post-quantum algorithms that appeared. These are the change you made, so they are counted apart from `new`.

Exit `1` names the id that is still open, an id that was never in the before file (copy ids from the plan, do not retype them) or the new high or critical finding. Fix that; do not edit the list.

The scan leaves `pqshift.py` and the JSON, SARIF and CBOM files it wrote out of the inventory, so keeping `pq/before.json` in the project does not change the second scan.

## P2: a real handshake

The endpoint actually picks the hybrid when a client offers it.

**TLS.** Probe only hosts the user confirmed they own (hard rule 1). Local or staging first; production only after the human deploys.

```sh
python pqshift.py probe 127.0.0.1:8443 --confirm-handshake --json pq/probe-after.json
python pqshift.py probe api.example.com:443 --authorized --confirm-handshake --json pq/probe-after.json
```

Proof lines in the output:

- `pq.selected_for_pq_client: X25519MLKEM768` (code `0x11EC`, found with a HelloRetryRequest), and
- `handshake_confirmed.done: true`: a full handshake that offered only `X25519MLKEM768` completed (through `openssl s_client` from OpenSSL 3.5+, or Node with OpenSSL 3.5+).

HelloRetryRequest shows which group the server requested. Record `CHANGED, NOT PROVEN HERE` until a full hybrid handshake succeeds. The built-in confirmation measures key exchange and skips certificate identity verification. Test the application’s normal trust chain and hostname separately.

Optional cross-checks, if the tools exist on the machine:

```sh
openssl s_client -connect api.example.com:443 -servername api.example.com -verify_hostname api.example.com -verify_return_error -tls1_3 -groups X25519MLKEM768 -brief </dev/null
nscurl --tls-diagnostics https://api.example.com                                           # macOS Tahoe 26+; not run here
```

**Local proof (consent tier D).** When the real server cannot be run here, a throwaway one on `127.0.0.1` still proves that a group list does what you think. It needs Node with OpenSSL 3.5+ (`node -p process.versions.openssl`) or OpenSSL 3.5+ itself.

```sh
# Run in a shell with mktemp. Use a fresh private directory outside the repository.
pq_tmp=$(mktemp -d) || exit 1
umask 077
openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:P-256 -nodes -days 2 -subj "/CN=localhost" -keyout "$pq_tmp/test.key" -out "$pq_tmp/test.crt"
node tests/pq_server.mjs 18443 "X25519MLKEM768:X25519:P-256" "$pq_tmp/test.crt" "$pq_tmp/test.key" &     # from pqshift-fixture.zip
pq_pid=$!
python pqshift.py probe 127.0.0.1:18443 --confirm-handshake --json pq/probe-local.json
kill "$pq_pid"
wait "$pq_pid" 2>/dev/null
rm -f "$pq_tmp/test.key" "$pq_tmp/test.crt"
rmdir "$pq_tmp"
```

For an OpenSSL-only local test, use `openssl s_server -accept 127.0.0.1:18443 -cert "$pq_tmp/test.crt" -key "$pq_tmp/test.key" -groups X25519MLKEM768:X25519:P-256 -www` in place of the Node server before cleanup. A local handshake proves the local library and group list. Mark the deployed endpoint `CHANGED, NOT PROVEN HERE` until a client tests it.

Run 2026-12-03 on Windows 11 with Node 24.11.1 (OpenSSL 3.5.4): the probe reported `X25519MLKEM768` (`0x11EC`) selected through a HelloRetryRequest, a hybrid-only handshake confirmed, and `classic.accepted: true` with `x25519` for a classic-only client.

What the probe cannot see (it says so in every result): STARTTLS services, QUIC / HTTP/3, endpoints that require a client certificate, the hop behind a CDN or load balancer (only the edge answers), and other IP addresses behind the same name.

**SSH.**

```sh
python pqshift.py probe git.example.com:22 --authorized --json pq/probe-ssh-after.json
```

The probe reads the server’s advertised algorithms. For proof of negotiation, use a representative client with its normal host-key verification and check the selected algorithm in its verbose log. SSH selects the first algorithm in the client’s preference order that the server also supports. [SSH transport protocol, section 7.1](https://www.rfc-editor.org/rfc/rfc4253#section-7.1)

```sh
ssh -v user@git.example.com true 2>&1 | grep "kex: algorithm"
```

## P3: it still works

Nothing broke, and the fallback is still there where it is meant to be.

- The project's own test suite passes. Never skip or delete a failing test to get here.
- A hybrid client connects (P2 shows this).
- A classic-only client still connects where fallback is intended. The probe already checks this: `classic.accepted: true` in its JSON, or "classic-only client gets: x25519" on screen. A cross-check with another tool:

  ```sh
  curl --curves X25519 -sS -o /dev/null -w '%{http_code}\n' https://api.example.com/   # curl built with OpenSSL; not run here
  ```

  The curl that ships with Windows uses Schannel and rejects `--curves` (tried here 2026-12-03), so on Windows rely on the probe line.

  Tested here with Node 24.11.1 (OpenSSL 3.5.4) against a local server configured `ecdhCurve: 'X25519MLKEM768:X25519:P-256'`: a classic-only client (`ecdhCurve: 'X25519'`) connected, a hybrid-only client connected. Against a classic-only server a hybrid-only client failed with `handshake_failure`, which is exactly what the probe's `pq_only` step looks for.

## P4: data still decrypts

For code that encrypts to a public key or wraps keys:

1. **Round trip:** new data encrypted with the new scheme decrypts.
2. **Old data:** a fixture written in the old format before the change still decrypts after it (keep a small test file for this; never a real customer record).
3. **Format version:** the new output carries a version or algorithm id, and the reader rejects an unknown version instead of guessing.

## Config with no local runtime: tripwire tests

When you cannot run the server here (for example an nginx config for a fleet), add a test that fails if the old value returns, and leave the status at `CHANGED, NOT PROVEN HERE` until the human deploys and P2 passes:

```python
# tests/test_pq_tripwire.py
import re, pathlib
def test_nginx_offers_hybrid_first():
    conf = pathlib.Path("deploy/nginx/nginx.conf").read_text()
    m = re.search(r"^\s*ssl_ecdh_curve\s+([^;]+);", conf, re.M)
    assert m is None or m.group(1).split(":")[0] == "X25519MLKEM768", "TLS groups pinned without the hybrid first"
```

## What goes in the report per change

One line each:

`F-3a9c1e7b02  deploy/nginx/nginx.conf  ssl_ecdh_curve now X25519MLKEM768:X25519:prime256v1  P1 closed; P2 staging.example.com:443 X25519MLKEM768 (handshake confirmed); P3 tests pass, X25519 client ok  PROVEN`
