Oficina ID native: revocation and Sign out all devices
Human
Prompt
Implement the Home (id.oficina.works) half of slice A of the approved Oficina ID native spec. Paul approved the spec and building on 2026-11-14.
Read first: native-levelup/BRIEF.md (own worktree from fresh origin/main, repo AGENTS.md, amadan workflow, agent account, never -as-human, pinned-toolchain make gates, no deploys, do not merge). Then in the Home repo: docs/superpowers/specs/2026-11-14-oficina-id-native.md (binding; slice table §14), 2026-11-13-oficina-id-slice-1.md (binding base), Home AGENTS.md.
Scope — slice A, Home side only (another agent does connect/NativeExchange/choose page/IsHomeDerived in parallel on its own branch; a third does the Swift client; coordinate only through the spec's wire formats, and if the spec is ambiguous about a wire detail, pick the reading most consistent with it, write it into a short "wire notes" section of your branch description, and flag it):
- the native grant + device-key proof (§3), persistent replay table, per-grant rate limit, server Date for clock offset;
- email code start/resend/verify with every limit in §4 (per-(address, device key) caps, daily cap, returning-key exemption by end_reason, per-IP-bucket live starts, 503 when full, shared email budget with the web, sealed addresses, no codes/addresses in logs; Keymail addresses get the code in slice A);
- native passkey sign-in (§5): passkey/begin, passkey/finish against RP id.oficina.works, plus the static /.well-known/apple-app-site-association with webcredentials for the five App IDs 9U4A84C4WK.works.oficina.{calls,docs,sheets,calendar,memoria} (no applinks);
- assert with the shared mintPolicy (empty in slice A), native nonce derivation;
- signout, "Sign out all devices" on the web, replacement revoking every grant, first passkey enrolment (native or web) revoking passkey-less grants;
- directory teams listing + zero-teams help;
- every slice-A gate in §13 that belongs to Home, as tests.
Not in scope: A2 (multiple identities UI, Devices page, Keymail sheet), B (native recovery/enrolment), C–E.
Process: small reviewable commits; make ci green; push; describe the branch on the hub with tasks; stop for review. Report: branch, tip, what's done vs deferred, gate output, wire notes, open questions.From this commit's own message. The prompt ledger has no entries for it — which is what a squashed, rebased or amended commit looks like, and what every commit looks like in a repo without a ledger.
Summary
Recovery-code replacement now ends every native grant (end_reason replacement); a first web passkey enrolment ends every grant whose method has no passkey (enrolment), the device that showed the nudge included. Adds Sign out all devices at id.oficina.works/devices/sign-out-all, behind RequireFresh(10 min), csrf.Protect and an in-transaction freshness recheck, linked from the directory's account menu beside Passkeys and Recovery codes; it ends every grant (all_devices) and leaves browser sessions alone.
Agent notes
The spec says 'in id.*'s account menu'; id.* pages draw a brand-only bar, so the item sits where Passkeys and Recovery codes already sit, in the directory's menu, pointing at id.*. Native enrolment (slice B) will call endPasskeylessGrants with its own grant as the exception.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
7 files changed,
+191
−0
internal/home/app.go+6 −0internal/home/chrome.go+1 −0internal/home/id_passkey.go+7 −0internal/home/id_recovery.go+5 −0internal/home/native_revoke_test.go+116 −0internal/home/signout_all.go+38 −0internal/home/templates/id_signout_all.html+18 −0
diff --git a/internal/home/app.go b/internal/home/app.go| index b42ad75..e76aba4 100644 |
| --- a/internal/home/app.go |
| +++ b/internal/home/app.go |
| @@ -267,6 +267,12 @@ func (a *App) Router() http.Handler { |
| // enrolFreshness for the lockout this closes. |
| r.Group(func(r chi.Router) { |
| r.Use(a.sessions.RequireFresh(enrolFreshness)) |
| + // Ending every device's grant changes who can get in, so it |
| + // wants a recent session too (§10). |
| + if a.runtime != nil && a.runtime.role == "credential" { |
| + r.Get(signoutAllPath, a.handleSignoutAllPage) |
| + r.Post(signoutAllPath, a.handleSignoutAll) |
| + } |
| r.Get("/passkey/enrol", a.handlePasskeyEnrol) |
| r.Post("/passkey/register/begin", a.idBegin("register")) |
| r.Post("/passkey/register/finish", a.idFinish("register")) |
diff --git a/internal/home/chrome.go b/internal/home/chrome.go| index bfbdba3..08de0fa 100644 |
| --- a/internal/home/chrome.go |
| +++ b/internal/home/chrome.go |
| @@ -95,6 +95,7 @@ func (a *App) account(r *http.Request, status int) *chrome.Account { |
| items = append(items, |
| menu.Item{Href: a.origins.Credential + "/passkey/enrol", Label: "Passkeys"}, |
| menu.Item{Href: a.origins.Credential + "/passkey/codes", Label: "Recovery codes"}, |
| + menu.Item{Href: a.origins.Credential + signoutAllPath, Label: "Sign out all devices"}, |
| ) |
| return &chrome.Account{ |
| TriggerLabel: "Account", |
diff --git a/internal/home/id_passkey.go b/internal/home/id_passkey.go| index 9c3c9f3..234fede 100644 |
| --- a/internal/home/id_passkey.go |
| +++ b/internal/home/id_passkey.go |
| @@ -328,6 +328,13 @@ func (a *App) idFinish(purpose string) http.HandlerFunc { |
| idRefuse(w) |
| return |
| } |
| + // A first passkey ends every grant that has none (§3). A web |
| + // enrolment has no enrolling grant, so every code-only device |
| + // signs in again, now with the passkey. |
| + if count == 0 && endPasskeylessGrants(tx, subject, "", now) != nil { |
| + idRefuse(w) |
| + return |
| + } |
| id := hex.EncodeToString(cred.ID) |
| if _, e = tx.Exec("INSERT INTO passkey_credentials(id,subject,public_key,sign_count,created_at) VALUES(?,?,?,?,?)", id, subject, cred.PublicKey, cred.SignCount, time.Unix(now, 0).UTC().Format(time.RFC3339)); e != nil { |
| idRefuse(w) |
diff --git a/internal/home/id_recovery.go b/internal/home/id_recovery.go| index 1448e40..8327b40 100644 |
| --- a/internal/home/id_recovery.go |
| +++ b/internal/home/id_recovery.go |
| @@ -331,6 +331,11 @@ func (a *App) replaceCredential(tx *sql.Tx, r *http.Request, subject string, cre |
| return errIDProof |
| } |
| } |
| + // Replacement by recovery code is full account control, and it is also |
| + // how a lost device is cut off: every native grant ends (§3). |
| + if err := endGrants(tx, subject, "replacement", now); err != nil { |
| + return err |
| + } |
| id := hex.EncodeToString(cred.ID) |
| if _, err := tx.Exec("INSERT INTO passkey_credentials(id,subject,public_key,sign_count,created_at) VALUES(?,?,?,?,?)", id, subject, cred.PublicKey, cred.SignCount, time.Unix(now, 0).UTC().Format(time.RFC3339)); err != nil { |
| return errIDProof |
diff --git a/internal/home/native_revoke_test.go b/internal/home/native_revoke_test.go| new file mode 100644 |
| index 0000000..85f9d1a |
| --- /dev/null |
| +++ b/internal/home/native_revoke_test.go |
| @@ -0,0 +1,116 @@ |
| +package home |
| + |
| +import ( |
| + "net/url" |
| + "strings" |
| + "testing" |
| + "time" |
| + |
| + "amadan.net/oficina/home/internal/home/sealtest" |
| + "amadan.net/rastrillo/rastrillo/webauthn" |
| +) |
| + |
| +// §13 Revocation: a first passkey enrolment on the web ends every |
| +// passkey-less grant; later enrolments end nothing. |
| +func TestNativeFirstEnrolmentRevokesPasskeylessGrants(t *testing.T) { |
| + app := newNativeApp(t) |
| + d := newDevice(t) |
| + g1, _ := d.signInByCode(t, app, sealtest.CanaryAddress) |
| + session := signInFully(t, app, sealtest.CanaryAddress) |
| + enrol(t, app, session) |
| + if ended, reason := grantState(t, app, g1); !ended || reason != "enrolment" { |
| + t.Fatal("code grant survived first enrolment", reason) |
| + } |
| + // It may sign in again, now with a passkey; a second enrolment leaves |
| + // that grant alone. |
| + app = app.restart(t) |
| + start := d.start(t, app, sealtest.CanaryAddress) |
| + if out := decodeReply(t, d.verify(t, app, start, lastCode(t, app))); out["pending"] == nil { |
| + t.Fatal("no pending", out) |
| + } |
| + if _, err := app.db.Writer().Exec("INSERT INTO home_id_grants(grant_hash,person_ref,identity_id,device_key,platform,method,auth_time,created_at,last_used_day,expires_at) VALUES('pk',?,'i','k','macos','passkey',1,1,?,?)", subjectOf(t, app, session), dayOf(time.Now().Unix()), time.Now().Unix()+day); err != nil { |
| + t.Fatal(err) |
| + } |
| + enrol(t, app, session) |
| + if n := count(t, app, "SELECT count(*) FROM home_id_grants WHERE grant_hash='pk' AND ended_at IS NULL"); n != 1 { |
| + t.Fatal("a second enrolment ended a passkey grant") |
| + } |
| +} |
| + |
| +// §13 Revocation: "Sign out all devices" ends every grant, behind a fresh |
| +// session and request-forgery protection. |
| +func TestNativeSignOutAllDevices(t *testing.T) { |
| + app := newNativeApp(t) |
| + g1, _ := newDevice(t).signInByCode(t, app, sealtest.CanaryAddress) |
| + app = app.restart(t) |
| + g2, _ := newDevice(t).signInByCode(t, app, sealtest.CanaryAddress) |
| + other, _ := newDevice(t).signInByCode(t, app, "other@example.invalid") |
| + session := signInFully(t, app, sealtest.CanaryAddress) |
| + |
| + page := exchangeRequest(app.App, "GET", Origin+signoutAllPath, "", nil, session) |
| + if page.Code != 200 || !strings.Contains(page.Body.String(), `action="/devices/sign-out-all"`) { |
| + t.Fatal("page", page.Code) |
| + } |
| + if forged := exchangeRequest(app.App, "POST", Origin+signoutAllPath, "https://evil.example", url.Values{}, session); forged.Code != 403 { |
| + t.Fatal("cross-origin sign-out-all", forged.Code) |
| + } |
| + if anon := exchangeRequest(app.App, "POST", Origin+signoutAllPath, Origin, url.Values{}); anon.Code == 200 { |
| + t.Fatal("no session ended devices") |
| + } |
| + // A stale session must re-authenticate first. |
| + if _, err := app.db.Writer().Exec("UPDATE sessions SET auth_time=?, created_at=?", time.Now().Add(-time.Hour).UTC().Format(time.RFC3339), time.Now().Add(-time.Hour).UTC().Format(time.RFC3339)); err != nil { |
| + t.Fatal(err) |
| + } |
| + if stale := exchangeRequest(app.App, "POST", Origin+signoutAllPath, Origin, url.Values{}, session); stale.Code == 200 { |
| + t.Fatal("a stale session ended devices") |
| + } |
| + if n := count(t, app, "SELECT count(*) FROM home_id_grants WHERE ended_at IS NOT NULL"); n != 0 { |
| + t.Fatal("grants ended without a fresh session", n) |
| + } |
| + session = signInFully(t, app.restart(t), sealtest.CanaryAddress) |
| + done := exchangeRequest(app.App, "POST", Origin+signoutAllPath, Origin, url.Values{}, session) |
| + if done.Code != 200 || !strings.Contains(done.Body.String(), "All devices are signed out") { |
| + t.Fatal("sign out all", done.Code) |
| + } |
| + for _, g := range []string{g1, g2} { |
| + if ended, reason := grantState(t, app, g); !ended || reason != "all_devices" { |
| + t.Fatal("grant survived", reason) |
| + } |
| + } |
| + if ended, _ := grantState(t, app, other); ended { |
| + t.Fatal("another person's grant ended") |
| + } |
| + if subjectOf(t, app, session) == "" { |
| + t.Fatal("this browser was signed out") |
| + } |
| +} |
| + |
| +// §13 Revocation: recovery-based replacement ends every grant. |
| +func TestNativeReplacementRevokesEveryGrant(t *testing.T) { |
| + app := newNativeApp(t) |
| + d := newDevice(t) |
| + g, _ := d.signInByCode(t, app, sealtest.CanaryAddress) |
| + session := signInFully(t, app, sealtest.CanaryAddress) |
| + subject := subjectOf(t, app, session) |
| + // A passkey grant, as native passkey sign-in would leave. |
| + if _, err := app.db.Writer().Exec("INSERT INTO home_id_grants(grant_hash,person_ref,identity_id,device_key,platform,method,auth_time,created_at,last_used_day,expires_at) VALUES('pk',?,'i','k','macos','passkey',1,1,?,?)", subject, dayOf(time.Now().Unix()), time.Now().Unix()+day); err != nil { |
| + t.Fatal(err) |
| + } |
| + tx, now, err := app.idTransaction(t.Context()) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + cred := webauthn.Credential{ID: []byte("replacement-credential"), PublicKey: []byte{1}} |
| + if err := app.replaceCredential(tx, nil, subject, cred, now); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := tx.Commit(); err != nil { |
| + t.Fatal(err) |
| + } |
| + if n := count(t, app, "SELECT count(*) FROM home_id_grants WHERE ended_at IS NULL"); n != 0 { |
| + t.Fatal("grants survived replacement", n) |
| + } |
| + if _, reason := grantState(t, app, g); reason != "replacement" { |
| + t.Fatal(reason) |
| + } |
| +} |
diff --git a/internal/home/signout_all.go b/internal/home/signout_all.go| new file mode 100644 |
| index 0000000..ebe0e59 |
| --- /dev/null |
| +++ b/internal/home/signout_all.go |
| @@ -0,0 +1,38 @@ |
| +package home |
| + |
| +import ( |
| + "net/http" |
| + "time" |
| +) |
| + |
| +// signoutAllPath is "Sign out all devices" (§10): the slice-A stand-in for |
| +// A2's Devices page. It ends every native grant the person holds. Browser |
| +// sessions are not native grants and are left alone; each device's team |
| +// sessions run out within seven days (the disclosed residual). |
| +const signoutAllPath = "/devices/sign-out-all" |
| + |
| +func (a *App) handleSignoutAllPage(w http.ResponseWriter, r *http.Request) { |
| + a.render(w, r, http.StatusOK, "id_signout_all.html", map[string]any{"Done": false}) |
| +} |
| + |
| +// handleSignoutAll is behind RequireFresh and csrf.Protect, and re-reads the |
| +// live session inside the writer transaction, as recovery-code generation |
| +// does, so a session revoked a moment ago cannot end anybody's devices. |
| +func (a *App) handleSignoutAll(w http.ResponseWriter, r *http.Request) { |
| + tx, now, err := a.idTransaction(r.Context()) |
| + if err != nil { |
| + a.serverError(w, r) |
| + return |
| + } |
| + defer tx.Rollback() |
| + live, _, err := a.idSession(tx, r, now) |
| + if err != nil || !idFreshSession(live, enrolFreshness, time.Unix(now, 0)) { |
| + a.signinFailed(w, r) |
| + return |
| + } |
| + if err = endGrants(tx, live.Subject, "all_devices", now); err != nil || tx.Commit() != nil { |
| + a.serverError(w, r) |
| + return |
| + } |
| + a.render(w, r, http.StatusOK, "id_signout_all.html", map[string]any{"Done": true, "Directory": a.origins.Directory}) |
| +} |
diff --git a/internal/home/templates/id_signout_all.html b/internal/home/templates/id_signout_all.html| new file mode 100644 |
| index 0000000..ebbe279 |
| --- /dev/null |
| +++ b/internal/home/templates/id_signout_all.html |
| @@ -0,0 +1,18 @@ |
| +{{define "title"}}Sign out all devices · Oficina{{end}} |
| +{{define "content"}} |
| +{{if .Data.Done}} |
| +<h1>All devices are signed out</h1> |
| +<p>Every Oficina app on every device is signed out of your Oficina ID. Each one asks you to sign in again the next time it opens.</p> |
| +<p>An app that is offline now finds out when it next connects. Until then it can keep using what it already has open for up to seven days.</p> |
| +<a href="{{.Data.Directory}}/" rst-btn="primary">Done</a> |
| +{{else}} |
| +<h1>Sign out all devices</h1> |
| +<p>This signs your Oficina ID out of the Oficina apps on every Mac, iPhone and iPad, including this one's apps. You stay signed in to this browser.</p> |
| +<p>Use it if you have lost a device, or if you signed in somewhere you shouldn't have.</p> |
| +<form method="post" action="/devices/sign-out-all" rst-form> |
| + <div rst-form-foot> |
| + <button type="submit" rst-btn="danger">Sign out all devices</button> |
| + </div> |
| +</form> |
| +{{end}} |
| +{{end}} |