oficina / home Public

feat/oficina-id-native-a

Human

Oficina ID native, slice A, the Home half (spec docs/superpowers/specs/2026-11-14-oficina-id-native.md, §3–§5, §7 step 1, §9 teams, §10, §13). Cut from main 979dac4; main e03a01a (the connect work) merged in, with handoff repinned to it. Fable reviewed cdad4ed: APPROVE AFTER FIXES. The fixes and Paul's 2026-11-14 rulings are on this branch. Not deployed, not merged.

What it adds

  • Grants and the device-key proof (§3). home_id_grants (identity migration 0004). Authorization: OficinaID <token> plus Oficina-Proof. The replay table is persistent and holds each jti 61 s. Each grant gets 120 calls a minute and each person 300. The table holds 250,000 rows and refuses everything when full. Every answer carries Date, and a 401 carries now. Lifetimes: 90 days idle, 365 days absolute, 20 live grants per person (LRU). An ended grant keeps its device key for 365 days.
  • Email code (§4). code/start, code/resend and code/verify, with every limit in the spec's table held in persistent buckets. The returning-key exemption is decided by end_reason. Live starts are capped per IP bucket, and a full table answers 503 full. Native and web share one email budget. The address is sealed under native.code, and Keymail addresses get a code in slice A. On an account with a passkey, verify returns {factor:["passkey"], pending}.
  • Native passkeys (§5). passkey/begin and passkey/finish, verified against Home's existing WebAuthn config (RP id.oficina.works). Also the static /.well-known/apple-app-site-association: five App IDs, webcredentials only.
  • assert (§7). It maps aud by exact origin and refuses the operator consumer. Home sets the nonce with handoff.NativeNonce. It calls mintPolicy, which is empty and now also called by /authorize.
  • Revocation (§3, §10). signout. "Sign out all devices" (Paul, 2026-11-14) ends every grant and every Home browser session of the person, the pressing browser's included. On id., the grants, every session of the person, half-finished sign-ins and a per-person mark (the press time) are written in one transaction. The browser then carries a signed receipt across ("Finishing signing out of oficina.works…"). That receipt is an assertion for the directory whose nonce is derived from its own jti (oficina-id/signout-all/v1). At oficina.works/auth/signed-out-all, the directory ends every directory session of the person (browser and native), records the mark and burns the jti in one transaction, then lands on "All devices are signed out". This browser's directory cookie is cleared only if it is that person's. The directory refuses any assertion issued at or before the mark, at its browser finish and its native exchange, so one minted in the 120 s before the press buys nothing. id. consumes no assertions, so its mark guards grants instead: none created at or before it authenticates. Recovery replacement ends every grant. A first web passkey enrolment ends every grant that has no passkey.
  • Directory (§9). POST oficina.works/native/oficina-id uses connect's NativeExchange request/answer shape and handoff's NativeChallenge/NativeNonce, Store.Verify and Store.Reserve. GET /api/native/teams ([] for none). POST /native/signout. GET /help/teams, the zero-teams help page. A native directory session reaches only the teams list and its own sign-out. On every other route its cookie is stripped before the session middleware runs, and teamFresh/directoryFresh never count it as fresh (Fable's finding 1).
  • Gates (§13) as tests. native_*_test.go and directory_native_test.go, plus gate 9 over the native routes (TestNoContentInLogsNative).

Additions to the spec (keep or drop)

  • passkey/begin is limited to 60 per IP and 300 per network (IPv4 /24, IPv6 /48) per 15 minutes. Paul: keep.
  • One live native challenge per device key: a new begin replaces the last. Native challenges may hold at most 5,000 of the 10,000 shared ceremony rows, so the web door always keeps half.
  • Code starts are also limited to 1,000 per network per day.
  • Each person gets 300 proof calls a minute across all their grants.

Residual of "Sign out all devices"

  • The hop between the two stores is not atomic. id. and oficina.works are separate databases. If the browser never completes the hop (closed tab, refused receipt), id. and the apps are signed out but oficina.works sessions run to their own expiry. The failure page says so and offers "Sign in and try again".
  • Team-app instances (connect) do not read the mark yet. An assertion for a team instance minted in the 120 s before the press can still be exchanged there; they rely on the assertion's 120 s life. Follow-up for connect (slice C).
  • App pages already open in a browser (a Docs tab, say) keep their instance session until it ends. A native app that stays offline keeps its team sessions for up to 7 days. The page copy says exactly this.

Residual denial of service (fail-closed caps)

  • Buckets: 500,000 rows. A start writes about 5 rows, one of them a day long. Filling the table takes on the order of 100,000 starts in a day from more than 100 distinct /48s (or /24s). That locks out new native code starts only, for up to a day. Existing starts still verify, and passkeys and the web are unaffected.
  • Replay: 250,000 rows of 61 s. Filling it takes about 830 accounts calling at the per-person cap, each behind a verified mailbox.
  • Ceremonies. A native flood can take only the native half, and is bounded per IP and per network.

Wire notes (flagged: the spec was silent or ambiguous)

  1. All base64 is base64url without padding. device_key is the 65-byte uncompressed P-256 point (87 chars). The grant token, start and pending are 32 random bytes (43 chars).
  2. The proof payload is exactly {v,htm,htu,iat,jti,bh}, with any key order and no unknown members. It is signed with rastrillo crypto.Sign under oficina-id/native-proof/v1 over the payload bytes as received. htu is https://id.oficina.works + path, with no query. bh is base64url(SHA-256(body)). jti is 16–64 chars of [A-Za-z0-9_-].
  3. 401. {"error":"grant_ended","now":…} means the grant is gone: unknown, revoked, signed out, expired, replaced, or ended by an enrolment. {"error":"proof_rejected","now":…} covers everything else. The client wipes the identity only on grant_ended.
  4. 429. {"error":"daily_limit"} is used only when the per-address daily wrong-code cap for new devices blocks a start or a verify. Every other 429 is rate_limited (verify-resend timing adds resend_after).
  5. Pre-grant calls. code/start {email, device_key, platform}. code/resend {start}. code/verify {start, code}. passkey/begin {device_key, platform, pending?}: with a pending, the key must be that start's key. passkey/finish {id, clientDataJSON, authenticatorData, signature, device_key, platform?, userHandle?}: device_key must be the challenge's bound key, and platform and userHandle are ignored. Every one of these is signed by that key.
  6. Answers. 202 {start, resend_after: 30} (seconds). 200 {grant, identity_id, auth_time} (unix seconds). 200 {challenge, rp_id, credentials}. 200 {assertion}. Other errors are {error}: request, email, code (400, wrong code), expired (410, the start or pending is gone), full / mail / unavailable (503), browser (403), audience (400), policy (403).
  7. platform must be one of macos, ios, ipados.
  8. Native nonce. challenge = SHA-256 of the verifier's base64url string. nonce = base64url(SHA-256("oficina-id/native/v1\0" ‖ the 32 challenge bytes)[:16]). Vector: AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8 → 6oZqdX5MOLq_qBJ8vppAnT4fk6AP8UiP9zX8-Rev_9A → ZVVVj2zbBfhkAIwAOKNylg.
  9. Directory exchange. It answers {state}: ok (with name, value, expires_at = 7 days, and target echoed), invalid 400, failed 401, unavailable 503. It never answers 403 unknown or 409 choose. teams needs a home-assertion-native directory session.
  10. Keys. identityid, the code MACs and the native blinds are HKDF-SHA256 subkeys of HOMEPEPPER with distinct labels oficina-id/{identity-id,native-code,native-address,native-ip,native-bucket}/v1; Paul accepted this. Pepper rotation changes every identity_id, kills every code in flight, and resets the native buckets: the same non-rotatable constraint the people index already has. Grants survive, because they are hashed with plain SHA-256.

Deferred or not here

A2 (several identities, Devices page, Keymail sheet). B (native recovery and enrolment; endPasskeylessGrants already takes the enrolling grant as its exception). C–E. Classification is skipped at code/start. Pre-existing, not fixed: the walked gate 9 logs to a discarded logger.

Commits 14
Discussions 1 1 open
Tasks 9/9 done

Activity