Spec: Oficina ID, the native slice (approved by Paul 2026-11-14)
docs/superpowers/specs/2026-11-14-oficina-id-native.md, revision 6.
Native apps sign in with Oficina ID without a browser round trip: in-app
email code, native passkeys in the first slice, a device-bound grant in a
keychain group shared by the five apps, per-team sessions via NativeExchange,
several Oficina IDs with teams under each. Extends slice 1; amends its browser
allocation so roster members choose ("Connect my existing account" / "I'm
new here") and non-members see today's answer unchanged.
Paul's rulings of 2026-11-14 are recorded in §16. Reviewed by Fable five times
(4cc21a8, 7acf2a1, 575e824, 1b74278, b6aea35), each READY AFTER FIXES, all
findings applied; revision 6's single fix checked by the lander. Paul approved
the spec and building on 2026-11-14. Doc only; no code, no deploy.
Squashed from spec/oficina-id-native into main.
1 file changed,
+273
−0
docs/superpowers/specs/2026-11-14-oficina-id-native.md+273 −0
CI passed — run details
landed from spec/oficina-id-native
diff --git a/docs/superpowers/specs/2026-11-14-oficina-id-native.md b/docs/superpowers/specs/2026-11-14-oficina-id-native.md| new file mode 100644 |
| index 0000000..95dcbe6 |
| --- /dev/null |
| +++ b/docs/superpowers/specs/2026-11-14-oficina-id-native.md |
| @@ -0,0 +1,273 @@ |
| +# 🤖 Oficina ID: the native slice |
| + |
| +Status: revision 6: Fable's fifth-pass finding applied; ready for Paul. Author: Claude (`claude-opus-5-5`) against Home `e9829fd`. Fable reviewed revisions 1–5 (`4cc21a8`, `7acf2a1`, `575e824`, `1b74278`, `b6aea35`). Each pass returned READY AFTER FIXES, and every finding is applied; the fifth pass found one defect, fixed here. No implementation, deployment or merge approval. |
| + |
| +## 1. Decision and boundary |
| + |
| +This spec extends [Oficina ID slice 1](2026-11-13-oficina-id-slice-1.md) and binds wherever it differs from it. Elsewhere slice 1 governs. It covers the native half that slice 1 left out, and one amendment to slice 1's browser path (§8). Paul's rulings are in §16. Evidence and line references are in Appendix A. Slices C–E are specified in Appendix B. |
| + |
| +**Out of scope:** Contra, CallKit/PiP, provisioning, roster writes and per-item grants. |
| + |
| +**What Home learns.** Home still gains no readable address, content or device name. It does learn three things: that a person has N signed-in devices, each with a self-reported platform and a `last_used_day`; each native assert's audience, at least daily per app and team (seen per request, stored only as a replay hash); and a sealed address while an email code is live. |
| + |
| +## 2. Ground facts |
| + |
| +**Mac.** Slice 0 checked this on macOS 27 with Paul's Developer ID, 2026-11-14. A Developer ID app that claims `keychain-access-groups` or `associated-domains` without an embedded provisioning profile is **killed at launch**. The team-prefixed App Group `9U4A84C4WK.works.oficina` works on Mac without a profile. iOS uses `group.works.oficina`. Profiles are therefore a hard prerequisite. |
| + |
| +**connect today** treats only `HomeMethod`, `magiclink` and `keymail` as sessions (`connect/bridge.go:75,251-255`; `routes.go:149`). rastrillo sessions have one TTL per process (`sessions/sessions.go:65-69`). |
| + |
| +## 3. The native credential |
| + |
| +**On the device.** Each identity has two secrets: a P-256 **device key**, in the Secure Enclave where there is one, otherwise a software key; a 32-byte random **grant token**. |
| + |
| +Both sit in the data-protection keychain, in the shared access group `9U4A84C4WK.works.oficina.id`, with `AfterFirstUnlockThisDeviceOnly`. They are never synced or exported. There is no profile-free variant. |
| + |
| +**At Home: `home_id_grants`.** Columns: `grant_hash`: SHA-256 of the token, primary key; `person_ref`; `identity_id`: HMAC of the person ref under a dedicated Home key; `device_key`; `platform`: self-reported; `method`; `auth_time`; `created_at`; `last_used_day`; `expires_at`; `ended_at` and `end_reason` (`expiry`, `lru`, `enrolment`, `signout`, `all_devices`, `revoke`, `replacement`). Ended rows keep `device_key` for 365 days so that §4 can recognise a returning device. |
| + |
| +A person holds at most 20 live grants. A 21st revokes the least recently used. Devices store `identity_id`, never the person ref. The ref does reach the app in transit, as the `sub` of the assertions it forwards; the app neither parses nor stores it. |
| + |
| +**Proof.** Every call carries `Authorization: OficinaID <token>` and `Oficina-Proof: base64url(payload).base64url(sig)`. The payload is `{v:1, htm, htu, iat, jti, bh=SHA-256(body)}`, signed with rastrillo `crypto` under the context `oficina-id/native-proof/v1`. There is no JWT and no algorithm field. Home checks that the grant is live and the signature verifies, that `htu` is the exact request URL, and that `|iat−now| ≤ 30 s`; each response carries `Date` (and `now` on a 401), from which the client corrects its clock offset. Only **after** those pass does `jti` go into a persistent replay table. That table survives restarts, holds 60 s of entries, is limited to 120 calls per grant per minute, and fails closed when full. |
| + |
| +The calls made before a grant exists are `code/*` and `passkey/begin`/`finish` without a grant. They are proof-only, signed by the start's key, or by the supplied key for a discoverable passkey. They never touch the `jti` table: their single-use start or challenge is their replay protection. Grants never rotate. Five apps share one item, so rotation would race, and holding the key is the possession proof. |
| + |
| +**Lifetime (Paul, confirmed).** A grant lasts 90 days idle and 365 days absolute. `auth_time` is the time of the sign-in gesture. A new factor ceremony on the same grant updates `method` and `auth_time` together. Using a grant never updates them. |
| + |
| +**Revocation.** A grant ends in five ways: device sign-out (§10); "Sign out all devices" (§10); expiry; passkey replacement by recovery code, which revokes every grant; a **first passkey enrolment**, native or on the web, which revokes every grant whose `method` has no passkey, except the enrolling grant. A web enrolment has no enrolling grant, so every code-only grant ends, including the device that showed the nudge; it then signs in with the passkey. |
| + |
| +## 4. Email code, for people with no passkey yet |
| + |
| +**Endpoints.** They live under `https://id.oficina.works/native/v1/`. They take JSON only, answer `no-store`, have no CORS and render nothing. Any request carrying `Origin` or `Sec-Fetch-Site` is refused. |
| + |
| +**`POST code/start {email, device_key, platform}` → `202 {start, resend_after}`.** Home classifies the address the way `/signin` does. In slice A, Keymail addresses also get a code: that is Q2's own "Email me a code instead" fallback. The Keymail sheet arrives in A2 (§9). Home then stores a `home_id_native_starts` row and mails the code. The row holds: `start_hash`; the address, sealed under `native.code`; `device_key`; `ip_bucket`; `code_mac`; `sends`, `attempts` and `expires_at`. |
| + |
| +The answer is identical for known and new addresses. |
| + |
| +**`code/resend`** replaces the code. A start gets at most 3 sends, 30 s apart. |
| + |
| +**`code/verify`** finds or mints the person, as `completeSignIn` does, and then runs `idGate`'s check: with no passkey, it returns `{grant, identity_id, auth_time}`; with a passkey, it returns `{factor:["passkey"], pending}`, valid 5 minutes and bound to the start and its key. Recovery is added in slice B. |
| + |
| +**Codes.** Six uniform digits. The server keeps only an HMAC-SHA256 under a Home key and compares in constant time. A code lives 10 minutes, is used once, and dies after 5 wrong tries. One code is live per (blinded address, device key). |
| + |
| +**Where the IP comes from.** The IP is the last `X-Forwarded-For` element written by the CARLOS edge, the same as `clientIP` in `signin.go`. `ip_bucket` is the IPv4 /32 or the IPv6 /64. |
| + |
| +**Limits.** All buckets are persistent; none uses the `home_id_attempts` keys that recovery uses. |
| + |
| +| Bucket | Limit | |
| +|---|---| |
| +| Starts per address | 5 per 15 min and 20 per day | |
| +| Starts per IP bucket | 20 per 15 min and 200 per day | |
| +| Wrong codes per (address, device key) | 5 per 15 min | |
| +| Wrong codes per address, from device keys that never held a grant for that person | **20 per day** (B) | |
| +| Live starts | 10,000 in total, at most 20 per IP bucket | |
| + |
| +**Returning devices.** A device key is exempt from the per-address start and daily caps only if it holds a live grant for that person, or one that ended by `expiry`, `lru` or `enrolment`. Keys whose grant ended by "Sign out all devices", per-grant Revoke or recovery replacement are **not** exempt, because those are how a lost device is cut off. An exempt key keeps its own limits: 5 starts and 5 wrong codes per 15 minutes per (address, key). Every native start, exempt or not, also spends the web's in-memory email budget, so an address has one shared allowance across both doors. |
| + |
| +**Full table.** When the starts table is full, new starts get `503` "Try again shortly", and existing starts still verify. Filling it takes 500 IP buckets; that is disclosed. The web's link sign-in is unaffected. |
| + |
| +**Privacy.** The address is sealed before the write and erased at verify or expiry, under `secure_delete`. Gates 1, 2 and 9 extend to this table. |
| + |
| +**What B costs (corrected).** The daily cap holds guessing to 20 a day from new devices, under 1% takeover a year for an account with no passkey. An attacker can spend that cap with about 4 mails a day (4 starts × 5 wrong codes). That blocks **new-device** code sign-in for the address until the next day. Returning devices and passkeys are unaffected. |
| + |
| +A blocked new device sees: "Too many attempts for this address today. Use a passkey or a device you've signed in on before, or sign in at id.oficina.works and make a passkey." The code is relayable by a phishing page, which a link is not; that is disclosed. |
| + |
| +**The nudge.** After every code-only sign-in, the app offers "Make a passkey". Native enrolment arrives in slice B; until then the app offers it on the web. |
| + |
| +**The mail.** It has no link, because a link would sign in a browser. Subject: "Your Oficina ID code". First line: "Your Oficina ID code is 123456". Then the expiry, and "ignore this if you didn't ask". The field uses `.textContentType(.oneTimeCode)`. Slice 0 checks Mail AutoFill with the real HTML mail on both platforms. Without it, typing and paste still work. |
| + |
| +## 5. Native passkeys (slice A, Q1a) |
| + |
| +**Associated domain.** Every build carries `webcredentials:id.oficina.works`. The credential role serves a static `/.well-known/apple-app-site-association` (`application/json`, no redirect). It lists each distinct App ID `9U4A84C4WK.works.oficina.<app>`, which is 5 if Mac and iPhone share bundle IDs and up to 10 if not. It holds no account-authored text and no `applinks`. The profiles, this file and Apple's CDN fetch are all on slice A's critical path. |
| + |
| +**Sign-in.** |
| +1. `passkey/begin {pending?}` returns discoverable WebAuthn options, so "Sign in with a passkey" needs no email. With `pending` it is restricted to that person. The challenge is single-use, lasts 5 minutes, is bound to the device key, and counts within `home_id_ceremonies`. |
| +2. The app runs `ASAuthorizationPlatformPublicKeyCredentialProvider(relyingPartyIdentifier: "id.oficina.works")`. |
| +3. `passkey/finish` runs Home's existing verification: exact RP and origin, user verification, and the person binding. It returns `{grant, identity_id, auth_time}`, with method `passkey` or `email+passkey`. |
| + |
| +`LegacyRPID` stays empty. Slice 0 confirms that `clientDataJSON.origin` is `https://id.oficina.works`. |
| + |
| +**Recovery (slice B, Paul's ruling C).** `POST recovery {pending, code}` mints an `email+recovery` grant. That grant is for sign-in only: no enrolment, no step-up, no linking. Routine sign-in may spend recovery codes. The app shows how many remain and prompts when fewer than 3 are left. Replacing a lost passkey stays on the web. |
| + |
| +**Enrolment (slice B).** `passkey/register` needs `auth_time` within `enrolFreshness`, on a method that contains neither `recovery` nor `native-web`. It shows the ten recovery codes once, under `e9829fd`'s rules, and revokes the passkey-less grants (§3). |
| + |
| +## 6. Names on the device |
| + |
| +An identity is keyed by `identity_id`. If a mint returns an `identity_id` already on the device, the app says "Already signed in" and revokes the duplicate grant at once. |
| + |
| +The label is the email typed on this device. After a passkey-only sign-in, the label is the identity's team names, until the person types an email to label it; that email is never sent. There is no name or avatar: the app draws initials. |
| + |
| +## 7. Credential to team session, without a browser |
| + |
| +**1. Home: `POST /native/v1/assert {aud, challenge}` → `{assertion}`.** `challenge` = SHA-256 of a fresh 32-byte verifier. Home maps `aud` (an origin) to a consumer by exact match in `consumers()`. It refuses the operator consumer. Home calls **`mintPolicy(consumer, method)`**, one shared function that `/authorize` also calls. It is empty in slice A; Contra's passkey-only rule lands there later. Claims are slice 1's v1: 120 s, a fresh `jti`, the person ref as `sub`, and the grant's `auth_time`. **Home sets the nonce itself:** `H("oficina-id/native/v1\0" ‖ challenge)`. A grant holder therefore cannot obtain a web-handle nonce (§12) from this call. There is no `max_age`, and native never links. |
| + |
| +**2. Instance: `POST <origin>/native/oficina-id {assertion, verifier, target?}`.** This is `connect.Bridge.NativeExchange`. It takes JSON only, sets no cookies and refuses `Origin`. It runs in this order: |
| +1. **Verify** the assertion (pinned keys, exact issuer and audience) and recompute the native nonce from the verifier. A grant holder cannot obtain an assertion with a browser or web nonce from `assert`, and this endpoint accepts only the native one. |
| +2. **Read** the link, then the Home-only person, with no write. |
| +3. **Decide.** If there is neither, call `Admit` with **no transaction open**: it is `Runtime.Check` and may wait on a roster fetch, and `runtime.go:89-92` forbids calling it while holding the writer. A non-member gets the unknown answer, an unavailable roster gets 503, and a Member gets 409 `choose`. All three return here, before any `jti` write (§8). |
| +4. **Allocate,** only with `choice:"new"` from a Member: call `Unlinked` (`connect/api.go:64`). It is idempotent and re-checks before it creates. If it returns `ErrNoPerson` or an error after step 3 said Member, re-resolve. A link found then means continue to step 5. Otherwise the answer is `403` unknown, or `503` for an availability error. No `jti` is kept. |
| +5. **Reserve, then resolve and mint.** Reserve `(iss,jti)` in `oficina_handoff_replay` in **its own short transaction**, and commit it. Then, with no transaction open, re-resolve the link and the Home-only person (`HomeOnly`, `connect/api.go:69`), recheck admission, and mint with method `home-assertion-native`. |
| + |
| +**No hook runs with the writer held.** `Admit`, `Unlinked`, `HomeOnly` and session minting each use their own database handle: |
| +- `Unlinked` is Docs' `EnsureHome`, which opens its own writer transaction (`principalstore/store.go:176-183`). |
| +- `HomeOnly` is `principalstore.Store.Resolve`. |
| +- `sessions.Mint`/`SignIn` run `s.cfg.DB.Exec` (`sessions/sessions.go:152-162`). |
| + |
| +Docs has a single writer connection (`app.go:498,508`; `home_connect.go:82`; rastrillo `db/db.go:78` `SetMaxOpenConns(1)`). Any of these calls made while holding a transaction would therefore wedge the writer **permanently**: the pool waits with no context. |
| + |
| +**Accepted non-atomicity.** The browser path already accepts it, and this path does too. A `jti` that is burned but produces no session (a crash, or a refusal at the recheck) only means the client fetches a fresh assertion. A `jti` is never reserved twice, so replay stays impossible. |
| + |
| +The verifier gives the "only the requester redeems" property without slice 1's pending row; a native client has no ambient browser for login CSRF to exploit. There is no Continue page (Paul's ruling A(i)). |
| + |
| +**One predicate.** `connect.IsHomeDerived(method)` is true for `HomeMethod`, `home-assertion-native` and `home-native-web`. Resolve, `ResolveSession`, `existingPerson`, `signedIn`, the same-person check, unlink and sign-out all use it in place of today's literal checks. |
| + |
| +**Lifetime (Paul, confirmed).** `connect` refuses a `home-assertion-native` or `home-native-web` session more than **7 days** after its `At`: absolute, not sliding. The app re-mints after 24 hours and on any 401. Unlink deletes every `IsHomeDerived` session. |
| + |
| +## 8. No account forks: members choose (Paul's ruling, 2026-11-14) |
| + |
| +**The rule, on both paths.** It replaces revision 3's instance-wide rule. When an assertion's subject has no link and no Home-only person, `connect` takes the **roster decision first**, through a new non-allocating hook `Admit(ctx, issuer, subject)`: teammode's `AdmitUnlinked` decision. It never asks whether the team has local or email accounts. `Admit` is set together with `Unlinked` and `HomeOnly`, or not at all, which extends `bridge.go:53`'s invariant. |
| + |
| +**What each subject gets:** |
| +- **A non-member, or any subject on an instance without the hooks:** today's "unknown" answer **byte for byte**, meaning the same status, body and set of headers. The link-resuming marker cookie (`bridge.go:229`) is freshly sealed each time, so only its value differs. Natively the answer is `403 {"state":"unknown"}`, identical for every such subject. |
| +- **An unavailable roster:** stays today's 503 "try again" on both paths, exactly as now (`teammode/runtime.go:130` → Docs `errTeamUnavailable`, `oficina/docs internal/docs/home_connect.go:215,225` → `connect/bridge.go:224-225,234-235`). |
| +- **A roster Member with no link:** gets the choice. Nothing is allocated until they choose, so a guest's local account never blocks a new member's first sign-in. |
| + |
| +**The app-session precondition stays.** Today, allocation is reachable only when no app session is present (`bridge.go:219-223`, `api.go:55-58`). If any app session is present at finish, the answer is today's unknown plus the marker, decided **before** `Admit` and with no proof issued. |
| + |
| +**Browser.** `Complete` records the state `choose` together with a sealed, single-use choice proof. The proof holds the subject and `auth_time`, is bound to the browser by a `__Host-` cookie, and lives 10 minutes. The Fail hook (`result.state`, as with "unknown") then 303s to `GET /account/home/choose`. `handoff.Finish` keeps the return path and hands `Complete` only the claims (`handoff/http.go:265-274`), so after a choice the person lands on **the default path**, `/`. |
| + |
| +**Request-forgery protection** on the choose page is §12's pattern: the form token is an HMAC of the choice-proof cookie, and the POST requires an exact same-origin `Origin`. The page: |
| +- Title: "Welcome to the team". |
| +- Body: "Do you already have an account here that signs in with email? Connect it, and your Oficina ID will open it from now on. If you're new here, continue with Oficina ID." |
| +- **"Connect my existing account"** consumes the proof, then goes to `/signin/local` with the link-resuming marker set, then to slice 1's linking. Abandoning the link step afterwards therefore leaves no proof to press "I'm new here" with. |
| +- **"I'm new here — continue with Oficina ID"** POSTs, and the POST **refuses when an app session is present**. Otherwise it consumes the proof in its own short transaction, and then, with no transaction open, rechecks `Admit` and that there is still no link. It allocates through `Unlinked` (the same `ErrNoPerson`/error handling as §7 step 4), re-resolves, and mints. If the proof is consumed and no session results, the person signs in with Oficina ID again. |
| +- Unlink clears pending choice proofs along with the other pending sets. |
| + |
| +**Native.** With no `choice`, a Member with no link always gets `409 {"state":"choose"}` and nothing is allocated. The app then offers the same two labelled routes: |
| +- **"Connect my existing account"** opens `<origin>/account/home` in the default browser. That is `connect`'s link start, which signs in locally first (`navigation.go:95-110`). |
| +- **"I'm new here — continue with Oficina ID"** gets a fresh assertion and re-posts with `choice:"new"`. The client sends `choice` only from this button. |
| + |
| +`choice` is ignored for a linked or Home-only subject. A non-member who sends `choice:"new"` gets the identical `403` unknown. |
| + |
| +**Scope of the change.** In `connect`: |
| +- `Bridge.complete` calls `Admit` in place of `Unlinked`; |
| +- new choose GET and POST handlers; |
| +- `NativeExchange`; |
| +- `Config.Admit`, which all five apps wire to teammode. |
| + |
| +The browser `Finish` keeps today's shape (`handoff/http.go` `Finish`: `Store.Finish`, then `Complete`), so the browser path is **not** claimed to be one transaction. Allocation happens only in the explicit choice handlers, which recheck before allocating. The apps' `Unlinked` takes `ctx`, opens its own writer transaction and re-checks before it creates. Like every hook, it is never called with the writer held (§7). The proof is single-use, so a race between two choices yields one person. |
| + |
| +## 9. Teams, store, onboarding |
| + |
| +**Teams.** The directory is a consumer. The app gets a directory session through `NativeExchange`, then calls `GET https://oficina.works/api/native/teams` → `[{sqid, label, name, role, apps:[{app, origin, consumer_id}]}]`. The list comes from `Store.AgentChoices`, filtered to live instances of the five apps, and is `no-store`. Apps use the returned origin as given. They never use portero. The app refreshes at launch, on opening the menu (at most every 5 minutes), and on any 403. The team colour is derived on the device from `sqid`. **Zero teams (Paul's ruling H):** once Alta runs, the empty state offers "Create a team" through Alta. While Alta is blocked, slice A shows help text only. Slice A needs Paul's teams to exist first, through Alta or the operator path. |
| + |
| +**Store (RastrilloApple).** Every record carries `v`. An older app reads what it understands, never rewrites a newer record, and asks for an update. **Shared keychain group:** each identity's record, key, token and **team cache**. Team names stay out of the Mac App Group because an unsandboxed app's group container is readable by any process running as the same user. **App Group** (`9U4A84C4WK.works.oficina` on Mac, `group.works.oficina` on iOS): identity order and the last-used (identity, team) only. **Each app's private keychain:** its sessions, keyed `(grant_id, origin)`. |
| + |
| +`works.oficina.id.changed` tells the other apps to reread. |
| + |
| +**Slice A (Docs):** one identity; onboarding: Welcome, then "Sign in with a passkey" or Email → Code, then a passkey if required, then Team (skipped when there is one; the empty state when there are none). A second app finds the identity and offers "Continue as <label>" or "Use another"; the "Make a passkey" nudge; the zero-teams help text. |
| + |
| +**Slice A2 adds:** up to 5 identities; the account menu (identities, the teams under each, Add, Manage, "Sign out of <label>"), with ⌃⌘1…9 on Mac and a per-window (identity, team), blocked mid-call or with unsaved edits; the Keymail sheet: ephemeral `ASWebAuthenticationSession` (`prefersEphemeralWebBrowserSession = true`, so no Safari cookies). The approval mints **no Home browser session**, only a one-time `start` returned to a fixed `works.oficina.<app>://id` callback, which the app redeems with its proof; the Devices page. |
| + |
| +## 10. Sign-out and revocation |
| + |
| +**"Sign out of <label>" (Paul's ruling I).** The app first signs the `POST /native/v1/signout` request with the device key and holds it, along with the token, in memory. Then it deletes the identity's key, token, record and cache locally, and notifies the other apps. Then, best effort with 5-second timeouts: |
| +1. it sends the pre-signed `POST /native/v1/signout`, which revokes the grant. The proof's `iat` window is 30 s, so a request that cannot be sent in time is dropped; the grant then ends at expiry or through "Sign out all devices"; |
| +2. each app sends `POST /native/web/end`, authenticated by its still-valid native session, to every instance it holds a session on. That ends that person's `home-native-web` browser sessions on the instance, **from all their devices**, as disclosed; |
| +3. each app sends `POST /signout` for its cached sessions. |
| + |
| +At launch, sessions found under a missing grant get the same steps 2 and 3. Nothing waits on Home; the tests use a hanging issuer. There is no per-team sign-out. |
| + |
| +**Sign out all devices (slice A).** A minimal **"Sign out all devices"** in `id.*`'s account menu, behind a fresh session and request-forgery protection, revokes every grant. The full Devices page, with fixed self-reported labels and per-grant Revoke, comes in A2, at `https://id.oficina.works/devices`. |
| + |
| +**Disclosed residual.** An offline device keeps its team sessions for up to 7 days after a remote revoke. |
| + |
| +## 11. Outages, and each app's own sign-in |
| + |
| +| Down | Behaviour | |
| +|---|---| |
| +| Credential origin | No new identities, sessions or renewals. Live sessions run to expiry and cached teams show. A team without a session shows "Can't reach Oficina ID", with Try again and the app's own sign-in. | |
| +| Directory | The team cache is used; minting still works. | |
| +| Instance | The app's offline banner. | |
| + |
| +Sign-out always completes locally, and nothing loops. |
| + |
| +**Each app's own sign-in (Paul, 11-13).** "Other ways to sign in…" keeps the server address and rastrillo/native's browser approval (`/native/request|start|authorize|exchange`), for self-hosted servers and local accounts. |
| + |
| +## 12. Native → web, "Open on the web" (slice D) |
| + |
| +**Opening any page** goes through `id.*` or explicitly in the default browser, never via the app's own universal link, which on Mac can loop back into the app. Copy Link and Handoff carry the plain team URL. |
| + |
| +**Open on the web, step by step (Paul's ruling A(ii)(a)):** |
| +1. **The app asks for a handle.** `POST /native/v1/web {aud, path}`, with grant and proof, returns a URL, `https://id.oficina.works/native/web/<handle>`, and a two-digit **match number** that the app shows ("Check the browser shows 47"). The handle is 32 bytes, single-use, sealed and never logged, and bound to the person, the consumer, a validated local `path`, the grant's `method` and its `auth_time`. |
| +2. **The browser opens the link.** The GET must arrive within 60 s. It renders a fixed-text page: the match number; "Open Oficina Docs on the web as the Oficina ID from your app? If you didn't just choose Open on the web, close this page."; **Continue**. |
| + |
| + The GET consumes nothing. It sets a sealed `__Host-` confirmation cookie, and the form's request-forgery token is an HMAC of that cookie. |
| +3. **The person presses Continue.** The POST is accepted within 5 minutes of the GET, with an exact same-origin `Origin`. It mints **no Home session and no `id.*` cookie**. It signs a one-shot assertion for that consumer, with nonce `H("oficina-id/native-web/v1\0" ‖ handle id)` and the grant's `auth_time`, and posts it to `/native/web/finish`. |
| +4. **The instance receives it (N1, copying `handoff.Callback`, `handoff/http.go:211-243`).** `POST /native/web/finish` requires the exact issuer `Origin`. It recomputes the web nonce from the handle id in the form, stores a sealed receipt, sets a `__Host-` inbox cookie, and 303s to `GET /native/web/complete`. |
| +5. **The instance finishes.** The GET carries the Lax session cookie. It consumes the receipt in its own short transaction, then checks the existing session with no transaction open. If a different person is signed in, it refuses with "Another account is signed in here. Sign out of it first", and nothing is replaced. Otherwise it mints a `home-native-web` session (7 days absolute, §7) and lands on `path`. |
| + |
| +**Which assertion goes where.** `/native/web/finish` accepts only web nonces, and `NativeExchange` only native ones; both are recomputed, never caller-supplied. `/authorize` still accepts a caller-chosen nonce. The guarantee is therefore one-way: a grant holder cannot obtain an assertion carrying a browser or web nonce through `assert`, and the browser's `/auth/assertion` matches only its own pending nonces. |
| + |
| +**Never fresh.** Any method containing `native-web` is refused at enrolment, codes, linking and step-up, alongside the `recovery` checks (`id_passkey.go:128`, `exchange.go:115`). |
| + |
| +**Handles may ride a URL path, assertions may not.** The handle is redeemable only at `id.*`, only through a confirmed POST, once. |
| + |
| +**Residual.** A victim lured to an attacker's handle who presses Continue despite a mismatched number lands in the attacker's team session. |
| + |
| +## 13. Gates (slices 0–A2; later gates are in Appendix B) |
| + |
| +**Codes:** the returning-key exemption excludes keys ended by sign-out-all, Revoke or replacement; exempt keys keep their own start limit; one email allowance shared with the web; no address at rest, and no address or code in logs; entropy, expiry and single use; persistent buckets that survive a restart and parallel requests; the per-(address, key) and daily caps, and the returning-key exemption; per-IP-bucket live starts, and 503 when the table is full; identical answers for known and unknown addresses; no grant from a code alone on an enrolled account. |
| + |
| +**Proof:** refused for a wrong key, a replayed `jti` (also across a restart), a full table (fails closed), a skewed `iat`, a wrong `htu`, a swapped body, or an `Origin` header; no `jti` row before the grant and signature verify; the per-grant rate limit. |
| + |
| +**Assert and exchange:** an unregistered `aud` is refused; `mintPolicy` is shared with `/authorize`; refused for a wrong verifier, a web nonce, a replay, or a swapped audience; the roster decision comes first. **Byte-identical:** non-members and instances without the hooks get the same status, body and header set on both paths, whether or not the instance has local accounts (the marker's value excepted). **Roster unavailable:** 503 on both paths. **Native with no `choice`:** a Member with no link always gets 409, and nothing is allocated. **`choice:"new"`:** ignored for a linked or Home-only subject; a non-member who sends it gets the identical 403. **Hooks:** `Admit`, `Unlinked` and `HomeOnly` are set together or not at all. **App session at finish:** gets unknown plus the marker, with no proof issued. **Choose POST:** refused when an app session is present. **Connect:** consumes the proof. **No `jti` is written** before the 409. **No hook (`Admit`, `Unlinked`, `HomeOnly`) and no session mint is ever called with the writer held**: a test holds a transaction on a single-connection pool, and the exchange, choose POST and web finish must not wait on it. If `Unlinked` returns `ErrNoPerson` or an error after Member, the exchange re-resolves and answers 403 or 503 with no `jti` kept. A burned `jti` with no session is retried with a fresh assertion. A guest's local account never blocks a new member's first sign-in. A choice proof is single-use, browser-bound and expiring, and its form token is bound to its cookie; `IsHomeDerived` everywhere; 7-day refusal; concurrent exchange, unlink and relink. |
| + |
| +**Revocation:** first passkey enrolment revokes the passkey-less grants; recovery-based replacement and "Sign out all devices" revoke every grant; a duplicate `identity_id` revokes the new grant; sign-out works against a **hanging** issuer. |
| + |
| +**Domains:** the association file's content; RP ID exactly `id.oficina.works`; `LegacyRPID` empty. |
| + |
| +**Mac launch:** the final signed, notarised artifact of every Mac build **launches and reads the shared group** before any Sparkle publish. A build killed at launch cannot update itself. |
| + |
| +## 14. Slices |
| + |
| +| Slice | Contents | |
| +|---|---| |
| +| **0a** | Profiles on every build; the Mac App Group ID; the launch gate; a shared Secure Enclave key read by two apps. | |
| +| **0b** | The association file on `id.*` plus Apple's CDN; spikes for passkey `clientDataJSON.origin` and Mail AutoFill on both platforms. | |
| +| **A** | **Docs**, one identity. **Home:** grant and proof, code (Keymail addresses included), native passkey sign-in, `assert`, `signout`, "Sign out all devices", replacement revoking every grant, first passkey enrolment (native or web) revoking passkey-less grants. **connect:** `NativeExchange`, `IsHomeDerived`, the 7-day limit, `Admit` with the member choice on **both** paths, and the choose page. **Directory:** `teams` and the zero-teams help. | |
| +| **A2** | Several identities, the account menu, team switching, the Keymail sheet, the Devices page. | |
| +| **B** | Native recovery (ruling C) and native passkey enrolment with the codes. | |
| +| **C–E** | Appendix B: the other four apps and Calls guests; universal links and Open on the web (§12); web multi-account. | |
| + |
| +## 15. Portal steps and release acknowledgements (Paul's ruling F, accepted) |
| + |
| +**Portal:** register `group.works.oficina` (iOS only); enable Associated Domains and keychain sharing on every `works.oficina.*` App ID; issue a profile for **every** Mac build, Developer ID and App Store. **Releases:** every Mac release depends on those profiles and the launch gate, and the Mac App Group becomes `9U4A84C4WK.works.oficina`. **Migration:** Appendix C. |
| + |
| +## 16. Paul's rulings, 2026-11-14 (all decided) |
| + |
| +Q1 (a): native passkey sign-in ships first; the email code is for people with no passkey yet, and slice 1's rule is intact. Q2 (a): the Keymail sheet, with "Email me a code instead" (moved to A2, with the code as the fallback until then). Q4: grants last 90 days idle and 365 absolute; team sessions last 7 days absolute (confirmed). Q5 (a): web IDs are labelled by their teams' names. Q6 (a): the team colour is derived on the device. Q7: Docs comes first. |
| + |
| +A(i): native sign-in skips Continue. A(ii)(a): one Continue tap signs that browser in to that one app only, never `id.*`. B (a): a daily cap plus a passkey nudge. Its lockout cost is corrected in §4 (about 4 mails a day blocks new devices only). C: recovery codes may be used for routine sign-in, showing what remains and prompting below 3; this moves to slice B. D (a): the shared-credential risk is accepted for slice A and disclosed. Any process in the keychain group can assert for any audience, so a bug in one app exposes every app's data, Memoria's private items included. Per-app keys need attestation and come later. E (a): Calls guests join by name by default, and use their Oficina ID only by explicit choice. F: accepted (§15). G: there is no code entry on the web door. H: "Create a team" through Alta once Alta runs; help text while it is blocked. I (a): app sign-out ends the browser sessions it opened, best effort, on all that person's devices per instance. J: migration covers Paul's machines only; Till must be told before slices C and D. Fork (replacing revision 3's rule): members choose. The roster decision comes first. Non-members keep today's "unknown" answer byte for byte. A Member with no link chooses "Connect my existing account" or "I'm new here — continue with Oficina ID", on the web and natively (§8). |
| + |
| +No questions remain open. |
| + |
| +## Appendix A. Evidence |
| + |
| +**Today:** no device holds an identity; "accounts" are host-plus-cookie (`native-levelup/reports/calls.md` §B3, `docs.md` §3). rastrillo/native's browser approval keeps a pending map in memory (5 minutes, 256 entries; `rastrillo-native/server/auth.go:23-37`). Calls has a one-slot store (`calls.md` §C). Keychain items have no access group (`sheets.md` §3). |
| + |
| +**Home:** P-256 assertion minting (`internal/home/exchange.go:72-146`); a consumer registry mapping id → origin only (`consumer_registry.go`); the passkey gate (`id_recovery.go:71-92`); `home_id_attempts` (`identity/migrations/0002_recovery.sql`); 30-day browser sessions (`app.go:123`); the in-memory email budget (`app.go:146-147`); directory tables populated only for Alta- or operator-provisioned teams, read by `Store.AgentChoices` (`directorydata/store.go:129-177`). |
| + |
| +**connect:** completion allocates Home-only people through `Unlinked` (`connect/bridge.go:214-227`). The resume-linking marker is set at `bridge.go:229`. |
| + |
| +**Mac spike:** see §2. `group.works.oficina` needs registering and prompts on macOS 15 and later. rastrillo/native branch `native/levelup-phase0-tools` embeds and validates profiles. |
| + |
| +## Appendix B. Later slices (C–E), with their gates |
| + |
| +**C: the other apps, and Calls guests (Paul's ruling E).** A link to a Calls instance outside your teams never asserts silently: an assertion would hand that operator your stable cross-team subject. The default is **Join as a guest by name**. "Use Oficina ID <label>" says "This meeting's server will learn your Oficina ID", and with two identities the person picks one. An Oficina ID guest is admitted only with a valid, unconsumed `/j/{token}`, consumed in the minting transaction. `/m/{sqid}` alone grants only Calls' lobby and knock (`native_auth.go:56-87`). The visit is held in memory. Name-only guests keep "Join in the app" (`native_auth.go:349-421`). Push registers per (identity, team). *Gates:* no silent guest assertion; the invitation consumed atomically; `/m/{sqid}` grants nothing. |
| + |
| +**D: universal links and Open on the web (§12).** Each app claims `applinks:<app>.oficina.works` and `applinks:*.<app>.oficina.works`. The wildcard file is fetched from the bare host, so portero serves `/.well-known/apple-app-site-association` (static, label-free); team hosts serve it too. The file lists item routes (Calls: `/m/*`, `/j/*`) and excludes `/auth/*`, `/signin*`, `/signout*`, `/native/*`, `/account/*`, `/api/*` and `/.well-known/*`. Routing: one identity with that origin → use it; several → always ask; none → guest choice (Calls) or "Add an Oficina ID". Self-hosted teams on other domains use the custom scheme only. `NSUserActivity` carries `webpageURL`. Web pages offer an "Open in the app" button on the custom scheme, because Safari does not open universal links on same-host taps. *Gates:* the handle is single-use, expires, is bound to its consumer, refuses a foreign path, and mints no Home session; the handle GET consumes nothing; Continue POST timing and token binding; the receipt-then-GET finish with no silent replacement of another account; web nonces accepted only at `/native/web/finish`; `native-web` never fresh; `/native/web/end`; excluded paths. |
| + |
| +**E: web multi-account.** `id.*` and the directory hold a set of up to 5 sessions in a sealed `__Host-oficina-ids` cookie, with "current" picked by the intent's subject (`exchange.go:107`). They are labelled by team names (Q5a). An instance keeps one session per host, so two IDs on one team host collide in a browser; that is disclosed. *Gates:* set size; no address rendered on `id.*`. |
| + |
| +## Appendix C. Migration and release plan (Paul's ruling J: Paul's machines only) |
| + |
| +New `works.oficina.*` builds start at Welcome. Old `net.amadan.oficina.*` builds still claim the custom schemes, so Paul deletes them. Each old appcast gets one final "Download the new app" release. Camera and microphone permissions reset. Alta's instances are fresh, so no server sessions carry over. Docs' existing links keep resolving through `connect.Resolve`. Till (team `lagged`) must be told before slices C and D, because his old apps must be deleted too. |