blindkey 0.3.9a1__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.
Files changed (84) hide show
  1. blindkey-0.3.9a1.dist-info/METADATA +157 -0
  2. blindkey-0.3.9a1.dist-info/RECORD +84 -0
  3. blindkey-0.3.9a1.dist-info/WHEEL +5 -0
  4. blindkey-0.3.9a1.dist-info/entry_points.txt +3 -0
  5. blindkey-0.3.9a1.dist-info/licenses/LICENSE +202 -0
  6. blindkey-0.3.9a1.dist-info/licenses/NOTICE +4 -0
  7. blindkey-0.3.9a1.dist-info/top_level.txt +1 -0
  8. gatekeeper/__init__.py +1 -0
  9. gatekeeper/cli/__init__.py +0 -0
  10. gatekeeper/cli/cakey.py +52 -0
  11. gatekeeper/cli/commands/__init__.py +0 -0
  12. gatekeeper/cli/commands/add_client.py +135 -0
  13. gatekeeper/cli/commands/audit_anchor.py +29 -0
  14. gatekeeper/cli/commands/audit_repair.py +52 -0
  15. gatekeeper/cli/commands/audit_verify.py +23 -0
  16. gatekeeper/cli/commands/client_status.py +53 -0
  17. gatekeeper/cli/commands/confirm.py +91 -0
  18. gatekeeper/cli/commands/decoy_create.py +55 -0
  19. gatekeeper/cli/commands/init.py +154 -0
  20. gatekeeper/cli/commands/list_clients.py +44 -0
  21. gatekeeper/cli/commands/renew.py +84 -0
  22. gatekeeper/cli/commands/renew_server.py +70 -0
  23. gatekeeper/cli/commands/run.py +22 -0
  24. gatekeeper/cli/commands/status.py +64 -0
  25. gatekeeper/cli/main.py +128 -0
  26. gatekeeper/cli/output.py +12 -0
  27. gatekeeper/client/__init__.py +1 -0
  28. gatekeeper/client/botapi.py +55 -0
  29. gatekeeper/client/http_io.py +54 -0
  30. gatekeeper/client/session.py +60 -0
  31. gatekeeper/client/transport.py +30 -0
  32. gatekeeper/core/__init__.py +0 -0
  33. gatekeeper/core/constants.py +27 -0
  34. gatekeeper/core/errors.py +25 -0
  35. gatekeeper/core/events.py +47 -0
  36. gatekeeper/core/kdf.py +47 -0
  37. gatekeeper/core/redact.py +89 -0
  38. gatekeeper/core/signing.py +139 -0
  39. gatekeeper/core/timeutil.py +29 -0
  40. gatekeeper/pki/__init__.py +0 -0
  41. gatekeeper/pki/ca.py +242 -0
  42. gatekeeper/pki/fingerprint.py +30 -0
  43. gatekeeper/py.typed +0 -0
  44. gatekeeper/server/__init__.py +0 -0
  45. gatekeeper/server/anomaly.py +71 -0
  46. gatekeeper/server/app.py +331 -0
  47. gatekeeper/server/audit/__init__.py +0 -0
  48. gatekeeper/server/audit/anchor.py +106 -0
  49. gatekeeper/server/audit/chain.py +282 -0
  50. gatekeeper/server/audit/repair.py +41 -0
  51. gatekeeper/server/audit/rotate.py +131 -0
  52. gatekeeper/server/audit/sink.py +172 -0
  53. gatekeeper/server/audit/verify.py +139 -0
  54. gatekeeper/server/config.py +264 -0
  55. gatekeeper/server/confirm_body.py +87 -0
  56. gatekeeper/server/honey/__init__.py +1 -0
  57. gatekeeper/server/honey/decoys.py +77 -0
  58. gatekeeper/server/http_io.py +185 -0
  59. gatekeeper/server/http_response.py +54 -0
  60. gatekeeper/server/identity.py +122 -0
  61. gatekeeper/server/limits.py +222 -0
  62. gatekeeper/server/nonce_cache.py +91 -0
  63. gatekeeper/server/observe.py +86 -0
  64. gatekeeper/server/pipeline.py +300 -0
  65. gatekeeper/server/policy.py +89 -0
  66. gatekeeper/server/providers/__init__.py +25 -0
  67. gatekeeper/server/providers/base.py +52 -0
  68. gatekeeper/server/providers/bearer.py +164 -0
  69. gatekeeper/server/providers/cloudflare.py +36 -0
  70. gatekeeper/server/providers/github.py +68 -0
  71. gatekeeper/server/providers/jsonscan.py +110 -0
  72. gatekeeper/server/providers/openai.py +34 -0
  73. gatekeeper/server/providers/telegram.py +106 -0
  74. gatekeeper/server/providers/vercel.py +31 -0
  75. gatekeeper/server/state.py +105 -0
  76. gatekeeper/server/tls.py +34 -0
  77. gatekeeper/server/upstream.py +128 -0
  78. gatekeeper/store/__init__.py +0 -0
  79. gatekeeper/store/approvals.py +257 -0
  80. gatekeeper/store/atomic.py +28 -0
  81. gatekeeper/store/fsperm.py +53 -0
  82. gatekeeper/store/layout.py +45 -0
  83. gatekeeper/store/registry.py +143 -0
  84. gatekeeper/store/secrets.py +30 -0
