client-attestation-sdk 0.2.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 (59) hide show
  1. client_attestation_sdk-0.2.0/LICENSE +202 -0
  2. client_attestation_sdk-0.2.0/PKG-INFO +157 -0
  3. client_attestation_sdk-0.2.0/README.md +122 -0
  4. client_attestation_sdk-0.2.0/pyproject.toml +57 -0
  5. client_attestation_sdk-0.2.0/setup.cfg +4 -0
  6. client_attestation_sdk-0.2.0/src/authz_challenge/__init__.py +55 -0
  7. client_attestation_sdk-0.2.0/src/authz_challenge/challenge.py +265 -0
  8. client_attestation_sdk-0.2.0/src/authz_challenge/ciba.py +346 -0
  9. client_attestation_sdk-0.2.0/src/authz_challenge/py.typed +0 -0
  10. client_attestation_sdk-0.2.0/src/authz_challenge/resolver.py +1030 -0
  11. client_attestation_sdk-0.2.0/src/client_attestation_sdk/__init__.py +83 -0
  12. client_attestation_sdk-0.2.0/src/client_attestation_sdk/_http.py +148 -0
  13. client_attestation_sdk-0.2.0/src/client_attestation_sdk/builders.py +244 -0
  14. client_attestation_sdk-0.2.0/src/client_attestation_sdk/credential.py +38 -0
  15. client_attestation_sdk-0.2.0/src/client_attestation_sdk/errors.py +20 -0
  16. client_attestation_sdk-0.2.0/src/client_attestation_sdk/evidence.py +208 -0
  17. client_attestation_sdk-0.2.0/src/client_attestation_sdk/issuance.py +109 -0
  18. client_attestation_sdk-0.2.0/src/client_attestation_sdk/keys.py +100 -0
  19. client_attestation_sdk-0.2.0/src/client_attestation_sdk/py.typed +0 -0
  20. client_attestation_sdk-0.2.0/src/client_attestation_sdk/signer.py +137 -0
  21. client_attestation_sdk-0.2.0/src/client_attestation_sdk/spiffe.py +144 -0
  22. client_attestation_sdk-0.2.0/src/client_attestation_sdk/svid_source.py +75 -0
  23. client_attestation_sdk-0.2.0/src/client_attestation_sdk/token_source.py +536 -0
  24. client_attestation_sdk-0.2.0/src/client_attestation_sdk.egg-info/PKG-INFO +157 -0
  25. client_attestation_sdk-0.2.0/src/client_attestation_sdk.egg-info/SOURCES.txt +57 -0
  26. client_attestation_sdk-0.2.0/src/client_attestation_sdk.egg-info/dependency_links.txt +1 -0
  27. client_attestation_sdk-0.2.0/src/client_attestation_sdk.egg-info/requires.txt +15 -0
  28. client_attestation_sdk-0.2.0/src/client_attestation_sdk.egg-info/top_level.txt +3 -0
  29. client_attestation_sdk-0.2.0/src/token_validator/__init__.py +22 -0
  30. client_attestation_sdk-0.2.0/src/token_validator/config.py +52 -0
  31. client_attestation_sdk-0.2.0/src/token_validator/discovery.py +19 -0
  32. client_attestation_sdk-0.2.0/src/token_validator/errors.py +18 -0
  33. client_attestation_sdk-0.2.0/src/token_validator/jwks.py +122 -0
  34. client_attestation_sdk-0.2.0/src/token_validator/py.typed +0 -0
  35. client_attestation_sdk-0.2.0/src/token_validator/resource.py +133 -0
  36. client_attestation_sdk-0.2.0/src/token_validator/result.py +35 -0
  37. client_attestation_sdk-0.2.0/src/token_validator/validator.py +158 -0
  38. client_attestation_sdk-0.2.0/tests/test_authz_challenge_ciba.py +237 -0
  39. client_attestation_sdk-0.2.0/tests/test_authz_challenge_hardening.py +450 -0
  40. client_attestation_sdk-0.2.0/tests/test_authz_challenge_parse.py +84 -0
  41. client_attestation_sdk-0.2.0/tests/test_authz_challenge_proofing.py +282 -0
  42. client_attestation_sdk-0.2.0/tests/test_authz_challenge_resolver.py +325 -0
  43. client_attestation_sdk-0.2.0/tests/test_builders.py +187 -0
  44. client_attestation_sdk-0.2.0/tests/test_dpop_bound_token.py +338 -0
  45. client_attestation_sdk-0.2.0/tests/test_evidence_detect.py +333 -0
  46. client_attestation_sdk-0.2.0/tests/test_http_transport.py +404 -0
  47. client_attestation_sdk-0.2.0/tests/test_issuance.py +66 -0
  48. client_attestation_sdk-0.2.0/tests/test_jwks_discovery.py +249 -0
  49. client_attestation_sdk-0.2.0/tests/test_keys.py +40 -0
  50. client_attestation_sdk-0.2.0/tests/test_openbao.py +148 -0
  51. client_attestation_sdk-0.2.0/tests/test_resource.py +96 -0
  52. client_attestation_sdk-0.2.0/tests/test_roundtrip.py +79 -0
  53. client_attestation_sdk-0.2.0/tests/test_signer_failures.py +112 -0
  54. client_attestation_sdk-0.2.0/tests/test_spiffe.py +73 -0
  55. client_attestation_sdk-0.2.0/tests/test_token_source.py +302 -0
  56. client_attestation_sdk-0.2.0/tests/test_token_source_hardening.py +239 -0
  57. client_attestation_sdk-0.2.0/tests/test_validator.py +79 -0
  58. client_attestation_sdk-0.2.0/tests/test_validator_edge_cases.py +214 -0
  59. client_attestation_sdk-0.2.0/tests/test_validator_header_safety.py +97 -0
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,157 @@
1
+ Metadata-Version: 2.4
2
+ Name: client-attestation-sdk
3
+ Version: 0.2.0
4
+ Summary: Client-side builder SDK for OAuth Attestation-Based Client Authentication
5
+ Author: ID Partners Pty Ltd
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/ID-Partners/client-attestation-sdk
8
+ Project-URL: Source, https://github.com/ID-Partners/client-attestation-sdk/tree/main/python
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3 :: Only
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Topic :: Security
19
+ Classifier: Typing :: Typed
20
+ Requires-Python: >=3.10
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Requires-Dist: pyjwt>=2.8
24
+ Requires-Dist: cryptography>=42
25
+ Provides-Extra: test
26
+ Requires-Dist: pytest>=7; extra == "test"
27
+ Requires-Dist: pytest-cov>=5; extra == "test"
28
+ Provides-Extra: httpx
29
+ Requires-Dist: httpx>=0.24; extra == "httpx"
30
+ Provides-Extra: requests
31
+ Requires-Dist: requests>=2.28; extra == "requests"
32
+ Provides-Extra: aws
33
+ Requires-Dist: boto3; extra == "aws"
34
+ Dynamic: license-file
35
+
36
+ # client-attestation-sdk (Python)
37
+
38
+ Client-side builder for **OAuth Attestation-Based Client Authentication**
39
+ (draft-ietf-oauth-attestation-based-client-auth). Mints the Client Attestation JWT (attester side) and the
40
+ PoP / DPoP proofs + request headers (client side). Depends only on `pyjwt` + `cryptography`.
41
+
42
+ Part of the [client-attestation-sdk](../README.md) monorepo; wire-compatible with the Java,
43
+ TypeScript, and Go ports.
44
+
45
+ ## Install
46
+
47
+ Not on PyPI yet. Install from a clone of this repository:
48
+
49
+ ```bash
50
+ pip install -e '.[test]'
51
+ ```
52
+
53
+ ## Use
54
+
55
+ ```python
56
+ from client_attestation_sdk import (
57
+ SigningKeyPair, ClientAttestationBuilder, ClientAttestationCredential,
58
+ )
59
+
60
+ # Attester issues the attestation, binding the client's public instance key
61
+ attester = SigningKeyPair.generate("ES256")
62
+ attestation = (
63
+ ClientAttestationBuilder(attester, "https://attester.example.com")
64
+ .client_id("https://rp.example.com")
65
+ .confirmation_jwk(client_instance_public_jwk)
66
+ .expires_in(300)
67
+ # optional: .authorization_details(...) / .workload(...) / .operator(sub, issuer=None) —
68
+ # operator names who's accountable for running the client (RFC 8693 may_act-shaped; an
69
+ # assertion, not proof of authorisation), distinct from client_id and from the principal.
70
+ .build()
71
+ )
72
+
73
+ # Client mints a fresh proof per token request
74
+ instance = SigningKeyPair.from_jwk(my_instance_private_jwk, "ES256")
75
+ cred = ClientAttestationCredential(attestation, instance)
76
+
77
+ headers = cred.pop_headers("https://rp.example.com", "https://as.example.com") # PoP-JWT mode
78
+ # or
79
+ headers = cred.dpop_headers("POST", "https://as.example.com/as/token.oauth2") # DPoP combined mode
80
+ # -> {"OAuth-Client-Attestation": "...", "OAuth-Client-Attestation-PoP" | "DPoP": "..."}
81
+ ```
82
+
83
+ The one-call `ClientAttestation` orchestration class (see the [root README](../README.md#get-a-token-in-one-call))
84
+ wraps this: `ClientAttestation(host, pop_method="dpop_combined")` switches it to DPoP mode, and a fetched
85
+ challenge is carried through automatically as the PoP JWT's `challenge` claim or the DPoP proof's `nonce`
86
+ claim, whichever mode is active.
87
+
88
+ In DPoP mode the AS can issue a DPoP-bound token (`token_type: DPoP`). Use `ca.request_headers(method, url)`
89
+ to get `Authorization: DPoP <token>` plus a fresh `DPoP` proof (with `ath` and any nonce the resource asked
90
+ for), or `ca.requests_auth()` / `ca.httpx_auth()`, which also re-send once on a `use_dpop_nonce` challenge.
91
+ Bearer tokens get just the `Authorization` header, as before.
92
+
93
+ Other options on `ClientAttestation`:
94
+
95
+ - `require_challenge=True` (default) - if the attester advertises a challenge endpoint and it fails, the flow
96
+ fails rather than minting without a challenge. `False` restores the old lenient behaviour.
97
+ - `allow_insecure=False` (default) - `pf_host` and the discovered endpoints must be https, except loopback.
98
+ - `trace=[...]` with `trace_redact=True` (default) - each wire call is recorded as a shell-quoted curl string
99
+ with every credential replaced by `<redacted:N bytes>`. `trace_redact=False` records them verbatim - for
100
+ local debugging only.
101
+
102
+ `CLIENT_ATTESTATION_TOKEN_FILE` or `SPIFFE_ENDPOINT_SOCKET` set to a path that does not exist now raises
103
+ `EvidenceNotFound` naming the variable, instead of falling through to the next evidence source.
104
+
105
+ ## Token validator
106
+
107
+ The same distribution ships a resource-server validator (`token_validator`) — the side that *receives* and
108
+ checks a token:
109
+
110
+ ```python
111
+ from token_validator import AccessTokenValidator, ValidatorConfig
112
+
113
+ validator = AccessTokenValidator(ValidatorConfig(
114
+ issuer="https://issuer.example.com", audiences=["https://api.example.com"],
115
+ jwks_uri="https://issuer.example.com/jwks", required_scopes=["read"]))
116
+
117
+ result = validator.validate(access_token) # signature + iss/exp/nbf + audience + scope
118
+ if result.valid:
119
+ print(result.subject, result.scopes)
120
+ else:
121
+ print(result.error) # e.g. "expired", "insufficient_scope"
122
+
123
+ # optional RFC 7662 introspection (opaque tokens / revocation):
124
+ result = validator.validate_active(access_token)
125
+ ```
126
+
127
+ ## SPIFFE workload identity → attestation bridge
128
+
129
+ `client_attestation_sdk.spiffe` is a lightweight, standards-shaped stand-in for a SPIRE **agent**'s
130
+ Workload API. It attests a workload by selector match and issues a **JWT-SVID** (`sub` = the SPIFFE ID,
131
+ signed by the trust domain), alongside the workload's **attested attributes** — which then become the
132
+ `workload` claim of a Client Attestation, so the AS discloses SPIFFE-attested attributes instead of static
133
+ metadata. Maps 1:1 onto real SPIRE later; only the transport differs.
134
+
135
+ ```python
136
+ from client_attestation_sdk import SpiffeAgent, SigningKeyPair, ClientAttestationBuilder, to_workload_claim
137
+
138
+ agent = SpiffeAgent("banking.demo", SigningKeyPair.generate("ES256"))
139
+ agent.register({"docker:label:app": "payment-agent"}, "payment-agent",
140
+ {"region": "emea", "entitlements": ["initiate_payment"]})
141
+
142
+ svid = agent.fetch_jwt_svid({"docker:label:app": "payment-agent"}, audience="https://as.example.com")
143
+ attestation = (ClientAttestationBuilder(attester, "https://attester.example.com")
144
+ .client_id(svid.spiffe_id).confirmation_key(instance)
145
+ .workload(to_workload_claim(svid)) # SPIFFE ID + attested attributes + the SVID
146
+ .expires_in(300).build())
147
+ ```
148
+
149
+ Runnable end to end: `PYTHONPATH=src python3 examples/spiffe_bridge.py`. Verify a JWT-SVID against the
150
+ trust bundle with `verify_jwt_svid(token, agent.trust_bundle(), audience, trust_domain)`.
151
+
152
+ ## Test
153
+
154
+ ```bash
155
+ pip install -e .[test]
156
+ pytest
157
+ ```
@@ -0,0 +1,122 @@
1
+ # client-attestation-sdk (Python)
2
+
3
+ Client-side builder for **OAuth Attestation-Based Client Authentication**
4
+ (draft-ietf-oauth-attestation-based-client-auth). Mints the Client Attestation JWT (attester side) and the
5
+ PoP / DPoP proofs + request headers (client side). Depends only on `pyjwt` + `cryptography`.
6
+
7
+ Part of the [client-attestation-sdk](../README.md) monorepo; wire-compatible with the Java,
8
+ TypeScript, and Go ports.
9
+
10
+ ## Install
11
+
12
+ Not on PyPI yet. Install from a clone of this repository:
13
+
14
+ ```bash
15
+ pip install -e '.[test]'
16
+ ```
17
+
18
+ ## Use
19
+
20
+ ```python
21
+ from client_attestation_sdk import (
22
+ SigningKeyPair, ClientAttestationBuilder, ClientAttestationCredential,
23
+ )
24
+
25
+ # Attester issues the attestation, binding the client's public instance key
26
+ attester = SigningKeyPair.generate("ES256")
27
+ attestation = (
28
+ ClientAttestationBuilder(attester, "https://attester.example.com")
29
+ .client_id("https://rp.example.com")
30
+ .confirmation_jwk(client_instance_public_jwk)
31
+ .expires_in(300)
32
+ # optional: .authorization_details(...) / .workload(...) / .operator(sub, issuer=None) —
33
+ # operator names who's accountable for running the client (RFC 8693 may_act-shaped; an
34
+ # assertion, not proof of authorisation), distinct from client_id and from the principal.
35
+ .build()
36
+ )
37
+
38
+ # Client mints a fresh proof per token request
39
+ instance = SigningKeyPair.from_jwk(my_instance_private_jwk, "ES256")
40
+ cred = ClientAttestationCredential(attestation, instance)
41
+
42
+ headers = cred.pop_headers("https://rp.example.com", "https://as.example.com") # PoP-JWT mode
43
+ # or
44
+ headers = cred.dpop_headers("POST", "https://as.example.com/as/token.oauth2") # DPoP combined mode
45
+ # -> {"OAuth-Client-Attestation": "...", "OAuth-Client-Attestation-PoP" | "DPoP": "..."}
46
+ ```
47
+
48
+ The one-call `ClientAttestation` orchestration class (see the [root README](../README.md#get-a-token-in-one-call))
49
+ wraps this: `ClientAttestation(host, pop_method="dpop_combined")` switches it to DPoP mode, and a fetched
50
+ challenge is carried through automatically as the PoP JWT's `challenge` claim or the DPoP proof's `nonce`
51
+ claim, whichever mode is active.
52
+
53
+ In DPoP mode the AS can issue a DPoP-bound token (`token_type: DPoP`). Use `ca.request_headers(method, url)`
54
+ to get `Authorization: DPoP <token>` plus a fresh `DPoP` proof (with `ath` and any nonce the resource asked
55
+ for), or `ca.requests_auth()` / `ca.httpx_auth()`, which also re-send once on a `use_dpop_nonce` challenge.
56
+ Bearer tokens get just the `Authorization` header, as before.
57
+
58
+ Other options on `ClientAttestation`:
59
+
60
+ - `require_challenge=True` (default) - if the attester advertises a challenge endpoint and it fails, the flow
61
+ fails rather than minting without a challenge. `False` restores the old lenient behaviour.
62
+ - `allow_insecure=False` (default) - `pf_host` and the discovered endpoints must be https, except loopback.
63
+ - `trace=[...]` with `trace_redact=True` (default) - each wire call is recorded as a shell-quoted curl string
64
+ with every credential replaced by `<redacted:N bytes>`. `trace_redact=False` records them verbatim - for
65
+ local debugging only.
66
+
67
+ `CLIENT_ATTESTATION_TOKEN_FILE` or `SPIFFE_ENDPOINT_SOCKET` set to a path that does not exist now raises
68
+ `EvidenceNotFound` naming the variable, instead of falling through to the next evidence source.
69
+
70
+ ## Token validator
71
+
72
+ The same distribution ships a resource-server validator (`token_validator`) — the side that *receives* and
73
+ checks a token:
74
+
75
+ ```python
76
+ from token_validator import AccessTokenValidator, ValidatorConfig
77
+
78
+ validator = AccessTokenValidator(ValidatorConfig(
79
+ issuer="https://issuer.example.com", audiences=["https://api.example.com"],
80
+ jwks_uri="https://issuer.example.com/jwks", required_scopes=["read"]))
81
+
82
+ result = validator.validate(access_token) # signature + iss/exp/nbf + audience + scope
83
+ if result.valid:
84
+ print(result.subject, result.scopes)
85
+ else:
86
+ print(result.error) # e.g. "expired", "insufficient_scope"
87
+
88
+ # optional RFC 7662 introspection (opaque tokens / revocation):
89
+ result = validator.validate_active(access_token)
90
+ ```
91
+
92
+ ## SPIFFE workload identity → attestation bridge
93
+
94
+ `client_attestation_sdk.spiffe` is a lightweight, standards-shaped stand-in for a SPIRE **agent**'s
95
+ Workload API. It attests a workload by selector match and issues a **JWT-SVID** (`sub` = the SPIFFE ID,
96
+ signed by the trust domain), alongside the workload's **attested attributes** — which then become the
97
+ `workload` claim of a Client Attestation, so the AS discloses SPIFFE-attested attributes instead of static
98
+ metadata. Maps 1:1 onto real SPIRE later; only the transport differs.
99
+
100
+ ```python
101
+ from client_attestation_sdk import SpiffeAgent, SigningKeyPair, ClientAttestationBuilder, to_workload_claim
102
+
103
+ agent = SpiffeAgent("banking.demo", SigningKeyPair.generate("ES256"))
104
+ agent.register({"docker:label:app": "payment-agent"}, "payment-agent",
105
+ {"region": "emea", "entitlements": ["initiate_payment"]})
106
+
107
+ svid = agent.fetch_jwt_svid({"docker:label:app": "payment-agent"}, audience="https://as.example.com")
108
+ attestation = (ClientAttestationBuilder(attester, "https://attester.example.com")
109
+ .client_id(svid.spiffe_id).confirmation_key(instance)
110
+ .workload(to_workload_claim(svid)) # SPIFFE ID + attested attributes + the SVID
111
+ .expires_in(300).build())
112
+ ```
113
+
114
+ Runnable end to end: `PYTHONPATH=src python3 examples/spiffe_bridge.py`. Verify a JWT-SVID against the
115
+ trust bundle with `verify_jwt_svid(token, agent.trust_bundle(), audience, trust_domain)`.
116
+
117
+ ## Test
118
+
119
+ ```bash
120
+ pip install -e .[test]
121
+ pytest
122
+ ```
@@ -0,0 +1,57 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "client-attestation-sdk"
7
+ version = "0.2.0"
8
+ description = "Client-side builder SDK for OAuth Attestation-Based Client Authentication"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = "Apache-2.0"
12
+ license-files = ["LICENSE"]
13
+ authors = [{ name = "ID Partners Pty Ltd" }]
14
+ classifiers = [
15
+ "Development Status :: 4 - Beta",
16
+ "Intended Audience :: Developers",
17
+ "Operating System :: OS Independent",
18
+ "Programming Language :: Python :: 3",
19
+ "Programming Language :: Python :: 3 :: Only",
20
+ "Programming Language :: Python :: 3.10",
21
+ "Programming Language :: Python :: 3.11",
22
+ "Programming Language :: Python :: 3.12",
23
+ "Programming Language :: Python :: 3.13",
24
+ "Topic :: Security",
25
+ "Typing :: Typed",
26
+ ]
27
+ dependencies = [
28
+ "pyjwt>=2.8",
29
+ "cryptography>=42",
30
+ ]
31
+
32
+ [project.urls]
33
+ Homepage = "https://github.com/ID-Partners/client-attestation-sdk"
34
+ Source = "https://github.com/ID-Partners/client-attestation-sdk/tree/main/python"
35
+
36
+ [project.optional-dependencies]
37
+ test = ["pytest>=7", "pytest-cov>=5"]
38
+ # Optional integrations. The core never imports these at module load; each is imported only by the
39
+ # feature that needs it.
40
+ httpx = ["httpx>=0.24"] # ClientAttestation.httpx_auth()
41
+ requests = ["requests>=2.28"] # ClientAttestation.requests_auth() is a requests auth hook
42
+ aws = ["boto3"] # AwsWebIdentitySvidSource (sts:GetWebIdentityToken)
43
+
44
+ [tool.setuptools.packages.find]
45
+ where = ["src"]
46
+
47
+ [tool.setuptools.package-data]
48
+ client_attestation_sdk = ["py.typed"]
49
+ token_validator = ["py.typed"]
50
+ authz_challenge = ["py.typed"]
51
+
52
+ [tool.coverage.run]
53
+ source = ["client_attestation_sdk", "token_validator", "authz_challenge"]
54
+
55
+ [tool.coverage.report]
56
+ # today's measured coverage; raise it, never lower it
57
+ fail_under = 94
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,55 @@
1
+ """Agent-side handling of a policy enforcement point's AUTHORIZATION CHALLENGES.
2
+
3
+ When a PEP will not let a call proceed as presented, it does not simply deny — it says what would
4
+ make the call permissible: an authenticated user, a specific authorisation for THIS instruction, a
5
+ verified credential, a consent, a lodged intent. This package is the client half of that
6
+ conversation:
7
+
8
+ * :func:`parse_challenge` — turn whatever the PEP said (REST status + ``WWW-Authenticate`` + body,
9
+ a JSON-RPC error, an MCP tool result) into one typed :class:`Challenge`. Pure; vector-pinned across
10
+ language ports.
11
+ * :class:`CibaClient` — the OpenID CIBA client: raise a decoupled push to the human's authenticator
12
+ and poll for the answer at the AS's cadence (the pacing rules are the part everyone gets wrong).
13
+ * :class:`CibaResolver` / :class:`WebConsentResolver` — the ceremony state machines: dedupe, channel
14
+ choice, push, settle, terminal record, and verification that a resumed call matches what the human
15
+ approved. Deployment edges (directories, device registries) are injected via :class:`Hooks`.
16
+
17
+ Vocabulary is fixed in :mod:`.challenge` (challenge types) and :mod:`.resolver` (statuses,
18
+ channels, assurance rungs the resolver may claim).
19
+ """
20
+ from . import challenge as _challenge
21
+ from . import ciba as _ciba
22
+ from . import resolver as _resolver
23
+ from .challenge import (
24
+ AUTHN, CHALLENGE_TYPES, CONSENT, IDENTITY_PROOFING, INTENT, RESOURCE_AUTHORISATION,
25
+ Challenge, parse_challenge, parse_www_authenticate,
26
+ )
27
+ from .ciba import (
28
+ APPROVED, CIBA_GRANT, DENIED, EXPIRED, PENDING,
29
+ CibaClient, CibaError, CibaRequest, ClientAuth, PrivateKeyJwtAuth,
30
+ private_key_jwt_assertion, urllib_http,
31
+ )
32
+ from .resolver import (
33
+ ASSURANCE_DEVICE_APPROVED, ASSURANCE_WEB_CONSENT, CHANNEL_DEVICE, CHANNEL_LOCAL, CHANNEL_WEB,
34
+ TERMINAL, Ceremony, CeremonyStore, ChallengeResolver, CibaResolver, Hooks, MemoryStore,
35
+ Pending, PollResult, ProofingResolver, Resolved, Unavailable, WebConsentResolver,
36
+ SUBJECT_KEY, new_code, new_handle, transaction_hash,
37
+ )
38
+
39
+ __all__ = [
40
+ # challenge
41
+ "Challenge", "parse_challenge", "parse_www_authenticate", "CHALLENGE_TYPES",
42
+ "AUTHN", "RESOURCE_AUTHORISATION", "CONSENT", "IDENTITY_PROOFING", "INTENT",
43
+ # ciba
44
+ "CibaClient", "CibaError", "CibaRequest", "ClientAuth", "PrivateKeyJwtAuth",
45
+ "private_key_jwt_assertion", "urllib_http", "CIBA_GRANT",
46
+ "PENDING", "APPROVED", "DENIED", "EXPIRED",
47
+ # resolver
48
+ "ChallengeResolver", "CibaResolver", "WebConsentResolver", "ProofingResolver", "Hooks",
49
+ "Ceremony", "CeremonyStore", "MemoryStore",
50
+ "Pending", "Resolved", "Unavailable", "PollResult",
51
+ "transaction_hash", "new_code", "new_handle", "SUBJECT_KEY", "TERMINAL",
52
+ "CHANNEL_DEVICE", "CHANNEL_WEB", "CHANNEL_LOCAL",
53
+ "ASSURANCE_DEVICE_APPROVED", "ASSURANCE_WEB_CONSENT",
54
+ ]
55
+ __version__ = "0.2.0"