quantum-scan 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. quantum_scan-0.1.0/.claude/agents/engineer.md +31 -0
  2. quantum_scan-0.1.0/.claude/agents/researcher.md +38 -0
  3. quantum_scan-0.1.0/.claude/agents/reviewer.md +29 -0
  4. quantum_scan-0.1.0/.claude/agents/security-auditor.md +29 -0
  5. quantum_scan-0.1.0/.claude/agents/tech-writer.md +25 -0
  6. quantum_scan-0.1.0/.claude/agents/ux-tester.md +33 -0
  7. quantum_scan-0.1.0/.github/workflows/ci.yml +26 -0
  8. quantum_scan-0.1.0/.github/workflows/release.yml +32 -0
  9. quantum_scan-0.1.0/.gitignore +30 -0
  10. quantum_scan-0.1.0/ARCHITECTURE.md +91 -0
  11. quantum_scan-0.1.0/CLAUDE.md +108 -0
  12. quantum_scan-0.1.0/LICENSE +202 -0
  13. quantum_scan-0.1.0/PKG-INFO +128 -0
  14. quantum_scan-0.1.0/PROGRESS.md +32 -0
  15. quantum_scan-0.1.0/README.md +91 -0
  16. quantum_scan-0.1.0/ROADMAP.md +21 -0
  17. quantum_scan-0.1.0/TASKS.md +107 -0
  18. quantum_scan-0.1.0/benchmarks/cases/js_ec/lookalike.ts +4 -0
  19. quantum_scan-0.1.0/benchmarks/cases/js_ec/tp.ts +4 -0
  20. quantum_scan-0.1.0/benchmarks/cases/js_jose/lookalike.ts +5 -0
  21. quantum_scan-0.1.0/benchmarks/cases/js_jose/tp.ts +5 -0
  22. quantum_scan-0.1.0/benchmarks/cases/js_jsonwebtoken/lookalike.js +4 -0
  23. quantum_scan-0.1.0/benchmarks/cases/js_jsonwebtoken/tp.js +3 -0
  24. quantum_scan-0.1.0/benchmarks/cases/js_rsa_keygen/lookalike.js +4 -0
  25. quantum_scan-0.1.0/benchmarks/cases/js_rsa_keygen/tp.js +3 -0
  26. quantum_scan-0.1.0/benchmarks/cases/keys/lookalike.md +8 -0
  27. quantum_scan-0.1.0/benchmarks/cases/keys/tp.pem +6 -0
  28. quantum_scan-0.1.0/benchmarks/cases/py_ec_keygen/lookalike.py +3 -0
  29. quantum_scan-0.1.0/benchmarks/cases/py_ec_keygen/tp.py +3 -0
  30. quantum_scan-0.1.0/benchmarks/cases/py_paramiko/lookalike.py +4 -0
  31. quantum_scan-0.1.0/benchmarks/cases/py_paramiko/tp.py +3 -0
  32. quantum_scan-0.1.0/benchmarks/cases/py_pycryptodome/lookalike.py +11 -0
  33. quantum_scan-0.1.0/benchmarks/cases/py_pycryptodome/tp.py +3 -0
  34. quantum_scan-0.1.0/benchmarks/cases/py_pyjwt/lookalike.py +4 -0
  35. quantum_scan-0.1.0/benchmarks/cases/py_pyjwt/tp.py +3 -0
  36. quantum_scan-0.1.0/benchmarks/cases/py_rsa_keygen/lookalike.py +5 -0
  37. quantum_scan-0.1.0/benchmarks/cases/py_rsa_keygen/tp.py +3 -0
  38. quantum_scan-0.1.0/benchmarks/labels.yaml +23 -0
  39. quantum_scan-0.1.0/benchmarks/run.py +66 -0
  40. quantum_scan-0.1.0/docs/adr/0001-record-architecture-decisions.md +22 -0
  41. quantum_scan-0.1.0/docs/adr/0002-tree-sitter-parsing.md +33 -0
  42. quantum_scan-0.1.0/docs/adr/0003-yaml-rule-format.md +51 -0
  43. quantum_scan-0.1.0/docs/adr/0004-output-formats.md +42 -0
  44. quantum_scan-0.1.0/docs/adr/0005-readiness-score.md +44 -0
  45. quantum_scan-0.1.0/docs/adr/0006-license-apache-2.md +24 -0
  46. quantum_scan-0.1.0/docs/adr/0007-severity-policy.md +41 -0
  47. quantum_scan-0.1.0/docs/assets/terminal.svg +164 -0
  48. quantum_scan-0.1.0/docs/research/2026-12-pqc-library-brief.md +66 -0
  49. quantum_scan-0.1.0/examples/vulnerable-app/EXPECTED.md +39 -0
  50. quantum_scan-0.1.0/examples/vulnerable-app/README.md +19 -0
  51. quantum_scan-0.1.0/examples/vulnerable-app/package.json +7 -0
  52. quantum_scan-0.1.0/examples/vulnerable-app/payments_api/__init__.py +1 -0
  53. quantum_scan-0.1.0/examples/vulnerable-app/payments_api/auth.py +18 -0
  54. quantum_scan-0.1.0/examples/vulnerable-app/payments_api/crypto_utils.py +32 -0
  55. quantum_scan-0.1.0/examples/vulnerable-app/payments_api/keys.py +9 -0
  56. quantum_scan-0.1.0/examples/vulnerable-app/payments_api/legacy.py +8 -0
  57. quantum_scan-0.1.0/examples/vulnerable-app/payments_api/pq_ready.py +8 -0
  58. quantum_scan-0.1.0/examples/vulnerable-app/requirements.txt +2 -0
  59. quantum_scan-0.1.0/examples/vulnerable-app/web/pq.js +7 -0
  60. quantum_scan-0.1.0/examples/vulnerable-app/web/server.js +16 -0
  61. quantum_scan-0.1.0/examples/vulnerable-app/web/token.ts +8 -0
  62. quantum_scan-0.1.0/pyproject.toml +69 -0
  63. quantum_scan-0.1.0/scripts/make_screenshot.py +33 -0
  64. quantum_scan-0.1.0/src/quantum_scan/__init__.py +3 -0
  65. quantum_scan-0.1.0/src/quantum_scan/__main__.py +6 -0
  66. quantum_scan-0.1.0/src/quantum_scan/accepted.py +202 -0
  67. quantum_scan-0.1.0/src/quantum_scan/cli.py +313 -0
  68. quantum_scan-0.1.0/src/quantum_scan/engine/__init__.py +1 -0
  69. quantum_scan-0.1.0/src/quantum_scan/engine/callsite.py +64 -0
  70. quantum_scan-0.1.0/src/quantum_scan/engine/javascript.py +912 -0
  71. quantum_scan-0.1.0/src/quantum_scan/engine/matcher.py +393 -0
  72. quantum_scan-0.1.0/src/quantum_scan/engine/python.py +807 -0
  73. quantum_scan-0.1.0/src/quantum_scan/mcp_server.py +128 -0
  74. quantum_scan-0.1.0/src/quantum_scan/models.py +158 -0
  75. quantum_scan-0.1.0/src/quantum_scan/py.typed +0 -0
  76. quantum_scan-0.1.0/src/quantum_scan/redact.py +183 -0
  77. quantum_scan-0.1.0/src/quantum_scan/reporters/__init__.py +1 -0
  78. quantum_scan-0.1.0/src/quantum_scan/reporters/html.py +264 -0
  79. quantum_scan-0.1.0/src/quantum_scan/reporters/templates/report.html.j2 +177 -0
  80. quantum_scan-0.1.0/src/quantum_scan/reporters/terminal.py +291 -0
  81. quantum_scan-0.1.0/src/quantum_scan/rule.py +131 -0
  82. quantum_scan-0.1.0/src/quantum_scan/rule_loader.py +543 -0
  83. quantum_scan-0.1.0/src/quantum_scan/rules/README.md +6 -0
  84. quantum_scan-0.1.0/src/quantum_scan/rules/any/committed-private-key.yaml +35 -0
  85. quantum_scan-0.1.0/src/quantum_scan/rules/javascript/jose-asymmetric-sign.yaml +51 -0
  86. quantum_scan-0.1.0/src/quantum_scan/rules/javascript/jsonwebtoken-asymmetric-sign.yaml +49 -0
  87. quantum_scan-0.1.0/src/quantum_scan/rules/javascript/node-crypto-ec.yaml +52 -0
  88. quantum_scan-0.1.0/src/quantum_scan/rules/javascript/node-crypto-rsa-keygen.yaml +57 -0
  89. quantum_scan-0.1.0/src/quantum_scan/rules/python/cryptography-ec-keygen.yaml +52 -0
  90. quantum_scan-0.1.0/src/quantum_scan/rules/python/cryptography-rsa-keygen.yaml +57 -0
  91. quantum_scan-0.1.0/src/quantum_scan/rules/python/paramiko-keygen.yaml +42 -0
  92. quantum_scan-0.1.0/src/quantum_scan/rules/python/pycryptodome-rsa-keygen.yaml +46 -0
  93. quantum_scan-0.1.0/src/quantum_scan/rules/python/pyjwt-asymmetric-sign.yaml +57 -0
  94. quantum_scan-0.1.0/src/quantum_scan/scan.py +91 -0
  95. quantum_scan-0.1.0/src/quantum_scan/scanners/__init__.py +1 -0
  96. quantum_scan-0.1.0/src/quantum_scan/scanners/base.py +31 -0
  97. quantum_scan-0.1.0/src/quantum_scan/scanners/code.py +416 -0
  98. quantum_scan-0.1.0/src/quantum_scan/scanners/keyfile.py +93 -0
  99. quantum_scan-0.1.0/src/quantum_scan/scope.py +4 -0
  100. quantum_scan-0.1.0/src/quantum_scan/scoring.py +158 -0
  101. quantum_scan-0.1.0/src/quantum_scan/walker.py +326 -0
  102. quantum_scan-0.1.0/tests/engine/test_javascript_resolver.py +672 -0
  103. quantum_scan-0.1.0/tests/engine/test_matcher.py +239 -0
  104. quantum_scan-0.1.0/tests/engine/test_python_resolver.py +543 -0
  105. quantum_scan-0.1.0/tests/fixtures/rules/valid.yaml +25 -0
  106. quantum_scan-0.1.0/tests/fixtures/rules_scan/js-jwt.yaml +19 -0
  107. quantum_scan-0.1.0/tests/fixtures/rules_scan/py-builder.yaml +17 -0
  108. quantum_scan-0.1.0/tests/fixtures/rules_scan/py-jwt.yaml +19 -0
  109. quantum_scan-0.1.0/tests/fixtures/rules_scan/py-query.yaml +18 -0
  110. quantum_scan-0.1.0/tests/fixtures/rules_scan/py-rsa.yaml +26 -0
  111. quantum_scan-0.1.0/tests/reporters/reporter_helpers.py +42 -0
  112. quantum_scan-0.1.0/tests/reporters/test_html.py +203 -0
  113. quantum_scan-0.1.0/tests/reporters/test_scoring.py +79 -0
  114. quantum_scan-0.1.0/tests/snapshots/clean.txt +10 -0
  115. quantum_scan-0.1.0/tests/snapshots/findings.txt +20 -0
  116. quantum_scan-0.1.0/tests/snapshots/single.txt +16 -0
  117. quantum_scan-0.1.0/tests/test_accepted.py +229 -0
  118. quantum_scan-0.1.0/tests/test_cli.py +203 -0
  119. quantum_scan-0.1.0/tests/test_code_scanner.py +491 -0
  120. quantum_scan-0.1.0/tests/test_keyfile.py +65 -0
  121. quantum_scan-0.1.0/tests/test_mcp.py +60 -0
  122. quantum_scan-0.1.0/tests/test_packaged_rules.py +46 -0
  123. quantum_scan-0.1.0/tests/test_redact.py +184 -0
  124. quantum_scan-0.1.0/tests/test_rule_loader.py +359 -0
  125. quantum_scan-0.1.0/tests/test_scan.py +146 -0
  126. quantum_scan-0.1.0/tests/test_terminal_snapshots.py +110 -0
  127. quantum_scan-0.1.0/tests/test_walker.py +408 -0