@@ -0,0 +1,157 @@
1
+ Metadata-Version: 2.4
2
+ Name: blindkey
3
+ Version: 0.3.9a1
4
+ Summary: Self-hosted mTLS gateway that keeps API tokens (Telegram, GitHub, OpenAI, Vercel, Cloudflare) off bots, scripts and AI agents
5
+ Author: Anonimman01
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/Anonimman01/blindkey
8
+ Project-URL: Repository, https://github.com/Anonimman01/blindkey
9
+ Project-URL: Issues, https://github.com/Anonimman01/blindkey/issues
10
+ Project-URL: Documentation, https://github.com/Anonimman01/blindkey#readme
11
+ Project-URL: Security, https://github.com/Anonimman01/blindkey/security/policy
12
+ Project-URL: Changelog, https://github.com/Anonimman01/blindkey/blob/main/CHANGELOG.md
13
+ Keywords: mtls,api-gateway,api-key,secrets,secret-management,credential-proxy,telegram,telegram-bot,github,openai,ai-agents,vercel,cloudflare,hmac,audit-log,honeytoken,zero-trust,security,gateway,proxy
14
+ Classifier: Development Status :: 3 - Alpha
15
+ Classifier: Environment :: Console
16
+ Classifier: Framework :: AsyncIO
17
+ Classifier: Intended Audience :: Developers
18
+ Classifier: Intended Audience :: System Administrators
19
+ Classifier: Topic :: Internet :: Proxy Servers
20
+ Classifier: Topic :: Security
21
+ Classifier: Topic :: Security :: Cryptography
22
+ Classifier: Topic :: System :: Logging
23
+ Classifier: Programming Language :: Python :: 3
24
+ Classifier: Programming Language :: Python :: 3.11
25
+ Classifier: Programming Language :: Python :: 3.12
26
+ Classifier: Programming Language :: Python :: 3.13
27
+ Classifier: Programming Language :: Python :: 3.14
28
+ Classifier: Operating System :: OS Independent
29
+ Classifier: Typing :: Typed
30
+ Requires-Python: >=3.11
31
+ Description-Content-Type: text/markdown
32
+ License-File: LICENSE
33
+ License-File: NOTICE
34
+ Requires-Dist: cryptography>=42
35
+ Requires-Dist: h11>=0.16
36
+ Provides-Extra: dev
37
+ Requires-Dist: pytest>=8; extra == "dev"
38
+ Requires-Dist: pytest-cov>=5; extra == "dev"
39
+ Requires-Dist: ruff>=0.9; extra == "dev"
40
+ Requires-Dist: mypy>=1.13; extra == "dev"
41
+ Requires-Dist: pip-audit; extra == "dev"
42
+ Dynamic: license-file
43
+
44
+ # BlindKey / gatekeeper: mTLS API-key gateway for bots, scripts and AI agents
45
+
46
+ **Language:** English · [Русский](README.ru.md)
47
+
48
+ [![CI](https://github.com/Anonimman01/blindkey/actions/workflows/ci.yml/badge.svg)](https://github.com/Anonimman01/blindkey/actions/workflows/ci.yml)
49
+ [![CodeQL](https://github.com/Anonimman01/blindkey/actions/workflows/codeql.yml/badge.svg)](https://github.com/Anonimman01/blindkey/actions/workflows/codeql.yml)
50
+ [![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](LICENSE)
51
+ ![Python](https://img.shields.io/badge/python-3.11%20%7C%203.12%20%7C%203.13%20%7C%203.14-blue)
52
+
53
+ **BlindKey** (PyPI: `blindkey`, command: `gatekeeper` or `blindkey`) is a small self-hosted Python gateway that sits in
54
+ front of third-party APIs and keeps your **real API token off the machines that use it**. Your bot,
55
+ script or AI agent never sees the Telegram, GitHub, OpenAI, Vercel or Cloudflare token. It gets a
56
+ revocable client certificate and an allowlist of API methods instead. If the client is compromised,
57
+ you revoke one certificate. The token is not leaked, and does not need to be rotated.
58
+
59
+ Typical uses: a **Telegram bot token proxy**, an **OpenAI API key proxy for AI agents**, a
60
+ **secretless credential gateway** for CI jobs and scripts, per-client allowlists for the GitHub API.
61
+
62
+ ## How it works
63
+
64
+ ```
65
+ bot / script / AI agent gatekeeper (your server) upstream API
66
+ ----------------------- ------------------------ ------------
67
+ client certificate (mTLS) ──TLS 1.3──▶ verify cert + HMAC signature
68
+ signed request, no token check allowlist, rate limit, budget
69
+ [dangerous method? wait for operator]
70
+ add the real token ───────────────────▶ api.telegram.org
71
+ filter response for token leaks ◀─────── api.github.com ...
72
+ response ◀──────── write hash-chained audit log
73
+ ```
74
+
75
+ ## Features
76
+
77
+ - **mTLS (TLS 1.3 only)** with your own CA: each client gets a revocable certificate.
78
+ - **HMAC-SHA256 request signing** bound to the certificate fingerprint, with replay protection
79
+ (nonce cache and a ±30 s time window).
80
+ - **Per-client allowlist** of `METHOD:api` rules. The upstream path comes from the rule, never from
81
+ the client request, so there is no SSRF through the gateway.
82
+ - **Response filter**: a response that contains the gateway's token is blocked (502) and logged.
83
+ Compressed responses and duplicate-key JSON tricks are rejected rather than inspected.
84
+ - **Hash-chained audit log** with size-based rotation, truncated-tail recovery and external
85
+ anchors (`audit-anchor`, `audit-verify`).
86
+ - **Decoys (honeytokens)**: a client that uses a decoy credential is caught and its IP banned.
87
+ - **Operator confirmation** for dangerous methods (`[confirm]`): the request waits until an
88
+ operator runs `gatekeeper approve`.
89
+ - **Rate limits, daily request budget, anomaly counters and auto-freeze** of misbehaving clients.
90
+ - **Several providers on one gateway**: Telegram Bot API, GitHub, OpenAI, Vercel, Cloudflare.
91
+ Each client is bound to one provider.
92
+ - Small footprint: Python 3.11+, two runtime dependencies (`cryptography`, `h11`),
93
+ hash-pinned lock files, Apache-2.0.
94
+
95
+ ## Supported providers
96
+
97
+ | Provider | Typical use |
98
+ |---|---|
99
+ | Telegram Bot API | keep the bot token off the bot host and off the app that talks to Telegram |
100
+ | GitHub | give scripts and agents a narrow slice of the GitHub API |
101
+ | OpenAI | keep the OpenAI API key away from agents and per-project runtimes |
102
+ | Vercel | limited access to selected Vercel API calls |
103
+ | Cloudflare | limited access to selected Cloudflare API calls |
104
+
105
+ ## Quick start (Linux)
106
+
107
+ pip install blindkey
108
+
109
+ The PyPI distribution is called `blindkey`. The command is `gatekeeper` (alias: `blindkey`) and the
110
+ Python package is `gatekeeper`. Do **not** run `pip install gatekeeper`: that name on PyPI belongs
111
+ to a different project. To work from a checkout with hash-pinned dependencies:
112
+
113
+ git clone https://github.com/Anonimman01/blindkey
114
+ cd blindkey
115
+ python -m venv .venv && source .venv/bin/activate
116
+ pip install --require-hashes -r requirements.lock
117
+ pip install --no-deps -e .
118
+
119
+ Create the CA and the gateway certificate, add a client, start the gateway:
120
+
121
+ useradd --system --create-home gatekeeper && su - gatekeeper
122
+ export GATEKEEPER_CONFIG_DIR=$HOME/etc GATEKEEPER_DATA_DIR=$HOME/data
123
+
124
+ gatekeeper init --host 203.0.113.10 --host gw.example.com --ca-key-out /safe/ca.key
125
+ gatekeeper add-client --id mybot --ca-key /safe/ca.key --out ./mybot-bundle \
126
+ --allow GET:getMe --allow POST:sendMessage
127
+ export GATEKEEPER_UPSTREAM_TOKEN='123456:ABC...'
128
+ gatekeeper run
129
+
130
+ Copy `mybot-bundle` to the bot's machine over a secure channel. `client.key` and `master.secret`
131
+ are secrets. A client example is in [examples/client_send_message.py](examples/client_send_message.py),
132
+ and all settings are in [examples/config.example.toml](examples/config.example.toml).
133
+
134
+ Production use is Linux only (file permissions 0600/0700 are enforced there). Windows works for
135
+ development. The full operator guide is currently in Russian: [README.ru.md](README.ru.md).
136
+
137
+ ## Status and security
138
+
139
+ - Beta (0.3.x). The test suite has 700+ tests and CI runs lint, type checks, `pip-audit`,
140
+ CodeQL and a lock-file drift check.
141
+ - The project has been through several internal and external audit passes. There is **no formal
142
+ third-party certification or penetration test**. Findings and fixes are tracked in
143
+ [docs/SECURITY-HISTORY.md](docs/SECURITY-HISTORY.md); the threat model is in
144
+ [docs/threat-model.md](docs/threat-model.md).
145
+ - All provider secrets live in the memory of one gateway process. Compromising the gateway host
146
+ compromises every configured provider token.
147
+ - Report vulnerabilities as described in [SECURITY.md](SECURITY.md).
148
+
149
+ ## Documentation
150
+
151
+ - [README.ru.md](README.ru.md): full guide in Russian (install, config, providers, audit log, decoys, limits)
152
+ - [SECURITY.md](SECURITY.md), [docs/threat-model.md](docs/threat-model.md)
153
+ - [CHANGELOG.md](CHANGELOG.md)
154
+
155
+ ## License
156
+
157
+ Apache-2.0, see [LICENSE](LICENSE) and [NOTICE](NOTICE).
@@ -0,0 +1,84 @@
1
+ blindkey-0.3.9a1.dist-info/licenses/LICENSE,sha256=-z-NJUbryZlZJ-BT77bi5fZvqPa2_d838uhpRe_KlPw,11348
2
+ blindkey-0.3.9a1.dist-info/licenses/NOTICE,sha256=ADHC4LVF0KZHOeg5xdTEzKPJ0Uk5Dv-LyEFzwgDj9rA,87
3
+ gatekeeper/__init__.py,sha256=iewMzRtaDPooRgantgCks6hCDqQmbxHS5oH20RmLyFs,53
4
+ gatekeeper/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ gatekeeper/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ gatekeeper/cli/cakey.py,sha256=yIOi4Zin4YdvOrJgGJFY2axaXA-BRb4KRPnZJntRdw0,2276
7
+ gatekeeper/cli/main.py,sha256=Zo0q97Q7Dj-WhDUHvtZnGp_vMfdP-wi2MOChYVmLz3w,6837
8
+ gatekeeper/cli/output.py,sha256=IxJtuJ5imaXF7oLE_Lotk96Bf8GbGXbP4gSKeaqyNGE,309
9
+ gatekeeper/cli/commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
+ gatekeeper/cli/commands/add_client.py,sha256=lyywXsAtVL8LNcTiLJi0ZZLJZLEWSHWlJF09CMGSOhk,5574
11
+ gatekeeper/cli/commands/audit_anchor.py,sha256=gsM823NnI9FeXO1zPX2uZKq6_d2o7R3qYWng_6fzjco,1380
12
+ gatekeeper/cli/commands/audit_repair.py,sha256=W4rYsuhSFzSp0QMWsjl-tARVGIGgkabXB22oYqObo5M,2835
13
+ gatekeeper/cli/commands/audit_verify.py,sha256=LORHy_xn-hjaZLS8OfmW7VcpF_RxQO8R-iNscGSUrqY,1155
14
+ gatekeeper/cli/commands/client_status.py,sha256=BNdH3apLjYCSaHMZLoDN0ukQIo2FXy2_2OI9Ah3V6s4,2475
15
+ gatekeeper/cli/commands/confirm.py,sha256=Omcrfi3uvQXp9MfbXqCpgUhe3FCNfszo0_KL7aI9PuE,3991
16
+ gatekeeper/cli/commands/decoy_create.py,sha256=YwkR5nxLT0gJ7KOq3hEt0ftJcCr_QLiMImhQo9EGtBo,2689
17
+ gatekeeper/cli/commands/init.py,sha256=mbJsI3bvCuYuyXJjxyyi96tZaNcs8W8Ag52JoVIHvlM,6680
18
+ gatekeeper/cli/commands/list_clients.py,sha256=PTp7gjSNVd8N3pZlFAUCq2_mVPFsbScudzl7zJ98bM0,1703
19
+ gatekeeper/cli/commands/renew.py,sha256=FnVfypxQM3oirH40e4AzcHnHCbjdZ_05T9tq2PCFCFA,4238
20
+ gatekeeper/cli/commands/renew_server.py,sha256=eJJS0bAzn-GaTN3aTQmAbmrlqYVqtDoo-gbjsxTo9_A,3311
21
+ gatekeeper/cli/commands/run.py,sha256=03nUQyk6nIYu6SKcvjcVS0MYlpeCRSq8gLTlH9EcQ1s,661
22
+ gatekeeper/cli/commands/status.py,sha256=ZlOyWZy8N0lVdhAjhjwmi5ecJsJJzjqx2jf0VxRaGHE,2997
23
+ gatekeeper/client/__init__.py,sha256=Zrruv0BvLqp5yozNV1ApPGU_zf4RLHsbAPjN2I1m_3w,102
24
+ gatekeeper/client/botapi.py,sha256=DCmRAbz1T5HGI0RSIXXMcQF6qDLVvYDb1pKBvASrVk4,2479
25
+ gatekeeper/client/http_io.py,sha256=_IZnKlM36Xaz35kUm9q2HhzEiKDCn0tCZuft2EqwOn0,2046
26
+ gatekeeper/client/session.py,sha256=OHZPEUf2hfkhdi0Xz70Zb9xgtsaRFrsmtp6E1uY7rRM,2671
27
+ gatekeeper/client/transport.py,sha256=G-7aa2ziYVRYqEoKvV_FhQfPzCzcCbdUfqPgxGkNuX8,1595
28
+ gatekeeper/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
29
+ gatekeeper/core/constants.py,sha256=tePAHaRNTsIXX4GQNzCqhe5S3nSZpv_JpmuU1BK-MK0,1217
30
+ gatekeeper/core/errors.py,sha256=ZgteSQjlL4r1UzDwfkur6oRBj7jink0lR3fN6XFzUJA,832
31
+ gatekeeper/core/events.py,sha256=gkA-lt_ImJvgH5lCLaCBEo0hJpknTQDPmDAlCxj5qwQ,2335
32
+ gatekeeper/core/kdf.py,sha256=eo1sa48RYhrnSlSt05GhFqfrq97BbsjQ-YKUOLFrnYE,1871
33
+ gatekeeper/core/redact.py,sha256=hdsMaxiqk-mP-bYteyyalhMdJnCQx9Y6-LjhgcqtFms,3925
34
+ gatekeeper/core/signing.py,sha256=CP-hSRnTIJf27puKghkjQqEK_h9VccJj8ODnbwbqxq4,4842
35
+ gatekeeper/core/timeutil.py,sha256=ptMEV93pB5rF9mSyh5hn-NXn6m-qeZItO_GhB6VpYiA,855
36
+ gatekeeper/pki/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
37
+ gatekeeper/pki/ca.py,sha256=BcWz3k_x9t9WcHUze3C3wclqihC_FqNCEPjv62rtm0A,9682
38
+ gatekeeper/pki/fingerprint.py,sha256=mNG8IL_EShY1huuBgnwYugYFTL7YArBli1KBpxtbvwM,1038
39
+ gatekeeper/server/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
40
+ gatekeeper/server/anomaly.py,sha256=VIf26NrCLudtm-O3W_BFu1NS662a_3Lxp24goxVfe8I,3233
41
+ gatekeeper/server/app.py,sha256=QtAsylIauWXf-DrTwBV0xLN5QH-5PGhbDtnzIDe7-6M,17606
42
+ gatekeeper/server/config.py,sha256=3m2BZmIBfESb0QruU7zr-TtBk4HNzs-mnFmMnkantfs,13473
43
+ gatekeeper/server/confirm_body.py,sha256=Hx2PTl2w8sLsKLhhf4W0x4v3Pw9TVNyI8Ri2qaLALpE,3960
44
+ gatekeeper/server/http_io.py,sha256=H4Iaq2EOU59YBG5V2lAVAG3Acd6HWkgC4o6wx9H8bcU,7654
45
+ gatekeeper/server/http_response.py,sha256=4f1m4qXP4R-fLq5WbdNMThC9HmgKYg0LDvIjcoXwnXU,2316
46
+ gatekeeper/server/identity.py,sha256=lRcaLBmqMxoLfVXA2XrEXf36b0X8qKqaGy-T78Jbn_8,4880
47
+ gatekeeper/server/limits.py,sha256=EbobxmYhH1Dofu8Y27V9eNi0p6uvalmBQAiCavYsbdA,8793
48
+ gatekeeper/server/nonce_cache.py,sha256=UeDgykcXAt8sh2Eg1-bapAvUZAILHalS6dGFtSqv-u8,3884
49
+ gatekeeper/server/observe.py,sha256=4gXCj40qZnAUUZyuevrlurwR8ikVvuECjLOtQKj94IU,3760
50
+ gatekeeper/server/pipeline.py,sha256=XA_0c2RhG5JcKfBsB6icv3Z-_BjmjiwdiF7iulHNnz4,19527
51
+ gatekeeper/server/policy.py,sha256=26v94Py1gXMLtSdTVTnICVAMR6JvSbc14K7w5OjVKM8,3532
52
+ gatekeeper/server/state.py,sha256=cINmmwDIYncTNljMNIpMw1r3f97bXCSmmf61KOXU_gI,5365
53
+ gatekeeper/server/tls.py,sha256=x-Osqi1XYL04ECquCNuUsW6r8TXLNm5_UVSTLGuSYgk,1621
54
+ gatekeeper/server/upstream.py,sha256=wrUnZFSDNDrmSE6nouycJsEzmMjuq514wKK5hfevSsM,5691
55
+ gatekeeper/server/audit/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
56
+ gatekeeper/server/audit/anchor.py,sha256=OzSxPYyfQxPbfkIwdk5hMDoq-ytfThi3FXrQrlK3ToA,4573
57
+ gatekeeper/server/audit/chain.py,sha256=RVCGItbNaf1EXLWWIJthjXlYkFVXjT799agvaG8OO3A,13733
58
+ gatekeeper/server/audit/repair.py,sha256=ILEPuLBIE8KEsBRZ2j_SeNifAMLS7naqI01ua9qPvv4,2063
59
+ gatekeeper/server/audit/rotate.py,sha256=FM8EUy9HAitJd1d2utmp-Vz7BU_hxbCac8WegXvY0hI,5792
60
+ gatekeeper/server/audit/sink.py,sha256=zpja6MZP2SmAY6gIy5hMlpgwD05nyqpK2oHr7w4yLZc,6819
61
+ gatekeeper/server/audit/verify.py,sha256=vBiZEp0KaK12owyhT77FwOo-9QPEMJXGtvkVbbo0mFg,6689
62
+ gatekeeper/server/honey/__init__.py,sha256=NJm4FTzKpcjp4i6BZNWLPAbeP4qcYCuYZmyGyNFoOYU,24
63
+ gatekeeper/server/honey/decoys.py,sha256=lyxTc4xSzi8tNZqQV1j_vRaOFf92SUNzI7jeQbDp1Os,3134
64
+ gatekeeper/server/providers/__init__.py,sha256=K7QLpaPf0771dDzYSEHysSZ-HAj0wCacX2trCf5meN8,1179
65
+ gatekeeper/server/providers/base.py,sha256=aR24JEo6sEH6Pfq1_u8dkXwVElKxs-8nvbnNp3oU-W0,1902
66
+ gatekeeper/server/providers/bearer.py,sha256=C4gXptJase_8ILMTOAEHoPXU0p2hv6AxY3e56UyAJFg,7911
67
+ gatekeeper/server/providers/cloudflare.py,sha256=7vhZKqu7kXYgTgjethgxLETZqxztydXHR_BfXZFfjEU,1977
68
+ gatekeeper/server/providers/github.py,sha256=RiQHg9lDVMP5jLMuFDGq8qBmiAPwSfpxcdhx8GJ5XPA,3116
69
+ gatekeeper/server/providers/jsonscan.py,sha256=LrvPKIlq1_fjsQ2PJlcGkrTmmH2Jbcbnqv5ZXQstEo4,4756
70
+ gatekeeper/server/providers/openai.py,sha256=PSMiIxc_7in3M633BbdJdft_WxNcFgUQG635nyZWRbI,1794
71
+ gatekeeper/server/providers/telegram.py,sha256=sC6jHMkpbIq0gKVbQB4-qgYPngsCZRm_5jdJmXIdaco,5800
72
+ gatekeeper/server/providers/vercel.py,sha256=zNyoqO5ULryvt-xCI93qhtBKHao2y8W0OEAxJfp_kOE,1562
73
+ gatekeeper/store/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
74
+ gatekeeper/store/approvals.py,sha256=4cCdzQhRz973t0hqt6RHFdzKFdwLqGZFnX9gZKVYtXU,12136
75
+ gatekeeper/store/atomic.py,sha256=oN-8Ay02geQjR71oazWBd9vWbtL-VErwMcaSDlbA13U,1097
76
+ gatekeeper/store/fsperm.py,sha256=5P8WKUbodHponAbD5R6HWwZkIHMLIafbTnHrdc-BeiE,2467
77
+ gatekeeper/store/layout.py,sha256=NF7FW3gm28obCbRElGpVStg4FsQPrShqHybDRinrEic,1599
78
+ gatekeeper/store/registry.py,sha256=QcoOuz_IhlHzilqEf6qnKAYlsl1V9hvsLY37TrXYGk8,6423
79
+ gatekeeper/store/secrets.py,sha256=VqJjV9Pe4sVF1HnXDU0kTizbukoiQwwFxBEbaOoUwns,1186
80
+ blindkey-0.3.9a1.dist-info/METADATA,sha256=T6eqRq00y3LYoMQJDVzirFk_GbGSDJ6xKiex9KbhqX8,8352
81
+ blindkey-0.3.9a1.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
82
+ blindkey-0.3.9a1.dist-info/entry_points.txt,sha256=8yA7OPxbj6nLOU9gVLl-O6kiAsQtgVHLnysgMpgHy6k,92
83
+ blindkey-0.3.9a1.dist-info/top_level.txt,sha256=sL8xT6obAhjxoAEWqpeB3KxA2i0vFZtfTkZHkfNP5Cc,11
84
+ blindkey-0.3.9a1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ blindkey = gatekeeper.cli.main:main
3
+ gatekeeper = gatekeeper.cli.main:main
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ https://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 [2026] [Anonimman01]
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
+ https://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,4 @@
1
+ gatekeeper
2
+ Copyright 2026 Anonimman01
3
+
4
+ Licensed under the Apache License, Version 2.0.
@@ -0,0 +1 @@
1
+ gatekeeper
gatekeeper/__init__.py ADDED
@@ -0,0 +1 @@
1
+ """gatekeeper: защищённый API-шлюз."""
File without changes
@@ -0,0 +1,52 @@
1
+ """Парольная фраза для `ca.key` (C-09).
2
+
3
+ Корневой ключ CA нужен только в операциях выпуска (`init`, `add-client`, `renew`,
4
+ `decoy-create`, `renew-server`). Хранить его незашифрованным не обязательно: `ca.key`
5
+ шифруется PKCS8, а фраза передаётся файлом (`--ca-key-pass-file`, права не шире 0600)
6
+ или переменной окружения `GATEKEEPER_CA_KEY_PASSPHRASE`. Фраза не пишется ни в журнал,
7
+ ни в вывод CLI.
8
+ """
9
+ from __future__ import annotations
10
+
11
+ import os
12
+ import stat
13
+ from pathlib import Path
14
+
15
+ from cryptography.hazmat.primitives.asymmetric import ec
16
+
17
+ from gatekeeper.core.errors import GatekeeperError
18
+ from gatekeeper.pki import ca
19
+
20
+ ENV_PASSPHRASE = "GATEKEEPER_CA_KEY_PASSPHRASE"
21
+
22
+
23
+ class CaKeyError(GatekeeperError):
24
+ """Ошибка чтения фразы или ключа CA."""
25
+
26
+
27
+ def read_passphrase(args) -> bytes | None:
28
+ """Прочитать фразу: файл важнее переменной окружения. None = ключ без пароля."""
29
+ path = getattr(args, "ca_key_pass_file", None)
30
+ if path:
31
+ try:
32
+ st = os.stat(path)
33
+ if os.name != "nt" and st.st_mode & (stat.S_IRWXG | stat.S_IRWXO):
34
+ raise CaKeyError(
35
+ "CA key passphrase file must not be accessible to group/others (chmod 0400)")
36
+ value = Path(path).read_text("utf-8").rstrip("\r\n")
37
+ except OSError as exc:
38
+ raise CaKeyError("cannot read CA key passphrase file") from exc
39
+ if not value:
40
+ raise CaKeyError("CA key passphrase file is empty")
41
+ return value.encode("utf-8")
42
+ value = os.environ.get(ENV_PASSPHRASE, "")
43
+ return value.encode("utf-8") if value else None
44
+
45
+
46
+ def load_ca_key(path: str | os.PathLike, passphrase: bytes | None) -> ec.EllipticCurvePrivateKey:
47
+ """Загрузить `ca.key` (зашифрованный или нет). Ошибка = понятный PkiError."""
48
+ try:
49
+ pem = Path(path).read_bytes()
50
+ except OSError as exc:
51
+ raise CaKeyError("cannot read CA key") from exc
52
+ return ca.load_key_pem(pem, password=passphrase)
File without changes
@@ -0,0 +1,135 @@
1
+ """gatekeeper add-client: выпустить сертификат + ключ подписи, зарегистрировать клиента.
2
+
3
+ Порядок: сначала пакет на диске, затем запись в реестре. Иначе при сбое посередине в реестре
4
+ оставался бы активный клиент без пакета, и `add-client` с тем же id уже не повторить.
5
+ """
6
+ from __future__ import annotations
7
+
8
+ import secrets as _secrets
9
+ from contextlib import suppress
10
+ from pathlib import Path
11
+
12
+ from gatekeeper.cli import output
13
+ from gatekeeper.cli.cakey import load_ca_key, read_passphrase
14
+ from gatekeeper.core import constants
15
+ from gatekeeper.core.errors import GatekeeperError, PolicyError
16
+ from gatekeeper.core.events import EventType
17
+ from gatekeeper.core.signing import is_valid_client_id
18
+ from gatekeeper.core.timeutil import unix_now
19
+ from gatekeeper.pki import ca
20
+ from gatekeeper.pki.fingerprint import cert_fingerprint
21
+ from gatekeeper.server.audit.chain import AuditChain
22
+ from gatekeeper.server.audit.sink import FileSink
23
+ from gatekeeper.server.policy import parse_rule
24
+ from gatekeeper.server.providers import KNOWN_PROVIDERS
25
+ from gatekeeper.store.layout import Layout
26
+ from gatekeeper.store.registry import Registry, RegistryError
27
+
28
+
29
+ def _valid_rule(rule: str) -> bool:
30
+ """Единый источник истины: то же правило, которое потом разберёт шлюз (policy.parse_rule)."""
31
+ try:
32
+ parse_rule(rule)
33
+ except PolicyError:
34
+ return False
35
+ return True
36
+
37
+
38
+ def _write_bundle(out: Path, files: dict[str, bytes]) -> list[Path]:
39
+ written: list[Path] = []
40
+ out.mkdir(mode=0o700, parents=True, exist_ok=True)
41
+ try:
42
+ for name, data in files.items():
43
+ path = out / name
44
+ ca.write_private_file(path, data)
45
+ written.append(path)
46
+ except (GatekeeperError, OSError):
47
+ for path in written:
48
+ with suppress(OSError):
49
+ path.unlink()
50
+ raise
51
+ return written
52
+
53
+
54
+ def run(args, layout: Layout) -> int:
55
+ if not is_valid_client_id(args.id):
56
+ output.error("invalid client id (letters/digits/._-, must start with letter or digit, max 64)")
57
+ return 1
58
+ bad = [r for r in args.allow if not _valid_rule(r)]
59
+ if bad:
60
+ output.error(f"invalid --allow rule(s): {bad} (expected GET|POST:apiName, e.g. POST:sendMessage)")
61
+ return 1
62
+ provider = getattr(args, "provider", None)
63
+ if provider is not None and provider not in KNOWN_PROVIDERS:
64
+ output.error(f"unknown provider: {provider} (known: {', '.join(KNOWN_PROVIDERS)})")
65
+ return 1
66
+ out = Path(args.out)
67
+ out_existed = out.exists()
68
+ if out_existed and any(out.iterdir()):
69
+ output.error(f"output directory is not empty: {out}")
70
+ return 1
71
+ try:
72
+ passphrase = read_passphrase(args)
73
+ ca_cert = ca.load_cert_pem(layout.ca_cert.read_bytes())
74
+ ca_key = load_ca_key(Path(args.ca_key), passphrase)
75
+ reg = Registry(layout.clients_file)
76
+ if args.id in reg.load():
77
+ raise RegistryError(f"client already exists: {args.id}")
78
+ cert, key = ca.issue_client_cert(ca_cert, ca_key, args.id, days=args.days)
79
+ except (GatekeeperError, OSError) as exc:
80
+ output.error(str(exc))
81
+ return 1
82
+
83
+ fp = cert_fingerprint(cert)
84
+ master = _secrets.token_bytes(constants.MASTER_SECRET_LEN)
85
+ now = unix_now()
86
+ entry = {
87
+ "fingerprint": fp,
88
+ "master_secret": master.hex(),
89
+ "status": "active",
90
+ "created": now,
91
+ "expires": now + args.days * 86400,
92
+ "allow": list(args.allow),
93
+ }
94
+ if provider is not None:
95
+ entry["provider"] = provider # без поля клиент работает с первым провайдером шлюза
96
+ # Пакет — до реестра (см. docstring): при сбое клиента в реестре ещё нет.
97
+ try:
98
+ _write_bundle(out, {
99
+ "ca.pem": ca.cert_to_pem(ca_cert),
100
+ "client.pem": ca.cert_to_pem(cert),
101
+ "client.key": ca.key_to_pem(key),
102
+ "master.secret": master.hex().encode("ascii"),
103
+ })
104
+ except (GatekeeperError, OSError) as exc:
105
+ if not out_existed:
106
+ with suppress(OSError):
107
+ out.rmdir()
108
+ output.error(f"cannot write the client bundle: {exc}")
109
+ return 1
110
+ try:
111
+ reg.add(args.id, entry)
112
+ except GatekeeperError as exc:
113
+ for name in ("ca.pem", "client.pem", "client.key", "master.secret"):
114
+ with suppress(OSError):
115
+ (out / name).unlink()
116
+ if not out_existed:
117
+ with suppress(OSError):
118
+ out.rmdir()
119
+ output.error(str(exc))
120
+ return 1
121
+
122
+ try:
123
+ AuditChain(FileSink(layout.audit_log), secrets=(master,)).append(
124
+ EventType.CLIENT_ADDED,
125
+ {"client": args.id, "fingerprint": fp, "allow": list(args.allow), "days": args.days,
126
+ **({"provider": provider} if provider else {})},
127
+ )
128
+ except (GatekeeperError, OSError) as exc:
129
+ output.info(f"client {args.id} added, fingerprint {fp}, bundle written to {out}")
130
+ output.error(f"WARNING: the client is registered but the event was not recorded in the "
131
+ f"journal: {exc}")
132
+ return 0
133
+ output.info(f"client {args.id} added, fingerprint {fp}")
134
+ output.info(f"bundle written to {out} (client.key and master.secret are secret)")
135
+ return 0