pqblocks-agility 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 (31) hide show
  1. pqblocks_agility-0.1.0/LICENSE +201 -0
  2. pqblocks_agility-0.1.0/NOTICE +7 -0
  3. pqblocks_agility-0.1.0/PKG-INFO +159 -0
  4. pqblocks_agility-0.1.0/README.md +128 -0
  5. pqblocks_agility-0.1.0/pyproject.toml +46 -0
  6. pqblocks_agility-0.1.0/setup.cfg +4 -0
  7. pqblocks_agility-0.1.0/src/pqblocks_agility/__init__.py +3 -0
  8. pqblocks_agility-0.1.0/src/pqblocks_agility/ast_decoupling.py +70 -0
  9. pqblocks_agility-0.1.0/src/pqblocks_agility/cars_scoring.py +87 -0
  10. pqblocks_agility-0.1.0/src/pqblocks_agility/cbom.py +311 -0
  11. pqblocks_agility-0.1.0/src/pqblocks_agility/ci_gate.py +288 -0
  12. pqblocks_agility-0.1.0/src/pqblocks_agility/cli.py +313 -0
  13. pqblocks_agility-0.1.0/src/pqblocks_agility/decouple.py +107 -0
  14. pqblocks_agility-0.1.0/src/pqblocks_agility/sarif.py +18 -0
  15. pqblocks_agility-0.1.0/src/pqblocks_agility/sarif_export.py +132 -0
  16. pqblocks_agility-0.1.0/src/pqblocks_agility.egg-info/PKG-INFO +159 -0
  17. pqblocks_agility-0.1.0/src/pqblocks_agility.egg-info/SOURCES.txt +29 -0
  18. pqblocks_agility-0.1.0/src/pqblocks_agility.egg-info/dependency_links.txt +1 -0
  19. pqblocks_agility-0.1.0/src/pqblocks_agility.egg-info/entry_points.txt +2 -0
  20. pqblocks_agility-0.1.0/src/pqblocks_agility.egg-info/requires.txt +4 -0
  21. pqblocks_agility-0.1.0/src/pqblocks_agility.egg-info/top_level.txt +1 -0
  22. pqblocks_agility-0.1.0/tests/test_ast_decoupling.py +73 -0
  23. pqblocks_agility-0.1.0/tests/test_cars_scoring.py +116 -0
  24. pqblocks_agility-0.1.0/tests/test_cbom.py +499 -0
  25. pqblocks_agility-0.1.0/tests/test_ci_gate.py +121 -0
  26. pqblocks_agility-0.1.0/tests/test_cli.py +272 -0
  27. pqblocks_agility-0.1.0/tests/test_decouple.py +233 -0
  28. pqblocks_agility-0.1.0/tests/test_gate_policy.py +168 -0
  29. pqblocks_agility-0.1.0/tests/test_review_fixes.py +281 -0
  30. pqblocks_agility-0.1.0/tests/test_sarif_export.py +209 -0
  31. pqblocks_agility-0.1.0/tests/test_suite.py +192 -0
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ Use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 The PQBlocks Authors
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,7 @@
1
+ pqblocks-agility
2
+ Copyright 2026 The PQBlocks Authors
3
+
4
+ This product is part of PQBlocks (https://github.com/PQBlocks).
5
+ Licensed under the Apache License, Version 2.0 (see LICENSE).
6
+
7
+
@@ -0,0 +1,159 @@
1
+ Metadata-Version: 2.4
2
+ Name: pqblocks-agility
3
+ Version: 0.1.0
4
+ Summary: Cryptographic Agility Readiness Scoring (CARS) and CI/CD regression firewall for CycloneDX 1.6 CBOM inventories.
5
+ Author: The PQBlocks Authors
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/PQBlocks/crypto-agility
8
+ Project-URL: Documentation, https://github.com/PQBlocks/crypto-agility#readme
9
+ Project-URL: Source, https://github.com/PQBlocks/crypto-agility
10
+ Project-URL: Changelog, https://github.com/PQBlocks/crypto-agility/blob/main/CHANGELOG.md
11
+ Project-URL: Issues, https://github.com/PQBlocks/crypto-agility/issues
12
+ Project-URL: Security, https://github.com/PQBlocks/crypto-agility/security/policy
13
+ Keywords: cbom,cars,crypto-agility,cyclonedx,sarif,ci-gate,post-quantum,pqc
14
+ Classifier: Development Status :: 3 - Alpha
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Topic :: Security :: Cryptography
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Programming Language :: Python :: 3.14
23
+ Requires-Python: >=3.11
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ License-File: NOTICE
27
+ Requires-Dist: click
28
+ Provides-Extra: test
29
+ Requires-Dist: pytest; extra == "test"
30
+ Dynamic: license-file
31
+
32
+ # pqblocks-agility
33
+
34
+ Computes Cryptographic Agility Readiness Scores (CARS) and acts as a CI/CD regression firewall for CycloneDX 1.6 Cryptographic Bills of Materials (CBOM).
35
+ Use it to quantitatively measure how easily your codebase can transition away from deprecated classical cryptography to post-quantum standards, and fail pull requests that re-introduce quantum-vulnerable primitives.
36
+ Implements the 5-dimension CARS model (Costa, IACR ePrint 2026/1467) and OASIS SARIF 2.1.0 telemetry export.
37
+
38
+ ```bash
39
+ pip install pqblocks-agility
40
+ ```
41
+
42
+ ```python
43
+ import json
44
+ from pqblocks_agility.cbom import parse_cbom_dict
45
+ from pqblocks_agility.cli import compute_cars_score
46
+
47
+ cbom_data = {
48
+ "bomFormat": "CycloneDX", "specVersion": "1.6",
49
+ "serialNumber": "urn:uuid:6c361972-23c3-4d4b-9721-a47fa266184a", "version": 1,
50
+ "components": [{"type": "cryptographic-asset", "name": "ML-KEM-768",
51
+ "properties": [{"name": "pqblocks-scan.algorithm", "value": "ML-KEM-768"},
52
+ {"name": "pqblocks-scan.grade", "value": "A"}]}]
53
+ }
54
+ score, dims = compute_cars_score(parse_cbom_dict(cbom_data))
55
+ print(f"CARS score: {score:.1f} / 100.0 (Grade A)")
56
+ ```
57
+
58
+ From the command line:
59
+
60
+ ```bash
61
+ # Evaluate agility score from a CBOM (exit 1 below --min-cars)
62
+ pqblocks-agility evaluate --cbom cbom.json --json-out summary.json
63
+
64
+ # Gate a GitHub Pull Request against regression
65
+ pqblocks-agility gate --cbom cbom.json --diff-file pr.diff --fail-on-regression --min-cars 60.0 --sarif-out results.sarif
66
+ ```
67
+
68
+ Exit codes: `0` pass, `1` policy failure (score below threshold, a Grade-F component, or a regression), `2` usage or input error (missing or malformed CBOM, missing or unparsable diff, bad option value).
69
+
70
+ ---
71
+
72
+ ## Why PQBlocks
73
+
74
+ - **Standardized scoring:** Implements the formal 5-dimension weighted composite model ($w = [0.20, 0.25, 0.25, 0.15, 0.15]$) covering inventory completeness, algorithm compliance, decoupling, toolchains, and governance.
75
+ - **CI/CD regression firewall:** Prevents pull requests from slipping deprecated classical algorithms (MD5, SHA-1, 1024-bit RSA) into repositories with established migration thresholds.
76
+ - **GitHub Advanced Security integration:** Emits standard SARIF 2.1.0 logs uploaded directly to GitHub Code Scanning or GitLab Security dashboards.
77
+ - **Pure Python:** No native C libraries or GPU requirements. Runs in milliseconds on standard CI runners.
78
+
79
+ ---
80
+
81
+ ## Usage
82
+
83
+ ### Command Line Interface
84
+
85
+ ```bash
86
+ pqblocks-agility [OPTIONS] COMMAND [ARGS]...
87
+ ```
88
+
89
+ Commands:
90
+ - `evaluate [OPTIONS]`: Evaluates CARS score and dimension breakdowns from a CycloneDX 1.6 CBOM.
91
+ - `--cbom PATH`: Path to CycloneDX 1.6 CBOM JSON.
92
+ - `--profile [default|cloud-enterprise|embedded-iot]`: Weight distribution profile.
93
+ - `--d1-mode [scenario|empirical]`: Inventory completeness estimation mode.
94
+ - `--min-cars FLOAT`: Exit 1 when the score is below this (0-100, default: 56.0).
95
+ - `--json-out PATH`, `--sarif-out PATH`, `--gitlab-report PATH`: Report outputs.
96
+ - `gate [OPTIONS]`: Enforces CI/CD gate policies on CBOM and git diffs.
97
+ - `--cbom PATH`: Path to CycloneDX 1.6 CBOM JSON.
98
+ - `--diff-file PATH` / `--diff-base REF`: Diff source for the regression firewall.
99
+ - `--fail-on-regression`: Enable the regression firewall (off by default). Requires `--diff-file` or `--diff-base`; a missing or unparsable diff exits 2, never passes.
100
+ - `--allow-disallowed`: Do not fail on Grade-F components. By default any Grade-F component fails the gate.
101
+ - `--min-cars FLOAT`: Minimum CARS score threshold, 0-100 (default: 56.0).
102
+ - `--sarif-out PATH`, `--json-out PATH`: Report outputs.
103
+ - `check-staged [OPTIONS]`: Pre-commit hook scanning staged blobs (`git show :path`) for private-key material and FIPS-disallowed primitive names (regex heuristics; exits 1 on a hit and never prints matched content).
104
+ - `scan [OPTIONS] SOURCE_DIR`: Writes an empty baseline CBOM template. It does not inspect SOURCE_DIR; an empty inventory is not evidence that no crypto exists.
105
+
106
+ ---
107
+
108
+ ## CARS 5-Dimension Agility Model
109
+
110
+ The readiness score is calculated as a weighted composite:
111
+ $$\text{CARS} = 100 \sum_{i=1}^5 w_i d_i$$
112
+
113
+ | Dimension | Meaning | Metric Basis |
114
+ |---|---|---|
115
+ | $d_1$ ($w_1 = 0.20$) | Inventory Completeness | Ratio of discovered components vs repository complexity |
116
+ | $d_2$ ($w_2 = 0.25$) | Algorithm Compliance | Mean algorithm grade ($A=1.0, B=0.85, C=0.60, D=0.30, E/F=0.0$) |
117
+ | $d_3$ ($w_2 = 0.25$) | Architectural Decoupling | Ratio of abstracted vs hardcoded direct cryptographic call sites |
118
+ | $d_4$ ($w_4 = 0.15$) | Toolchain Readiness | CI/CD automation and automated scanning integration |
119
+ | $d_5$ ($w_5 = 0.15$) | Governance Alignment | Sunset planning, cryptographic migration policies |
120
+
121
+ Score tiers:
122
+ Tiers as implemented in `ci_gate.get_cars_tier`: Critical $\le 30$, At-Risk $\le 55$, Transitional $\le 75$, Advanced $\le 90$, Ready $> 90$.
123
+
124
+ ---
125
+
126
+ ## API Reference
127
+
128
+ | Module | Function / Class | Purpose |
129
+ |---|---|---|
130
+ | `pqblocks_agility.cbom` | `parse_cbom(path: str) -> CBOM` | Parse a CycloneDX 1.6 CBOM file into a structured dataclass |
131
+ | | `parse_cbom_dict(data: dict) -> CBOM` | Parse a CBOM dictionary in-memory |
132
+ | | `CBOM`, `CBOMComponent` | Dataclasses holding components, algorithm properties, and grades |
133
+ | `pqblocks_agility.cars_scoring` | `compute_cars_score(cbom, profile, d1_mode) -> (float, dict)` | The single CARS implementation (CLI and API); `score_cbom(cbom)` is the default-profile alias |
134
+ | `pqblocks_agility.ci_gate` | `evaluate_gate(cbom, min_cars, diff, ..., allow_disallowed=False)` | Evaluate gate policy (score, Grade-F, regression firewall); raises `DiffError` on an unparsable diff |
135
+ | `pqblocks_agility.sarif_export` | `export_sarif(cbom, score, dimensions, ...)` | Generate SARIF 2.1.0 telemetry dictionary |
136
+ | `pqblocks_agility.ast_decoupling` | `compute_d3(cbom: CBOM) -> float` | Evaluate AST decoupling ratios from call site metadata |
137
+
138
+ ---
139
+
140
+ ## Limitations
141
+
142
+ - **CycloneDX 1.6 required:** CycloneDX 1.4/1.5/1.7 files are rejected (`CBOMVersionError`).
143
+ - **Static analysis heuristic:** $d_3$ evaluates AST call sites and configuration locations. It does not trace dynamic object loading or C shared-object symbol resolution.
144
+ - **Dimensions $d_1, d_4, d_5$ defaults:** In standalone offline CBOM evaluation, $d_1, d_4, d_5$ default to 0.50 scenario mode unless explicit CI flags or empirical scans are supplied.
145
+ - **Not a cryptographic engine:** Does not perform encryption, decryption, or signing.
146
+
147
+ ---
148
+
149
+ ## Security Notes
150
+
151
+ See [SECURITY_NOTES.md](SECURITY_NOTES.md) for details on AST parsing limits, denial of service mitigation, and dependency integrity.
152
+
153
+ ## Verification
154
+
155
+ [TESTING.md](TESTING.md) · [BENCHMARKS.md](BENCHMARKS.md) · [EVIDENCE.md](EVIDENCE.md) · [VERIFICATION_REPORT.md](VERIFICATION_REPORT.md) · [USE_CASES.md](USE_CASES.md)
156
+
157
+ ## Part of PQBlocks
158
+
159
+ [PQBlocks](https://github.com/PQBlocks) builds modular, verified building blocks for post-quantum cryptographic transitions.
@@ -0,0 +1,128 @@
1
+ # pqblocks-agility
2
+
3
+ Computes Cryptographic Agility Readiness Scores (CARS) and acts as a CI/CD regression firewall for CycloneDX 1.6 Cryptographic Bills of Materials (CBOM).
4
+ Use it to quantitatively measure how easily your codebase can transition away from deprecated classical cryptography to post-quantum standards, and fail pull requests that re-introduce quantum-vulnerable primitives.
5
+ Implements the 5-dimension CARS model (Costa, IACR ePrint 2026/1467) and OASIS SARIF 2.1.0 telemetry export.
6
+
7
+ ```bash
8
+ pip install pqblocks-agility
9
+ ```
10
+
11
+ ```python
12
+ import json
13
+ from pqblocks_agility.cbom import parse_cbom_dict
14
+ from pqblocks_agility.cli import compute_cars_score
15
+
16
+ cbom_data = {
17
+ "bomFormat": "CycloneDX", "specVersion": "1.6",
18
+ "serialNumber": "urn:uuid:6c361972-23c3-4d4b-9721-a47fa266184a", "version": 1,
19
+ "components": [{"type": "cryptographic-asset", "name": "ML-KEM-768",
20
+ "properties": [{"name": "pqblocks-scan.algorithm", "value": "ML-KEM-768"},
21
+ {"name": "pqblocks-scan.grade", "value": "A"}]}]
22
+ }
23
+ score, dims = compute_cars_score(parse_cbom_dict(cbom_data))
24
+ print(f"CARS score: {score:.1f} / 100.0 (Grade A)")
25
+ ```
26
+
27
+ From the command line:
28
+
29
+ ```bash
30
+ # Evaluate agility score from a CBOM (exit 1 below --min-cars)
31
+ pqblocks-agility evaluate --cbom cbom.json --json-out summary.json
32
+
33
+ # Gate a GitHub Pull Request against regression
34
+ pqblocks-agility gate --cbom cbom.json --diff-file pr.diff --fail-on-regression --min-cars 60.0 --sarif-out results.sarif
35
+ ```
36
+
37
+ Exit codes: `0` pass, `1` policy failure (score below threshold, a Grade-F component, or a regression), `2` usage or input error (missing or malformed CBOM, missing or unparsable diff, bad option value).
38
+
39
+ ---
40
+
41
+ ## Why PQBlocks
42
+
43
+ - **Standardized scoring:** Implements the formal 5-dimension weighted composite model ($w = [0.20, 0.25, 0.25, 0.15, 0.15]$) covering inventory completeness, algorithm compliance, decoupling, toolchains, and governance.
44
+ - **CI/CD regression firewall:** Prevents pull requests from slipping deprecated classical algorithms (MD5, SHA-1, 1024-bit RSA) into repositories with established migration thresholds.
45
+ - **GitHub Advanced Security integration:** Emits standard SARIF 2.1.0 logs uploaded directly to GitHub Code Scanning or GitLab Security dashboards.
46
+ - **Pure Python:** No native C libraries or GPU requirements. Runs in milliseconds on standard CI runners.
47
+
48
+ ---
49
+
50
+ ## Usage
51
+
52
+ ### Command Line Interface
53
+
54
+ ```bash
55
+ pqblocks-agility [OPTIONS] COMMAND [ARGS]...
56
+ ```
57
+
58
+ Commands:
59
+ - `evaluate [OPTIONS]`: Evaluates CARS score and dimension breakdowns from a CycloneDX 1.6 CBOM.
60
+ - `--cbom PATH`: Path to CycloneDX 1.6 CBOM JSON.
61
+ - `--profile [default|cloud-enterprise|embedded-iot]`: Weight distribution profile.
62
+ - `--d1-mode [scenario|empirical]`: Inventory completeness estimation mode.
63
+ - `--min-cars FLOAT`: Exit 1 when the score is below this (0-100, default: 56.0).
64
+ - `--json-out PATH`, `--sarif-out PATH`, `--gitlab-report PATH`: Report outputs.
65
+ - `gate [OPTIONS]`: Enforces CI/CD gate policies on CBOM and git diffs.
66
+ - `--cbom PATH`: Path to CycloneDX 1.6 CBOM JSON.
67
+ - `--diff-file PATH` / `--diff-base REF`: Diff source for the regression firewall.
68
+ - `--fail-on-regression`: Enable the regression firewall (off by default). Requires `--diff-file` or `--diff-base`; a missing or unparsable diff exits 2, never passes.
69
+ - `--allow-disallowed`: Do not fail on Grade-F components. By default any Grade-F component fails the gate.
70
+ - `--min-cars FLOAT`: Minimum CARS score threshold, 0-100 (default: 56.0).
71
+ - `--sarif-out PATH`, `--json-out PATH`: Report outputs.
72
+ - `check-staged [OPTIONS]`: Pre-commit hook scanning staged blobs (`git show :path`) for private-key material and FIPS-disallowed primitive names (regex heuristics; exits 1 on a hit and never prints matched content).
73
+ - `scan [OPTIONS] SOURCE_DIR`: Writes an empty baseline CBOM template. It does not inspect SOURCE_DIR; an empty inventory is not evidence that no crypto exists.
74
+
75
+ ---
76
+
77
+ ## CARS 5-Dimension Agility Model
78
+
79
+ The readiness score is calculated as a weighted composite:
80
+ $$\text{CARS} = 100 \sum_{i=1}^5 w_i d_i$$
81
+
82
+ | Dimension | Meaning | Metric Basis |
83
+ |---|---|---|
84
+ | $d_1$ ($w_1 = 0.20$) | Inventory Completeness | Ratio of discovered components vs repository complexity |
85
+ | $d_2$ ($w_2 = 0.25$) | Algorithm Compliance | Mean algorithm grade ($A=1.0, B=0.85, C=0.60, D=0.30, E/F=0.0$) |
86
+ | $d_3$ ($w_2 = 0.25$) | Architectural Decoupling | Ratio of abstracted vs hardcoded direct cryptographic call sites |
87
+ | $d_4$ ($w_4 = 0.15$) | Toolchain Readiness | CI/CD automation and automated scanning integration |
88
+ | $d_5$ ($w_5 = 0.15$) | Governance Alignment | Sunset planning, cryptographic migration policies |
89
+
90
+ Score tiers:
91
+ Tiers as implemented in `ci_gate.get_cars_tier`: Critical $\le 30$, At-Risk $\le 55$, Transitional $\le 75$, Advanced $\le 90$, Ready $> 90$.
92
+
93
+ ---
94
+
95
+ ## API Reference
96
+
97
+ | Module | Function / Class | Purpose |
98
+ |---|---|---|
99
+ | `pqblocks_agility.cbom` | `parse_cbom(path: str) -> CBOM` | Parse a CycloneDX 1.6 CBOM file into a structured dataclass |
100
+ | | `parse_cbom_dict(data: dict) -> CBOM` | Parse a CBOM dictionary in-memory |
101
+ | | `CBOM`, `CBOMComponent` | Dataclasses holding components, algorithm properties, and grades |
102
+ | `pqblocks_agility.cars_scoring` | `compute_cars_score(cbom, profile, d1_mode) -> (float, dict)` | The single CARS implementation (CLI and API); `score_cbom(cbom)` is the default-profile alias |
103
+ | `pqblocks_agility.ci_gate` | `evaluate_gate(cbom, min_cars, diff, ..., allow_disallowed=False)` | Evaluate gate policy (score, Grade-F, regression firewall); raises `DiffError` on an unparsable diff |
104
+ | `pqblocks_agility.sarif_export` | `export_sarif(cbom, score, dimensions, ...)` | Generate SARIF 2.1.0 telemetry dictionary |
105
+ | `pqblocks_agility.ast_decoupling` | `compute_d3(cbom: CBOM) -> float` | Evaluate AST decoupling ratios from call site metadata |
106
+
107
+ ---
108
+
109
+ ## Limitations
110
+
111
+ - **CycloneDX 1.6 required:** CycloneDX 1.4/1.5/1.7 files are rejected (`CBOMVersionError`).
112
+ - **Static analysis heuristic:** $d_3$ evaluates AST call sites and configuration locations. It does not trace dynamic object loading or C shared-object symbol resolution.
113
+ - **Dimensions $d_1, d_4, d_5$ defaults:** In standalone offline CBOM evaluation, $d_1, d_4, d_5$ default to 0.50 scenario mode unless explicit CI flags or empirical scans are supplied.
114
+ - **Not a cryptographic engine:** Does not perform encryption, decryption, or signing.
115
+
116
+ ---
117
+
118
+ ## Security Notes
119
+
120
+ See [SECURITY_NOTES.md](SECURITY_NOTES.md) for details on AST parsing limits, denial of service mitigation, and dependency integrity.
121
+
122
+ ## Verification
123
+
124
+ [TESTING.md](TESTING.md) · [BENCHMARKS.md](BENCHMARKS.md) · [EVIDENCE.md](EVIDENCE.md) · [VERIFICATION_REPORT.md](VERIFICATION_REPORT.md) · [USE_CASES.md](USE_CASES.md)
125
+
126
+ ## Part of PQBlocks
127
+
128
+ [PQBlocks](https://github.com/PQBlocks) builds modular, verified building blocks for post-quantum cryptographic transitions.
@@ -0,0 +1,46 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "pqblocks-agility"
7
+ version = "0.1.0"
8
+ description = "Cryptographic Agility Readiness Scoring (CARS) and CI/CD regression firewall for CycloneDX 1.6 CBOM inventories."
9
+ readme = "README.md"
10
+ license = "Apache-2.0"
11
+ license-files = ["LICENSE", "NOTICE"]
12
+ requires-python = ">=3.11"
13
+ authors = [{name = "The PQBlocks Authors"}]
14
+ keywords = ["cbom", "cars", "crypto-agility", "cyclonedx", "sarif", "ci-gate", "post-quantum", "pqc"]
15
+ classifiers = [
16
+ "Development Status :: 3 - Alpha",
17
+ "Intended Audience :: Developers",
18
+ "Operating System :: OS Independent",
19
+ "Programming Language :: Python :: 3",
20
+ "Topic :: Security :: Cryptography",
21
+ "Programming Language :: Python :: 3.11",
22
+ "Programming Language :: Python :: 3.12",
23
+ "Programming Language :: Python :: 3.13",
24
+ "Programming Language :: Python :: 3.14",
25
+ ]
26
+ dependencies = ["click"]
27
+
28
+ [project.optional-dependencies]
29
+ test = ["pytest"]
30
+
31
+ [project.scripts]
32
+ pqblocks-agility = "pqblocks_agility.cli:main"
33
+
34
+ [project.urls]
35
+ Homepage = "https://github.com/PQBlocks/crypto-agility"
36
+ Documentation = "https://github.com/PQBlocks/crypto-agility#readme"
37
+ Source = "https://github.com/PQBlocks/crypto-agility"
38
+ Changelog = "https://github.com/PQBlocks/crypto-agility/blob/main/CHANGELOG.md"
39
+ Issues = "https://github.com/PQBlocks/crypto-agility/issues"
40
+ Security = "https://github.com/PQBlocks/crypto-agility/security/policy"
41
+
42
+ [tool.setuptools.packages.find]
43
+ where = ["src"]
44
+
45
+ [tool.pytest.ini_options]
46
+ testpaths = ["tests"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,3 @@
1
+ """pqblocks-agility: crypto-agility assessment and CI gate."""
2
+
3
+ __version__ = "0.1.0"
@@ -0,0 +1,70 @@
1
+ """
2
+ AST Decoupling Heuristics (Slice feature 3).
3
+ Implements the IS_DECOUPLED predicate and dimension d3 calculation per Spec §3.2 & §3.3.
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ import ast
9
+ import re
10
+ from typing import Optional, List
11
+ from pqblocks_agility.cbom import CBOM, CBOMComponent
12
+
13
+ CONFIG_EXTENSIONS = (".yaml", ".yml", ".json", ".toml", ".ini", ".env", ".conf", ".cfg")
14
+ HARDCODED_KEY_PATTERNS = [
15
+ re.compile(r"-----BEGIN (RSA|EC|OPENSSH|PRIVATE) KEY-----"),
16
+ re.compile(r"b['\"][0-9a-fA-F]{32,}['\"]"),
17
+ re.compile(r"b['\"][0-9a-zA-Z+/=]{32,}['\"]"),
18
+ ]
19
+
20
+ def is_decoupled(component: CBOMComponent, source_code: Optional[str] = None) -> bool:
21
+ """Evaluate if a cryptographic asset is decoupled from application logic.
22
+
23
+ Condition (a): Zero cryptographic keys hardcoded.
24
+ Condition (b): Algorithm replaceable via policy/configuration change without recompilation.
25
+ Condition (c): Key rotation feasible operationally without service downtime.
26
+ """
27
+ loc = (component.location or "").lower()
28
+ file_part = loc.split(":")[0] if ":" in loc else loc
29
+
30
+ # Rule 1: Config file locations are configurable/replaceable by definition
31
+ if any(file_part.endswith(ext) for ext in CONFIG_EXTENSIONS):
32
+ return True
33
+
34
+ # Rule 2: If source code is provided, inspect for hardcoded keys and provider abstraction
35
+ if source_code:
36
+ for pattern in HARDCODED_KEY_PATTERNS:
37
+ if pattern.search(source_code):
38
+ return False
39
+
40
+ # AST analysis: check if primitive is called directly or via an abstracted provider/release pipeline
41
+ try:
42
+ tree = ast.parse(source_code)
43
+ for node in ast.walk(tree):
44
+ if isinstance(node, ast.Call) and isinstance(node.func, ast.Attribute):
45
+ # Direct inline constructor calls like AES.new, RSA.generate without wrapper
46
+ if node.func.attr in ("new", "generate") and isinstance(node.func.value, ast.Name):
47
+ if node.func.value.id in ("AES", "RSA", "DES", "ARC4"):
48
+ return False
49
+ except Exception:
50
+ pass
51
+
52
+ # Rule 3: Legacy/quantum-vulnerable assets directly in code are tightly coupled by default
53
+ if component.quantum_vulnerable:
54
+ return False
55
+
56
+ # Default for PQC or modern components without hardcoded locations
57
+ return True
58
+
59
+ def compute_d3(cbom: CBOM) -> float:
60
+ """Calculate the d3 Architectural Decoupling dimension score in [0.0, 1.0].
61
+
62
+ Formula:
63
+ d3 = (1 / |I|) * sum(1 for a in I if IS_DECOUPLED(a))
64
+ Empty inventory yields 0.0 per Edge Case E6.
65
+ """
66
+ if not cbom.components:
67
+ return 0.0
68
+
69
+ decoupled_count = sum(1 for c in cbom.components if is_decoupled(c))
70
+ return round(decoupled_count / len(cbom.components), 4)