@@ -0,0 +1,31 @@
1
+ ---
2
+ name: engineer
3
+ description: Senior software engineer. Use to implement one assigned task (engine code, rules, reporters, CLI, tests, benchmark cases) with tests. Runs ruff, mypy and pytest before reporting.
4
+ tools: Read, Write, Edit, Bash, Grep, Glob
5
+ model: sonnet
6
+ ---
7
+ You are a senior software engineer on quantum-scan. Read CLAUDE.md, ARCHITECTURE.md and
8
+ the relevant ADRs in docs/adr/ before you start.
9
+
10
+ Implement ONLY the task you were assigned, to its acceptance criteria in TASKS.md.
11
+
12
+ Standards:
13
+ - Python 3.11+, type hints everywhere, mypy strict on src/quantum_scan, small functions,
14
+ clear names. typer + rich for CLI. No network calls anywhere in the tool.
15
+ - Every rule ships with ≥1 true positive, ≥1 look-alike false positive and ≥1 edge case
16
+ as annotated benchmark files (see ADR 0003).
17
+ - Never print, log or store secret/key contents: only locations and fingerprints.
18
+ - Load YAML with `yaml.safe_load` only. Escape everything rendered into HTML.
19
+ - Only free, OSS dependencies that ship prebuilt wheels. Never add paid or non-OSS deps.
20
+ - Never push, never commit secrets. Do not commit unless the manager asks you to.
21
+
22
+ Before reporting, run and make green:
23
+ ```bash
24
+ .venv/bin/ruff check . && .venv/bin/ruff format --check .
25
+ .venv/bin/mypy
26
+ .venv/bin/pytest -q
27
+ .venv/bin/python benchmarks/run.py # once it exists
28
+ ```
29
+
30
+ Report back: files changed, commands run with results (pass/fail counts, P/R numbers),
31
+ anything unfinished or any decision you had to make.
@@ -0,0 +1,38 @@
1
+ ---
2
+ name: researcher
3
+ description: Senior applied-cryptography and post-quantum researcher. Use before writing or changing a detection rule, a severity, or a fix recommendation. Returns exact APIs to detect, false-positive traps, recommended PQC replacement and primary-source references. Never writes production code.
4
+ tools: Read, Grep, Glob, WebSearch, WebFetch
5
+ model: sonnet
6
+ ---
7
+ You are a senior applied-cryptography and post-quantum cryptography (PQC) researcher on
8
+ the quantum-scan project (read CLAUDE.md first).
9
+
10
+ Your job: produce a research brief that an engineer can turn directly into YAML rules and
11
+ plain-English finding text.
12
+
13
+ Sources, in order of authority: NIST FIPS 203 (ML-KEM), FIPS 204 (ML-DSA), FIPS 205
14
+ (SLH-DSA), NIST IR 8547, NSA CNSA 2.0, PCI DSS 4.0 (req. 12.3.3), IETF RFCs/drafts, then
15
+ official library docs and source code (cryptography, pycryptodome, PyJWT, python-jose,
16
+ paramiko, node:crypto, jsonwebtoken, jose, node-forge). Cite a URL for every claim.
17
+
18
+ For each library or API in scope, return:
19
+ 1. **APIs to detect**: fully-qualified names, import paths and aliases, the argument that
20
+ selects the algorithm (e.g. `algorithm="RS256"`, `type: 'rsa'`), the minimum and
21
+ maximum library versions where it applies.
22
+ 2. **Classification**: algorithm (RSA/ECDSA/ECDH/EdDSA/X25519/DH/DSA), primitive
23
+ (keygen/sign/verify/encrypt/decrypt/key-exchange/key-load), and whether the quantum
24
+ threat is harvest-now-decrypt-later (confidentiality) or future forgery (authentication).
25
+ 3. **False-positive traps**: look-alike names, symmetric/hash APIs with similar names,
26
+ test helpers, strings and comments, dead code patterns.
27
+ 4. **Edge cases**: aliases, re-exports, star imports, dynamic imports/require, wrappers.
28
+ 5. **Recommended replacement**: the PQC algorithm and parameter set (ML-KEM-768,
29
+ ML-DSA-65, hybrid X25519MLKEM768, ...), and whether a production-ready library exists
30
+ today for that language, with version. If none exists, say so honestly and recommend
31
+ the interim step (crypto-agility, inventory, hybrid TLS at the edge).
32
+ 6. **References** and **compliance tags** (NIST IR 8547 section, CNSA 2.0 timeline,
33
+ PCI DSS 4.0 12.3.3).
34
+
35
+ Rules:
36
+ - Mark anything you could not confirm from a primary source as **UNVERIFIED**.
37
+ - Never write production code or edit files. Small illustrative snippets in the brief are fine.
38
+ - Be concise: tables over prose.
@@ -0,0 +1,29 @@
1
+ ---
2
+ name: reviewer
3
+ description: Principal-level code reviewer and QA. Use after every engineer task. Runs lint, types, tests and benchmarks, actively tries to break rules, and returns PASS/FAIL with numbered issues. Never edits code.
4
+ tools: Read, Grep, Glob, Bash
5
+ model: sonnet
6
+ ---
7
+ You are a principal engineer reviewing work on quantum-scan. Read CLAUDE.md, the task's
8
+ acceptance criteria in TASKS.md, and the relevant ADRs.
9
+
10
+ Do:
11
+ 1. Run ruff, mypy, pytest and `benchmarks/run.py`. Report exact results.
12
+ 2. Check every acceptance criterion of the task, one by one.
13
+ 3. When asked for **blind adversarial cases** (T2.8): read ONLY the rule's id, title and
14
+ description in the task (or `quantum-scan explain`), NOT the rule YAML or engine code.
15
+ Write cases to `benchmarks/cases/adversarial/` — this is the one place you may write.
16
+ 4. Try to break each changed rule: write throwaway cases in the scratch/tmp dir (never in
17
+ the repo) covering aliases, `import x as y`, `from x import *`, re-exports, wrappers,
18
+ comments, strings, docstrings, dynamic import/require, minified JS, TS type-only
19
+ imports, and look-alike symmetric APIs. Report any false positive or false negative.
20
+ 5. Check code quality: correctness, error handling (every error says what to do next),
21
+ type safety, small functions, naming, test quality, no dead code.
22
+ 6. Check finding text: plain English first, technical second, copy-paste fix present.
23
+
24
+ Return:
25
+ - **PASS** or **FAIL**
26
+ - Numbered issues: `file:line` — severity (BLOCKER/MAJOR/MINOR) — problem — suggested fix.
27
+ - FAIL if any BLOCKER or MAJOR, or any check is red.
28
+
29
+ Never edit files in the repo (except blind adversarial cases, step 3).
@@ -0,0 +1,29 @@
1
+ ---
2
+ name: security-auditor
3
+ description: Application security engineer who audits the quantum-scan TOOL itself. Use for any change touching the engine, file IO, rule loading, or report output. Returns PASS/FAIL with issues. Never edits code.
4
+ tools: Read, Grep, Glob, Bash
5
+ model: sonnet
6
+ ---
7
+ You audit quantum-scan itself — a security tool that will run on untrusted repositories.
8
+ Read CLAUDE.md and ARCHITECTURE.md first.
9
+
10
+ Check, with evidence (file:line, and a reproducing command or test where possible):
11
+ 1. **No network**: no imports of socket/http/urllib/requests in the scan path; the
12
+ no-network test actually blocks sockets and DNS; no update checks or telemetry.
13
+ 2. **No secret leakage**: private key bodies, tokens and passwords never appear in
14
+ terminal output, report.html/md, CBOM, SARIF, logs, exceptions or tracebacks. Only
15
+ paths, line numbers and non-reversible fingerprints.
16
+ 3. **Safe file handling**: symlinks not followed out of the scan root; path traversal;
17
+ huge files (size cap), binary files, unreadable files, invalid UTF-8, deeply nested
18
+ ASTs (recursion limits), pathological regexes (ReDoS), many files (fd limits).
19
+ 4. **Safe YAML**: `safe_load` only; rule files validated; user rule dirs can't execute code.
20
+ 5. **Report escaping**: HTML report escapes all scanned content (paths, snippets,
21
+ messages); no XSS from a crafted filename or code line; CSP meta tag; no external
22
+ resources. Markdown output can't inject HTML. SARIF/CBOM are valid JSON.
23
+ 6. **Dependency hygiene**: minimal deps, all OSS, wheels available, pinned lower bounds,
24
+ no install-time scripts.
25
+ 7. **`init` command**: never overwrites files without confirmation; writes only inside the repo.
26
+
27
+ Return **PASS** or **FAIL** + numbered issues with severity (HIGH/MEDIUM/LOW), `file:line`,
28
+ impact and fix. FAIL if any HIGH. Never edit files in the repo; put any proof-of-concept
29
+ files in a temp directory.
@@ -0,0 +1,25 @@
1
+ ---
2
+ name: tech-writer
3
+ description: Developer-docs writer. Use for README (≤ 3-command quickstart at the top), ARCHITECTURE.md, CONTRIBUTING.md, SECURITY.md, CHANGELOG.md, rule docs, and all plain-English finding messages (message/why/fix in rule YAML).
4
+ tools: Read, Write, Edit, Grep, Glob
5
+ model: sonnet
6
+ ---
7
+ You write the docs and user-facing text for quantum-scan. Read CLAUDE.md first.
8
+
9
+ Style:
10
+ - Short sentences. Everyday words. Define a technical term the first time, in a few words.
11
+ - Tables over prose. Copy-pasteable commands that actually work (check the CLI help).
12
+ - Plain English first, technical detail second.
13
+ Bad: "RSA-2048 keygen detected."
14
+ Good: "This creates an RSA key that future quantum computers can break. Data it
15
+ protects could be recorded now and decrypted later. Fix: ..."
16
+
17
+ Deliverables you own:
18
+ - README.md: what it is in one line, a ≤ 3-command quickstart as the FIRST block, a
19
+ sample of the terminal output, what it finds, outputs, CI usage, FAQ (privacy, accuracy).
20
+ - ARCHITECTURE.md, CONTRIBUTING.md ("add a rule in 5 minutes"), SECURITY.md, CHANGELOG.md.
21
+ - Finding text in rule YAML (`message`, `why`, `fix`): every rule must have all three;
22
+ `fix` must contain a concrete copy-paste snippet or command.
23
+
24
+ Never invent facts about cryptography or standards: use the researcher's briefs and keep
25
+ their references. Never include secrets or real customer data in examples.
@@ -0,0 +1,33 @@
1
+ ---
2
+ name: ux-tester
3
+ description: Usability tester. Use at the end of every milestone. Follows only the README from a fresh shell as three personas, runs the tool on examples/, reads terminal output and report.html, times each step, and returns PASS/FAIL against the ease-of-use metrics. Never edits code.
4
+ tools: Read, Bash, Grep, Glob
5
+ model: sonnet
6
+ ---
7
+ You are a usability tester for quantum-scan. You know NOTHING except what README.md says.
8
+ Do not read source code, ADRs or CLAUDE.md to figure out how to use the tool.
9
+
10
+ Test as three personas, one after another:
11
+ 1. **Junior developer** who has never heard of post-quantum cryptography.
12
+ 2. **Busy startup CTO** with 2 minutes. Wants: how bad is it, what do I fix first.
13
+ 3. **Non-technical compliance manager** who must answer a bank questionnaire. Reads only
14
+ the executive summary in report.html.
15
+
16
+ Procedure:
17
+ - Start from a fresh shell in a temp directory. Follow ONLY the first block of the README.
18
+ Time each step with `date +%s` (or `time`). Note every extra step, wait, or decision.
19
+ - Run the tool on `examples/vulnerable-app/`. Read the terminal output top to bottom.
20
+ - Open report.html as text and read it as each persona would. Also try `--help`,
21
+ `explain <rule-id>`, a wrong path, and a bad flag — judge each error message.
22
+
23
+ Metrics (PASS only if all hold):
24
+ - Nothing → readable report in ≤ 60 s using only the README's first block; ≤ 3 commands.
25
+ - Terminal summary shows score, high-risk count, top 3 fixes and the next command first.
26
+ - Every finding has a plain-English explanation and a copy-paste fix.
27
+ - Persona 3 can explain the executive summary back in their own words (write that
28
+ explanation in your report). Any undefined jargon = FAIL.
29
+ - Every error says what went wrong and what to do next.
30
+
31
+ Return **PASS/FAIL** per persona and overall, the timings, and a numbered list of every
32
+ confusion, jargon word, unclear error or extra step — each with a suggested rewrite.
33
+ Never edit files in the repo.
@@ -0,0 +1,26 @@
1
+ name: CI
2
+ on:
3
+ push:
4
+ branches: [main]
5
+ pull_request:
6
+ permissions:
7
+ contents: read
8
+ jobs:
9
+ test:
10
+ runs-on: ${{ matrix.os }}
11
+ strategy:
12
+ fail-fast: false
13
+ matrix:
14
+ os: [ubuntu-latest, macos-latest, windows-latest]
15
+ python: ["3.11", "3.12", "3.13"]
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+ - uses: actions/setup-python@v5
19
+ with:
20
+ python-version: ${{ matrix.python }}
21
+ - run: python -m pip install -e ".[dev]"
22
+ - run: ruff check .
23
+ - run: ruff format --check .
24
+ - run: mypy
25
+ - run: pytest -q
26
+ - run: python benchmarks/run.py
@@ -0,0 +1,32 @@
1
+ name: Release
2
+ on:
3
+ push:
4
+ tags: ["v*"]
5
+ permissions:
6
+ contents: read
7
+ jobs:
8
+ build:
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: actions/checkout@v4
12
+ - uses: actions/setup-python@v5
13
+ with:
14
+ python-version: "3.12"
15
+ - run: python -m pip install build
16
+ - run: python -m build
17
+ - uses: actions/upload-artifact@v4
18
+ with:
19
+ name: dist
20
+ path: dist/
21
+ publish:
22
+ needs: build
23
+ runs-on: ubuntu-latest
24
+ environment: pypi
25
+ permissions:
26
+ id-token: write # PyPI Trusted Publishing: no API token stored anywhere
27
+ steps:
28
+ - uses: actions/download-artifact@v4
29
+ with:
30
+ name: dist
31
+ path: dist/
32
+ - uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,30 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.egg-info/
5
+ .eggs/
6
+ build/
7
+ dist/
8
+ .venv/
9
+ venv/
10
+ .pytest_cache/
11
+ .mypy_cache/
12
+ .ruff_cache/
13
+ .coverage
14
+ htmlcov/
15
+
16
+ # quantum-scan output when run on this repo
17
+ quantum-scan-report/
18
+
19
+ # OS / editors
20
+ .DS_Store
21
+ .idea/
22
+ .vscode/
23
+
24
+ # Never commit secrets
25
+ .env
26
+ *.env
27
+ .claude/settings.local.json
28
+
29
+ # Personal agent notes
30
+ CLAUDE.local.md
@@ -0,0 +1,91 @@
1
+ # Architecture
2
+
3
+ Status: v0.1 design, approved 2026-12-03; M1 in progress. Decisions behind it are in `docs/adr/`.
4
+
5
+ ## One-screen view
6
+
7
+ ```
8
+ quantum-scan scan [path]
9
+ │
10
+ ▼
11
+ cli.py (typer) ── smart defaults, no config needed ──┐
12
+ │ │
13
+ ▼ │
14
+ walker.py list files: skip .git, node_modules,│ .venv, dist, build, vendor,
15
+ binaries, files > 2 MB; never follow symlinks out of the root
16
+ │
17
+ ▼
18
+ scanners/ one interface: Scanner.scan(files) -> list[Finding]
19
+ ├─ code.py Python + JS/TS via the rule engine below
20
+ └─ keyfile.py committed private keys (any file) -> location + fingerprint only
21
+ │
22
+ ▼
23
+ engine/ (code scanner internals, mypy strict)
24
+ ├─ prefilter cheap byte search for each rule's trigger words; most files stop here
25
+ ├─ parse tree-sitter parse (prebuilt grammar wheels), ProcessPool across files
26
+ ├─ resolve imports/aliases/requires -> canonical names
27
+ │ `from cryptography.hazmat.primitives.asymmetric import rsa as r`
28
+ │ `r.generate_private_key(...)` -> `cryptography...rsa.generate_private_key`
29
+ └─ match rule `match` (canonical call + argument constraints) -> Finding
30
+ │
31
+ ▼
32
+ scoring.py readiness score 0–100, unique (rule, file) pairs (ADR 0005), counts, prioritised migration plan
33
+ │
34
+ ▼
35
+ reporters/ terminal (rich) · report.html · report.md · cbom.json · results.sarif
36
+ ```
37
+
38
+ ## Key types (`models.py`)
39
+
40
+ | Type | Fields (abridged) |
41
+ |---|---|
42
+ | `Rule` | id, title, languages, severity, confidence, crypto{algorithm, primitive, usage}, match, message, why, fix, references, compliance |
43
+ | `Finding` | rule_id, severity, confidence, location{path, line, col, end_line, end_col}, snippet (redacted for key material), message, why, fix, references, compliance, crypto{algorithm, primitive, usage, key_size?, curve?}, library, language, fingerprint, risk_context |
44
+ | `risk_context` | quantum_exposure (`harvest-now-decrypt-later` \| `future-forgery`), path_kind (`source` \| `test` \| `example`), data_shelf_life (null in v0.1), migration_effort (null in v0.1). Stored so Mosca scoring (v0.3) needs no re-scan. |
45
+ | `ScanResult` | findings, score, counts, files_scanned, files_skipped, duration, tool/rule versions |
46
+
47
+ `Finding.fingerprint` = stable hash of rule id + path + normalised matched text. It lets
48
+ SARIF/CI de-duplicate across runs. For key files it is `sha256` of the decoded key body
49
+ (not reversible; the body itself is never stored).
50
+
51
+ ## Rules are data
52
+
53
+ Rules live in `src/quantum_scan/rules/<language>/*.yaml` and are packaged with the
54
+ wheel. Format: ADR 0003. Authors describe **what** to match by canonical name; the
55
+ engine handles **how** (aliases, imports, tree-sitter). A raw tree-sitter `query:` escape
56
+ hatch exists for patterns the canonical matcher can't express.
57
+
58
+ ## Accuracy
59
+
60
+ - `benchmarks/cases/` holds annotated source files: `# qs-expect: <rule-id>` above a line
61
+ that must be found, `# qs-ok: <rule-id>` above a look-alike that must not be.
62
+ - `benchmarks/run.py` prints precision/recall per rule and overall; CI fails below
63
+ P ≥ 0.90, R ≥ 0.85. The same files drive per-rule pytest cases.
64
+ - A meta-test requires each rule to have ≥1 TP, ≥1 look-alike and ≥1 edge case.
65
+
66
+ ## Speed
67
+
68
+ Prefilter (bytes `in` check, no parsing) → only candidate files are parsed → parse +
69
+ match runs in a `ProcessPoolExecutor` (chunked). Measured: ~0.6 ms to parse a 100-line
70
+ Python file. A perf test generates a 10k-file fixture; target < 10 s.
71
+
72
+ ## Trust and safety
73
+
74
+ - No network code in the package. A test blocks `socket` and DNS and runs a full scan.
75
+ - Key material: the key-file scanner reads, fingerprints and drops the body; snippets for
76
+ those findings are replaced by `-----BEGIN … PRIVATE KEY----- [redacted]`.
77
+ - YAML via `safe_load` only. HTML via Jinja2 with autoescape + strict CSP, no external
78
+ resources. Symlinks are not followed; per-file size cap; parse errors are skipped and
79
+ counted, never fatal.
80
+ - Accepted risk: inline `quantum-scan: ignore[<rule-id>]`, `.quantum-scan-ignore`
81
+ (gitignore syntax), or `--baseline <file>` (made with `--write-baseline`, matched on
82
+ fingerprint). Such findings stay in every report under "Accepted risk" but don't count
83
+ toward the score or `--fail-on`. All optional.
84
+ - Exit code 0 by default; `--fail-on` is opt-in (ADR 0004). The output dir gets a
85
+ `.gitignore` containing `*`.
86
+
87
+ ## Extending
88
+
89
+ - New library → new YAML rule + annotated benchmark cases. No code.
90
+ - New language → add the grammar wheel + a `resolve` adapter (imports → canonical names).
91
+ - New scanner (dependencies, TLS, certificates, cloud KMS…) → implement `Scanner`.
@@ -0,0 +1,108 @@
1
+ # quantum-scan — project instructions
2
+
3
+ Free, open-source CLI + CI tool that finds quantum-vulnerable cryptography (RSA, ECC, DH)
4
+ in code and infrastructure, ranks risk, suggests post-quantum fixes (ML-KEM / ML-DSA,
5
+ hybrid where appropriate), and produces an audit-ready report.
6
+
7
+ ## How this session works (LEAN MODE, since 2026-12-05)
8
+ - Work inline. No subagents per task. ONE reviewer subagent pass at the end of a release
9
+ only (`.claude/agents/reviewer.md`; the other role files stay for later use).
10
+ - Updates to the user: ≤ 5 lines. No long reports, no re-pasting code. Read only the files
11
+ you need; don't re-read files you just wrote.
12
+ - Hardening is proportional: block only on crashes, hangs, secret leaks. Log the rest in
13
+ TASKS.md follow-ups.
14
+ - Commit after each item. **Never push
15
+ without asking.** Ask before creating the GitHub repo, pushing, or publishing to PyPI.
16
+ - Never mark an item done without green checks (ruff, mypy, pytest, benchmark once it exists).
17
+ - Keep `TASKS.md` live. Log measured metrics in `PROGRESS.md`.
18
+
19
+ ## Mission & users (CEO)
20
+ Mission: make post-quantum readiness free, fast, trustworthy and effortless for every team.
21
+ Why now: NIST IR 8547 deprecates RSA/ECC by 2030 and disallows them by 2035; regulators
22
+ and bank vendor questionnaires ask "what's your post-quantum plan?".
23
+ Users (v0.1): (1) developer at a 10–200 person fintech selling to banks, (2) busy startup
24
+ CTO with 2 minutes, (3) non-technical compliance manager answering a bank questionnaire.
25
+ Job to be done: "an accurate crypto inventory and a credible migration plan in one command,
26
+ without configuring anything or sending my code anywhere."
27
+ Positioning: the free, developer-first standard for PQC readiness (Trivy for vulns,
28
+ Semgrep for patterns). Win on ease, speed, accuracy, openness. Open core later; $0 now.
29
+
30
+ ### v0.1 success metrics (measure and report in PROGRESS.md)
31
+ | Metric | Target |
32
+ |---|---|
33
+ | Benchmark precision / recall | ≥ 0.90 / ≥ 0.85 |
34
+ | Speed | 10k-file repo < 10 s on a laptop |
35
+ | Trust | zero network calls during a scan (test-enforced) |
36
+ | Ease | nothing → readable report in ≤ 60 s from README's first block; quickstart ≤ 3 commands |
37
+ | Clarity | 100% of findings have plain-English explanation + copy-paste fix |
38
+ | Comprehension | ux-tester non-technical persona understands the executive summary |
39
+
40
+ ## Technical principles (CTO)
41
+ - Trust first: 100% local, no telemetry/uploads/network. Never print or store secret/key
42
+ contents — only locations and fingerprints.
43
+ - Accuracy over breadth. Every rule benchmarked. False positives are bugs.
44
+ - Rules are data: YAML rule files (see docs/adr/0003). Adding a library = adding a rule.
45
+ - tree-sitter parsing via prebuilt wheels (docs/adr/0002); no compilers to install.
46
+ - Open output standards: HTML, Markdown, CycloneDX CBOM, SARIF (docs/adr/0004).
47
+ - Pluggable scanners behind one `Scanner` interface (code + key files in v0.1).
48
+ - Store per-finding context for Mosca's theorem later (usage, exposure, key size).
49
+ - Tag rules with NIST IR 8547 / CNSA 2.0 / PCI DSS 4.0 references.
50
+ - Every significant decision → ADR in `docs/adr/` (context, options, decision,
51
+ consequences; < 1 page).
52
+
53
+ ## Radical ease of use (non-negotiable)
54
+ - `uvx quantum-scan`, `pipx run quantum-scan`, `pip install quantum-scan` all work; no
55
+ system deps. No args = scan current folder. No config file required, ever.
56
+ - Terminal: short coloured summary first (score, high-risk count, top 3 fixes, next
57
+ command). report.html: one self-contained offline file with score, findings by risk,
58
+ why-it-matters, copy-paste fix, filters, executive summary. Print its path at the end.
59
+ - Plain English first, technical detail second.
60
+ - Commands: `scan` (default), `init` (GitHub Action + optional pre-commit, confirm
61
+ prompt), `explain <rule-id>`, `fix --dry-run` (stub in v0.1). `--help` fits one screen.
62
+ - Every error says what went wrong AND what to do next. Auto-ignore vendor/build dirs;
63
+ progress for big repos; clean Ctrl+C; macOS/Linux/Windows; offline.
64
+
65
+ ## Engineering standards (Principal Engineer)
66
+ - Python 3.11+, typer, rich, pyproject (hatchling), pytest, ruff (lint+format), mypy
67
+ strict on `src/quantum_scan`. Small functions, type hints, clear names.
68
+ - Benchmark honesty: the reviewer writes adversarial cases WITHOUT reading the rule
69
+ implementation; M5 adds real-world precision on 5 OSS repos (50 hand-labelled findings),
70
+ reported separately from the benchmark.
71
+ - Every rule: ≥1 true positive, ≥1 look-alike false positive, ≥1 edge case (aliases,
72
+ re-exports, comments, strings, dynamic imports) — enforced by a meta-test.
73
+ - `benchmarks/` labelled cases + script printing per-rule and overall P/R; CI fails below
74
+ targets. Perf test on a generated 10k-file fixture.
75
+ - Skip node_modules/.venv/.git/dist/build and binaries; parallel parsing.
76
+ - CLI: `scan [path] [--format html,md,cbom,sarif|all] [--fail-on SEV] [--out dir]
77
+ [--baseline FILE] [--write-baseline FILE]`.
78
+ Exit codes: **0 by default, even with findings** (a local scan reports, it doesn't fail);
79
+ 1 only when `--fail-on` is given and an active finding is at/above it; 2 tool error;
80
+ 130 Ctrl+C. The Action written by `init` passes `--fail-on high`.
81
+ - Suppressed (inline / `.quantum-scan-ignore`) and baselined findings are "accepted risk":
82
+ shown in reports, excluded from score and `--fail-on`. The output dir gets a
83
+ `.gitignore` containing `*`.
84
+ - Severity policy, hybrid-PQC exclusion and JWT advice: docs/adr/0007. Score counts each
85
+ unique (rule, file) pair once: docs/adr/0005.
86
+ - SemVer, CHANGELOG.md, Apache-2.0, SECURITY.md, CONTRIBUTING.md ("add a rule in 5 min").
87
+ - Free CI: `.github/workflows/ci.yml` (lint, types, tests, benchmark). Create it; don't push.
88
+
89
+ Dev commands:
90
+ ```bash
91
+ python3 -m venv .venv && .venv/bin/pip install -e '.[dev]'
92
+ .venv/bin/ruff check . && .venv/bin/ruff format --check .
93
+ .venv/bin/mypy
94
+ .venv/bin/pytest -q
95
+ .venv/bin/python benchmarks/run.py
96
+ ```
97
+
98
+ ## Roadmap
99
+ See ROADMAP.md. Build only v0.1 now.
100
+
101
+ ## ASK THE USER (stop and wait) before
102
+ - Anything that costs money or needs a paid plan
103
+ - Creating any account; pushing to GitHub; publishing to PyPI/npm/marketplaces
104
+ - Changing v0.1 scope, dropping a feature, or missing a success metric
105
+ - A cryptography judgment you're unsure of that changes product behaviour
106
+ - Renaming the project
107
+ Everything else (structure, free OSS libs, internal naming, tests, ADRs): decide like a
108
+ principal engineer and tell the user what you chose.