codemod/pqc-audit
Inventory of public-key crypto (RSA, ECDSA, ECDH, ...) for post-quantum migration: an HTML report, findings and a CBOM. Never changes your existing files; adds its report under pqc-report/
# pqc-audit
Find where a repository uses public-key cryptography that a large quantum computer would break (RSA, ECDSA,
EdDSA, ECDH, finite-field Diffie-Hellman, DSA), and see how much of each use the code itself decides.
It is one [Codemod](https://codemod.com) workflow, [`workflow.ts`](workflow.ts), that runs on the
`codemod@2.0.0` engine. It never changes your existing files; it adds its report under `pqc-report/`. There is
no AI and no network step, and it names key and secret files without opening them. Two runs on the same commit
give the same report, byte for byte.
## Why now
In December 2026 the NSA told owners of national security systems to accelerate the move to post-quantum
cryptography. Its advisory, "Immediate Actions to Push Toward Post-Quantum," starts with an inventory: find
the systems and code that use the algorithms that need replacing. A joint ONCD/NSA/CISA statement said recent
advances "do not present an immediate and widespread threat," and asked industry to "expeditiously upgrade."
This workflow does the code part of that first step, the same way every time, so you can run it on every
commit and see what changes.
## Quick start
The workflow is published to the Codemod registry as
[`@codemod/pqc-audit`](https://app.codemod.com/registry/@codemod/pqc-audit). Run it from inside the repository
you want to scan:
```bash
cd your-repo
npx codemod@next @codemod/pqc-audit
```
Then open `pqc-report/report.html`. The terminal shows a one-line summary, for example
`6 need validation, 0 confirmed, 0 rejected · ECDH 4, RSA 2 · 6 text matches · open pqc-report/report.html`.
Requires Node.js 18 or later and a git repository. Run it again any time: it rewrites the files in
`pqc-report/` and never scans them. `pqc-report/` is safe to commit, so you can track how the inventory changes
from one commit to the next. If you keep it out of git instead, don't list it in `.gitignore`: in codemod 2.0 a
workflow can't rewrite files `.gitignore` hides, so the run stops and asks you to delete the folder.
Codemod checks for uncommitted changes before a workflow writes. If your working tree has any (this includes an
uncommitted `pqc-report/` from an earlier run, when the new report differs), a run in a terminal asks first, and
an unattended one stops without writing. Add `--allow-dirty` to go ahead: this workflow still only writes under
`pqc-report/`.
Keep the report private (if you commit it, keep that repository private): it is a map of where your cryptography is weakest.
From a clone you can also run the workflow file directly: `npx codemod@next workflow run -w workflow.ts -t /path/to/repo`.
Parameters (all optional, `--param key=value`):
| Param | What |
|---|---|
| `name` | repository name in the report (default: the target directory's name) |
| `unit` | coverage unit id (default `repo/<name>`) |
| `review` | path, inside the target, of a review file (default `.pqc-review.json` when present) |
| `reviewJson` | the review entries inline, as JSON |
| `exclude` | extra globs to leave out |
| `asOf` | a date for the CBOM timestamp (left out by default so two runs are byte-identical) |
| `output=full` | make the run's output (`--format jsonl`: `run_finished.output`) the whole result instead of the summary |
## Outputs
All in `pqc-report/`:
| File | What |
|---|---|
| `report.html` | one self-contained page (works offline): counts, and the findings in a table you can filter by text and verdict; click a row for how the call was resolved and what blocks a confirmed verdict |
| `findings.json` | every finding, rejected lookalike, text match and listing, with the chain of hops that resolved each call |
| `REPORT.md` | a readable summary: findings, why each is not confirmed, how each call was resolved, coverage |
| `cbom.json` | a CycloneDX cryptographic bill of materials |
| `factory/findings.json`, `factory/coverage-ledger.json` | the same findings in the Factory skill's schema |
The Factory output passes that project's own validators, pinned in `vendor/`:
```bash
node vendor/upstream-6f636d23/skills/migrate-post-quantum/validate-findings.cjs pqc-report/factory/findings.json
node vendor/upstream-6f636d23/skills/migrate-post-quantum/validate-coverage-ledger.cjs \
pqc-report/factory/coverage-ledger.json --findings pqc-report/factory/findings.json
```
So an agent running that skill can start from this inventory and do the judgment and follow-up.
## What it does, step by step
1. **List every file, and name the key and secret files without opening them.**
2. **Find every line that might use public-key crypto.** Line patterns from the upstream skill, file and line
only, no excerpts. Private-key blocks are recorded by location only.
3. **Find crypto libraries declared in dependency manifests.** The upstream library list plus the cloud KMS SDKs.
4. **Check which JavaScript and TypeScript calls really reach a crypto library.** Every call whose callee is
imported, required, a Web Crypto global, or named like a crypto operation is followed with
`definition()`: through aliases, `import * as`, default imports, `require` and its destructuring, dynamic
`import()`, `promisify`, re-exports through repository barrels, class fields, and objects a modeled call made
(`keyPair.publicKey.export()`). Algorithm values are followed the same way, into constants in other files.
`references()` gives one level of reach: where the enclosing function is used.
5. **Check which Python calls really reach a crypto library.** The same, for Python. In `codemod@2.0.0`, Python
`definition()` stays inside one file, so imports between repository modules are followed by reading those
modules (`from .keys import rsa`, `security.ALGORITHM`).
6. **Mark Rust, Go, Java and config lines that look like crypto (text match, not verified).** Crate and
package imports, documented API names, sign/verify calls in files that use a crypto package, nginx, sshd,
TLS, Terraform and YAML key settings, and `openssl`/`ssh-keygen`/`cosign`/`gpg`/... command lines. These
never become findings.
7. **Read the optional review file that rates confirmed findings.**
Then the workflow sorts everything, gives verdicts and writes `pqc-report/`: the HTML and markdown reports,
the findings, the CBOM and the Factory output.
## Verdicts
- `confirmed`: the code fixes both the algorithm and the key size, **and** the review file has an entry for the
file and line with a severity. A scan does not rate severity, exposure or blast radius.
- `needs_validation`: anything else that reaches a crypto library. `blockers` say what the code does not fix
(key from a parameter, algorithm from the environment, a library default, KMS metadata).
- `rejected`: a call named like crypto (`sign`, `verify`, `encrypt`, ...) that resolves to the repository's own
code, which uses no crypto library itself. A repository wrapper that does call a crypto library is listed,
not rejected: its library calls are reported where they happen.
- Evidence level is always `code`.
Review file (`.pqc-review.json` in the target, or `--param review=...`):
```json
{ "reviewer": "name", "entries": [ { "unit": "repo/x", "file": "src/a.ts", "line": 8,
"severity": { "level": "high", "rationale": "..." }, "exposure": { ... }, "blast_radius": { ... },
"control": "first_party", "migration": { ... } } ] }
```
Fields follow upstream's `findings-schema.json`. See [`tests/reviews/sample-target.json`](tests/reviews/sample-target.json) for an example.
## Coverage
| Language or file kind | What the audit does |
|---|---|
| TypeScript, TSX, JavaScript | semantic: `definition()` / `references()`, findings |
| Python | semantic: `definition()` within a file, repository modules read for cross-file names, findings |
| Rust, Go, Java | text match, not verified: candidates only |
| nginx, sshd, TLS, Terraform, YAML, shell, CI | text match, not verified: candidates only |
| Kotlin, C/C++, C#, Ruby, PHP, Swift, Scala, HTML and templates, ... | **not covered**: listed with file and line-candidate counts |
The library tables come from ecosystem usage: upstream's `crypto-patterns.json` libraries (npm, PyPI) plus the
cloud KMS SDKs (AWS, Google Cloud, Azure Key Vault) and the Node and Web Crypto built-ins. A call into a
library outside the tables is not a finding. A crypto-looking call into it, or one handed key material, is
listed as a lookalike, and a crypto-looking import is listed under unmodeled imports.
Two scope rules:
1. A KMS call is a `needs_validation` finding only when the code fixes the algorithm identifier it sends. A
value from the environment, configuration or key metadata is a marker, not a finding.
2. TLS that code only inherits (a default HTTPS client, database `ssl` options) is not reported. Code that pins
ciphers, curves, versions or certificates, or turns verification off, is.
## Limits
- **It finds part of what is there.** On hand-labeled repositories it found about 30–52% of known uses in
JavaScript and TypeScript, at 93–99% precision. Details in [`REPORT.md`](REPORT.md).
- **Rust, Go and Java get text matches only.** Nothing in those languages becomes a finding.
- **Libraries outside the tables are listed, not found.** Read the lookalike and unmodeled-import lists.
- **No dataflow.** A key that arrives as a function parameter cannot be classified. Reach is one level.
- **Almost, not fully, deterministic.** In `codemod@2.0.0`, about one `definition()` of an imported name in
30,000 resolves differently from one run to the next. In six runs on a 5,000-file repository the findings and
listings were identical every time, and one internal counter differed in two of them.
- **Code only.** Nothing is observed on a running system. This is an aid to a migration, not a certification.
## Repository layout
| Path | What |
|---|---|
| `workflow.ts` | the workflow (one file, imports only `codemod/*`) |
| `tests/run.mjs`, `tests/expect.json`, `tests/fixtures/` | fixture tests: each fixture twice (dry runs), identical output, untouched copy, validators, expectations |
| `eval/` | evaluation scripts: clone the public targets, run them, score against answer keys, leak scan |
| `results/` | the aggregate numbers `REPORT.md` quotes |
| `vendor/upstream-6f636d23/` | Factory-AI/migrate-post-quantum validators, schema and patterns at `6f636d23`, with its LICENSE and NOTICE |
| `vendor/SOURCES.blobs` | git blob ids of every copied file |
```bash
node tests/run.mjs # fixtures: PASS
./eval/clone-targets.sh # public targets at their pinned commits into .work/targets
./eval/run-targets.sh <stage> # each target twice; times, identical, untouched
node eval/score-all.mjs <stage> --heldout # needs answer keys in .work/keys (not published)
node eval/leak-scan.mjs <stage>
```
`env.sh` isolates every run: temporary HOME, XDG dirs, npm cache and TMPDIR under `.work/`, `DO_NOT_TRACK=1`,
`HUSKY=0`, `RUSTUP_AUTO_INSTALL=0`, `CARGO_NET_OFFLINE=true`, `--disable-analytics`. The test and eval scripts
use `codemod@2.0.0` installed into `.work/engine`:
```bash
source env.sh && npm install --prefix .work/engine codemod@2.0.0
```
## Credits
Built on [Factory-AI/migrate-post-quantum](https://github.com/Factory-AI/migrate-post-quantum), an agent skill
for post-quantum audits and migrations, at commit `6f636d23bbcb2585ba2bcef72fcd117725a4a403` (MIT License,
Copyright (c) 2026 The San Francisco AI Factory Inc.). From it come the line patterns and library lists
(inlined in `workflow.ts`), the findings schema, the validators in `vendor/`, and the sample target in
`tests/fixtures/sample-target/`. See `vendor/upstream-6f636d23/LICENSE` and `NOTICE.md`.
## License
MIT. See [`LICENSE`](LICENSE), which also carries the upstream notice.