mirror of
https://github.com/block/buzz.git
synced 2026-11-28 04:01:45 +00:00
Follow-up to [#9811 enroll Android devices for push](https://github.com/block/buzz/pull/9811), covering the gateway side of its non-blocking review comments. Two enrollment states could make an Android phone discard a key its committed installation still holds, after which its fresh enrollment hits `409 installation_conflict` for the installation's whole lifetime (up to about 30 days of no push). Both now answer in a way the client already treats as "keep the key and retry". - **Enrollment replay racing the original request** ([review comment](https://github.com/block/buzz/pull/9811#discussion_r4648232889)). Enrollment consumed its challenge in one statement and created the installation in another. A client that timed out between them and replayed the same signed request found a spent challenge and no installation, and got `404 not_authorized`. Consuming the challenge and creating the installation are now one transaction. A concurrent replay locks the challenge row before judging its expiry, so it waits even when the challenge expires meanwhile, then returns the installation the first request committed, or enrolls itself if that request rolled back or was cancelled. A request that finds its challenge expired deletes it before answering `404`, so a slower request that read its clock earlier cannot spend it afterwards. A refused creation (`409`) also leaves the challenge unspent. - **Enrollment before the attestation status list loads.** A restarted gateway has no status list until its first refresh (and a list past its grace period is equally unusable), so every Android chain was refused with `401 invalid_attestation`, which the client treats as final. The verifier now reports a missing or stale list as unavailable, and enrollment answers `503 temporarily_unavailable` before spending anything. A listed certificate is still refused. - **NIP-PL** now specifies Android enrollment: the `android_attestation` chain and FCM token request, the `buzz.push.enroll.android.v1` transcript whose SHA-256 is the Keystore attestation challenge, what the gateway checks in the chain, and the SHA256withECDSA signature Android installation calls carry in `assertion`. It also records the two behaviors above, corrects the enrollment body ceiling for the Android chain allowance, names the transcript separator as one LF byte, and says a client stores its installation handle before delegating (replay recovery ends once a delegation extends the installation's expiry). ### Validation Added tests: - [`enrollment_replay_waits_for_an_uncommitted_enrollment`](61c7ef2480/crates/buzz-push-gateway/src/postgres.rs) (PostgreSQL): stages an enrollment whose challenge is spent but whose installation is uncommitted, starts an exact replay, and waits until PostgreSQL shows the replay blocked on it, then checks that the replay recovers the original installation after commit or enrolls itself after rollback, both inside and past the challenge's expiry. `expired_replay_first_retires_the_challenge` and `refused_enrollment_leaves_its_challenge_unspent` cover the other arrival order and the `409` case. - [`enrollment_replay_of_a_spent_challenge_recovers_the_installation_that_spent_it` and `refused_enrollment_leaves_its_challenge_unspent`, `expired_replay_first_retires_the_challenge`](61c7ef2480/crates/buzz-push-gateway/src/authority.rs): the same contract on the in-memory reference store. - [`enrollment_waits_out_a_missing_revocation_list_without_spending_anything`](61c7ef2480/crates/buzz-push-gateway/src/http_android_tests.rs): through the router, a fresh enrollment and a lost-response replay both get `503` while the list is missing, then `201` with the same handle once it loads. - [`the_trait_defers_rather_than_rejects_without_a_fresh_list`](61c7ef2480/crates/buzz-push-gateway/src/android_attestation/key_attestation_tests.rs): the production verifier reports a missing or stale list as unavailable and a listed certificate as invalid. ### Regressions - Enrollment holds one transaction across the challenge delete and the installation insert instead of two short ones. The insert already ran in a transaction with row locks; the only added wait is a replay of the same challenge, which previously failed. - A refused enrollment no longer burns its challenge. The challenge stays single-use for success and still expires after 300 seconds; replaying a refused request only gets the same refusal. - While the status list is missing or stale, Android enrollment answers `503` instead of `401`. Nothing is admitted that wasn't before; clients retry instead of giving up. iOS enrollment and signed calls are unchanged. --------- Signed-off-by: Tom Brow <tomb@block.xyz> Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@buzz.block.builderlab.xyz>