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

atproto: PLC operations, DID documents and service-auth tokens

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

What changes

crates/atproto gets identity, the last of step 2's parts:

  • plc: PLC operations made and signed (genesis, update, tombstone), the DID a genesis makes, each operation's CID, which rotation key signed one, and operations read from and written as the directory's JSON. A prev is a CID written as text, inside the signed bytes too, as the directory has it.
  • did: DID documents read as knotless reads them (services and keys found by the end of their id, #atproto_pds, #atproto, the space alpha's #atproto_kem, the claimed handle), and the document of a service's own did:web, which the host serves for itself.
  • service_auth: service-auth JWTs signed, read and checked: alg must be the key's, the signature low-S, exp after the time given; check holds aud and lxm and answers the account asking, a service's #fragment taken off iss.

Why

The host mints its groups' did:plcs and rotates their keys, serves its own did:web, and checks the service token on nearly every call it answers. These follow knotless's conventions where knotless already does the same thing (its crypto, identity and auth), so the two read documents and tokens alike.

How it was checked

Against the reference implementations, with fixed keys (tests/reference/identity.json, from identity.mjs): every operation @did-plc/lib makes, for a secp256k1 rotation key and for a P-256 one beside a second key, is byte for byte the same here (genesis, handle update, PDS update, tombstone), signatures included, as both sign by RFC 6979; so are the DID and CIDs. The directory's DID document reads here, and a JWT @atproto/xrpc-server signs checks.

Against knotless, with a scratch crate linking both (not kept, as CI has no knotless checkout): 505 DRISL records encoded and read back the same; did:keys from the same secrets; P-256 signatures identical, each checking the other's; every signature vector judged alike; 5,000 TIDs; all handle vectors. knotless's verify_jwt takes this crate's tokens on both curves, and a token knotless signs is kept as tests/reference/knotless.json and checks here. The one difference: a float like 123.0 encodes here, as the interop vectors call it valid, and knotless refuses it.

Locally, cargo llvm-cov at 100% of lines and functions, clippy clean.

Shortcomings

Stacked on the repo pull. Reading a DID's whole operation log, as the directory's audit log has it, with nullification, is not here: the host only ever writes its own groups' operations and reads documents. Nothing in the host uses these yet.

Review

src/plc.rs (fields, did, signed_by) and src/service_auth.rs (verify).

Approved

This adds the plc, did and service_auth modules to crates/atproto. I read all three source files in full. The diff against main also carries the whole repo pull this is stacked on, and I did not review that part. I found nothing that has to change.

  • plc.rs: The signed bytes leave out sig and write prev as CID text, as the directory does. did() hashes the signed genesis, and cid() and signed_by() are consistent with that. Your byte-for-byte comparison against @did-plc/lib backs this up.
  • service_auth.rs: verify checks that alg matches the key and verifies the signature before it checks exp. check holds aud and lxm, and account() takes the #fragment off iss. A token with extra or missing segments fails the signature check, so the rsplit_once fallback is safe.
  • did.rs: Lookup by the end of the id is the same as in knotless, as you say.

Small things, none worth holding the pull for:

  • Signed::from_json reads a prev that is neither null nor a string as a genesis, with no error. That is lenient for input from outside.
  • Signed::did() does not check that the operation is a genesis, so it will give a DID for an operation that has a prev. The doc comment says what it is for, but callers need to know.
Approved

This round, I read the diff from my last reviewed head (6fe7ef9) to 275f34b. It has three changes besides the docs. I found nothing that has to change.

  • mst.rs: read_node now refuses a node reached twice, using a seen set. A valid MST never reaches one node from two places, and Tree::read checks the root against the tree the keys make. So this refuses nothing valid and closes the exponential walk. The new test covers it.
  • commit.rs: map.len() != 6 rejects extra fields, so a commit written back still comes to its CID. It is tested.
  • Cargo.toml: bs58 is no longer a dev-dependency, and sha2 moved. Nothing in the diff's tests uses bs58.

The two small points from my last review are unchanged and still not worth holding the pull for. Signed::from_json reads a non-string prev as a genesis. Signed::did() does not check that the operation is a genesis.

Merged as 275f34b