toolfence-crypto 0.3.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 (37) hide show
  1. toolfence_crypto-0.3.0/.gitignore +12 -0
  2. toolfence_crypto-0.3.0/LICENSE +21 -0
  3. toolfence_crypto-0.3.0/PKG-INFO +89 -0
  4. toolfence_crypto-0.3.0/README.md +68 -0
  5. toolfence_crypto-0.3.0/pyproject.toml +53 -0
  6. toolfence_crypto-0.3.0/src/toolfence_crypto/__init__.py +3 -0
  7. toolfence_crypto-0.3.0/src/toolfence_crypto/__main__.py +3 -0
  8. toolfence_crypto-0.3.0/src/toolfence_crypto/cli.py +158 -0
  9. toolfence_crypto-0.3.0/src/toolfence_crypto/config.py +77 -0
  10. toolfence_crypto-0.3.0/src/toolfence_crypto/deps.py +214 -0
  11. toolfence_crypto-0.3.0/src/toolfence_crypto/export.py +288 -0
  12. toolfence_crypto-0.3.0/src/toolfence_crypto/github_fetch.py +91 -0
  13. toolfence_crypto-0.3.0/src/toolfence_crypto/go_scan.py +141 -0
  14. toolfence_crypto-0.3.0/src/toolfence_crypto/html_report.py +316 -0
  15. toolfence_crypto-0.3.0/src/toolfence_crypto/js_scan.py +197 -0
  16. toolfence_crypto-0.3.0/src/toolfence_crypto/models.py +133 -0
  17. toolfence_crypto-0.3.0/src/toolfence_crypto/pem.py +143 -0
  18. toolfence_crypto-0.3.0/src/toolfence_crypto/policy.py +132 -0
  19. toolfence_crypto-0.3.0/src/toolfence_crypto/prioritize.py +73 -0
  20. toolfence_crypto-0.3.0/src/toolfence_crypto/python_ast.py +163 -0
  21. toolfence_crypto-0.3.0/src/toolfence_crypto/repo.py +142 -0
  22. toolfence_crypto-0.3.0/src/toolfence_crypto/report.py +116 -0
  23. toolfence_crypto-0.3.0/src/toolfence_crypto/rules.py +277 -0
  24. toolfence_crypto-0.3.0/src/toolfence_crypto/scanner.py +255 -0
  25. toolfence_crypto-0.3.0/tests/fixtures/demo.test.ts +4 -0
  26. toolfence_crypto-0.3.0/tests/fixtures/requirements.txt +5 -0
  27. toolfence_crypto-0.3.0/tests/fixtures/sample_api.js +16 -0
  28. toolfence_crypto-0.3.0/tests/fixtures/sample_app.py +24 -0
  29. toolfence_crypto-0.3.0/tests/fixtures/sample_crypto.ts +24 -0
  30. toolfence_crypto-0.3.0/tests/fixtures/sample_go.go +18 -0
  31. toolfence_crypto-0.3.0/tests/fixtures/sample_key.pem +6 -0
  32. toolfence_crypto-0.3.0/tests/fixtures/sample_pqc.py +10 -0
  33. toolfence_crypto-0.3.0/tests/test_go_pqc.py +34 -0
  34. toolfence_crypto-0.3.0/tests/test_policy_js.py +51 -0
  35. toolfence_crypto-0.3.0/tests/test_repo.py +34 -0
  36. toolfence_crypto-0.3.0/tests/test_scanner.py +88 -0
  37. toolfence_crypto-0.3.0/toolfence-crypto.example.toml +19 -0
