regent-httpsig 0.7.2__py3-none-any.whl → 0.8.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.
@@ -1,309 +0,0 @@
1
- Metadata-Version: 2.5
2
- Name: regent-httpsig
3
- Version: 0.7.2
4
- Summary: Verify and sign AI agent HTTP traffic in Python — RFC 9421 HTTP Message Signatures: Web Bot Auth (what OpenAI ships) and AAuth.
5
- Project-URL: Homepage, https://github.com/regent-protocol/regent-httpsig
6
- Project-URL: Repository, https://github.com/regent-protocol/regent-httpsig
7
- Project-URL: Issues, https://github.com/regent-protocol/regent-httpsig/issues
8
- Author-email: Regent Protocol <info@regentprotocol.org>
9
- License-Expression: Apache-2.0
10
- License-File: LICENSE
11
- Keywords: aauth,agent-identity,ai-agents,bot-detection,ed25519,http-message-signatures,rfc9421,web-bot-auth
12
- Classifier: Development Status :: 4 - Beta
13
- Classifier: Intended Audience :: Developers
14
- Classifier: Programming Language :: Python :: 3.11
15
- Classifier: Programming Language :: Python :: 3.12
16
- Classifier: Programming Language :: Python :: 3.13
17
- Classifier: Topic :: Internet :: WWW/HTTP
18
- Classifier: Topic :: Security :: Cryptography
19
- Classifier: Typing :: Typed
20
- Requires-Python: >=3.11
21
- Requires-Dist: cryptography>=42
22
- Requires-Dist: http-message-signatures<3,>=2.0.1
23
- Requires-Dist: httpx>=0.25
24
- Requires-Dist: typing-extensions>=4.10
25
- Provides-Extra: aauth
26
- Requires-Dist: pyjwt>=2.8.0; extra == 'aauth'
27
- Provides-Extra: fastapi
28
- Requires-Dist: fastapi>=0.100; extra == 'fastapi'
29
- Description-Content-Type: text/markdown
30
-
31
- # regent-httpsig
32
-
33
- **Verify and sign AI agent HTTP traffic in Python — the way OpenAI signs and Cloudflare verifies.**
34
- RFC 9421 · Web Bot Auth · AAuth
35
-
36
- OpenAI's agents cryptographically sign every HTTP request they make. Cloudflare, AWS WAF and
37
- Google verify those signatures. This library brings both sides of that handshake to Python:
38
- **verify** signed agents hitting your API, and **sign** your own agent's traffic so bot walls
39
- recognize it.
40
-
41
- ```bash
42
- pip install regent-httpsig
43
- ```
44
-
45
- ## Verify: know which AI agent is calling — in 5 lines
46
-
47
- ```python
48
- from fastapi import FastAPI
49
- from regent_httpsig import HttpsigVerifier
50
- from regent_httpsig.fastapi import attach, SignatureDep, VerifiedSignature
51
-
52
- app = FastAPI()
53
- attach(app, HttpsigVerifier())
54
-
55
- @app.post("/v1/orders")
56
- async def create_order(sig: VerifiedSignature | None = SignatureDep):
57
- if sig:
58
- print(sig.agent) # "https://chatgpt.com"
59
- print(sig.keyid) # RFC 7638 key thumbprint
60
- ...
61
- ```
62
-
63
- No FastAPI? The core has no framework dependencies:
64
-
65
- ```python
66
- verifier = HttpsigVerifier()
67
- sig = await verifier.verify(method, url, headers) # VerifiedSignature | None
68
- out = await verifier.verify_detailed(method, url, headers, body)
69
- # VerifiedSignature | VerificationError(code="expired_jwt", …) | None
70
- ```
71
-
72
- Verification is **enrichment by default**: no `Signature` header costs nothing, a bad
73
- signature yields `None`, and nothing ever raises on untrusted input. `verify_detailed()`
74
- says *why* with the `Signature-Error` code of draft-hardt-httpbis-signature-key exactly
75
- as AAuth -11 §11.3.4 assigns it (`invalid_signature`, `invalid_input`, `unsupported_scheme`,
76
- `unsupported_algorithm`, `invalid_key`, `unknown_key`, `issuer_missing`, `issuer_mismatch`,
77
- `invalid_jwt`, `expired_jwt`, `revoked_jwt`, `clock_skew`); `error.headers()` is the 401's
78
- header set and `error.problem()` its problem+json body. Use
79
- `regent_httpsig.fastapi.RequiredSignatureDep` when a signature must be present — the 401
80
- carries that header, or `AAuth-Requirement: requirement=agent-token` when nothing was signed.
81
-
82
- > **Behind a reverse proxy?** The agent signed the *public* URL
83
- > (`https://api.example/…`), but your ASGI server sees `http://container/…`. The FastAPI
84
- > dependency rebuilds the signed URL from `X-Forwarded-Proto` + `Host`, so make sure your
85
- > proxy forwards the scheme — nginx: `proxy_set_header X-Forwarded-Proto $scheme;`.
86
- > If signatures mysteriously fail to verify in production, check this first.
87
-
88
- ## Sign: get your agent past bot walls
89
-
90
- ```python
91
- from regent_httpsig import EgressSigner
92
-
93
- signer = EgressSigner(seed=os.environ["AGENT_KEY_SEED"],
94
- signature_agent="https://myagent.example")
95
- headers = signer.sign("POST", url, {"content-type": "application/json"})
96
- resp = httpx.post(url, json=body, headers=headers)
97
- ```
98
-
99
- Generate a key and the ready-to-publish `/.well-known/` files in one command:
100
-
101
- ```bash
102
- regent-httpsig keygen --agent https://myagent.example --out ./well-known/
103
- ```
104
-
105
- Publish the directory at `https://myagent.example/.well-known/http-message-signatures-directory`
106
- and every Web Bot Auth verifier on the internet can now identify your agent.
107
-
108
- The same key signs as an **AAuth agent** (-11 §11.3.3) — the token in `Signature-Key`,
109
- the required components covered, `Content-Digest` computed when there is a body:
110
-
111
- ```python
112
- headers = signer.sign_aauth("POST", url, {"content-type": "application/json"},
113
- token=agent_token, body=raw_body)
114
- ```
115
-
116
- and a **server** (a PS or AS calling a resource's usage or revocation endpoint, §11.3.2)
117
- signs under the `jwks_uri` scheme with `ServerSigner(seed=…, server_id="https://ps.example",
118
- dwk="aauth-person.json")` — publish `.jwks()` at your metadata document's `jwks_uri`.
119
-
120
- ## What exactly is verified
121
-
122
- | Check | Status |
123
- |---|---|
124
- | RFC 9421 Appendix B.2.6 Ed25519 vector (byte-exact) | ✅ in CI |
125
- | Web Bot Auth draft -05 A.2.2 — sf-dictionary `Signature-Agent` covered with `;key=` | ✅ in CI¹ |
126
- | Web Bot Auth A.2.3 — legacy sf-string form (**what OpenAI ships in production**) | ✅ in CI |
127
- | Sign → verify roundtrip (fresh keys, full pipeline) | ✅ in CI |
128
- | AAuth -11 agent / person / auth tokens (`cnf.jwk` proof of possession, required components, body digest, 60 s `created` window, RS-51 token time, fully-specified algs, Ed25519 + ES256 possession keys) | ✅ in CI |
129
- | AAuth -11 server scheme (`jwks_uri` with `id`/`dwk`/`kid`, `issuer_mismatch`, key rotation refetch) | ✅ in CI |
130
- | Every -11 §11.3.4 Signature-Error code, `revoked_jwt` via the revocation record, RS-52 case-exact ids | ✅ in CI |
131
- | Signed by [`aauth-signing`](https://github.com/christian-posta/aauth-python-library) (jwt scheme, keyid-less) → verified | ✅² |
132
- | Tampered request / expired signature / wrong directory key rejected | ✅ in CI |
133
-
134
- ¹ The signature bytes printed in the draft's own A.2.2 example do **not** verify over the
135
- draft's own signature base (the legacy A.2.3 vector and RFC 9421 B.2.6 both do, so the defect
136
- is in the example, not the canonicalization). Ed25519 is deterministic, so our test pins the
137
- vector re-signed with the same RFC test key over the same byte-exact base — reported upstream.
138
-
139
- ² Cross-library interop with `aauth-signing`'s jwt scheme: token layer, `cnf.jwk` proof of
140
- possession and canonicalization all verify. Its signers correctly omit the optional `keyid`
141
- parameter — which exposed an unconditional `keyid` read in the underlying RFC 9421 library
142
- that we now handle. One deviation reported upstream to `aauth-signing`: it emits the
143
- `Signature` byte sequence as base64url, while RFC 8941 requires standard base64. The
144
- keyid-less shape is pinned in CI.
145
-
146
- ## Both dialects, one verifier
147
-
148
- - **Web Bot Auth** (`draft-meunier-web-bot-auth-architecture`): key discovery via
149
- `{Signature-Agent}/.well-known/http-message-signatures-directory`. Both wire forms of
150
- `Signature-Agent` are accepted — the current sf-dictionary and the legacy bare sf-string
151
- OpenAI actually sends.
152
- - **AAuth** (`draft-hardt-oauth-aauth-protocol-11`): the agent carries its token in
153
- `Signature-Key` under the `jwt` scheme — an agent token (`aa-agent+jwt`), a person token
154
- (`aa-person+jwt`, opt-in via `HttpsigConfig.resource_url`) or an auth token
155
- (`aa-auth+jwt`, pinned via `trusted_ps`); the issuer's JWKS, discovered through
156
- `{iss}/.well-known/{dwk}`, verifies the token, the token's `cnf.jwk` verifies the request
157
- signature. Servers sign under `jwks_uri` (`id`/`dwk`/`kid`). Install with
158
- `pip install 'regent-httpsig[aauth]'`. 0.7.0 is the **-11 cut-over** — one dialect, as
159
- published: fully-specified algorithms only (RFC 9864; `EdDSA` is refused), the required
160
- covered components, the 60-second `created` window, no tolerance on `exp`, revoked tokens
161
- named as revoked. `require_fully_specified_algs=False` survives for private test rigs only.
162
- For a full-protocol AAuth implementation (both roles, all token types) see
163
- [christian-posta/aauth-python-library](https://github.com/christian-posta/aauth-python-library) —
164
- this library is the thin relying-party verifier that handles both dialects.
165
-
166
- ## Budgets: meter a spending envelope (draft-hardt-aauth-budgets)
167
-
168
- An agent can carry a PS-issued **auth token** (`typ: aa-auth+jwt`) with a
169
- `budget` claim — a spending envelope it uses offline, no per-call round trip
170
- to the control plane. The middleware does the whole resource-side checklist:
171
- verify the token against your pinned PS, atomically reserve → commit →
172
- release per request, answer with `AAuth-Budget`, and refuse exhausted
173
- envelopes with a `401` + `AAuth-Requirement` (optionally carrying your signed
174
- resource token with **one** consumption record — the presented token's
175
- `{jti, consumed}` — so one agent never learns about a sibling's spending).
176
- The cap is **per token**: a jti never draws on a sibling's grant; the
177
- `(iss, sub, aud)` key is only the per-person ledger behind records and usage:
178
-
179
- ```python
180
- from regent_httpsig import HttpsigConfig, HttpsigVerifier, InMemoryMeter
181
- from regent_httpsig.fastapi import BudgetMiddleware
182
-
183
- app.add_middleware(
184
- BudgetMiddleware,
185
- verifier=HttpsigVerifier(HttpsigConfig(
186
- resource_url="https://api.example",
187
- trusted_ps={"my-ps": "https://ps.example/jwks.json"},
188
- )),
189
- meter=InMemoryMeter(),
190
- price_fn=lambda request: PRICES.get(request.url.path), # max cost, minor units
191
- )
192
- ```
193
-
194
- The only thing the library cannot do for you is pricing (`price_fn`) — that
195
- is your domain. First known implementation of the draft; running in
196
- production on [get4agent.com](https://get4agent.com).
197
-
198
- **The August 20 additions** are covered too:
199
-
200
- - `insufficient-budget` refusals carry **`required`** — the refused request's
201
- maximum cost — so the agent lowers its bound and retries instead of guessing.
202
- - **Revocation** (-11 §11.12): `make_revocation_endpoint(meter, authenticate_ps=…)`
203
- takes the signed `POST {"jti", "exp"}`, keys the record by the caller's
204
- verified identity, answers an empty `200` always (no 404) and problem+json
205
- `invalid_request` / `unsupported_iss`. A revoked token stops spending at
206
- once, in-flight requests complete, and a later presentation is answered
207
- `401` + `Signature-Error: error=revoked_jwt` + `AAuth-Requirement:
208
- requirement=person-token` — no resource token (§11.12.5). Wire
209
- `HttpsigVerifier(is_revoked=meter.is_revoked)` so the verifier names it first.
210
- - An **expired** auth token is answered the same way with `expired_jwt`
211
- (budgets editor's copy, 6 October): nothing is served or metered, and the
212
- token's final consumption record reaches its issuer through the usage
213
- endpoint, not on the challenge.
214
- - **Streaming** responses run in the draft's cost-omitted mode: `reserved` in
215
- the header, commit when the stream ends (set `request.state.budget_cost`
216
- mid-stream if you learn the actual), and the agent recovers the exact cost
217
- from the next response's `remaining`.
218
- - The **usage endpoint** (§Usage Counters) lets your PS query consumption
219
- without the agent in the loop — scope counters (`sub`, UTC calendar buckets)
220
- and per-key `jkts` totals, optionally signed:
221
-
222
- ```python
223
- from regent_httpsig import InMemoryMeter, ResponseSigner, make_usage_endpoint
224
-
225
- async def authenticate_ps(request): # the PS signs as a server, §11.3.2
226
- return await verifier.verify_server(request.method, str(request.url),
227
- dict(request.headers), await request.body())
228
-
229
- handler = make_usage_endpoint(
230
- meter,
231
- authenticate_ps=authenticate_ps,
232
- unit="USD", decimals=6,
233
- signer=ResponseSigner(seed=SEED, server_id="https://api.example"), # dwk aauth-resource.json
234
- )
235
-
236
- @app.post("/usage")
237
- async def usage(request: Request):
238
- return await handler(request)
239
- ```
240
-
241
- - `validate_budget_grant(unit, decimals, budget_units)` enforces the resource
242
- metadata MUSTs before you mint a resource token — the "thousandfold error"
243
- guard.
244
-
245
- **Test vectors**: [`vectors/aauth-budgets-vectors.json`](vectors/aauth-budgets-vectors.json) —
246
- header serializations (including `required` and the cost-omitted streaming
247
- case), the budget object, consumption records, and a fully worked signed
248
- usage response with a fixed key, ready for cross-implementation checks.
249
-
250
- ## Security model (what a naive implementation gets wrong)
251
-
252
- The verifier fetches key directories from **attacker-nameable origins** — whoever signs a
253
- request chooses its `Signature-Agent`. regent-httpsig ships with the guard rails on:
254
-
255
- - **SSRF protection by default**: https-only, every resolved IP must be public (catches
256
- `169.254.169.254`, loopback, private ranges, DNS names mapping to internal services),
257
- redirects never followed, responses size-capped.
258
- - **Bounded caching**: per-instance TTL cache with eviction — a keyid-spam attack can't
259
- grow memory; failures are negative-cached so a dead origin can't be used to slow you down.
260
- - **A valid signature proves key possession — not trustworthiness.** `VerifiedSignature.trusted`
261
- reflects only your configured allow-list; deciding *whether to trust* a key is your policy
262
- layer's job.
263
-
264
- Known sharp edges of the underlying ecosystem, already handled: the upstream
265
- `http-message-signatures` library cannot resolve RFC 9421 `;key=` dictionary members (we
266
- provide the component resolver), it looks up header names case-sensitively while ASGI
267
- frameworks lowercase them (we wrap), and it forgets to declare `typing_extensions` (we
268
- declare it).
269
-
270
- ## Configuration
271
-
272
- ```python
273
- from regent_httpsig import HttpsigConfig, HttpsigVerifier
274
-
275
- verifier = HttpsigVerifier(HttpsigConfig(
276
- trusted_agents=frozenset({"https://chatgpt.com", "https://operator.openai.com"}),
277
- max_age_hours=25, # Web Bot Auth: reject signatures created earlier than this
278
- signature_window_seconds=60, # AAuth -11: the `created` window (advertise as signature_window)
279
- resource_url="https://api.example", # accept person / auth tokens for us
280
- trusted_ps={"https://ps.example": ""}, # pinned issuers ("" = discover the JWKS)
281
- cache_ttl=600, # key-directory cache seconds
282
- ), is_revoked=meter.is_revoked) # optional: name revoked tokens as revoked
283
- ```
284
-
285
- Pass your app's shared client to reuse its pool: `HttpsigVerifier(http_client=my_async_client)`.
286
-
287
- ## Honest limitations
288
-
289
- - Web Bot Auth and AAuth are **IETF drafts** (RFC 9421 itself is a final standard). We track
290
- the drafts; breaking draft changes land as minor releases while we're 0.x.
291
- - Web Bot Auth is **Ed25519 only** — it's what the agent ecosystem ships. AAuth
292
- possession keys may be Ed25519 or P-256 (ES256); RS256 is accepted for issuer keys.
293
- - On the AAuth path a request with a body **must** cover `content-digest` and
294
- `content-type` (-11 §11.3.3.1) and the digest is checked against the body you pass;
295
- the FastAPI layer reads the body for you. Web Bot Auth keeps its per-route choice.
296
- - Not in 0.7.0: issuing person/resource tokens, missions, the `202` deferred
297
- `requirement=auth-token`, federated mode — the PS half of the protocol.
298
-
299
- ## Related projects
300
-
301
- [cloudflare/web-bot-auth](https://github.com/cloudflare/web-bot-auth) (TypeScript/Rust) ·
302
- [christian-posta/aauth-python-library](https://github.com/christian-posta/aauth-python-library)
303
- (full AAuth protocol) · [pyauth/http-message-signatures](https://github.com/pyauth/http-message-signatures)
304
- (the RFC 9421 primitive this builds on)
305
-
306
- ---
307
-
308
- Built and battle-tested in production by [Regent Protocol](https://regentprotocol.org) —
309
- runtime control and identity for AI agents. Apache-2.0.
@@ -1,17 +0,0 @@
1
- regent_httpsig/__init__.py,sha256=sf-Xv-BhospFQimivhZiolMrlvGU0f6zjdt9Y9sji1Y,2191
2
- regent_httpsig/budget.py,sha256=o4RMS8v9CfDXZlu3Ov_CWB798B-9mc5x4M_I3jj1MGA,21988
3
- regent_httpsig/cli.py,sha256=WUSLQ2WuEX4E85L2C2EgoUfu5cWpj6MRSG1UVNHpzcw,2005
4
- regent_httpsig/config.py,sha256=7fyIKZeUWs4BIJfc0TXJA_5P_v4-Z7iCFdEkmu_E9-E,3537
5
- regent_httpsig/fastapi.py,sha256=gGUi08yMahtgRrOWN_339lm2Ano0Gu-zjRLAK81bXl0,21581
6
- regent_httpsig/jwk.py,sha256=h4vgnIgpnyKeWdWpm7g_hEyXZOPVREWn-bD4JN07tT0,1637
7
- regent_httpsig/netguard.py,sha256=Sqg08mdC94RWvnQLJaH4weZW0nN2VlTJF5wVF8VYGHY,2121
8
- regent_httpsig/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
- regent_httpsig/sfv.py,sha256=C8CVW8-3uSRZ6-Vy3lQANxDm-wuJU6XLDGL5mtISmLE,10450
10
- regent_httpsig/sign.py,sha256=myqUIhWe2y62DGhvyDzTPPlXKfta8EpHskpM0nJzbqk,13180
11
- regent_httpsig/usage.py,sha256=6qeN7_4a-cNTJOglcgKumqNmag8w7-UF9xTJ1ohI5uU,14818
12
- regent_httpsig/verify.py,sha256=fwsCWiKclez-KQzrIRwMNDdN4bpPbI45cxIU6_lqxCA,34783
13
- regent_httpsig-0.7.2.dist-info/METADATA,sha256=2bjPlpTB7-cvIsNbmak2zvh7QWblEAKTeLju2J0pKRY,15982
14
- regent_httpsig-0.7.2.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
15
- regent_httpsig-0.7.2.dist-info/entry_points.txt,sha256=SgZdmc27V14IAmwOjbBoCYLsbrALaqdTUHNHLbil2dU,59
16
- regent_httpsig-0.7.2.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
17
- regent_httpsig-0.7.2.dist-info/RECORD,,