~ knotless Search/
↑↓ move↵ open⇧↵ all results
0
0

atproto: space tokens, credentials and signed requests

Merged
Merged chadtmiller.com asked to merge into main from chadtmiller.com/group-host:atproto/space-auth

What changes

atproto::space_auth: who may read a space, as the space alpha says (@atproto/space's credential.ts and http-signature.ts):

  • Tokens of three kinds, made (create), read for shape (parse) and checked (verify, its time given): a delegation token, a member's PDS vouching for a minute and once that its account asks; a space credential, the authority granting access for up to an hour, bound to a key of the member's (cnf.kid); a client attestation, an app vouching for itself. Each kind's typ, kid, audience, binding and lifetime are held as the reference holds them, and each refusal carries its code (BadJwt, BadJwtType, JwtExpired, BadJwtSignature, …), with 5 seconds of clock skew.
  • Signed requests: sign_request makes the four headers of a request made with a credential, an HTTP message signature over the credential and its audience; verify_request checks one against the credential's key, holding what it covers, its tag, algorithm and keyid as the reference does, and passing over other members of the headers' dictionaries.
  • PublicKey::verify_either_s: such a signature may be high-S, as the alpha's check allows; every other signature here stays low-S only.

Why

Step 4: the host is the authority for its groups' spaces, so it checks the delegation tokens members' PDSes send, grants space credentials, and checks each signed request made with one. Next: the repos the host keeps in spaces.

How it was checked

The reference's signed request (space-vectors.json's httpSignature) verifies, and refuses once its audience changes. Requests knotless's client signs (knotless::space::signed, 20 of them, in a scratch crate linking both) verify. Each token kind made and checked; each refusal of making and of checking, by code; the signed request's every malformed form. The interop vectors' high-S signatures are refused by verify and taken by verify_either_s. cargo llvm-cov at 100% of lines and functions, clippy clean.

Shortcomings

A token's single use (the jti spent once) is the caller's to keep, as in the reference. The structured-field parsing is enough for these headers, not a general one.

Approved

This adds atproto::space_auth: delegation tokens, space credentials and client attestations (create, parse, verify), plus sign_request and verify_request for HTTP message signatures. It also adds PublicKey::verify_either_s. I read the whole diff and found nothing that needs changing. Checks pass, including the 100% coverage gate, fmt and clippy. The docs page is updated.

I checked these points:

  • verify runs the time, audience and subject checks before the signature check, and the algorithm must match the key's curve.
  • parse rejects a credential whose lifetime exceeds an hour or is not positive, and one whose iat is in the future.
  • verify_request signs and verifies over the raw signature-params text it received, so there is no re-serialisation mismatch.
  • verify_either_s is used only for the HTTP signature. Every other signature stays low-S only.

One optional note. The member scanner toggles quoted on every " and does not handle \" escapes. A header with an escaped quote could split in the wrong place. That can only make a valid request fail to verify, not make a bad one pass, and the PR already names the parser's limits, so I'd leave it.

Merged as 80850cb