@@ -0,0 +1,12 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.py[cod]
4
+ .pytest_cache/
5
+ *.egg-info/
6
+ dist/
7
+ build/
8
+ report.html
9
+ report.json
10
+ *.sarif
11
+ cbom.json
12
+ .DS_Store
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ToolFence contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,89 @@
1
+ Metadata-Version: 2.5
2
+ Name: toolfence-crypto
3
+ Version: 0.3.0
4
+ Summary: ToolFence Crypto — free crypto checkup for repos (PQC debt, weak crypto, keys, deps)
5
+ Project-URL: Homepage, https://toolfence.ai
6
+ Project-URL: Repository, https://github.com/StockGorilla/toolfence
7
+ Project-URL: Documentation, https://toolfence.ai
8
+ Author: ToolFence contributors
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: cbom,cryptography,post-quantum,pqc,sarif,scanner,security,toolfence
12
+ Requires-Python: >=3.10
13
+ Provides-Extra: color
14
+ Requires-Dist: rich>=13.0; extra == 'color'
15
+ Provides-Extra: dev
16
+ Requires-Dist: pytest>=8.0; extra == 'dev'
17
+ Requires-Dist: rich>=13.0; extra == 'dev'
18
+ Provides-Extra: toml310
19
+ Requires-Dist: tomli>=2.0; extra == 'toml310'
20
+ Description-Content-Type: text/markdown
21
+
22
+ # ToolFence Crypto
23
+
24
+ **Free crypto checkup for solo developers and small teams.**
25
+
26
+ Scan a local folder or GitHub repo for quantum-vulnerable cryptography (RSA, ECC, DH/DSA), classical weak crypto, crypto-related dependencies, and PEM keys/certs. Part of ToolFence:
27
+
28
+ > **Scan** what you install → **Scan crypto** in what you ship → **Gate** what can hurt you → **Radar** on cost and risk.
29
+
30
+ ## Install
31
+
32
+ ```bash
33
+ # npm (needs Python 3.10+ on PATH)
34
+ npx toolfence-crypto .
35
+ npx toolfence-crypto https://github.com/owner/repo --html report.html
36
+
37
+ # PyPI
38
+ pip install toolfence-crypto
39
+ toolfence-crypto .
40
+
41
+ # from the monorepo
42
+ cd packages/toolfence-crypto
43
+ pip install -e ".[dev]"
44
+ toolfence-crypto .
45
+ ```
46
+
47
+ Hosted (public GitHub only): [toolfence.ai/crypto](https://toolfence.ai/crypto)
48
+
49
+ ## Common commands
50
+
51
+ ```bash
52
+ toolfence-crypto .
53
+ toolfence-crypto ./my-app --html report.html
54
+ toolfence-crypto https://github.com/owner/repo
55
+ toolfence-crypto owner/repo --branch main --fail-on high --sarif results.sarif --cbom cbom.json
56
+ toolfence-crypto . --policy baseline-weak
57
+ toolfence-crypto . --policy nist-8547 --html report.html
58
+ ```
59
+
60
+ | Policy | Use when |
61
+ |--------|----------|
62
+ | `baseline-weak` | Weak crypto + secrets (high+) — best solo default |
63
+ | `nist-8547` | Also fail quantum-vulnerable public-key (medium+) |
64
+ | `cnsa-2.0` | Stricter posture incl. TLS + key material |
65
+
66
+ **Zero required third-party packages** (stdlib only). `git` is required only for remote URLs on the CLI. Hosted scan uses GitHub zipballs (no git). JS/TS and Go call sites use structured scanners with higher confidence; `Math.random` in test files is downranked. Positive PQC signals (ML-KEM / ML-DSA / hybrid) are reported as info and do not lower the readiness grade.
67
+
68
+ ## Outputs
69
+
70
+ - Terminal: readiness grade + **Top fixes for you**
71
+ - `--html` standalone report
72
+ - `--sarif` for CI / code scanning
73
+ - `--cbom` CycloneDX 1.6 cryptographic bill of materials (deduped assets + quantum risk tags)
74
+
75
+ ## Config
76
+
77
+ Copy [`toolfence-crypto.example.toml`](toolfence-crypto.example.toml) to `toolfence-crypto.toml`:
78
+
79
+ ```toml
80
+ [toolfence-crypto]
81
+ fail_on = "high"
82
+ ignore_rules = ["DEP001"]
83
+ ```
84
+
85
+ Inline suppress: `# toolfence-crypto: ignore`
86
+
87
+ ## License
88
+
89
+ MIT. Lives in the [ToolFence](https://github.com/StockGorilla/toolfence) monorepo under `packages/toolfence-crypto`.
@@ -0,0 +1,68 @@
1
+ # ToolFence Crypto
2
+
3
+ **Free crypto checkup for solo developers and small teams.**
4
+
5
+ Scan a local folder or GitHub repo for quantum-vulnerable cryptography (RSA, ECC, DH/DSA), classical weak crypto, crypto-related dependencies, and PEM keys/certs. Part of ToolFence:
6
+
7
+ > **Scan** what you install → **Scan crypto** in what you ship → **Gate** what can hurt you → **Radar** on cost and risk.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ # npm (needs Python 3.10+ on PATH)
13
+ npx toolfence-crypto .
14
+ npx toolfence-crypto https://github.com/owner/repo --html report.html
15
+
16
+ # PyPI
17
+ pip install toolfence-crypto
18
+ toolfence-crypto .
19
+
20
+ # from the monorepo
21
+ cd packages/toolfence-crypto
22
+ pip install -e ".[dev]"
23
+ toolfence-crypto .
24
+ ```
25
+
26
+ Hosted (public GitHub only): [toolfence.ai/crypto](https://toolfence.ai/crypto)
27
+
28
+ ## Common commands
29
+
30
+ ```bash
31
+ toolfence-crypto .
32
+ toolfence-crypto ./my-app --html report.html
33
+ toolfence-crypto https://github.com/owner/repo
34
+ toolfence-crypto owner/repo --branch main --fail-on high --sarif results.sarif --cbom cbom.json
35
+ toolfence-crypto . --policy baseline-weak
36
+ toolfence-crypto . --policy nist-8547 --html report.html
37
+ ```
38
+
39
+ | Policy | Use when |
40
+ |--------|----------|
41
+ | `baseline-weak` | Weak crypto + secrets (high+) — best solo default |
42
+ | `nist-8547` | Also fail quantum-vulnerable public-key (medium+) |
43
+ | `cnsa-2.0` | Stricter posture incl. TLS + key material |
44
+
45
+ **Zero required third-party packages** (stdlib only). `git` is required only for remote URLs on the CLI. Hosted scan uses GitHub zipballs (no git). JS/TS and Go call sites use structured scanners with higher confidence; `Math.random` in test files is downranked. Positive PQC signals (ML-KEM / ML-DSA / hybrid) are reported as info and do not lower the readiness grade.
46
+
47
+ ## Outputs
48
+
49
+ - Terminal: readiness grade + **Top fixes for you**
50
+ - `--html` standalone report
51
+ - `--sarif` for CI / code scanning
52
+ - `--cbom` CycloneDX 1.6 cryptographic bill of materials (deduped assets + quantum risk tags)
53
+
54
+ ## Config
55
+
56
+ Copy [`toolfence-crypto.example.toml`](toolfence-crypto.example.toml) to `toolfence-crypto.toml`:
57
+
58
+ ```toml
59
+ [toolfence-crypto]
60
+ fail_on = "high"
61
+ ignore_rules = ["DEP001"]
62
+ ```
63
+
64
+ Inline suppress: `# toolfence-crypto: ignore`
65
+
66
+ ## License
67
+
68
+ MIT. Lives in the [ToolFence](https://github.com/StockGorilla/toolfence) monorepo under `packages/toolfence-crypto`.
@@ -0,0 +1,53 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "toolfence-crypto"
7
+ version = "0.3.0"
8
+ description = "ToolFence Crypto — free crypto checkup for repos (PQC debt, weak crypto, keys, deps)"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = "MIT"
12
+ authors = [{ name = "ToolFence contributors" }]
13
+ keywords = [
14
+ "toolfence",
15
+ "cryptography",
16
+ "post-quantum",
17
+ "pqc",
18
+ "security",
19
+ "cbom",
20
+ "sarif",
21
+ "scanner",
22
+ ]
23
+ dependencies = []
24
+
25
+ [project.urls]
26
+ Homepage = "https://toolfence.ai"
27
+ Repository = "https://github.com/StockGorilla/toolfence"
28
+ Documentation = "https://toolfence.ai"
29
+
30
+ [project.optional-dependencies]
31
+ color = ["rich>=13.0"]
32
+ toml310 = ["tomli>=2.0"]
33
+ dev = ["pytest>=8.0", "rich>=13.0"]
34
+
35
+ [project.scripts]
36
+ toolfence-crypto = "toolfence_crypto.cli:main"
37
+
38
+ [tool.hatch.build.targets.wheel]
39
+ packages = ["src/toolfence_crypto"]
40
+
41
+ [tool.hatch.build.targets.sdist]
42
+ include = [
43
+ "src/toolfence_crypto",
44
+ "README.md",
45
+ "LICENSE",
46
+ "pyproject.toml",
47
+ "tests",
48
+ "toolfence-crypto.example.toml",
49
+ ]
50
+
51
+ [tool.pytest.ini_options]
52
+ pythonpath = ["src"]
53
+ testpaths = ["tests"]
@@ -0,0 +1,3 @@
1
+ """ToolFence Crypto: scan repositories for quantum-vulnerable and weak cryptography."""
2
+
3
+ __version__ = "0.3.0"
@@ -0,0 +1,3 @@
1
+ from .cli import main
2
+
3
+ raise SystemExit(main())
@@ -0,0 +1,158 @@
1
+ from __future__ import annotations
2
+
3
+ import argparse
4
+ import sys
5
+ from pathlib import Path
6
+
7
+ from . import __version__
8
+ from .config import ScanConfig, load_config
9
+ from .export import write_cbom, write_json_report, write_sarif
10
+ from .html_report import write_html
11
+ from .models import SEVERITY_RANK
12
+ from .policy import POLICY_IDS, evaluate_policy
13
+ from .repo import looks_like_remote, prepare_scan_target
14
+ from .report import print_report
15
+ from .scanner import scan_path
16
+
17
+
18
+ def build_parser() -> argparse.ArgumentParser:
19
+ parser = argparse.ArgumentParser(
20
+ prog="toolfence-crypto",
21
+ description=(
22
+ "Simple crypto checkup for solo developers and small teams: "
23
+ "scan a local folder or a GitHub repo URL. "
24
+ "Zero required third-party dependencies (git required for remote URLs)."
25
+ ),
26
+ )
27
+ parser.add_argument(
28
+ "target",
29
+ nargs="?",
30
+ default=".",
31
+ help=(
32
+ "Local path, GitHub URL, or owner/repo "
33
+ "(examples: . ./my-app https://github.com/org/app org/app)"
34
+ ),
35
+ )
36
+ parser.add_argument(
37
+ "--branch",
38
+ "-b",
39
+ default=None,
40
+ help="Branch or tag to clone when scanning a remote repo (default: remote default branch)",
41
+ )
42
+ parser.add_argument(
43
+ "--json",
44
+ dest="json_out",
45
+ metavar="FILE",
46
+ help="Write JSON report to FILE",
47
+ )
48
+ parser.add_argument(
49
+ "--cbom",
50
+ dest="cbom_out",
51
+ metavar="FILE",
52
+ help="Write CycloneDX 1.6 CBOM JSON to FILE",
53
+ )
54
+ parser.add_argument(
55
+ "--sarif",
56
+ dest="sarif_out",
57
+ metavar="FILE",
58
+ help="Write SARIF 2.1.0 report to FILE (CI / code scanning)",
59
+ )
60
+ parser.add_argument(
61
+ "--html",
62
+ dest="html_out",
63
+ metavar="FILE",
64
+ help="Write a standalone HTML report to FILE (easy to open in a browser)",
65
+ )
66
+ parser.add_argument(
67
+ "--fail-on",
68
+ choices=list(SEVERITY_RANK),
69
+ default=None,
70
+ help="Exit 1 if any finding at this severity or higher is found",
71
+ )
72
+ parser.add_argument(
73
+ "--policy",
74
+ choices=list(POLICY_IDS),
75
+ default=None,
76
+ help=(
77
+ "Evaluate a built-in policy pack and exit 1 on failure "
78
+ "(baseline-weak | nist-8547 | cnsa-2.0)"
79
+ ),
80
+ )
81
+ parser.add_argument(
82
+ "--no-config",
83
+ action="store_true",
84
+ help="Ignore toolfence-crypto.toml",
85
+ )
86
+ parser.add_argument(
87
+ "--verbose",
88
+ "-v",
89
+ action="store_true",
90
+ help="Show the full finding list (default shows Top fixes only)",
91
+ )
92
+ parser.add_argument(
93
+ "--quiet",
94
+ action="store_true",
95
+ help="Suppress terminal report (useful with --json/--cbom/--sarif/--html)",
96
+ )
97
+ parser.add_argument("--version", action="version", version=f"toolfence-crypto {__version__}")
98
+ return parser
99
+
100
+
101
+ def main(argv: list[str] | None = None) -> int:
102
+ parser = build_parser()
103
+ args = parser.parse_args(argv)
104
+
105
+ try:
106
+ with prepare_scan_target(args.target, branch=args.branch) as (target, label):
107
+ if not target.exists():
108
+ print(f"Path not found: {target}", file=sys.stderr)
109
+ return 2
110
+
111
+ if looks_like_remote(args.target) and not args.quiet:
112
+ print(f"Cloned {label} — scanning…")
113
+
114
+ config = ScanConfig() if args.no_config else load_config(target)
115
+ summary = scan_path(target, config)
116
+
117
+ policy_id = args.policy or config.policy
118
+ if policy_id:
119
+ summary.policy = evaluate_policy(policy_id, summary.findings)
120
+
121
+ if not args.quiet:
122
+ print_report(summary, verbose=args.verbose)
123
+
124
+ wrote: list[str] = []
125
+ if args.json_out:
126
+ write_json_report(summary, Path(args.json_out))
127
+ wrote.append(args.json_out)
128
+ if args.cbom_out:
129
+ write_cbom(summary, Path(args.cbom_out))
130
+ wrote.append(args.cbom_out)
131
+ if args.sarif_out:
132
+ write_sarif(summary, Path(args.sarif_out))
133
+ wrote.append(args.sarif_out)
134
+ if args.html_out:
135
+ write_html(summary, Path(args.html_out), scanned_path=label)
136
+ wrote.append(args.html_out)
137
+
138
+ if wrote and not args.quiet:
139
+ print("Wrote: " + ", ".join(wrote))
140
+
141
+ exit_code = 0
142
+ fail_on = args.fail_on or config.fail_on
143
+ if fail_on:
144
+ threshold = SEVERITY_RANK[fail_on]
145
+ if any(SEVERITY_RANK.get(f.severity, 99) <= threshold for f in summary.findings):
146
+ exit_code = 1
147
+
148
+ if summary.policy is not None and not summary.policy.passed:
149
+ exit_code = 1
150
+
151
+ return exit_code
152
+ except (ValueError, RuntimeError) as exc:
153
+ print(str(exc), file=sys.stderr)
154
+ return 2
155
+
156
+
157
+ if __name__ == "__main__":
158
+ sys.exit(main())
@@ -0,0 +1,77 @@
1
+ from __future__ import annotations
2
+
3
+ import sys
4
+ from dataclasses import dataclass, field
5
+ from pathlib import Path
6
+
7
+ if sys.version_info >= (3, 11):
8
+ import tomllib
9
+ else: # pragma: no cover - py3.10
10
+ try:
11
+ import tomli as tomllib # type: ignore
12
+ except ImportError:
13
+ tomllib = None # type: ignore
14
+
15
+
16
+ @dataclass
17
+ class ScanConfig:
18
+ """Minimal project config — no schema framework required."""
19
+
20
+ ignore_rules: set[str] = field(default_factory=set)
21
+ ignore_paths: list[str] = field(default_factory=list)
22
+ fail_on: str | None = None
23
+ policy: str | None = None
24
+
25
+ def is_path_ignored(self, relative_path: str) -> bool:
26
+ norm = relative_path.replace("\\", "/")
27
+ for pattern in self.ignore_paths:
28
+ p = pattern.replace("\\", "/").lstrip("./")
29
+ if not p:
30
+ continue
31
+ if p.endswith("/**"):
32
+ prefix = p[:-3]
33
+ if norm == prefix.rstrip("/") or norm.startswith(prefix):
34
+ return True
35
+ elif p.endswith("/*"):
36
+ parent = p[:-2].rstrip("/")
37
+ parent_part = str(Path(norm).parent).replace("\\", "/")
38
+ if parent_part == parent or (parent == "." and "/" not in norm):
39
+ return True
40
+ elif norm == p or norm.endswith("/" + p) or norm.startswith(p.rstrip("/") + "/"):
41
+ return True
42
+ elif Path(norm).match(p):
43
+ return True
44
+ return False
45
+
46
+
47
+ def load_config(start: Path) -> ScanConfig:
48
+ """Load toolfence-crypto.toml from start or nearest parent. Missing file = defaults."""
49
+ path = _find_config(start)
50
+ if path is None:
51
+ return ScanConfig()
52
+ if tomllib is None:
53
+ raise RuntimeError(
54
+ "toolfence-crypto.toml found but TOML parsing needs Python 3.11+ "
55
+ "(or install optional 'tomli' on 3.10)."
56
+ )
57
+ data = tomllib.loads(path.read_text(encoding="utf-8"))
58
+ section = data.get("toolfence-crypto") or data.get("cryptoscan") or data
59
+ return ScanConfig(
60
+ ignore_rules={str(x) for x in section.get("ignore_rules", [])},
61
+ ignore_paths=[str(x) for x in section.get("ignore_paths", [])],
62
+ fail_on=section.get("fail_on"),
63
+ policy=section.get("policy"),
64
+ )
65
+
66
+
67
+ def _find_config(start: Path) -> Path | None:
68
+ cur = start.resolve()
69
+ if cur.is_file():
70
+ cur = cur.parent
71
+ for directory in [cur, *cur.parents]:
72
+ candidate = directory / "toolfence-crypto.toml"
73
+ if candidate.is_file():
74
+ return candidate
75
+ if (directory / ".git").exists():
76
+ break
77
+ return None