regent-httpsig 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- regent_httpsig-0.1.0/.github/workflows/ci.yml +22 -0
- regent_httpsig-0.1.0/.github/workflows/release.yml +33 -0
- regent_httpsig-0.1.0/.gitignore +8 -0
- regent_httpsig-0.1.0/CHANGELOG.md +23 -0
- regent_httpsig-0.1.0/LICENSE +202 -0
- regent_httpsig-0.1.0/PKG-INFO +176 -0
- regent_httpsig-0.1.0/README.md +146 -0
- regent_httpsig-0.1.0/SECURITY.md +22 -0
- regent_httpsig-0.1.0/examples/fastapi_verify.py +29 -0
- regent_httpsig-0.1.0/examples/httpx_signer.py +25 -0
- regent_httpsig-0.1.0/pyproject.toml +79 -0
- regent_httpsig-0.1.0/src/regent_httpsig/__init__.py +31 -0
- regent_httpsig-0.1.0/src/regent_httpsig/cli.py +55 -0
- regent_httpsig-0.1.0/src/regent_httpsig/config.py +32 -0
- regent_httpsig-0.1.0/src/regent_httpsig/fastapi.py +94 -0
- regent_httpsig-0.1.0/src/regent_httpsig/jwk.py +46 -0
- regent_httpsig-0.1.0/src/regent_httpsig/netguard.py +62 -0
- regent_httpsig-0.1.0/src/regent_httpsig/sfv.py +132 -0
- regent_httpsig-0.1.0/src/regent_httpsig/sign.py +121 -0
- regent_httpsig-0.1.0/src/regent_httpsig/verify.py +342 -0
- regent_httpsig-0.1.0/tests/test_netguard.py +35 -0
- regent_httpsig-0.1.0/tests/test_signer.py +36 -0
- regent_httpsig-0.1.0/tests/test_vectors.py +231 -0
- regent_httpsig-0.1.0/tests/test_verifier.py +150 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
test:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
strategy:
|
|
12
|
+
matrix:
|
|
13
|
+
python-version: ["3.11", "3.12", "3.13"]
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v4
|
|
16
|
+
- uses: actions/setup-python@v5
|
|
17
|
+
with:
|
|
18
|
+
python-version: ${{ matrix.python-version }}
|
|
19
|
+
- run: python -m pip install -e ".[aauth,fastapi]" pytest pytest-asyncio ruff mypy
|
|
20
|
+
- run: ruff check src tests
|
|
21
|
+
- run: mypy src
|
|
22
|
+
- run: pytest -q
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags: ["v*"]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
build:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
steps:
|
|
11
|
+
- uses: actions/checkout@v4
|
|
12
|
+
- uses: actions/setup-python@v5
|
|
13
|
+
with:
|
|
14
|
+
python-version: "3.12"
|
|
15
|
+
- run: python -m pip install build
|
|
16
|
+
- run: python -m build
|
|
17
|
+
- uses: actions/upload-artifact@v4
|
|
18
|
+
with:
|
|
19
|
+
name: dist
|
|
20
|
+
path: dist/
|
|
21
|
+
|
|
22
|
+
publish:
|
|
23
|
+
needs: build
|
|
24
|
+
runs-on: ubuntu-latest
|
|
25
|
+
environment: pypi
|
|
26
|
+
permissions:
|
|
27
|
+
id-token: write # OIDC trusted publishing — no tokens anywhere
|
|
28
|
+
steps:
|
|
29
|
+
- uses: actions/download-artifact@v4
|
|
30
|
+
with:
|
|
31
|
+
name: dist
|
|
32
|
+
path: dist/
|
|
33
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
Initial release, extracted from Regent Protocol's production marketplace
|
|
6
|
+
(get4agent.com), where it authenticates self-onboarding AI agents.
|
|
7
|
+
|
|
8
|
+
- `HttpsigVerifier` — RFC 9421 verification for both agent dialects:
|
|
9
|
+
- Web Bot Auth (draft -05): sf-dictionary `Signature-Agent` with `;key=`
|
|
10
|
+
member selection AND the legacy sf-string form OpenAI ships in production;
|
|
11
|
+
key discovery via `/.well-known/http-message-signatures-directory`.
|
|
12
|
+
- AAuth (identity-based mode, `[aauth]` extra): `aa-agent+jwt` in
|
|
13
|
+
`Signature-Key`, issuer JWKS discovery, `cnf.jwk` proof of possession.
|
|
14
|
+
- SSRF-guarded directory fetching (https-only, public-IP-only, no redirects,
|
|
15
|
+
size-capped) with bounded per-instance caching.
|
|
16
|
+
- `EgressSigner` + `regent-httpsig keygen` — sign outbound agent traffic
|
|
17
|
+
(Web Bot Auth), generate keys and ready-to-publish well-known files.
|
|
18
|
+
- FastAPI integration (`[fastapi]` extra): `SignatureDep` (enrichment) and
|
|
19
|
+
`RequiredSignatureDep` (authentication with a self-explaining 401).
|
|
20
|
+
- Test suite pinned to the official RFC 9421 B.2.6 vector, both Web Bot Auth
|
|
21
|
+
appendix vectors (A.2.2 re-signed — the draft's printed signature does not
|
|
22
|
+
verify over its own base; reported), and full sign→verify roundtrips for
|
|
23
|
+
both dialects.
|
|
@@ -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,176 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: regent-httpsig
|
|
3
|
+
Version: 0.1.0
|
|
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>=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
|
+
```
|
|
69
|
+
|
|
70
|
+
Verification is **enrichment by default**: no `Signature` header costs nothing, a bad
|
|
71
|
+
signature yields `None`, and nothing ever raises on untrusted input. Use
|
|
72
|
+
`regent_httpsig.fastapi.RequiredSignatureDep` when a signature must be present — the 401
|
|
73
|
+
tells the agent exactly how to sign.
|
|
74
|
+
|
|
75
|
+
## Sign: get your agent past bot walls
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
from regent_httpsig import EgressSigner
|
|
79
|
+
|
|
80
|
+
signer = EgressSigner(seed=os.environ["AGENT_KEY_SEED"],
|
|
81
|
+
signature_agent="https://myagent.example")
|
|
82
|
+
headers = signer.sign("POST", url, {"content-type": "application/json"})
|
|
83
|
+
resp = httpx.post(url, json=body, headers=headers)
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Generate a key and the ready-to-publish `/.well-known/` files in one command:
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
regent-httpsig keygen --agent https://myagent.example --out ./well-known/
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Publish the directory at `https://myagent.example/.well-known/http-message-signatures-directory`
|
|
93
|
+
and every Web Bot Auth verifier on the internet can now identify your agent.
|
|
94
|
+
|
|
95
|
+
## What exactly is verified
|
|
96
|
+
|
|
97
|
+
| Check | Status |
|
|
98
|
+
|---|---|
|
|
99
|
+
| RFC 9421 Appendix B.2.6 Ed25519 vector (byte-exact) | ✅ in CI |
|
|
100
|
+
| Web Bot Auth draft -05 A.2.2 — sf-dictionary `Signature-Agent` covered with `;key=` | ✅ in CI¹ |
|
|
101
|
+
| Web Bot Auth A.2.3 — legacy sf-string form (**what OpenAI ships in production**) | ✅ in CI |
|
|
102
|
+
| Sign → verify roundtrip (fresh keys, full pipeline) | ✅ in CI |
|
|
103
|
+
| AAuth identity-mode roundtrip (`aa-agent+jwt` + `cnf.jwk` proof of possession) | ✅ in CI |
|
|
104
|
+
| Tampered request / expired signature / wrong directory key rejected | ✅ in CI |
|
|
105
|
+
|
|
106
|
+
¹ The signature bytes printed in the draft's own A.2.2 example do **not** verify over the
|
|
107
|
+
draft's own signature base (the legacy A.2.3 vector and RFC 9421 B.2.6 both do, so the defect
|
|
108
|
+
is in the example, not the canonicalization). Ed25519 is deterministic, so our test pins the
|
|
109
|
+
vector re-signed with the same RFC test key over the same byte-exact base — reported upstream.
|
|
110
|
+
|
|
111
|
+
## Both dialects, one verifier
|
|
112
|
+
|
|
113
|
+
- **Web Bot Auth** (`draft-meunier-web-bot-auth-architecture`): key discovery via
|
|
114
|
+
`{Signature-Agent}/.well-known/http-message-signatures-directory`. Both wire forms of
|
|
115
|
+
`Signature-Agent` are accepted — the current sf-dictionary and the legacy bare sf-string
|
|
116
|
+
OpenAI actually sends.
|
|
117
|
+
- **AAuth** (`draft-hardt-oauth-aauth-protocol`, identity-based mode): the agent carries a
|
|
118
|
+
JWT `agent_token` in `Signature-Key`; the issuer's JWKS verifies the token, the token's
|
|
119
|
+
`cnf.jwk` verifies the request signature. Install with `pip install 'regent-httpsig[aauth]'`.
|
|
120
|
+
For a full-protocol AAuth implementation (both roles, all token types) see
|
|
121
|
+
[christian-posta/aauth-python-library](https://github.com/christian-posta/aauth-python-library) —
|
|
122
|
+
this library is the thin relying-party verifier that handles both dialects.
|
|
123
|
+
|
|
124
|
+
## Security model (what a naive implementation gets wrong)
|
|
125
|
+
|
|
126
|
+
The verifier fetches key directories from **attacker-nameable origins** — whoever signs a
|
|
127
|
+
request chooses its `Signature-Agent`. regent-httpsig ships with the guard rails on:
|
|
128
|
+
|
|
129
|
+
- **SSRF protection by default**: https-only, every resolved IP must be public (catches
|
|
130
|
+
`169.254.169.254`, loopback, private ranges, DNS names mapping to internal services),
|
|
131
|
+
redirects never followed, responses size-capped.
|
|
132
|
+
- **Bounded caching**: per-instance TTL cache with eviction — a keyid-spam attack can't
|
|
133
|
+
grow memory; failures are negative-cached so a dead origin can't be used to slow you down.
|
|
134
|
+
- **A valid signature proves key possession — not trustworthiness.** `VerifiedSignature.trusted`
|
|
135
|
+
reflects only your configured allow-list; deciding *whether to trust* a key is your policy
|
|
136
|
+
layer's job.
|
|
137
|
+
|
|
138
|
+
Known sharp edges of the underlying ecosystem, already handled: the upstream
|
|
139
|
+
`http-message-signatures` library cannot resolve RFC 9421 `;key=` dictionary members (we
|
|
140
|
+
provide the component resolver), it looks up header names case-sensitively while ASGI
|
|
141
|
+
frameworks lowercase them (we wrap), and it forgets to declare `typing_extensions` (we
|
|
142
|
+
declare it).
|
|
143
|
+
|
|
144
|
+
## Configuration
|
|
145
|
+
|
|
146
|
+
```python
|
|
147
|
+
from regent_httpsig import HttpsigConfig, HttpsigVerifier
|
|
148
|
+
|
|
149
|
+
verifier = HttpsigVerifier(HttpsigConfig(
|
|
150
|
+
trusted_agents=frozenset({"https://chatgpt.com", "https://operator.openai.com"}),
|
|
151
|
+
max_age_hours=25, # reject signatures created earlier than this
|
|
152
|
+
cache_ttl=600, # key-directory cache seconds
|
|
153
|
+
))
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Pass your app's shared client to reuse its pool: `HttpsigVerifier(http_client=my_async_client)`.
|
|
157
|
+
|
|
158
|
+
## Honest limitations
|
|
159
|
+
|
|
160
|
+
- Web Bot Auth and AAuth are **IETF drafts** (RFC 9421 itself is a final standard). We track
|
|
161
|
+
the drafts; breaking draft changes land as minor releases while we're 0.x.
|
|
162
|
+
- **Ed25519 only** for now — it's what the agent ecosystem ships.
|
|
163
|
+
- Body coverage (`content-digest`) is verified when covered by the signature, but this
|
|
164
|
+
library does not require it; decide per-route whether you need it.
|
|
165
|
+
|
|
166
|
+
## Related projects
|
|
167
|
+
|
|
168
|
+
[cloudflare/web-bot-auth](https://github.com/cloudflare/web-bot-auth) (TypeScript/Rust) ·
|
|
169
|
+
[christian-posta/aauth-python-library](https://github.com/christian-posta/aauth-python-library)
|
|
170
|
+
(full AAuth protocol) · [pyauth/http-message-signatures](https://github.com/pyauth/http-message-signatures)
|
|
171
|
+
(the RFC 9421 primitive this builds on)
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
Built and battle-tested in production by [Regent Protocol](https://regentprotocol.org) —
|
|
176
|
+
runtime control and identity for AI agents. Apache-2.0.
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# regent-httpsig
|
|
2
|
+
|
|
3
|
+
**Verify and sign AI agent HTTP traffic in Python — the way OpenAI signs and Cloudflare verifies.**
|
|
4
|
+
RFC 9421 · Web Bot Auth · AAuth
|
|
5
|
+
|
|
6
|
+
OpenAI's agents cryptographically sign every HTTP request they make. Cloudflare, AWS WAF and
|
|
7
|
+
Google verify those signatures. This library brings both sides of that handshake to Python:
|
|
8
|
+
**verify** signed agents hitting your API, and **sign** your own agent's traffic so bot walls
|
|
9
|
+
recognize it.
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pip install regent-httpsig
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Verify: know which AI agent is calling — in 5 lines
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
from fastapi import FastAPI
|
|
19
|
+
from regent_httpsig import HttpsigVerifier
|
|
20
|
+
from regent_httpsig.fastapi import attach, SignatureDep, VerifiedSignature
|
|
21
|
+
|
|
22
|
+
app = FastAPI()
|
|
23
|
+
attach(app, HttpsigVerifier())
|
|
24
|
+
|
|
25
|
+
@app.post("/v1/orders")
|
|
26
|
+
async def create_order(sig: VerifiedSignature | None = SignatureDep):
|
|
27
|
+
if sig:
|
|
28
|
+
print(sig.agent) # "https://chatgpt.com"
|
|
29
|
+
print(sig.keyid) # RFC 7638 key thumbprint
|
|
30
|
+
...
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
No FastAPI? The core has no framework dependencies:
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
verifier = HttpsigVerifier()
|
|
37
|
+
sig = await verifier.verify(method, url, headers) # VerifiedSignature | None
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Verification is **enrichment by default**: no `Signature` header costs nothing, a bad
|
|
41
|
+
signature yields `None`, and nothing ever raises on untrusted input. Use
|
|
42
|
+
`regent_httpsig.fastapi.RequiredSignatureDep` when a signature must be present — the 401
|
|
43
|
+
tells the agent exactly how to sign.
|
|
44
|
+
|
|
45
|
+
## Sign: get your agent past bot walls
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
from regent_httpsig import EgressSigner
|
|
49
|
+
|
|
50
|
+
signer = EgressSigner(seed=os.environ["AGENT_KEY_SEED"],
|
|
51
|
+
signature_agent="https://myagent.example")
|
|
52
|
+
headers = signer.sign("POST", url, {"content-type": "application/json"})
|
|
53
|
+
resp = httpx.post(url, json=body, headers=headers)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Generate a key and the ready-to-publish `/.well-known/` files in one command:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
regent-httpsig keygen --agent https://myagent.example --out ./well-known/
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Publish the directory at `https://myagent.example/.well-known/http-message-signatures-directory`
|
|
63
|
+
and every Web Bot Auth verifier on the internet can now identify your agent.
|
|
64
|
+
|
|
65
|
+
## What exactly is verified
|
|
66
|
+
|
|
67
|
+
| Check | Status |
|
|
68
|
+
|---|---|
|
|
69
|
+
| RFC 9421 Appendix B.2.6 Ed25519 vector (byte-exact) | ✅ in CI |
|
|
70
|
+
| Web Bot Auth draft -05 A.2.2 — sf-dictionary `Signature-Agent` covered with `;key=` | ✅ in CI¹ |
|
|
71
|
+
| Web Bot Auth A.2.3 — legacy sf-string form (**what OpenAI ships in production**) | ✅ in CI |
|
|
72
|
+
| Sign → verify roundtrip (fresh keys, full pipeline) | ✅ in CI |
|
|
73
|
+
| AAuth identity-mode roundtrip (`aa-agent+jwt` + `cnf.jwk` proof of possession) | ✅ in CI |
|
|
74
|
+
| Tampered request / expired signature / wrong directory key rejected | ✅ in CI |
|
|
75
|
+
|
|
76
|
+
¹ The signature bytes printed in the draft's own A.2.2 example do **not** verify over the
|
|
77
|
+
draft's own signature base (the legacy A.2.3 vector and RFC 9421 B.2.6 both do, so the defect
|
|
78
|
+
is in the example, not the canonicalization). Ed25519 is deterministic, so our test pins the
|
|
79
|
+
vector re-signed with the same RFC test key over the same byte-exact base — reported upstream.
|
|
80
|
+
|
|
81
|
+
## Both dialects, one verifier
|
|
82
|
+
|
|
83
|
+
- **Web Bot Auth** (`draft-meunier-web-bot-auth-architecture`): key discovery via
|
|
84
|
+
`{Signature-Agent}/.well-known/http-message-signatures-directory`. Both wire forms of
|
|
85
|
+
`Signature-Agent` are accepted — the current sf-dictionary and the legacy bare sf-string
|
|
86
|
+
OpenAI actually sends.
|
|
87
|
+
- **AAuth** (`draft-hardt-oauth-aauth-protocol`, identity-based mode): the agent carries a
|
|
88
|
+
JWT `agent_token` in `Signature-Key`; the issuer's JWKS verifies the token, the token's
|
|
89
|
+
`cnf.jwk` verifies the request signature. Install with `pip install 'regent-httpsig[aauth]'`.
|
|
90
|
+
For a full-protocol AAuth implementation (both roles, all token types) see
|
|
91
|
+
[christian-posta/aauth-python-library](https://github.com/christian-posta/aauth-python-library) —
|
|
92
|
+
this library is the thin relying-party verifier that handles both dialects.
|
|
93
|
+
|
|
94
|
+
## Security model (what a naive implementation gets wrong)
|
|
95
|
+
|
|
96
|
+
The verifier fetches key directories from **attacker-nameable origins** — whoever signs a
|
|
97
|
+
request chooses its `Signature-Agent`. regent-httpsig ships with the guard rails on:
|
|
98
|
+
|
|
99
|
+
- **SSRF protection by default**: https-only, every resolved IP must be public (catches
|
|
100
|
+
`169.254.169.254`, loopback, private ranges, DNS names mapping to internal services),
|
|
101
|
+
redirects never followed, responses size-capped.
|
|
102
|
+
- **Bounded caching**: per-instance TTL cache with eviction — a keyid-spam attack can't
|
|
103
|
+
grow memory; failures are negative-cached so a dead origin can't be used to slow you down.
|
|
104
|
+
- **A valid signature proves key possession — not trustworthiness.** `VerifiedSignature.trusted`
|
|
105
|
+
reflects only your configured allow-list; deciding *whether to trust* a key is your policy
|
|
106
|
+
layer's job.
|
|
107
|
+
|
|
108
|
+
Known sharp edges of the underlying ecosystem, already handled: the upstream
|
|
109
|
+
`http-message-signatures` library cannot resolve RFC 9421 `;key=` dictionary members (we
|
|
110
|
+
provide the component resolver), it looks up header names case-sensitively while ASGI
|
|
111
|
+
frameworks lowercase them (we wrap), and it forgets to declare `typing_extensions` (we
|
|
112
|
+
declare it).
|
|
113
|
+
|
|
114
|
+
## Configuration
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
from regent_httpsig import HttpsigConfig, HttpsigVerifier
|
|
118
|
+
|
|
119
|
+
verifier = HttpsigVerifier(HttpsigConfig(
|
|
120
|
+
trusted_agents=frozenset({"https://chatgpt.com", "https://operator.openai.com"}),
|
|
121
|
+
max_age_hours=25, # reject signatures created earlier than this
|
|
122
|
+
cache_ttl=600, # key-directory cache seconds
|
|
123
|
+
))
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Pass your app's shared client to reuse its pool: `HttpsigVerifier(http_client=my_async_client)`.
|
|
127
|
+
|
|
128
|
+
## Honest limitations
|
|
129
|
+
|
|
130
|
+
- Web Bot Auth and AAuth are **IETF drafts** (RFC 9421 itself is a final standard). We track
|
|
131
|
+
the drafts; breaking draft changes land as minor releases while we're 0.x.
|
|
132
|
+
- **Ed25519 only** for now — it's what the agent ecosystem ships.
|
|
133
|
+
- Body coverage (`content-digest`) is verified when covered by the signature, but this
|
|
134
|
+
library does not require it; decide per-route whether you need it.
|
|
135
|
+
|
|
136
|
+
## Related projects
|
|
137
|
+
|
|
138
|
+
[cloudflare/web-bot-auth](https://github.com/cloudflare/web-bot-auth) (TypeScript/Rust) ·
|
|
139
|
+
[christian-posta/aauth-python-library](https://github.com/christian-posta/aauth-python-library)
|
|
140
|
+
(full AAuth protocol) · [pyauth/http-message-signatures](https://github.com/pyauth/http-message-signatures)
|
|
141
|
+
(the RFC 9421 primitive this builds on)
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
Built and battle-tested in production by [Regent Protocol](https://regentprotocol.org) —
|
|
146
|
+
runtime control and identity for AI agents. Apache-2.0.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## Reporting a vulnerability
|
|
4
|
+
|
|
5
|
+
Email **security@regentprotocol.org**. We aim to acknowledge within 72 hours and follow
|
|
6
|
+
coordinated disclosure: please give us up to 90 days before publishing details.
|
|
7
|
+
|
|
8
|
+
Please include a minimal reproduction. PGP is available on request.
|
|
9
|
+
|
|
10
|
+
## Scope notes
|
|
11
|
+
|
|
12
|
+
- The verifier is designed to be safe against untrusted input by construction: it never
|
|
13
|
+
raises on malformed signatures, fetches attacker-nameable URLs only through an SSRF
|
|
14
|
+
guard (https-only, public-IP-only, no redirects, size caps), and bounds its caches.
|
|
15
|
+
- A **valid signature proves key possession, not trustworthiness** — reports along the
|
|
16
|
+
lines of "any agent can sign up" describe the protocol's design, not a vulnerability.
|
|
17
|
+
- Vulnerabilities in the underlying `http-message-signatures` library should be reported
|
|
18
|
+
upstream; we will ship mitigations where feasible.
|
|
19
|
+
|
|
20
|
+
## Supported versions
|
|
21
|
+
|
|
22
|
+
The latest minor release receives security fixes.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""Minimal FastAPI service that knows which AI agent is calling.
|
|
2
|
+
|
|
3
|
+
Run: pip install 'regent-httpsig[fastapi]' uvicorn
|
|
4
|
+
uvicorn examples.fastapi_verify:app
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from fastapi import FastAPI
|
|
8
|
+
|
|
9
|
+
from regent_httpsig import HttpsigConfig, HttpsigVerifier
|
|
10
|
+
from regent_httpsig.fastapi import RequiredSignatureDep, SignatureDep, VerifiedSignature, attach
|
|
11
|
+
|
|
12
|
+
app = FastAPI()
|
|
13
|
+
attach(app, HttpsigVerifier(HttpsigConfig(
|
|
14
|
+
trusted_agents=frozenset({"https://chatgpt.com", "https://operator.openai.com"}),
|
|
15
|
+
)))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@app.get("/whoami")
|
|
19
|
+
async def whoami(sig: VerifiedSignature | None = SignatureDep) -> dict:
|
|
20
|
+
"""Enrichment: works for everyone, tells signed agents apart."""
|
|
21
|
+
if sig is None:
|
|
22
|
+
return {"agent": None, "note": "unsigned request"}
|
|
23
|
+
return {"agent": sig.agent, "keyid": sig.keyid, "trusted": sig.trusted}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@app.post("/agents-only")
|
|
27
|
+
async def agents_only(sig: VerifiedSignature = RequiredSignatureDep) -> dict:
|
|
28
|
+
"""Authentication: unsigned callers get a 401 explaining how to sign."""
|
|
29
|
+
return {"welcome": sig.agent}
|