Project 01 · Rust · Spec stage
atropos
A small Rust proxy that keeps an API key split in two.
The server stores the provider key only as ciphertext. My machine stores only a random token. To use the key, a request has to pass through the proxy with the token.
The protocol spec and the Cargo workspace are in. The core crypto crate is next.
How it works ↓Authorization: Bearerat1_7h2kq4m6xw3b5n7d_3vq7…
- 1kid → rowfound
- 2HKDF(secret, kid) → verifiermatches
- 3HKDF(secret, kid) → enc_keyin memory
- 4open(ciphertext, enc_key)provider key
- 5forward to the row’s hostapi.anthropic.com
Simplified: the full order is under “A request”. The key is decrypted for one request and never written down.
How it works
The token is three parts joined by underscores. The key ID in the middle may be shown and logged; the secret at the end never is.
at1at1 format
Product prefix and format version. A new format becomes at2.
7h2kq4m6xw3b5n7dkid 10 random bytes · public
The key ID, 16 base32 characters. Safe to log and show.
3vq7…secret 32 random bytes · never stored
52 base32 characters. The server never stores it and never logs it.
Base32 has no underscore or dash, so the underscores split the token without doubt and a double-click selects all of it.
Two keys from one secret
HKDF-SHA256 (secret, salt = kid)
verifierstored
info “atropos v1 verifier”
A cheap check that a token is valid, compared in constant time before anything is decrypted.
enc_keynever stored
info “atropos v1 encryption”
Encrypts and decrypts the provider key.
No slow password hash: the secret is 256 random bits, so it cannot be guessed. The separate info strings make the two outputs independent, so a leaked verifier says nothing about enc_key.
Sealing the provider key
XChaCha20-Poly1305, a fresh random 24-byte nonce every time
Bound into the associated data
- atropos/v1
- kid
- provider
- upstream_host
- auth_header
Someone who can write to the database and points a key at another host, or moves a ciphertext under another key ID, gets a decryption failure.
A request
Every request goes through nine named steps, in this order. The order is part of the spec.
- 01404
Route
The path prefix names the provider; the method and path must be on its allowlist.
- 02401
Token
Read from Authorization: Bearer or the provider’s own header. Never from the URL, because URLs end up in logs.
- 03401
Row
Load the key by its ID. Missing, revoked or expired stops here.
- 04401
Verify
Derive the verifier from the secret and compare in constant time.
- 05403
Provider
The key’s provider must match the route.
- 06403 · 429
Policy
IP allowlist, rate limit and monthly budget.
- 07403
Body
Read the body up to a size cap, then check the model allowlist.
- 08
Decrypt and forward
Rebuild the associated data from the row, open the key, send the request to the row’s host.
- 09
Reply and record
Stream the answer back, then write usage and one metadata row.
The key ID is public, so nothing after step 4 runs for a token that has not been verified. Otherwise anyone who saw a key ID could use up its rate limit or read its policy from the error codes.
If something leaks
What each kind of leak gives an attacker. A hollow dot is a leak the split cannot help with.
The server’s database, disk or a backup
Ciphertext only. The keys to open it are never stored on the server.
The token from my machine
Not the real key. The token works through the proxy until it is revoked, within its expiry and limits.
Live code execution on the server
The keys of requests made while the attacker is in. Keys not used around that time stay safe.
The token and an old copy of the ciphertext
The real key. Revoking erases the ciphertext, but old backups keep it.
Both sides, fully
The real key. Only rotating it at the provider helps.
Rules for the code
A bug here can leak a real key, so the code follows strict rules.
No unsafe
Every crate starts with #![forbid(unsafe_code)].
No hand-written crypto
Primitives come only from vetted crates: chacha20poly1305, hkdf, sha2, subtle, zeroize, secrecy, rustls.
Secret types stay secret
Wiped on drop, never printed, cloned or serialised, and compared only in constant time.
Nothing secret in logs
Logs carry the key ID, route, status and latency, and nothing else.
The host comes from the row
Never from the request. The upstream client follows no redirects and ignores proxy settings.
No panics
No unwrap, expect or indexing that can go out of bounds outside tests.
Roadmap
- next
Spec and setup
The protocol spec, the Cargo workspace, and one check that runs fmt, clippy, the tests, cargo audit and cargo deny.
- planned
Core crypto
Token generation and parsing, key derivation, seal and open, with tamper tests and test vectors checked against a second implementation.
- planned
Storage and admin API
Provider definitions and enrolled keys in SQLite; revoke erases the ciphertext.
- planned
Enroll from the CLI
The key is sealed on the PC and only ciphertext reaches the server.
- planned
The proxy
Route, verify, decrypt, forward, in the order the spec sets.
- planned
Streaming
Server-sent events passed through chunk by chunk.
- planned
Hardening and deploy
- planned
Policies and usage
Budgets, rate limits, model and IP allowlists, usage per token.
- planned
Management CLI
Rotate, revoke, and revoke everything at once.
The name
Named after Atropos, the Fate who cuts the thread of life. Revoking a key is the cut.