Oficina ID native: passkey sign-in and the association file
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
POST /native/v1/passkey/begin ({device_key, platform} for a discoverable sign-in, or {pending} after a code on an enrolled account) and passkey/finish, verified by Home's existing WebAuthn config: exact RP id.oficina.works and origin, user verification, discoverable-only without a pending, that person's credentials with one. Challenges count within home_id_ceremonies, are bound to the device key and spent even on failure. Serves the static apple-app-site-association with webcredentials for the five App IDs and no applinks.Agent notes
The device key and platform a native challenge is bound to live in home_id_native_ceremonies, keyed by the same challenge, so passkey/finish carries only the WebAuthn fields. passkey/begin has a per-IP bucket (60 per 15 min) the spec does not name; it keeps a flood from filling the shared 10,000-row ceremonies table that the web door also uses.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 files changed,
+477
−0
internal/home/native.go+3 −0internal/home/native_passkey.go+274 −0internal/home/native_passkey_test.go+200 −0
diff --git a/internal/home/native.go b/internal/home/native.go| index 872061d..11959c9 100644 |
| --- a/internal/home/native.go |
| +++ b/internal/home/native.go |
| @@ -63,8 +63,11 @@ func (a *App) mountNative(r chi.Router) { |
| r.Post(nativePrefix+"/code/start", a.nativeCodeStart) |
| r.Post(nativePrefix+"/code/resend", a.nativeCodeResend) |
| r.Post(nativePrefix+"/code/verify", a.nativeCodeVerify) |
| + r.Post(nativePrefix+"/passkey/begin", a.nativePasskeyBegin) |
| + r.Post(nativePrefix+"/passkey/finish", a.nativePasskeyFinish) |
| r.Post(nativePrefix+"/assert", a.nativeAuthed(a.nativeAssert)) |
| r.Post(nativePrefix+"/signout", a.nativeAuthed(a.nativeSignout)) |
| + r.Get(aasaPath, a.serveAASA) |
| }) |
| } |
diff --git a/internal/home/native_passkey.go b/internal/home/native_passkey.go| new file mode 100644 |
| index 0000000..1aaccdc |
| --- /dev/null |
| +++ b/internal/home/native_passkey.go |
| @@ -0,0 +1,274 @@ |
| +package home |
| + |
| +import ( |
| + "database/sql" |
| + "encoding/base64" |
| + "encoding/hex" |
| + "encoding/json" |
| + "errors" |
| + "net/http" |
| + |
| + "amadan.net/rastrillo/rastrillo/webauthn" |
| +) |
| + |
| +// Native passkey sign-in (§5). The app runs the platform ceremony against |
| +// RP id.oficina.works; Home verifies it exactly as the web door does — the |
| +// same RP, origin, user-verification and person-binding checks — and mints a |
| +// grant instead of a cookie. |
| +const nativeCeremonyPurpose = "native" |
| + |
| +// nativePasskeyBegin is POST passkey/begin, either |
| +// {device_key, platform} for a discoverable sign-in that needs no email, or |
| +// {pending} to finish a code sign-in on an enrolled account. The challenge is |
| +// single-use, lives five minutes, is bound to the device key and counts |
| +// within home_id_ceremonies. |
| +func (a *App) nativePasskeyBegin(w http.ResponseWriter, r *http.Request) { |
| + body, ok := nativeIntake(w, r) |
| + if !ok { |
| + return |
| + } |
| + var in struct { |
| + DeviceKey string `json:"device_key,omitzero"` |
| + Platform string `json:"platform,omitzero"` |
| + Pending string `json:"pending,omitzero"` |
| + } |
| + if !decodeNative(body, &in) || (in.Pending == "") == (in.DeviceKey == "") || (in.Pending != "" && in.Platform != "") || (in.Pending == "" && !nativePlatforms[in.Platform]) { |
| + nativeFail(w, http.StatusBadRequest, "request") |
| + return |
| + } |
| + tx, now, err := a.idTransaction(r.Context()) |
| + if err != nil { |
| + nativeFail(w, http.StatusServiceUnavailable, "unavailable") |
| + return |
| + } |
| + defer tx.Rollback() |
| + if sweepCodes(tx, now) != nil { |
| + nativeFail(w, http.StatusServiceUnavailable, "unavailable") |
| + return |
| + } |
| + subject, key, platform, pendingHash := "", in.DeviceKey, in.Platform, "" |
| + if in.Pending != "" { |
| + if _, ok := decodeB64(in.Pending, 32); !ok { |
| + nativeFail(w, http.StatusBadRequest, "pending") |
| + return |
| + } |
| + pendingHash = nativeHash(in.Pending) |
| + if tx.QueryRow("SELECT person_ref,device_key,platform FROM home_id_native_pending WHERE pending_hash=? AND expires_at>?", pendingHash, now).Scan(&subject, &key, &platform) != nil { |
| + nativeFail(w, http.StatusBadRequest, "pending") |
| + return |
| + } |
| + } |
| + if !a.nativePreGrant(r, body, key, now) { |
| + nativeUnauthorized(w, "proof") |
| + return |
| + } |
| + if ip := nativeIPBucket(r); ip != "" { |
| + b := nativeBucket{a.bucketKey(passkeyBeginsPerIP, a.nativeMAC("native-ip", ip)), passkeyBeginsPerIP, errNativeLimited} |
| + if err = checkThenSpend(tx, []nativeBucket{b}, now); err != nil { |
| + nativeLimitFail(w, err) |
| + return |
| + } |
| + } |
| + for _, q := range []string{"DELETE FROM home_id_ceremonies WHERE expires_at<=?", "DELETE FROM home_id_native_ceremonies WHERE expires_at<=?"} { |
| + if _, err = tx.Exec(q, now); err != nil { |
| + nativeFail(w, http.StatusServiceUnavailable, "unavailable") |
| + return |
| + } |
| + } |
| + var n int |
| + if tx.QueryRow("SELECT count(*) FROM home_id_ceremonies").Scan(&n) != nil || n >= 10000 { |
| + nativeFail(w, http.StatusServiceUnavailable, "full") |
| + return |
| + } |
| + challenge, err := webauthn.NewChallenge() |
| + if err != nil { |
| + nativeFail(w, http.StatusServiceUnavailable, "unavailable") |
| + return |
| + } |
| + id := hex.EncodeToString(challenge) |
| + if _, err = tx.Exec("INSERT INTO home_id_ceremonies VALUES (?,?,?,?,?)", id, nativeHash("native\x00"+key), subject, nativeCeremonyPurpose, now+300); err != nil { |
| + nativeFail(w, http.StatusServiceUnavailable, "unavailable") |
| + return |
| + } |
| + if _, err = tx.Exec("INSERT INTO home_id_native_ceremonies VALUES (?,?,?,?,?)", id, key, platform, pendingHash, now+300); err != nil { |
| + nativeFail(w, http.StatusServiceUnavailable, "unavailable") |
| + return |
| + } |
| + credentials := []string{} |
| + if subject != "" { |
| + rows, err := tx.Query("SELECT id FROM passkey_credentials WHERE subject=? ORDER BY id LIMIT 100", subject) |
| + if err != nil { |
| + nativeFail(w, http.StatusServiceUnavailable, "unavailable") |
| + return |
| + } |
| + for rows.Next() { |
| + var hexID string |
| + if rows.Scan(&hexID) != nil { |
| + rows.Close() |
| + nativeFail(w, http.StatusServiceUnavailable, "unavailable") |
| + return |
| + } |
| + raw, err := hex.DecodeString(hexID) |
| + if err != nil { |
| + rows.Close() |
| + nativeFail(w, http.StatusServiceUnavailable, "unavailable") |
| + return |
| + } |
| + credentials = append(credentials, base64.RawURLEncoding.EncodeToString(raw)) |
| + } |
| + err = rows.Err() |
| + rows.Close() |
| + if err != nil { |
| + nativeFail(w, http.StatusServiceUnavailable, "unavailable") |
| + return |
| + } |
| + } |
| + if tx.Commit() != nil { |
| + nativeFail(w, http.StatusServiceUnavailable, "unavailable") |
| + return |
| + } |
| + nativeReply(w, http.StatusOK, map[string]any{"challenge": base64.RawURLEncoding.EncodeToString(challenge), "rp_id": a.credentialHost, "credentials": credentials}) |
| +} |
| + |
| +// nativePasskeyFinish is POST passkey/finish {id, clientDataJSON, |
| +// authenticatorData, signature}. It is signed by the key its challenge is |
| +// bound to, and returns {grant, identity_id, auth_time}. |
| +func (a *App) nativePasskeyFinish(w http.ResponseWriter, r *http.Request) { |
| + body, ok := nativeIntake(w, r) |
| + if !ok { |
| + return |
| + } |
| + var in idCeremony |
| + if !decodeNative(body, &in) || in.Attestation != "" { |
| + nativeFail(w, http.StatusBadRequest, "request") |
| + return |
| + } |
| + cd, err := base64.RawURLEncoding.Strict().DecodeString(in.ClientData) |
| + if err != nil { |
| + nativeFail(w, http.StatusBadRequest, "request") |
| + return |
| + } |
| + var c struct { |
| + Challenge string `json:"challenge"` |
| + } |
| + if json.Unmarshal(cd, &c) != nil { |
| + nativeFail(w, http.StatusBadRequest, "request") |
| + return |
| + } |
| + challenge, err := base64.RawURLEncoding.Strict().DecodeString(c.Challenge) |
| + if err != nil || len(challenge) != 32 { |
| + nativeFail(w, http.StatusBadRequest, "request") |
| + return |
| + } |
| + id := hex.EncodeToString(challenge) |
| + tx, now, err := a.idTransaction(r.Context()) |
| + if err != nil { |
| + nativeFail(w, http.StatusServiceUnavailable, "unavailable") |
| + return |
| + } |
| + defer tx.Rollback() |
| + var key, platform, pendingHash string |
| + if tx.QueryRow("SELECT device_key,platform,pending FROM home_id_native_ceremonies WHERE challenge=? AND expires_at>?", id, now).Scan(&key, &platform, &pendingHash) != nil { |
| + nativeFail(w, http.StatusBadRequest, "passkey") |
| + return |
| + } |
| + if !a.nativePreGrant(r, body, key, now) { |
| + nativeUnauthorized(w, "proof") |
| + return |
| + } |
| + // Consume the challenge first and keep it consumed whatever follows: a |
| + // challenge that survived a failed verification could be tried again. |
| + var subject string |
| + if tx.QueryRow("DELETE FROM home_id_ceremonies WHERE challenge=? AND browser_hash=? AND purpose=? AND expires_at>? RETURNING subject", id, nativeHash("native\x00"+key), nativeCeremonyPurpose, now).Scan(&subject) != nil { |
| + nativeFail(w, http.StatusBadRequest, "passkey") |
| + return |
| + } |
| + if _, err = tx.Exec("DELETE FROM home_id_native_ceremonies WHERE challenge=?", id); err != nil { |
| + nativeFail(w, http.StatusServiceUnavailable, "unavailable") |
| + return |
| + } |
| + refuse := func() { |
| + if tx.Commit() != nil { |
| + nativeFail(w, http.StatusServiceUnavailable, "unavailable") |
| + return |
| + } |
| + nativeFail(w, http.StatusBadRequest, "passkey") |
| + } |
| + credID, e1 := base64.RawURLEncoding.Strict().DecodeString(in.ID) |
| + ad, e2 := base64.RawURLEncoding.Strict().DecodeString(in.AuthData) |
| + sig, e3 := base64.RawURLEncoding.Strict().DecodeString(in.Signature) |
| + if e1 != nil || e2 != nil || e3 != nil { |
| + refuse() |
| + return |
| + } |
| + // A discoverable sign-in accepts only discoverable credentials, as the |
| + // web's direct sign-in does; a pending one accepts only that person's. |
| + query := "SELECT subject,public_key,sign_count FROM passkey_credentials WHERE id=?" |
| + if subject == "" { |
| + query += " AND id IN (SELECT credential_id FROM home_id_discoverable)" |
| + } |
| + var owner string |
| + cred := webauthn.Credential{ID: credID} |
| + if err = tx.QueryRow(query, hex.EncodeToString(credID)).Scan(&owner, &cred.PublicKey, &cred.SignCount); err != nil || (subject != "" && owner != subject) { |
| + refuse() |
| + return |
| + } |
| + next, err := a.idWebAuthn().Verify(cred, challenge, cd, ad, sig) |
| + if err != nil { |
| + refuse() |
| + return |
| + } |
| + if _, err = tx.Exec("UPDATE passkey_credentials SET sign_count=? WHERE id=?", next, hex.EncodeToString(credID)); err != nil { |
| + nativeFail(w, http.StatusServiceUnavailable, "unavailable") |
| + return |
| + } |
| + method := "passkey" |
| + if pendingHash != "" { |
| + var person, first string |
| + err = tx.QueryRow("DELETE FROM home_id_native_pending WHERE pending_hash=? AND device_key=? AND expires_at>? RETURNING person_ref,method", pendingHash, key, now).Scan(&person, &first) |
| + if errors.Is(err, sql.ErrNoRows) || (err == nil && person != owner) { |
| + refuse() |
| + return |
| + } |
| + if err != nil { |
| + nativeFail(w, http.StatusServiceUnavailable, "unavailable") |
| + return |
| + } |
| + method = first + "+passkey" |
| + } |
| + reply, err := a.mintGrant(tx, owner, key, platform, method, now, now) |
| + if err != nil || tx.Commit() != nil { |
| + nativeFail(w, http.StatusServiceUnavailable, "unavailable") |
| + return |
| + } |
| + nativeReply(w, http.StatusOK, reply) |
| +} |
| + |
| +// The association file (§5). Static, application/json, no redirect, no |
| +// applinks and no account-authored text: it lists each App ID allowed to use |
| +// passkeys for id.oficina.works. Mac and iPhone share bundle IDs, so there |
| +// are five. |
| +const aasaPath = "/.well-known/apple-app-site-association" |
| + |
| +var nativeAppIDs = []string{ |
| + "9U4A84C4WK.works.oficina.calls", |
| + "9U4A84C4WK.works.oficina.docs", |
| + "9U4A84C4WK.works.oficina.sheets", |
| + "9U4A84C4WK.works.oficina.calendar", |
| + "9U4A84C4WK.works.oficina.memoria", |
| +} |
| + |
| +var aasaBody = func() []byte { |
| + b, err := json.Marshal(map[string]any{"webcredentials": map[string]any{"apps": nativeAppIDs}}) |
| + if err != nil { |
| + panic(err) |
| + } |
| + return b |
| +}() |
| + |
| +func (a *App) serveAASA(w http.ResponseWriter, r *http.Request) { |
| + w.Header().Set("Content-Type", "application/json") |
| + w.Header().Set("Cache-Control", "public, max-age=3600") |
| + w.Header().Set("X-Content-Type-Options", "nosniff") |
| + _, _ = w.Write(aasaBody) |
| +} |
diff --git a/internal/home/native_passkey_test.go b/internal/home/native_passkey_test.go| new file mode 100644 |
| index 0000000..a466a42 |
| --- /dev/null |
| +++ b/internal/home/native_passkey_test.go |
| @@ -0,0 +1,200 @@ |
| +package home |
| + |
| +import ( |
| + "encoding/base64" |
| + "encoding/json" |
| + "net/http/httptest" |
| + "strings" |
| + "testing" |
| + |
| + "amadan.net/oficina/home/internal/home/sealtest" |
| + "amadan.net/rastrillo/rastrillo/webauthn/authtest" |
| +) |
| + |
| +func nativeChallenge(t *testing.T, w *httptest.ResponseRecorder) ([]byte, []string) { |
| + t.Helper() |
| + if w.Code != 200 { |
| + t.Fatalf("begin: %d %s", w.Code, w.Body.String()) |
| + } |
| + var out struct { |
| + Challenge string `json:"challenge"` |
| + RPID string `json:"rp_id"` |
| + Credentials []string `json:"credentials"` |
| + } |
| + if err := json.Unmarshal(w.Body.Bytes(), &out); err != nil || out.RPID != credentialHost { |
| + t.Fatal("begin reply", w.Body.String()) |
| + } |
| + raw, err := base64.RawURLEncoding.DecodeString(out.Challenge) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + return raw, out.Credentials |
| +} |
| + |
| +// §5: "Sign in with a passkey" needs no email; Home verifies the platform |
| +// ceremony exactly as the web does and mints a passkey grant. |
| +func TestNativePasskeySignIn(t *testing.T) { |
| + app := newNativeApp(t) |
| + session := signInFully(t, app, sealtest.CanaryAddress) |
| + key := enrol(t, app, session) |
| + d := newDevice(t) |
| + challenge, creds := nativeChallenge(t, d.call(t, app, nativePrefix+"/passkey/begin", map[string]string{"device_key": d.public(), "platform": "ios"}, "")) |
| + if len(creds) != 0 { |
| + t.Fatal("a discoverable begin named credentials") |
| + } |
| + zero := uint32(0) |
| + body := assertionBody(key, challenge, authtest.Options{RPID: credentialHost, Origin: Origin, Count: &zero}) |
| + // Bound to the device key: another key cannot finish it. |
| + if w := newDevice(t).call(t, app, nativePrefix+"/passkey/finish", body, ""); w.Code != 401 { |
| + t.Fatal("another device finished the ceremony", w.Code) |
| + } |
| + w := d.call(t, app, nativePrefix+"/passkey/finish", body, "") |
| + out := decodeReply(t, w) |
| + if w.Code != 200 || out["grant"] == nil || out["identity_id"] != app.identityID(subjectOf(t, app, session)) { |
| + t.Fatal("finish", w.Code, w.Body.String()) |
| + } |
| + var method, platform string |
| + app.db.Writer().QueryRow("SELECT method,platform FROM home_id_grants").Scan(&method, &platform) |
| + if method != "passkey" || platform != "ios" { |
| + t.Fatal("grant", method, platform) |
| + } |
| + // Single use. |
| + if w := d.call(t, app, nativePrefix+"/passkey/finish", body, ""); w.Code == 200 { |
| + t.Fatal("a challenge was used twice") |
| + } |
| + sealtest.AssertNoPlaintext(t, app.dbPath) |
| +} |
| + |
| +// §5: the exact RP, origin and user-verification checks, and a failed |
| +// ceremony still spends its challenge. |
| +func TestNativePasskeyRejectsBadCeremonies(t *testing.T) { |
| + for _, kind := range []string{"origin", "rp", "uv", "signature", "unknown"} { |
| + t.Run(kind, func(t *testing.T) { |
| + app := newNativeApp(t) |
| + session := signInFully(t, app, sealtest.CanaryAddress) |
| + key := enrol(t, app, session) |
| + d := newDevice(t) |
| + challenge, _ := nativeChallenge(t, d.call(t, app, nativePrefix+"/passkey/begin", map[string]string{"device_key": d.public(), "platform": "macos"}, "")) |
| + zero := uint32(0) |
| + opts := authtest.Options{RPID: credentialHost, Origin: Origin, Count: &zero} |
| + switch kind { |
| + case "origin": |
| + opts.Origin = "https://oficina.works" |
| + case "rp": |
| + opts.RPID = "oficina.works" |
| + case "uv": |
| + opts.Flags = authtest.FlagUserPresent |
| + case "signature": |
| + opts.CorruptSig = true |
| + case "unknown": |
| + key, _ = authtest.New() |
| + } |
| + w := d.call(t, app, nativePrefix+"/passkey/finish", assertionBody(key, challenge, opts), "") |
| + if w.Code == 200 { |
| + t.Fatal("bad ceremony minted a grant") |
| + } |
| + good := assertionBody(key, challenge, authtest.Options{RPID: credentialHost, Origin: Origin, Count: &zero}) |
| + if w := d.call(t, app, nativePrefix+"/passkey/finish", good, ""); w.Code == 200 { |
| + t.Fatal("a refused challenge was reusable") |
| + } |
| + if n := count(t, app, "SELECT count(*) FROM home_id_grants"); n != 0 { |
| + t.Fatal("grant row after a refusal") |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// §4 + §5: a code on an enrolled account, finished with that person's |
| +// passkey, mints an email+passkey grant; another person's passkey cannot. |
| +func TestNativePendingFinishedByPasskey(t *testing.T) { |
| + app := newNativeApp(t) |
| + session := signInFully(t, app, sealtest.CanaryAddress) |
| + key := enrol(t, app, session) |
| + otherSession := signInFully(t, app, "other@example.invalid") |
| + otherKey := enrol(t, app, otherSession) |
| + d := newDevice(t) |
| + start := d.start(t, app, sealtest.CanaryAddress) |
| + pending := decodeReply(t, d.verify(t, app, start, lastCode(t, app)))["pending"].(string) |
| + if w := newDevice(t).call(t, app, nativePrefix+"/passkey/begin", map[string]string{"pending": pending}, ""); w.Code != 401 { |
| + t.Fatal("another key began a pending", w.Code) |
| + } |
| + challenge, creds := nativeChallenge(t, d.call(t, app, nativePrefix+"/passkey/begin", map[string]string{"pending": pending}, "")) |
| + if len(creds) != 1 || creds[0] != base64.RawURLEncoding.EncodeToString(key.CredID) { |
| + t.Fatal("pending begin is not restricted to the person", creds) |
| + } |
| + zero := uint32(0) |
| + if w := d.call(t, app, nativePrefix+"/passkey/finish", assertionBody(otherKey, challenge, authtest.Options{RPID: credentialHost, Origin: Origin, Count: &zero}), ""); w.Code == 200 { |
| + t.Fatal("another person's passkey finished the pending") |
| + } |
| + challenge, _ = nativeChallenge(t, d.call(t, app, nativePrefix+"/passkey/begin", map[string]string{"pending": pending}, "")) |
| + w := d.call(t, app, nativePrefix+"/passkey/finish", assertionBody(key, challenge, authtest.Options{RPID: credentialHost, Origin: Origin, Count: &zero}), "") |
| + if w.Code != 200 || decodeReply(t, w)["grant"] == nil { |
| + t.Fatal("pending finish", w.Code, w.Body.String()) |
| + } |
| + var method string |
| + app.db.Writer().QueryRow("SELECT method FROM home_id_grants").Scan(&method) |
| + if method != "email+passkey" { |
| + t.Fatal("method", method) |
| + } |
| + if n := count(t, app, "SELECT count(*) FROM home_id_native_pending"); n != 0 { |
| + t.Fatal("pending survived") |
| + } |
| +} |
| + |
| +// §13 Domains: the association file's content, and nothing else in it. |
| +func TestNativeAssociationFile(t *testing.T) { |
| + app := newNativeApp(t) |
| + r := httptest.NewRequest("GET", Origin+aasaPath, nil) |
| + w := httptest.NewRecorder() |
| + app.Router().ServeHTTP(w, r) |
| + if w.Code != 200 || w.Header().Get("Content-Type") != "application/json" || w.Header().Get("Location") != "" { |
| + t.Fatal("aasa", w.Code, w.Header()) |
| + } |
| + var got map[string]map[string][]string |
| + if err := json.Unmarshal(w.Body.Bytes(), &got); err != nil { |
| + t.Fatal(err) |
| + } |
| + want := []string{"9U4A84C4WK.works.oficina.calls", "9U4A84C4WK.works.oficina.docs", "9U4A84C4WK.works.oficina.sheets", "9U4A84C4WK.works.oficina.calendar", "9U4A84C4WK.works.oficina.memoria"} |
| + if len(got) != 1 || len(got["webcredentials"]) != 1 || strings.Join(got["webcredentials"]["apps"], ",") != strings.Join(want, ",") { |
| + t.Fatal("aasa content", w.Body.String()) |
| + } |
| + if strings.Contains(w.Body.String(), "applinks") { |
| + t.Fatal("applinks in slice A") |
| + } |
| + // Only the credential origin serves it. |
| + r = httptest.NewRequest("GET", directoryOrigin+aasaPath, nil) |
| + w = httptest.NewRecorder() |
| + app.Router().ServeHTTP(w, r) |
| + if w.Code == 200 { |
| + t.Fatal("served on the directory host") |
| + } |
| +} |
| + |
| +// §4: every native endpoint refuses browser evidence and non-JSON, and |
| +// renders nothing. |
| +func TestNativeEndpointsRefuseBrowsers(t *testing.T) { |
| + app := newNativeApp(t) |
| + for _, path := range []string{"/code/start", "/code/resend", "/code/verify", "/passkey/begin", "/passkey/finish", "/assert", "/signout"} { |
| + for _, h := range []map[string]string{{"Origin": Origin}, {"Sec-Fetch-Site": "same-origin"}, {"Content-Type": "application/x-www-form-urlencoded"}} { |
| + r := httptest.NewRequest("POST", Origin+nativePrefix+path, strings.NewReader("{}")) |
| + r.Header.Set("Content-Type", "application/json") |
| + for k, v := range h { |
| + r.Header.Set(k, v) |
| + } |
| + w := httptest.NewRecorder() |
| + app.Router().ServeHTTP(w, r) |
| + if w.Code < 400 || w.Header().Get("Content-Type") != "application/json" || w.Header().Get("Cache-Control") != "no-store" || strings.Contains(w.Body.String(), "<") { |
| + t.Fatal(path, h, w.Code, w.Header()) |
| + } |
| + } |
| + } |
| + // The legacy role mounts none of it. |
| + legacy := newTestApp(t) |
| + r := httptest.NewRequest("POST", Origin+nativePrefix+"/code/start", strings.NewReader("{}")) |
| + r.Header.Set("Content-Type", "application/json") |
| + w := httptest.NewRecorder() |
| + legacy.Router().ServeHTTP(w, r) |
| + if w.Code != 404 && w.Code != 405 { |
| + t.Fatal("legacy role served native", w.Code) |
| + } |
| +} |