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 ↓

one request, simplifiedfrom the spec

Authorization: Bearerat1_7h2kq4m6xw3b5n7d_3vq7…

  1. 1kid → rowfound
  2. 2HKDF(secret, kid) → verifiermatches
  3. 3HKDF(secret, kid) → enc_keyin memory
  4. 4open(ciphertext, enc_key)provider key
  5. 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.

  1. at1

    at1 format

    Product prefix and format version. A new format becomes at2.

  2. 7h2kq4m6xw3b5n7d

    kid 10 random bytes · public

    The key ID, 16 base32 characters. Safe to log and show.

  3. 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

  1. atropos/v1
  2. kid
  3. provider
  4. upstream_host
  5. 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.

  1. 01

    Route

    The path prefix names the provider; the method and path must be on its allowlist.

    404
  2. 02

    Token

    Read from Authorization: Bearer or the provider’s own header. Never from the URL, because URLs end up in logs.

    401
  3. 03

    Row

    Load the key by its ID. Missing, revoked or expired stops here.

    401
  4. 04

    Verify

    Derive the verifier from the secret and compare in constant time.

    401
  5. 05

    Provider

    The key’s provider must match the route.

    403
  6. 06

    Policy

    IP allowlist, rate limit and monthly budget.

    403 · 429
  7. 07

    Body

    Read the body up to a size cap, then check the model allowlist.

    403
  8. 08

    Decrypt and forward

    Rebuild the associated data from the row, open the key, send the request to the row’s host.

  9. 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

  1. Spec and setup

    The protocol spec, the Cargo workspace, and one check that runs fmt, clippy, the tests, cargo audit and cargo deny.

    next
  2. Core crypto

    Token generation and parsing, key derivation, seal and open, with tamper tests and test vectors checked against a second implementation.

    planned
  3. Storage and admin API

    Provider definitions and enrolled keys in SQLite; revoke erases the ciphertext.

    planned
  4. Enroll from the CLI

    The key is sealed on the PC and only ciphertext reaches the server.

    planned
  5. The proxy

    Route, verify, decrypt, forward, in the order the spec sets.

    planned
  6. Streaming

    Server-sent events passed through chunk by chunk.

    planned
  7. Hardening and deploy

    planned
  8. Policies and usage

    Budgets, rate limits, model and IP allowlists, usage per token.

    planned
  9. Management CLI

    Rotate, revoke, and revoke everything at once.

    planned

The name

Named after Atropos, the Fate who cuts the thread of life. Revoking a key is the cut.

Jump to

↑ ↓ move↵ openesc close

You found the 8.

mi8ess can read this board but cannot generate moves yet, so both sides are moved by hand.

Play e4 to start

Open mi8ess

Click anywhere to close