Align the native wire with the Swift client and connect
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
Coordinator decisions after reviewing the Swift client (rastrillo/native native/oficina-id-slice-a @a1039a1) and the connect branch (@a4da657): the exchange challenge is SHA-256 of the verifier's base64url string (vector AAEC…Hh8 -> 6oZq…_9A -> ZVVVj2zbBfhkAIwAOKNylg, pinned); a 401 says grant_ended only when the grant is gone (unknown, revoked, signed out, expired, replaced, enrolment), proof_rejected for every other refusal, both with now; a gone start (unknown, expired, used, dead) is 410 expired on verify and resend; passkey/begin always takes device_key and platform, and with a pending the key must be the start's; passkey/finish takes device_key (must be the challenge's bound key), and accepts and ignores platform and userHandle; the directory exchange also refuses a jti whose browser receipt is waiting, as handoff.Store.Reserve does.
Agent notes
nativeNonce and the directory's jti reservation duplicate handoff.NativeNonce/NativeChallenge and Store.Verify/Reserve on the unlanded connect branch; the vector test keeps them identical until they can be deduped after both land.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
7 files changed,
+149
−49
internal/home/directory_native.go+16 −3internal/home/native.go+18 −7internal/home/native_code.go+7 −5internal/home/native_grant_test.go+48 −9internal/home/native_helpers_test.go+5 −3internal/home/native_passkey.go+29 −14internal/home/native_passkey_test.go+26 −8
CI failed — run details
diff --git a/internal/home/directory_native.go b/internal/home/directory_native.go| index 0070998..fe5cda5 100644 |
| --- a/internal/home/directory_native.go |
| +++ b/internal/home/directory_native.go |
| @@ -78,8 +78,7 @@ func (a *App) directoryNativeExchange(w http.ResponseWriter, r *http.Request) { |
| answer(http.StatusBadRequest, "invalid") |
| return |
| } |
| - verifierRaw, ok := decodeB64(in.Verifier, 32) |
| - if !ok { |
| + if _, ok := decodeB64(in.Verifier, 32); !ok { |
| answer(http.StatusBadRequest, "invalid") |
| return |
| } |
| @@ -90,7 +89,9 @@ func (a *App) directoryNativeExchange(w http.ResponseWriter, r *http.Request) { |
| } |
| now := time.Now() |
| claims, err := v.Verify(in.Assertion, now) |
| - challenge := sha256.Sum256(verifierRaw) |
| + // The challenge is SHA-256 of the verifier as sent, the base64url |
| + // string (rastrillo's PKCE convention, and the client's). |
| + challenge := sha256.Sum256([]byte(in.Verifier)) |
| if err != nil || subtle.ConstantTimeCompare([]byte(claims.Nonce), []byte(nativeNonce(challenge[:]))) != 1 || !ValidPersonRef(claims.Subject) { |
| answer(http.StatusUnauthorized, "failed") |
| return |
| @@ -103,7 +104,19 @@ func (a *App) directoryNativeExchange(w http.ResponseWriter, r *http.Request) { |
| defer tx.Rollback() |
| // The same replay ledger, and the same key for it, as the browser |
| // callback (handoff.Store): one jti is redeemable once, by either door. |
| + // Implemented as handoff.Store.Reserve does on the connect branch |
| + // (unlanded): a jti whose browser receipt is still waiting in the inbox |
| + // is refused too. Dedupe onto Reserve once that lands. |
| jti := sha256.Sum256([]byte(claims.Issuer + "\x00" + claims.ID)) |
| + var waiting int |
| + if err = tx.QueryRow("SELECT count(*) FROM oficina_handoff_inbox WHERE jti_hash=?", hex.EncodeToString(jti[:])).Scan(&waiting); err != nil { |
| + answer(http.StatusServiceUnavailable, "unavailable") |
| + return |
| + } |
| + if waiting != 0 { |
| + answer(http.StatusUnauthorized, "failed") |
| + return |
| + } |
| res, err := tx.Exec("INSERT INTO oficina_handoff_replay(jti_hash,expires_at) VALUES(?,?) ON CONFLICT DO NOTHING", hex.EncodeToString(jti[:]), claims.ExpiresAt) |
| if err != nil { |
| answer(http.StatusServiceUnavailable, "unavailable") |
diff --git a/internal/home/native.go b/internal/home/native.go| index 11959c9..3475ba3 100644 |
| --- a/internal/home/native.go |
| +++ b/internal/home/native.go |
| @@ -88,6 +88,17 @@ func nativeFail(w http.ResponseWriter, status int, code string) { |
| nativeReply(w, status, map[string]string{"error": code}) |
| } |
| +// The two 401 answers. The client wipes the device's identity only on |
| +// nativeGrantEnded: the grant is gone (never existed, revoked, signed out, |
| +// expired, replaced or swept by an enrolment). Every other refusal — a bad |
| +// signature, a skewed iat, a wrong htu or body, a replayed jti, a malformed |
| +// header — is nativeProofRejected, which the client may retry once after |
| +// correcting its clock from "now". |
| +const ( |
| + nativeGrantEnded = "grant_ended" |
| + nativeProofRejected = "proof_rejected" |
| +) |
| + |
| // nativeUnauthorized carries the server's clock, so a client whose proof |
| // failed on iat can correct its offset and retry once (§3). |
| func nativeUnauthorized(w http.ResponseWriter, code string) { |
| @@ -297,16 +308,16 @@ func (a *App) nativeAuthed(handle func(tx *sql.Tx, g nativeGrant, body []byte, n |
| token, found = strings.CutPrefix(auth[0], "OficinaID ") |
| } |
| if !found || len(token) != 43 { |
| - nativeUnauthorized(w, "grant") |
| + nativeUnauthorized(w, nativeProofRejected) |
| return |
| } |
| if _, ok := decodeB64(token, 32); !ok { |
| - nativeUnauthorized(w, "grant") |
| + nativeUnauthorized(w, nativeProofRejected) |
| return |
| } |
| p, payload, sig, err := parseNativeProof(r) |
| if err != nil { |
| - nativeUnauthorized(w, "proof") |
| + nativeUnauthorized(w, nativeProofRejected) |
| return |
| } |
| tx, now, err := a.idTransaction(r.Context()) |
| @@ -323,7 +334,7 @@ func (a *App) nativeAuthed(handle func(tx *sql.Tx, g nativeGrant, body []byte, n |
| err = tx.QueryRow("SELECT person_ref,identity_id,device_key,platform,method,auth_time,expires_at,last_used_day,ended_at FROM home_id_grants WHERE grant_hash=?", g.hash). |
| Scan(&g.person, &g.identityID, &g.deviceKey, &g.platform, &g.method, &g.authTime, &expires, &lastUsed, &ended) |
| if errors.Is(err, sql.ErrNoRows) || (err == nil && ended.Valid) { |
| - nativeUnauthorized(w, "grant") |
| + nativeUnauthorized(w, nativeGrantEnded) |
| return |
| } |
| if err != nil { |
| @@ -335,12 +346,12 @@ func (a *App) nativeAuthed(handle func(tx *sql.Tx, g nativeGrant, body []byte, n |
| nativeFail(w, http.StatusServiceUnavailable, "unavailable") |
| return |
| } |
| - nativeUnauthorized(w, "grant") |
| + nativeUnauthorized(w, nativeGrantEnded) |
| return |
| } |
| key, ok := decodeDeviceKey(g.deviceKey) |
| if !ok || !a.verifyNativeProof(r, body, key, p, payload, sig, now) { |
| - nativeUnauthorized(w, "proof") |
| + nativeUnauthorized(w, nativeProofRejected) |
| return |
| } |
| // Only now, with the grant live and the signature good, does the jti |
| @@ -377,7 +388,7 @@ func (a *App) nativeAuthed(handle func(tx *sql.Tx, g nativeGrant, body []byte, n |
| return |
| } |
| if n, err := res.RowsAffected(); err != nil || n != 1 { |
| - nativeUnauthorized(w, "replay") |
| + nativeUnauthorized(w, nativeProofRejected) |
| return |
| } |
| if today := dayOf(now); lastUsed != today { |
diff --git a/internal/home/native_code.go b/internal/home/native_code.go| index 0736436..875b285 100644 |
| --- a/internal/home/native_code.go |
| +++ b/internal/home/native_code.go |
| @@ -242,7 +242,7 @@ func (a *App) nativeCodeStart(w http.ResponseWriter, r *http.Request) { |
| return |
| } |
| if !a.nativePreGrant(r, body, in.DeviceKey, time.Now().Unix()) { |
| - nativeUnauthorized(w, "proof") |
| + nativeUnauthorized(w, nativeProofRejected) |
| return |
| } |
| address, blind, err := a.nativeAddress(in.Email) |
| @@ -426,11 +426,13 @@ func (a *App) nativeCodeResend(w http.ResponseWriter, r *http.Request) { |
| defer tx.Rollback() |
| s, found := loadStart(tx, in.Start, now) |
| if !found { |
| - nativeFail(w, http.StatusBadRequest, "start") |
| + // Unknown, expired, used or dead after five wrong tries: one answer, |
| + // and the app starts again. |
| + nativeFail(w, http.StatusGone, "expired") |
| return |
| } |
| if !a.nativePreGrant(r, body, s.deviceKey, now) { |
| - nativeUnauthorized(w, "proof") |
| + nativeUnauthorized(w, nativeProofRejected) |
| return |
| } |
| if s.sends >= nativeCodeSends { |
| @@ -497,11 +499,11 @@ func (a *App) nativeCodeVerify(w http.ResponseWriter, r *http.Request) { |
| defer tx.Rollback() |
| s, found := loadStart(tx, in.Start, now) |
| if !found { |
| - nativeFail(w, http.StatusBadRequest, "code") |
| + nativeFail(w, http.StatusGone, "expired") |
| return |
| } |
| if !a.nativePreGrant(r, body, s.deviceKey, now) { |
| - nativeUnauthorized(w, "proof") |
| + nativeUnauthorized(w, nativeProofRejected) |
| return |
| } |
| plain, err := a.secrets.Sealer.Open(nativeCodeSealScope, s.sealed) |
diff --git a/internal/home/native_grant_test.go b/internal/home/native_grant_test.go| index 8d1c998..6bd9392 100644 |
| --- a/internal/home/native_grant_test.go |
| +++ b/internal/home/native_grant_test.go |
| @@ -67,7 +67,7 @@ func TestNativeProofReplay(t *testing.T) { |
| if w := d.assert(t, app, grant, teamDocs, challenge, o); w.Code != 200 { |
| t.Fatal("first", w.Code, w.Body.String()) |
| } |
| - if w := d.assert(t, app, grant, teamDocs, challenge, o); w.Code != 401 || decodeReply(t, w)["error"] != "replay" { |
| + if w := d.assert(t, app, grant, teamDocs, challenge, o); w.Code != 401 || decodeReply(t, w)["error"] != nativeProofRejected { |
| t.Fatal("replay accepted", w.Code) |
| } |
| app = app.restart(t) |
| @@ -272,22 +272,61 @@ func TestNativeSignout(t *testing.T) { |
| } |
| } |
| -// The derivation's shared vector (verifier = 0x00..0x1f), the same bytes the |
| -// connect branch's handoff.NativeNonce test pins, so Home's assert, every |
| -// instance's NativeExchange and the Swift client agree. |
| +// The derivation's shared vector (verifier = base64url of 0x00..0x1f). The |
| +// challenge is SHA-256 of the verifier's base64url STRING, the convention the |
| +// coordinator fixed for all three halves (Home, connect, the Swift client). |
| func TestNativeNonceVector(t *testing.T) { |
| raw := make([]byte, 32) |
| for i := range raw { |
| raw[i] = byte(i) |
| } |
| - if v := base64.RawURLEncoding.EncodeToString(raw); v != "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8" { |
| - t.Fatal(v) |
| + verifier := base64.RawURLEncoding.EncodeToString(raw) |
| + if verifier != "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8" { |
| + t.Fatal(verifier) |
| } |
| - challenge := sha256.Sum256(raw) |
| - if c := base64.RawURLEncoding.EncodeToString(challenge[:]); c != "Yw3NKWbEM2aRElRIu7JbT_QSpJxzLbLIq8G4WBvXEN0" { |
| + challenge := sha256.Sum256([]byte(verifier)) |
| + if c := base64.RawURLEncoding.EncodeToString(challenge[:]); c != "6oZqdX5MOLq_qBJ8vppAnT4fk6AP8UiP9zX8-Rev_9A" { |
| t.Fatal("challenge", c) |
| } |
| - if n := nativeNonce(challenge[:]); n != "cU9jQRCTNby9G46AOrt78A" { |
| + if n := nativeNonce(challenge[:]); n != "ZVVVj2zbBfhkAIwAOKNylg" { |
| t.Fatal("nonce", n) |
| } |
| } |
| + |
| +// The two 401 markers: the client wipes the identity only on grant_ended. |
| +func TestNativeUnauthorizedMarkers(t *testing.T) { |
| + app := newNativeApp(t) |
| + d := newDevice(t) |
| + grant, _ := d.signInByCode(t, app, "markers@example.invalid") |
| + _, challenge := verifierFor(40) |
| + for name, o := range map[string]proofOpts{"skew": {iat: time.Now().Unix() - 60}, "key": {signer: newDevice(t)}} { |
| + w := d.assert(t, app, grant, teamDocs, challenge, o) |
| + if out := decodeReply(t, w); w.Code != 401 || out["error"] != nativeProofRejected || out["now"] == nil { |
| + t.Fatal(name, w.Code, out) |
| + } |
| + } |
| + if w := d.assert(t, app, strings.Repeat("A", 43), teamDocs, challenge); decodeReply(t, w)["error"] != nativeGrantEnded { |
| + t.Fatal("unknown grant", w.Body.String()) |
| + } |
| + if w := d.call(t, app, nativePrefix+"/signout", map[string]string{}, grant); w.Code != 200 { |
| + t.Fatal(w.Code) |
| + } |
| + w := d.assert(t, app, grant, teamDocs, challenge) |
| + if out := decodeReply(t, w); w.Code != 401 || out["error"] != nativeGrantEnded || out["now"] == nil { |
| + t.Fatal("ended grant", w.Code, out) |
| + } |
| + // A gone start is 410 expired, on verify and resend alike. |
| + start := d.start(t, app, "gone@example.invalid") |
| + if _, err := app.db.Writer().Exec("UPDATE home_id_native_starts SET expires_at=1"); err != nil { |
| + t.Fatal(err) |
| + } |
| + for _, path := range []string{"/code/verify", "/code/resend"} { |
| + body := map[string]string{"start": start} |
| + if path == "/code/verify" { |
| + body["code"] = "123456" |
| + } |
| + if w := d.call(t, app, nativePrefix+path, body, ""); w.Code != 410 || decodeReply(t, w)["error"] != "expired" { |
| + t.Fatal(path, w.Code, w.Body.String()) |
| + } |
| + } |
| +} |
diff --git a/internal/home/native_helpers_test.go b/internal/home/native_helpers_test.go| index fab831f..acfb89a 100644 |
| --- a/internal/home/native_helpers_test.go |
| +++ b/internal/home/native_helpers_test.go |
| @@ -215,14 +215,16 @@ func count(t *testing.T, app *testApp, query string, args ...any) int { |
| return n |
| } |
| -// verifierFor is a native client's verifier and challenge. |
| +// verifierFor is a native client's verifier and challenge: SHA-256 of the |
| +// verifier's base64url string. |
| func verifierFor(seed byte) (verifier string, challenge []byte) { |
| raw := make([]byte, 32) |
| for i := range raw { |
| raw[i] = seed + byte(i) |
| } |
| - sum := sha256.Sum256(raw) |
| - return base64.RawURLEncoding.EncodeToString(raw), sum[:] |
| + verifier = base64.RawURLEncoding.EncodeToString(raw) |
| + sum := sha256.Sum256([]byte(verifier)) |
| + return verifier, sum[:] |
| } |
| func verifyAssertion(t *testing.T, app *testApp, token, aud string) assertion.Claims { |
diff --git a/internal/home/native_passkey.go b/internal/home/native_passkey.go| index 1aaccdc..42a675b 100644 |
| --- a/internal/home/native_passkey.go |
| +++ b/internal/home/native_passkey.go |
| @@ -17,11 +17,11 @@ import ( |
| // 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. |
| +// nativePasskeyBegin is POST passkey/begin {device_key, platform, pending?}. |
| +// Without pending it is a discoverable sign-in that needs no email; with one |
| +// it finishes a code sign-in on an enrolled account, and device_key must be |
| +// the key that start was made with. 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 { |
| @@ -32,7 +32,7 @@ func (a *App) nativePasskeyBegin(w http.ResponseWriter, r *http.Request) { |
| 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]) { |
| + if !decodeNative(body, &in) || in.DeviceKey == "" || !nativePlatforms[in.Platform] { |
| nativeFail(w, http.StatusBadRequest, "request") |
| return |
| } |
| @@ -54,12 +54,18 @@ func (a *App) nativePasskeyBegin(w http.ResponseWriter, r *http.Request) { |
| } |
| 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") |
| + nativeFail(w, http.StatusGone, "expired") |
| + return |
| + } |
| + // The pending is bound to its start's key; the proof below is |
| + // checked against that key, never the one in the body. |
| + if key != in.DeviceKey { |
| + nativeUnauthorized(w, nativeProofRejected) |
| return |
| } |
| } |
| if !a.nativePreGrant(r, body, key, now) { |
| - nativeUnauthorized(w, "proof") |
| + nativeUnauthorized(w, nativeProofRejected) |
| return |
| } |
| if ip := nativeIPBucket(r); ip != "" { |
| @@ -131,15 +137,24 @@ func (a *App) nativePasskeyBegin(w http.ResponseWriter, r *http.Request) { |
| } |
| // 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}. |
| +// authenticatorData, signature, device_key, platform?, userHandle?}: the web |
| +// door's finish fields plus the device key. device_key must be the key the |
| +// challenge was bound to at begin, and the proof is checked against that |
| +// bound key. platform was fixed at begin and userHandle decides nothing |
| +// (the credential id names the owner, as on the web); both are accepted |
| +// and ignored. It 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 != "" { |
| + var in struct { |
| + idCeremony |
| + DeviceKey string `json:"device_key"` |
| + Platform string `json:"platform,omitzero"` |
| + UserHandle string `json:"userHandle,omitzero"` |
| + } |
| + if !decodeNative(body, &in) || in.Attestation != "" || in.DeviceKey == "" || len(in.UserHandle) > 128 || (in.Platform != "" && !nativePlatforms[in.Platform]) { |
| nativeFail(w, http.StatusBadRequest, "request") |
| return |
| } |
| @@ -172,8 +187,8 @@ func (a *App) nativePasskeyFinish(w http.ResponseWriter, r *http.Request) { |
| nativeFail(w, http.StatusBadRequest, "passkey") |
| return |
| } |
| - if !a.nativePreGrant(r, body, key, now) { |
| - nativeUnauthorized(w, "proof") |
| + if key != in.DeviceKey || !a.nativePreGrant(r, body, key, now) { |
| + nativeUnauthorized(w, nativeProofRejected) |
| return |
| } |
| // Consume the challenge first and keep it consumed whatever follows: a |
diff --git a/internal/home/native_passkey_test.go b/internal/home/native_passkey_test.go| index a466a42..787b515 100644 |
| --- a/internal/home/native_passkey_test.go |
| +++ b/internal/home/native_passkey_test.go |
| @@ -11,6 +11,14 @@ import ( |
| "amadan.net/rastrillo/rastrillo/webauthn/authtest" |
| ) |
| +// finishBody is the web finish fields plus what the app adds. |
| +func finishBody(d *device, body map[string]string) map[string]string { |
| + body["device_key"] = d.public() |
| + body["platform"] = d.platform |
| + body["userHandle"] = "ignored-handle" |
| + return body |
| +} |
| + |
| func nativeChallenge(t *testing.T, w *httptest.ResponseRecorder) ([]byte, []string) { |
| t.Helper() |
| if w.Code != 200 { |
| @@ -43,11 +51,20 @@ func TestNativePasskeySignIn(t *testing.T) { |
| t.Fatal("a discoverable begin named credentials") |
| } |
| zero := uint32(0) |
| - body := assertionBody(key, challenge, authtest.Options{RPID: credentialHost, Origin: Origin, Count: &zero}) |
| + body := finishBody(d, 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) |
| } |
| + // The body's device_key must be the bound key. |
| + swapped := map[string]string{} |
| + for k, v := range body { |
| + swapped[k] = v |
| + } |
| + swapped["device_key"] = newDevice(t).public() |
| + if w := d.call(t, app, nativePrefix+"/passkey/finish", swapped, ""); w.Code != 401 { |
| + t.Fatal("a body naming another key finished", 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)) { |
| @@ -89,11 +106,11 @@ func TestNativePasskeyRejectsBadCeremonies(t *testing.T) { |
| case "unknown": |
| key, _ = authtest.New() |
| } |
| - w := d.call(t, app, nativePrefix+"/passkey/finish", assertionBody(key, challenge, opts), "") |
| + w := d.call(t, app, nativePrefix+"/passkey/finish", finishBody(d, 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}) |
| + good := finishBody(d, 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") |
| } |
| @@ -115,19 +132,20 @@ func TestNativePendingFinishedByPasskey(t *testing.T) { |
| 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 { |
| + e := newDevice(t) |
| + if w := e.call(t, app, nativePrefix+"/passkey/begin", map[string]string{"pending": pending, "device_key": e.public(), "platform": "macos"}, ""); 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}, "")) |
| + challenge, creds := nativeChallenge(t, d.call(t, app, nativePrefix+"/passkey/begin", map[string]string{"pending": pending, "device_key": d.public(), "platform": "macos"}, "")) |
| 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 { |
| + if w := d.call(t, app, nativePrefix+"/passkey/finish", finishBody(d, 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}), "") |
| + challenge, _ = nativeChallenge(t, d.call(t, app, nativePrefix+"/passkey/begin", map[string]string{"pending": pending, "device_key": d.public(), "platform": "macos"}, "")) |
| + w := d.call(t, app, nativePrefix+"/passkey/finish", finishBody(d, 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()) |
| } |