agentrust-trace-tests 0.1.0__py3-none-any.whl
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.
- agentrust_trace_tests-0.1.0.dist-info/METADATA +94 -0
- agentrust_trace_tests-0.1.0.dist-info/RECORD +18 -0
- agentrust_trace_tests-0.1.0.dist-info/WHEEL +4 -0
- agentrust_trace_tests-0.1.0.dist-info/entry_points.txt +2 -0
- agentrust_trace_tests-0.1.0.dist-info/licenses/LICENSE +202 -0
- trace_tests/__init__.py +3 -0
- trace_tests/cli.py +98 -0
- trace_tests/loader.py +61 -0
- trace_tests/modules/__init__.py +1 -0
- trace_tests/modules/tr_anc.py +34 -0
- trace_tests/modules/tr_env.py +59 -0
- trace_tests/modules/tr_pol.py +40 -0
- trace_tests/modules/tr_rte.py +57 -0
- trace_tests/modules/tr_sca.py +43 -0
- trace_tests/modules/tr_sig.py +130 -0
- trace_tests/modules/tr_txn.py +44 -0
- trace_tests/result.py +35 -0
- trace_tests/runner.py +55 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: agentrust-trace-tests
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: TRACE conformance test suite
|
|
5
|
+
Project-URL: Homepage, https://github.com/agentrust-io/trace-tests
|
|
6
|
+
Project-URL: Repository, https://github.com/agentrust-io/trace-tests
|
|
7
|
+
Project-URL: Documentation, https://github.com/agentrust-io/trace-tests#readme
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/agentrust-io/trace-tests/issues
|
|
9
|
+
Author: agentrust.io
|
|
10
|
+
License: Apache-2.0
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: ai-agents,attestation,conformance,provenance,trace
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Topic :: Security
|
|
21
|
+
Classifier: Topic :: Software Development :: Testing
|
|
22
|
+
Requires-Python: >=3.11
|
|
23
|
+
Requires-Dist: click>=8.1
|
|
24
|
+
Requires-Dist: cryptography>=42
|
|
25
|
+
Requires-Dist: jsonschema>=4.23
|
|
26
|
+
Provides-Extra: dev
|
|
27
|
+
Requires-Dist: bandit; extra == 'dev'
|
|
28
|
+
Requires-Dist: mypy; extra == 'dev'
|
|
29
|
+
Requires-Dist: pip-audit; extra == 'dev'
|
|
30
|
+
Requires-Dist: pytest-cov; extra == 'dev'
|
|
31
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
32
|
+
Requires-Dist: ruff; extra == 'dev'
|
|
33
|
+
Provides-Extra: test
|
|
34
|
+
Requires-Dist: pytest-cov; extra == 'test'
|
|
35
|
+
Requires-Dist: pytest>=8.0; extra == 'test'
|
|
36
|
+
Description-Content-Type: text/markdown
|
|
37
|
+
|
|
38
|
+
[](LICENSE)
|
|
39
|
+
[](https://github.com/agentrust-io/trace-spec)
|
|
40
|
+
[]()
|
|
41
|
+
|
|
42
|
+
# TRACE Conformance Test Suite
|
|
43
|
+
|
|
44
|
+
Conformance tests for TRACE v0.1 - Trust, Runtime Attestation, and Compliance Evidence. An implementation producing Trust Records must pass all tests in the applicable level before using the "TRACE-conformant" mark.
|
|
45
|
+
|
|
46
|
+
If you are building a gateway, agent runtime, or orchestration layer that produces TRACE records, run this suite against your output to verify conformance before claiming TRACE compliance.
|
|
47
|
+
|
|
48
|
+
## Test modules
|
|
49
|
+
|
|
50
|
+
| Module | ID prefix | Spec section | What it tests |
|
|
51
|
+
|---|---|---|---|
|
|
52
|
+
| Envelope | `TR-ENV` | §3.2 | EAT envelope structure, `eat_profile` URI, required fields, `iat` validity |
|
|
53
|
+
| Signature | `TR-SIG` | §3.2.1 | Algorithm conformance (ES256/ES384/EdDSA), key binding, chain verification |
|
|
54
|
+
| Runtime | `TR-RTE` | §3.1 | TEE platform enum, measurement format, RIM URI resolution |
|
|
55
|
+
| Policy | `TR-POL` | §3.1 | Policy bundle hash format, enforcement mode values, TEE binding |
|
|
56
|
+
| Transcript | `TR-TXN` | §3.1 | Tool-call transcript hash binding (Phase 2+ records) |
|
|
57
|
+
| Transparency | `TR-ANC` | §3.2 | SCITT receipt URI format, inclusion proof structure |
|
|
58
|
+
| Provenance | `TR-SCA` | §3.1 | SLSA provenance level, builder URI, digest format |
|
|
59
|
+
|
|
60
|
+
## Conformance levels
|
|
61
|
+
|
|
62
|
+
| Level | Required modules | Use case |
|
|
63
|
+
|---|---|---|
|
|
64
|
+
| 0 | TR-ENV, TR-SIG, TR-POL | Software-only development and staging |
|
|
65
|
+
| 1 | Level 0 + TR-RTE, TR-SCA | Production TEE-attested records |
|
|
66
|
+
| 2 | Level 1 + TR-TXN, TR-ANC | Full records with transparency anchoring |
|
|
67
|
+
|
|
68
|
+
## Running
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
pip install trace-tests
|
|
72
|
+
trace-tests verify --record path/to/trust-record.jwt --level 1
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Test structure
|
|
76
|
+
|
|
77
|
+
Each test case includes:
|
|
78
|
+
- A normative reference to the spec section it exercises
|
|
79
|
+
- A **positive case** - valid input, expected result: `PASS`
|
|
80
|
+
- A **negative case** - invalid input, expected result: `FAIL` with a structured error code
|
|
81
|
+
|
|
82
|
+
Error codes follow the form `TR-<MODULE>-<NNN>` (e.g., `TR-ENV-001`: missing `eat_profile`).
|
|
83
|
+
|
|
84
|
+
## Status
|
|
85
|
+
|
|
86
|
+
Test suite v0.1, in development. The TRACE spec publishes at Confidential Computing Summit, June 23 2026, and the test suite will be usable at that point. The certification program is on a separate timeline, launching 2027.
|
|
87
|
+
|
|
88
|
+
## Contributing
|
|
89
|
+
|
|
90
|
+
Open an issue or PR. New tests must include the normative spec reference, a positive case, and a negative case.
|
|
91
|
+
|
|
92
|
+
## License
|
|
93
|
+
|
|
94
|
+
Apache 2.0
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
trace_tests/__init__.py,sha256=asXJY2hqdtEsFdF0TS8Qu2KZ1ceNDGw25bXBerSEDC8,59
|
|
2
|
+
trace_tests/cli.py,sha256=oZb8EhFvaQnDM-iDpclLEpQWMXqnCksrnTNy6HmxtV8,3016
|
|
3
|
+
trace_tests/loader.py,sha256=9uiJeIX6yYY1iWr8lmE3KdDZeTM3GkxesRNx5kwJ2Fg,2191
|
|
4
|
+
trace_tests/result.py,sha256=b-asQDRlxWY1g1eb8eVzmkAgFaSmqe7wE8x9aEfyKzM,858
|
|
5
|
+
trace_tests/runner.py,sha256=f0MS3bU5oCr-OazjhBHsIVYZSPfscok5CMPHhRYM6H4,1664
|
|
6
|
+
trace_tests/modules/__init__.py,sha256=XUJLK152b-ZtPRhS4eaH8ZZu3b4y8ifA-epDiuTvk2g,57
|
|
7
|
+
trace_tests/modules/tr_anc.py,sha256=_dPJdJ-XRb6TpPwR8CHHgHr1KevGFGsyZmfkckugXpQ,1301
|
|
8
|
+
trace_tests/modules/tr_env.py,sha256=UCy3c8_uoX78Q9a2ehOeFzuQbcTeBNdVeaaebXWgQx4,2465
|
|
9
|
+
trace_tests/modules/tr_pol.py,sha256=sYNJ1bI4L6C95Rrk31fDA0Dt_y9UzJNxZRmXvs79nbY,1471
|
|
10
|
+
trace_tests/modules/tr_rte.py,sha256=QS6ZA56N_FXmXwCorQfFPHk6S62yAd6vuWUCcXq3xIY,2092
|
|
11
|
+
trace_tests/modules/tr_sca.py,sha256=oROga39IQO_PePLKXbyEVeax2ZFosPqPoKr3LeFhXxo,1535
|
|
12
|
+
trace_tests/modules/tr_sig.py,sha256=jntSytet4t9XSoMi04vtnaOaYzV-XpPubbDfQu5DV7E,4703
|
|
13
|
+
trace_tests/modules/tr_txn.py,sha256=Bh-dp-zM8m_S1eEa23RYJZMbO91IZMrMT6scmiAGAPE,1661
|
|
14
|
+
agentrust_trace_tests-0.1.0.dist-info/METADATA,sha256=Bl3iXqtv-EPqYdgBxf56YzImFO-Cttav6SiOYGvBlfg,4099
|
|
15
|
+
agentrust_trace_tests-0.1.0.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
|
|
16
|
+
agentrust_trace_tests-0.1.0.dist-info/entry_points.txt,sha256=ukz9BrnLM-Bc-gtkWmJXWRx6h5BILqrbAccJ7zWW8sw,53
|
|
17
|
+
agentrust_trace_tests-0.1.0.dist-info/licenses/LICENSE,sha256=yVuuHRzgI17MzTVgt3LsHvuX80innw--CmNPDCzO_iw,11358
|
|
18
|
+
agentrust_trace_tests-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,202 @@
|
|
|
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 [yyyy] [name of copyright owner]
|
|
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.
|
|
202
|
+
|
trace_tests/__init__.py
ADDED
trace_tests/cli.py
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"""trace-tests CLI."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import sys
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
import click
|
|
9
|
+
|
|
10
|
+
from trace_tests import __version__
|
|
11
|
+
from trace_tests.loader import LoadError, load_record
|
|
12
|
+
from trace_tests.modules.tr_env import DEFAULT_MAX_AGE_SECONDS
|
|
13
|
+
from trace_tests.result import Status
|
|
14
|
+
from trace_tests.runner import run
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _fmt_status(status: Status) -> str:
|
|
18
|
+
return status.value.upper().ljust(10)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _print_report(path: str, fmt: str, level: int, results: dict[str, list[Any]]) -> int:
|
|
22
|
+
"""Print the conformance report and return exit code (0=pass, 1=fail)."""
|
|
23
|
+
click.echo(f"\nTRACE Conformance Report -- Level {level}")
|
|
24
|
+
click.echo(f"Format : {fmt}")
|
|
25
|
+
click.echo(f"Record : {path}")
|
|
26
|
+
click.echo("")
|
|
27
|
+
|
|
28
|
+
failures = 0
|
|
29
|
+
skips = 0
|
|
30
|
+
passes = 0
|
|
31
|
+
unverified = 0
|
|
32
|
+
|
|
33
|
+
for module, findings in results.items():
|
|
34
|
+
for f in findings:
|
|
35
|
+
prefix = _fmt_status(f.status)
|
|
36
|
+
click.echo(f" {module} {prefix} {f.message}")
|
|
37
|
+
if f.failed():
|
|
38
|
+
failures += 1
|
|
39
|
+
elif f.passed():
|
|
40
|
+
passes += 1
|
|
41
|
+
elif f.unverified():
|
|
42
|
+
unverified += 1
|
|
43
|
+
else:
|
|
44
|
+
skips += 1
|
|
45
|
+
|
|
46
|
+
# Defense in depth: unverified findings must fail the run at any level that
|
|
47
|
+
# requires signatures, even if a module forgot to emit a hard FAIL.
|
|
48
|
+
if unverified and level >= 1:
|
|
49
|
+
failures += unverified
|
|
50
|
+
|
|
51
|
+
total = passes + failures + skips + (unverified if level == 0 else 0)
|
|
52
|
+
click.echo("")
|
|
53
|
+
if failures == 0:
|
|
54
|
+
if unverified:
|
|
55
|
+
click.echo(
|
|
56
|
+
f"Result: PASS ({total} checks, {skips} skipped, {unverified} UNVERIFIED "
|
|
57
|
+
f"-- record is NOT cryptographically verified)"
|
|
58
|
+
)
|
|
59
|
+
else:
|
|
60
|
+
click.echo(f"Result: PASS ({total} checks, {skips} skipped)")
|
|
61
|
+
return 0
|
|
62
|
+
else:
|
|
63
|
+
click.echo(f"Result: FAIL ({total} checks, {failures} failure(s), {skips} skipped)")
|
|
64
|
+
return 1
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
@click.group()
|
|
68
|
+
@click.version_option(__version__)
|
|
69
|
+
def main() -> None:
|
|
70
|
+
"""TRACE conformance test suite."""
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
@main.command()
|
|
74
|
+
@click.option("--record", required=True, type=click.Path(), help="Path to the trust record (JSON)")
|
|
75
|
+
@click.option("--level", default=0, type=click.IntRange(0, 2), show_default=True, help="Conformance level to check (0, 1, or 2)")
|
|
76
|
+
@click.option(
|
|
77
|
+
"--max-age",
|
|
78
|
+
"max_age",
|
|
79
|
+
default=DEFAULT_MAX_AGE_SECONDS,
|
|
80
|
+
type=click.IntRange(min=1),
|
|
81
|
+
show_default=True,
|
|
82
|
+
help="Maximum allowed record age in seconds (iat freshness window)",
|
|
83
|
+
)
|
|
84
|
+
def verify(record: str, level: int, max_age: int) -> None:
|
|
85
|
+
"""Verify a TRACE trust record against the conformance suite."""
|
|
86
|
+
try:
|
|
87
|
+
data, fmt = load_record(record)
|
|
88
|
+
except LoadError as exc:
|
|
89
|
+
click.echo(f"Error: {exc}", err=True)
|
|
90
|
+
sys.exit(2)
|
|
91
|
+
|
|
92
|
+
results = run(data, fmt, level, max_age_seconds=max_age)
|
|
93
|
+
exit_code = _print_report(record, fmt, level, results)
|
|
94
|
+
sys.exit(exit_code)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
if __name__ == "__main__":
|
|
98
|
+
main()
|
trace_tests/loader.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"""Load and normalize trust records from disk."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import pathlib
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class LoadError(Exception):
|
|
11
|
+
pass
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def load_record(path: str) -> tuple[dict[str, Any], str]:
|
|
15
|
+
"""Load a trust record from *path*.
|
|
16
|
+
|
|
17
|
+
Returns ``(record_dict, format_string)`` where format is one of:
|
|
18
|
+
- ``"cmcp-runtime"``: cmcp RuntimeClaim envelope (positive marker: ``cmcp_version``)
|
|
19
|
+
- ``"trace"``: canonical TRACE Trust Record (fields at top level)
|
|
20
|
+
|
|
21
|
+
Format detection is based on positive structural markers so an attacker cannot
|
|
22
|
+
downgrade a cmcp envelope to the weaker plain-trace path by stripping fields.
|
|
23
|
+
Records that look like partial cmcp envelopes are rejected outright.
|
|
24
|
+
"""
|
|
25
|
+
p = pathlib.Path(path)
|
|
26
|
+
if not p.exists():
|
|
27
|
+
raise LoadError(f"File not found: {path}")
|
|
28
|
+
|
|
29
|
+
try:
|
|
30
|
+
data: dict[str, Any] = json.loads(p.read_text(encoding="utf-8"))
|
|
31
|
+
except json.JSONDecodeError as exc:
|
|
32
|
+
raise LoadError(f"Invalid JSON: {exc}") from exc
|
|
33
|
+
|
|
34
|
+
if not isinstance(data, dict):
|
|
35
|
+
raise LoadError("Record must be a JSON object")
|
|
36
|
+
|
|
37
|
+
if "cmcp_version" in data:
|
|
38
|
+
if not isinstance(data.get("trace"), dict):
|
|
39
|
+
raise LoadError(
|
|
40
|
+
"Record declares cmcp_version but has no 'trace' object; refusing malformed cmcp-runtime envelope"
|
|
41
|
+
)
|
|
42
|
+
return data, "cmcp-runtime"
|
|
43
|
+
|
|
44
|
+
# Envelope-only keys present without cmcp_version: this is a partial/stripped
|
|
45
|
+
# cmcp envelope, not a canonical TRACE record. Reject rather than silently
|
|
46
|
+
# downgrading to the weaker plain-trace verification path.
|
|
47
|
+
partial_markers = sorted(k for k in ("trace", "gateway", "signature") if k in data)
|
|
48
|
+
if partial_markers:
|
|
49
|
+
raise LoadError(
|
|
50
|
+
f"Record contains cmcp envelope field(s) {partial_markers} but no 'cmcp_version'; "
|
|
51
|
+
"refusing to treat a partial cmcp-runtime envelope as a plain trace record"
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
return data, "trace"
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def extract_trace(record: dict[str, Any], fmt: str) -> dict[str, Any]:
|
|
58
|
+
"""Return the TRACE fields dict from *record*."""
|
|
59
|
+
if fmt == "cmcp-runtime":
|
|
60
|
+
return record["trace"]
|
|
61
|
+
return record
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Conformance check modules for TRACE trust records."""
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""TR-ANC: Transparency anchoring checks (spec §3.2)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
from urllib.parse import urlparse
|
|
7
|
+
|
|
8
|
+
from trace_tests.result import Finding, Status
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def check(trace: dict[str, Any]) -> list[Finding]:
|
|
12
|
+
"""Return TR-ANC findings for the transparency claim."""
|
|
13
|
+
findings: list[Finding] = []
|
|
14
|
+
transparency = trace.get("transparency")
|
|
15
|
+
|
|
16
|
+
if not transparency:
|
|
17
|
+
return [Finding("TR-ANC-001", Status.FAIL, "TR-ANC-001: transparency field is required at Level 2")]
|
|
18
|
+
|
|
19
|
+
if not isinstance(transparency, str):
|
|
20
|
+
return [Finding("TR-ANC-001", Status.FAIL, f"TR-ANC-001: transparency must be a string URI, got {type(transparency).__name__}")]
|
|
21
|
+
|
|
22
|
+
try:
|
|
23
|
+
parsed = urlparse(transparency)
|
|
24
|
+
if parsed.scheme == "https" and parsed.netloc:
|
|
25
|
+
findings.append(Finding("TR-ANC-001", Status.PASS, f"transparency is a valid URI ({transparency[:80]})"))
|
|
26
|
+
else:
|
|
27
|
+
findings.append(Finding(
|
|
28
|
+
"TR-ANC-001", Status.FAIL,
|
|
29
|
+
f"TR-ANC-001: transparency must be an https URI, got scheme={parsed.scheme!r}",
|
|
30
|
+
))
|
|
31
|
+
except Exception as exc:
|
|
32
|
+
findings.append(Finding("TR-ANC-001", Status.FAIL, f"TR-ANC-001: could not parse transparency URI: {exc}"))
|
|
33
|
+
|
|
34
|
+
return findings
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"""TR-ENV: EAT envelope structure checks (spec §3.2)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import time
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from trace_tests.result import Finding, Status
|
|
9
|
+
|
|
10
|
+
_PROFILE = "tag:agentrust.io,2026:trace-v0.1"
|
|
11
|
+
_IAT_MIN = 1_700_000_000
|
|
12
|
+
|
|
13
|
+
#: Default maximum record age (seconds). Records older than this fail freshness.
|
|
14
|
+
DEFAULT_MAX_AGE_SECONDS = 24 * 60 * 60
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def check(trace: dict[str, Any], max_age_seconds: int = DEFAULT_MAX_AGE_SECONDS) -> list[Finding]:
|
|
18
|
+
"""Return findings for the EAT envelope structure.
|
|
19
|
+
|
|
20
|
+
*max_age_seconds* bounds how old ``iat`` may be; without an upper bound any
|
|
21
|
+
historical record would pass freshness forever and be trivially replayable.
|
|
22
|
+
"""
|
|
23
|
+
findings: list[Finding] = []
|
|
24
|
+
|
|
25
|
+
profile = trace.get("eat_profile")
|
|
26
|
+
if profile == _PROFILE:
|
|
27
|
+
findings.append(Finding("TR-ENV-001", Status.PASS, "eat_profile sentinel matches"))
|
|
28
|
+
else:
|
|
29
|
+
findings.append(Finding("TR-ENV-001", Status.FAIL, f"eat_profile must be {_PROFILE!r}, got {profile!r}"))
|
|
30
|
+
|
|
31
|
+
iat = trace.get("iat")
|
|
32
|
+
if isinstance(iat, int) and iat >= _IAT_MIN:
|
|
33
|
+
now = int(time.time())
|
|
34
|
+
if iat > now + 60:
|
|
35
|
+
findings.append(Finding("TR-ENV-002", Status.FAIL, f"iat {iat} is in the future (now={now})"))
|
|
36
|
+
elif now - iat > max_age_seconds:
|
|
37
|
+
findings.append(Finding(
|
|
38
|
+
"TR-ENV-002", Status.FAIL,
|
|
39
|
+
f"TR-ENV-002: record is stale: iat {iat} is {now - iat}s old, "
|
|
40
|
+
f"exceeding the maximum allowed age of {max_age_seconds}s",
|
|
41
|
+
))
|
|
42
|
+
else:
|
|
43
|
+
findings.append(Finding("TR-ENV-002", Status.PASS, f"iat is valid and fresh ({iat})"))
|
|
44
|
+
else:
|
|
45
|
+
findings.append(Finding("TR-ENV-002", Status.FAIL, f"iat must be a Unix timestamp >= {_IAT_MIN}, got {iat!r}"))
|
|
46
|
+
|
|
47
|
+
subject = trace.get("subject", "")
|
|
48
|
+
if isinstance(subject, str) and subject.startswith("spiffe://"):
|
|
49
|
+
findings.append(Finding("TR-ENV-003", Status.PASS, "subject is a SPIFFE URI"))
|
|
50
|
+
else:
|
|
51
|
+
findings.append(Finding("TR-ENV-003", Status.FAIL, f"subject must start with 'spiffe://', got {subject!r}"))
|
|
52
|
+
|
|
53
|
+
cnf = trace.get("cnf")
|
|
54
|
+
if isinstance(cnf, dict) and isinstance(cnf.get("jwk"), dict) and "kty" in cnf["jwk"]:
|
|
55
|
+
findings.append(Finding("TR-ENV-004", Status.PASS, f"cnf.jwk.kty present ({cnf['jwk']['kty']!r})"))
|
|
56
|
+
else:
|
|
57
|
+
findings.append(Finding("TR-ENV-004", Status.FAIL, "cnf must contain jwk with kty"))
|
|
58
|
+
|
|
59
|
+
return findings
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""TR-POL: Policy bundle checks (spec §3.1)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from trace_tests.result import Finding, Status
|
|
9
|
+
|
|
10
|
+
_DIGEST_RE = re.compile(r"^sha(256:[0-9a-f]{64}|384:[0-9a-f]{96})$")
|
|
11
|
+
_VALID_ENFORCEMENT = frozenset({"enforce", "advisory", "silent"})
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def check(trace: dict[str, Any]) -> list[Finding]:
|
|
15
|
+
"""Return TR-POL findings for the policy bundle claim."""
|
|
16
|
+
findings: list[Finding] = []
|
|
17
|
+
policy = trace.get("policy")
|
|
18
|
+
|
|
19
|
+
if not isinstance(policy, dict):
|
|
20
|
+
return [Finding("TR-POL-001", Status.FAIL, "TR-POL-001: policy field is missing or not an object")]
|
|
21
|
+
|
|
22
|
+
bundle_hash = policy.get("bundle_hash", "")
|
|
23
|
+
if _DIGEST_RE.match(str(bundle_hash)):
|
|
24
|
+
findings.append(Finding("TR-POL-001", Status.PASS, "policy.bundle_hash has valid digest format"))
|
|
25
|
+
else:
|
|
26
|
+
findings.append(Finding(
|
|
27
|
+
"TR-POL-001", Status.FAIL,
|
|
28
|
+
f"TR-POL-001: policy.bundle_hash must match sha256:<64hex> or sha384:<96hex>, got {bundle_hash!r}",
|
|
29
|
+
))
|
|
30
|
+
|
|
31
|
+
enforcement = policy.get("enforcement_mode")
|
|
32
|
+
if enforcement in _VALID_ENFORCEMENT:
|
|
33
|
+
findings.append(Finding("TR-POL-002", Status.PASS, f"policy.enforcement_mode is valid ({enforcement!r})"))
|
|
34
|
+
else:
|
|
35
|
+
findings.append(Finding(
|
|
36
|
+
"TR-POL-002", Status.FAIL,
|
|
37
|
+
f"TR-POL-002: policy.enforcement_mode must be one of {sorted(_VALID_ENFORCEMENT)}, got {enforcement!r}",
|
|
38
|
+
))
|
|
39
|
+
|
|
40
|
+
return findings
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"""TR-RTE: Runtime / TEE platform checks (spec §3.1)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from trace_tests.result import Finding, Status
|
|
9
|
+
|
|
10
|
+
_DIGEST_RE = re.compile(r"^sha(256:[0-9a-f]{64}|384:[0-9a-f]{96})$")
|
|
11
|
+
_VALID_PLATFORMS = frozenset({
|
|
12
|
+
"intel-tdx",
|
|
13
|
+
"amd-sev-snp",
|
|
14
|
+
"nvidia-h100",
|
|
15
|
+
"nvidia-blackwell",
|
|
16
|
+
"aws-nitro",
|
|
17
|
+
"arm-cca",
|
|
18
|
+
"google-confidential-space",
|
|
19
|
+
"tpm2",
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def check(trace: dict[str, Any]) -> list[Finding]:
|
|
24
|
+
"""Return TR-RTE findings for the runtime / TEE platform claim."""
|
|
25
|
+
findings: list[Finding] = []
|
|
26
|
+
runtime = trace.get("runtime")
|
|
27
|
+
|
|
28
|
+
if not isinstance(runtime, dict):
|
|
29
|
+
return [Finding("TR-RTE-001", Status.FAIL, "TR-RTE-001: runtime field is missing or not an object")]
|
|
30
|
+
|
|
31
|
+
platform = runtime.get("platform")
|
|
32
|
+
if platform in _VALID_PLATFORMS:
|
|
33
|
+
findings.append(Finding("TR-RTE-001", Status.PASS, f"runtime.platform is registered ({platform!r})"))
|
|
34
|
+
else:
|
|
35
|
+
findings.append(Finding(
|
|
36
|
+
"TR-RTE-001", Status.FAIL,
|
|
37
|
+
f"TR-RTE-001: runtime.platform {platform!r} is not in the registered set; valid: {sorted(_VALID_PLATFORMS)}",
|
|
38
|
+
))
|
|
39
|
+
|
|
40
|
+
measurement = runtime.get("measurement", "")
|
|
41
|
+
if _DIGEST_RE.match(str(measurement)):
|
|
42
|
+
findings.append(Finding("TR-RTE-002", Status.PASS, "runtime.measurement has valid digest format"))
|
|
43
|
+
else:
|
|
44
|
+
findings.append(Finding(
|
|
45
|
+
"TR-RTE-002", Status.FAIL,
|
|
46
|
+
f"TR-RTE-002: runtime.measurement must match sha256:<64hex> or sha384:<96hex>, got {measurement!r}",
|
|
47
|
+
))
|
|
48
|
+
|
|
49
|
+
rim_uri = runtime.get("rim_uri")
|
|
50
|
+
if rim_uri is None:
|
|
51
|
+
findings.append(Finding("TR-RTE-003", Status.SKIP, "runtime.rim_uri not present (optional)"))
|
|
52
|
+
elif isinstance(rim_uri, str) and rim_uri.startswith("https://"):
|
|
53
|
+
findings.append(Finding("TR-RTE-003", Status.PASS, f"runtime.rim_uri is an https URI ({rim_uri[:60]})"))
|
|
54
|
+
else:
|
|
55
|
+
findings.append(Finding("TR-RTE-003", Status.FAIL, f"TR-RTE-003: runtime.rim_uri must be an https URI, got {rim_uri!r}"))
|
|
56
|
+
|
|
57
|
+
return findings
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"""TR-SCA: Supply-chain provenance checks (spec §3.1)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from trace_tests.result import Finding, Status
|
|
9
|
+
|
|
10
|
+
_DIGEST_RE = re.compile(r"^sha(256:[0-9a-f]{64}|384:[0-9a-f]{96})$")
|
|
11
|
+
_SLSA_LEVELS = frozenset({1, 2, 3})
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def check(trace: dict[str, Any]) -> list[Finding]:
|
|
15
|
+
"""Return TR-SCA findings for the build provenance claim."""
|
|
16
|
+
findings: list[Finding] = []
|
|
17
|
+
prov = trace.get("build_provenance")
|
|
18
|
+
|
|
19
|
+
if prov is None:
|
|
20
|
+
return [Finding("TR-SCA-001", Status.FAIL, "TR-SCA-001: build_provenance is required at Level 1+")]
|
|
21
|
+
|
|
22
|
+
if not isinstance(prov, dict):
|
|
23
|
+
return [Finding("TR-SCA-001", Status.FAIL, "TR-SCA-001: build_provenance must be an object")]
|
|
24
|
+
|
|
25
|
+
slsa_level = prov.get("slsa_level")
|
|
26
|
+
if slsa_level in _SLSA_LEVELS:
|
|
27
|
+
findings.append(Finding("TR-SCA-001", Status.PASS, f"build_provenance.slsa_level is valid ({slsa_level})"))
|
|
28
|
+
else:
|
|
29
|
+
findings.append(Finding(
|
|
30
|
+
"TR-SCA-001", Status.FAIL,
|
|
31
|
+
f"TR-SCA-001: build_provenance.slsa_level must be 1, 2, or 3, got {slsa_level!r}",
|
|
32
|
+
))
|
|
33
|
+
|
|
34
|
+
digest = prov.get("digest", "")
|
|
35
|
+
if _DIGEST_RE.match(str(digest)):
|
|
36
|
+
findings.append(Finding("TR-SCA-002", Status.PASS, "build_provenance.digest has valid digest format"))
|
|
37
|
+
else:
|
|
38
|
+
findings.append(Finding(
|
|
39
|
+
"TR-SCA-002", Status.FAIL,
|
|
40
|
+
f"TR-SCA-002: build_provenance.digest must match sha256:<64hex> or sha384:<96hex>, got {digest!r}",
|
|
41
|
+
))
|
|
42
|
+
|
|
43
|
+
return findings
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"""TR-SIG: Signature verification (spec §3.2.1).
|
|
2
|
+
|
|
3
|
+
For cmcp-runtime records: Ed25519 over canonical JSON (sorted keys, no whitespace,
|
|
4
|
+
excluding the ``signature`` field). Key is in ``trace.cnf.jwk``.
|
|
5
|
+
|
|
6
|
+
For plain trace records no signature can be cryptographically verified, so TR-SIG
|
|
7
|
+
fails closed: at any level that requires signatures (level >= 1) the result is FAIL;
|
|
8
|
+
at level 0 the result is an explicit UNVERIFIED finding so the record can never be
|
|
9
|
+
reported as cryptographically verified.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import base64
|
|
15
|
+
import json
|
|
16
|
+
from typing import Any
|
|
17
|
+
|
|
18
|
+
from trace_tests.result import Finding, Status
|
|
19
|
+
|
|
20
|
+
_SUPPORTED_KTY = {"OKP", "EC"}
|
|
21
|
+
_ED25519_CRV = "Ed25519"
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _b64url_decode(s: str) -> bytes:
|
|
25
|
+
pad = 4 - len(s) % 4
|
|
26
|
+
if pad != 4:
|
|
27
|
+
s += "=" * pad
|
|
28
|
+
return base64.urlsafe_b64decode(s)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _canonical_json(d: dict[str, Any]) -> bytes:
|
|
32
|
+
return json.dumps(d, sort_keys=True, separators=(",", ":"), ensure_ascii=True).encode()
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _verify_ed25519(pub_x: str, sig_b64: str, body: bytes) -> tuple[bool, str]:
|
|
36
|
+
try:
|
|
37
|
+
from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PublicKey
|
|
38
|
+
from cryptography.exceptions import InvalidSignature
|
|
39
|
+
except ImportError:
|
|
40
|
+
return False, "cryptography library not installed; run: pip install cryptography"
|
|
41
|
+
|
|
42
|
+
try:
|
|
43
|
+
pub_bytes = _b64url_decode(pub_x)
|
|
44
|
+
pub_key = Ed25519PublicKey.from_public_bytes(pub_bytes)
|
|
45
|
+
except Exception as exc:
|
|
46
|
+
return False, f"TR-SIG-002: invalid public key in cnf.jwk.x: {exc}"
|
|
47
|
+
|
|
48
|
+
try:
|
|
49
|
+
sig_bytes = _b64url_decode(sig_b64)
|
|
50
|
+
except Exception as exc:
|
|
51
|
+
return False, f"TR-SIG-003: invalid base64url signature: {exc}"
|
|
52
|
+
|
|
53
|
+
try:
|
|
54
|
+
pub_key.verify(sig_bytes, body)
|
|
55
|
+
return True, "Ed25519 signature verified"
|
|
56
|
+
except InvalidSignature:
|
|
57
|
+
return False, "TR-SIG-001: signature verification failed"
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def check_cmcp_runtime(record: dict[str, Any]) -> list[Finding]:
|
|
61
|
+
"""Verify the Ed25519 signature on a cmcp RuntimeClaim."""
|
|
62
|
+
findings: list[Finding] = []
|
|
63
|
+
|
|
64
|
+
sig = record.get("signature", "")
|
|
65
|
+
if not sig:
|
|
66
|
+
findings.append(Finding("TR-SIG-001", Status.FAIL, "TR-SIG-001: signature field is missing or empty"))
|
|
67
|
+
return findings
|
|
68
|
+
|
|
69
|
+
jwk = record.get("trace", {}).get("cnf", {}).get("jwk", {})
|
|
70
|
+
kty = jwk.get("kty")
|
|
71
|
+
crv = jwk.get("crv")
|
|
72
|
+
x = jwk.get("x")
|
|
73
|
+
|
|
74
|
+
if kty != "OKP" or crv != _ED25519_CRV:
|
|
75
|
+
findings.append(Finding("TR-SIG-002", Status.FAIL, f"TR-SIG-002: expected OKP/Ed25519 key, got kty={kty!r} crv={crv!r}"))
|
|
76
|
+
return findings
|
|
77
|
+
|
|
78
|
+
if not x:
|
|
79
|
+
findings.append(Finding("TR-SIG-002", Status.FAIL, "TR-SIG-002: cnf.jwk.x is missing"))
|
|
80
|
+
return findings
|
|
81
|
+
|
|
82
|
+
body = _canonical_json({k: v for k, v in record.items() if k != "signature"})
|
|
83
|
+
ok, msg = _verify_ed25519(x, sig, body)
|
|
84
|
+
status = Status.PASS if ok else Status.FAIL
|
|
85
|
+
findings.append(Finding("TR-SIG-001", status, msg))
|
|
86
|
+
return findings
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def check(trace: dict[str, Any], record: dict[str, Any], fmt: str, level: int = 0) -> list[Finding]:
|
|
90
|
+
"""Return TR-SIG findings. *record* is the full raw dict, *trace* is the extracted TRACE fields.
|
|
91
|
+
|
|
92
|
+
*level* is the conformance level being checked. Plain trace records carry no
|
|
93
|
+
verifiable signature, so they FAIL at level >= 1 and are reported UNVERIFIED
|
|
94
|
+
(never PASS) at level 0.
|
|
95
|
+
"""
|
|
96
|
+
if fmt == "cmcp-runtime":
|
|
97
|
+
return check_cmcp_runtime(record)
|
|
98
|
+
|
|
99
|
+
# Plain trace format: no signature can be cryptographically verified.
|
|
100
|
+
findings: list[Finding] = []
|
|
101
|
+
jwk = trace.get("cnf", {}).get("jwk", {})
|
|
102
|
+
kty = jwk.get("kty")
|
|
103
|
+
crv = jwk.get("crv")
|
|
104
|
+
|
|
105
|
+
if kty in _SUPPORTED_KTY:
|
|
106
|
+
label = f"kty={kty!r}" + (f", crv={crv!r}" if crv else "")
|
|
107
|
+
findings.append(Finding("TR-SIG-004", Status.PASS, f"cnf.jwk key type is supported ({label})"))
|
|
108
|
+
elif kty is None:
|
|
109
|
+
findings.append(Finding("TR-SIG-004", Status.FAIL, "TR-SIG-004: cnf.jwk.kty is missing"))
|
|
110
|
+
else:
|
|
111
|
+
findings.append(Finding(
|
|
112
|
+
"TR-SIG-004", Status.FAIL,
|
|
113
|
+
f"TR-SIG-004: unsupported key type {kty!r}; expected one of {sorted(_SUPPORTED_KTY)}",
|
|
114
|
+
))
|
|
115
|
+
|
|
116
|
+
if level >= 1:
|
|
117
|
+
findings.append(Finding(
|
|
118
|
+
"TR-SIG-005",
|
|
119
|
+
Status.FAIL,
|
|
120
|
+
f"TR-SIG-005: plain trace records carry no verifiable signature; "
|
|
121
|
+
f"Level {level} requires cryptographic signature verification (use a signed envelope, e.g. cmcp-runtime)",
|
|
122
|
+
))
|
|
123
|
+
else:
|
|
124
|
+
findings.append(Finding(
|
|
125
|
+
"TR-SIG-005",
|
|
126
|
+
Status.UNVERIFIED,
|
|
127
|
+
"TR-SIG-005: no signature present; this record is NOT cryptographically verified",
|
|
128
|
+
))
|
|
129
|
+
|
|
130
|
+
return findings
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"""TR-TXN: Tool-call transcript checks (spec §3.1, Phase 2+ records)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from trace_tests.result import Finding, Status
|
|
9
|
+
|
|
10
|
+
_DIGEST_RE = re.compile(r"^sha(256:[0-9a-f]{64}|384:[0-9a-f]{96})$")
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def check(trace: dict[str, Any]) -> list[Finding]:
|
|
14
|
+
"""Return TR-TXN findings for the tool transcript claim."""
|
|
15
|
+
findings: list[Finding] = []
|
|
16
|
+
txn = trace.get("tool_transcript")
|
|
17
|
+
|
|
18
|
+
if txn is None:
|
|
19
|
+
return [Finding("TR-TXN-001", Status.FAIL, "TR-TXN-001: tool_transcript is required at Level 2")]
|
|
20
|
+
|
|
21
|
+
if not isinstance(txn, dict):
|
|
22
|
+
return [Finding("TR-TXN-001", Status.FAIL, "TR-TXN-001: tool_transcript must be an object")]
|
|
23
|
+
|
|
24
|
+
h = txn.get("hash", "")
|
|
25
|
+
if _DIGEST_RE.match(str(h)):
|
|
26
|
+
findings.append(Finding("TR-TXN-001", Status.PASS, "tool_transcript.hash has valid digest format"))
|
|
27
|
+
else:
|
|
28
|
+
findings.append(Finding(
|
|
29
|
+
"TR-TXN-001", Status.FAIL,
|
|
30
|
+
f"TR-TXN-001: tool_transcript.hash must match sha256:<64hex> or sha384:<96hex>, got {h!r}",
|
|
31
|
+
))
|
|
32
|
+
|
|
33
|
+
call_count = txn.get("call_count")
|
|
34
|
+
if call_count is None:
|
|
35
|
+
findings.append(Finding("TR-TXN-002", Status.SKIP, "tool_transcript.call_count not present (optional)"))
|
|
36
|
+
elif isinstance(call_count, int) and call_count >= 0:
|
|
37
|
+
findings.append(Finding("TR-TXN-002", Status.PASS, f"tool_transcript.call_count is non-negative ({call_count})"))
|
|
38
|
+
else:
|
|
39
|
+
findings.append(Finding(
|
|
40
|
+
"TR-TXN-002", Status.FAIL,
|
|
41
|
+
f"TR-TXN-002: tool_transcript.call_count must be a non-negative integer, got {call_count!r}",
|
|
42
|
+
))
|
|
43
|
+
|
|
44
|
+
return findings
|
trace_tests/result.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"""Conformance finding types."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from enum import StrEnum
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class Status(StrEnum):
|
|
10
|
+
PASS = "pass"
|
|
11
|
+
FAIL = "fail"
|
|
12
|
+
SKIP = "skip"
|
|
13
|
+
# No cryptographic verification was possible. Distinct from SKIP so callers
|
|
14
|
+
# can never mistake an unverified record for a benign omission. Treated as
|
|
15
|
+
# a failure at any conformance level that requires signatures (level >= 1).
|
|
16
|
+
UNVERIFIED = "unverified"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@dataclass
|
|
20
|
+
class Finding:
|
|
21
|
+
code: str
|
|
22
|
+
status: Status
|
|
23
|
+
message: str
|
|
24
|
+
|
|
25
|
+
def passed(self) -> bool:
|
|
26
|
+
return self.status == Status.PASS
|
|
27
|
+
|
|
28
|
+
def failed(self) -> bool:
|
|
29
|
+
return self.status == Status.FAIL
|
|
30
|
+
|
|
31
|
+
def skipped(self) -> bool:
|
|
32
|
+
return self.status == Status.SKIP
|
|
33
|
+
|
|
34
|
+
def unverified(self) -> bool:
|
|
35
|
+
return self.status == Status.UNVERIFIED
|
trace_tests/runner.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"""Run conformance modules for a given level against a trust record."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from trace_tests.loader import extract_trace
|
|
8
|
+
from trace_tests.modules import tr_anc, tr_env, tr_pol, tr_rte, tr_sca, tr_sig, tr_txn
|
|
9
|
+
from trace_tests.result import Finding
|
|
10
|
+
|
|
11
|
+
# Modules that run at each level (cumulative).
|
|
12
|
+
_LEVEL_MODULES: dict[int, list[str]] = {
|
|
13
|
+
0: ["TR-ENV", "TR-SIG", "TR-POL"],
|
|
14
|
+
1: ["TR-ENV", "TR-SIG", "TR-POL", "TR-RTE", "TR-SCA"],
|
|
15
|
+
2: ["TR-ENV", "TR-SIG", "TR-POL", "TR-RTE", "TR-SCA", "TR-TXN", "TR-ANC"],
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def run(
|
|
20
|
+
record: dict[str, Any],
|
|
21
|
+
fmt: str,
|
|
22
|
+
level: int,
|
|
23
|
+
max_age_seconds: int = tr_env.DEFAULT_MAX_AGE_SECONDS,
|
|
24
|
+
) -> dict[str, list[Finding]]:
|
|
25
|
+
"""Run all modules required for *level* and return findings keyed by module ID."""
|
|
26
|
+
if level not in _LEVEL_MODULES:
|
|
27
|
+
raise ValueError(f"Unknown conformance level {level!r}; valid: 0, 1, 2")
|
|
28
|
+
|
|
29
|
+
trace = extract_trace(record, fmt)
|
|
30
|
+
results: dict[str, list[Finding]] = {}
|
|
31
|
+
|
|
32
|
+
active = set(_LEVEL_MODULES[level])
|
|
33
|
+
|
|
34
|
+
if "TR-ENV" in active:
|
|
35
|
+
results["TR-ENV"] = tr_env.check(trace, max_age_seconds=max_age_seconds)
|
|
36
|
+
|
|
37
|
+
if "TR-SIG" in active:
|
|
38
|
+
results["TR-SIG"] = tr_sig.check(trace, record, fmt, level)
|
|
39
|
+
|
|
40
|
+
if "TR-POL" in active:
|
|
41
|
+
results["TR-POL"] = tr_pol.check(trace)
|
|
42
|
+
|
|
43
|
+
if "TR-RTE" in active:
|
|
44
|
+
results["TR-RTE"] = tr_rte.check(trace)
|
|
45
|
+
|
|
46
|
+
if "TR-SCA" in active:
|
|
47
|
+
results["TR-SCA"] = tr_sca.check(trace)
|
|
48
|
+
|
|
49
|
+
if "TR-TXN" in active:
|
|
50
|
+
results["TR-TXN"] = tr_txn.check(trace)
|
|
51
|
+
|
|
52
|
+
if "TR-ANC" in active:
|
|
53
|
+
results["TR-ANC"] = tr_anc.check(trace)
|
|
54
|
+
|
|
55
|
+
return results
|