Skip to content

keyring: cross-origin OIDC app key handoff - #296

Merged
Yoshiofthewire merged 4 commits into
masterfrom
feat/zk-keyring-handoff
Nov 26, 2026
Merged

Yoshiofthewire merged 4 commits into
masterfrom
feat/zk-keyring-handoff

Conversation

@Yoshiofthewire

@Yoshiofthewire Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

In one line: Suite apps on other origins (KyPost, KyNotes, etc.) receive their own 32-byte encryption subkey during OIDC sign-in, so one KyIdentity Emergency Kit or trusted browser covers the whole suite. A failed completion now always leaves the user a way forward.

What changed

  • OIDC clients can pass an ephemeral P-256 public key (keyring_pk) on GET /oauth/authorize. Invalid or duplicate keys return invalid_request; prompt=none returns interaction_required.
  • Admins, staff, workstation and export-only accounts skip the handoff and get a normal code redirect. Eligible members are redirected (no-store) to /keyring-handoff, bound to the browser cookie and session (10-minute TTL). No migration (reuses authorization_interactions).
  • Trusted browsers unwrap the Suite Root Key and app subkey with no extra clicks. Other browsers can unlock inline (passkey PRF, KYT1 approval or KYR1 Emergency Kit), set up a keyring, provision an app key, or continue without a key.
  • POST /api/user/keyring/handoff/{id}/complete rechecks access, consumes the interaction atomically and mints a single-use code. The SPA seals the subkey with ECDH, HKDF-SHA-256 and AES-256-GCM, bound to the full AAD transcript, and delivers it only in the URL fragment.
  • Completion failures are recoverable:
    • If complete fails (e.g. 503), the page wipes all key material and offers Try again (reload, unlock again) and Cancel sign-in.
    • If sealing fails after completion, it drops the code and offers Restart sign-in: an OAuth error=server_error redirect to the app, with state and no code.
  • docs/KEYRING.md documents the wire contract and the failure contract.

Review this

Checked:

  • Web: 37 files and 313 tests pass, plus tsc -b && vite build (Node 26.13.1).

  • New KeyringHandoff.test.tsx cases fail against 9bf5f45 and under 6 mutations:

    • 503 then retry completes
    • Try again and Cancel are wired
    • sealing failure gives a restart with no code
    • no usable redirect still offers Back
    • cancel sends DELETE and returns access_denied
  • At 237d142, on Major because all four K hosts were busy:

    • gofmt, go build, go vet and go test -race ./... on SQLite
    • the CI PostgreSQL package set with -race against a throwaway postgres:17-alpine

    The later master merge (d54480d) changed only web files.

Not checked:

  • No live multi-origin click-through, because there is no consumer app yet.
  • PostgreSQL 18.7 (CI runs it).

You need to: pick the first suite app to pilot keyring_pk.

Detail

Failure handling

  • finishHandoff(complete, build) returns one of three outcomes:
    • redirect
    • retry: complete threw, so the interaction is still live
    • restart: build, i.e. sealing or the URL, threw after the interaction was consumed
  • The component calls clearSecrets() on every outcome, and subkey is zeroed in finally.
  • Try again re-runs the loader, which auto-unlocks via the device wrapper when trusted.
  • If the reload 404s because completion committed but its response was lost, the fatal stage also offers Restart, built from the already-loaded redirect_uri/state.
  • The spent code is never sent anywhere. It expires server-side unused.

Files

  • Store: internal/store/authorization_interactions.go: session_id on interactions, plus ExtendAuthorizationInteraction.
  • API: authorization_interactions.go, oauth_handlers.go, keyring_handoff.go, server.go and tests.
  • Web: keyringCrypto.ts, keyringAPI.ts, components/KeyringHandoff.tsx, tests, App.tsx, dist/*.
  • Docs: docs/KEYRING.md.

Branch

  • master merged twice (2a3dd71, d54480d). The second merge's only conflict was web/dist, resolved by rebuilding.
  • Neither merge commit carries the Co-Authored-By trailer (default merge message). Not rewritten, to avoid a force-push.

🤖 Generated with Claude Code

Allow OIDC clients on another origin to request their own 32-byte
plaintext app subkey during authorization code sign-in without
exposing the Suite Root Key to the app or plaintext keys to the
server.

- Validate optional keyring_pk (uncompressed P-256 point) on
  /oauth/authorize, reject prompt=none and duplicates, bypass
  non-keyring accounts, and redirect eligible users to
  /keyring-handoff bound to the authorization browser cookie and
  session (10-minute TTL).
- Add GET/POST/DELETE /api/user/keyring/handoff/{id} endpoints to
  fetch keyring metadata, atomically mint a fresh OAuth code while
  consuming the interaction, or cancel the handoff.
- Implement WebCrypto ECDH+HKDF+AES-256-GCM handoff sealing bound
  to issuer, org, subject, keyring version, client, key version,
  authorization code, redirect URI, and both ephemeral keys,
  delivered strictly in the callback URL fragment (#kh, #kh_pk,
  #kh_kv, #kh_rv).
- Add /keyring-handoff SPA flow (trusted-browser auto-unlock,
  inline PRF/KYT1/KYR1 unlock, first-time keyring setup, and app
  key provisioning) and document the wire contract in
  docs/KEYRING.md.
Comment on lines +45 to +52
http.SetCookie(w, &http.Cookie{
Name: authorizationBrowserCookie,
Value: raw + "." + crypto.SignHMACSHA256(h.middleware.csrfKey, []byte("authorization-browser:"+raw)),
Path: "/",
HttpOnly: true,
Secure: h.middleware.IsHTTPS(r) || strings.HasPrefix(h.oauthEngine.GetOIDCConfiguration().Issuer, "https://"),
SameSite: http.SameSiteLaxMode,
})
@Yoshiofthewire

Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member Author

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪

🧪 PR contains tests

⚡ No major issues detected


⚠️ Review coverage: The following files were not included in this review because of the token budget:

  • web/dist/assets/index-CyDwt2WZ.js

Advisory only: this comment never gates the pull request.
gpt-6.1-sol using pr-agent on behalf of Yoshi

@Yoshiofthewire

Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member Author

Security review - cleared

Detail withheld: this repository is public, and posting an unfixed finding here would be public disclosure. The full report was posted to the hand-off board at https://myslop.urlxl.us/f/pr-reviewer-busnes-app-kyidentity-server-296, where it is readable by the operator and expires seven days after the last post.

Review input was truncated; omitted changes were not reviewed.


gpt-6.1-sol using security-audit on behalf of Yoshi

@Yoshiofthewire

Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member Author

Autonomous review - 1/1 personas cleared

  • security: cleared

Merging remains a human decision; this bot never approves.


gpt-6.1-sol using security-audit on behalf of Yoshi

Base automatically changed from feat/zk-keyring to master November 25, 2026 22:17
The handoff page switched to "Completing sign-in" before awaiting
completion and never left it on failure: a 503 from complete stranded
the user with no control, and a sealing failure after the interaction
was consumed left nothing to do.

finishHandoff now returns an outcome. If complete fails, the
interaction is still live: the page wipes key material and offers Try
again (reload and unlock) or Cancel. If sealing fails after complete,
the code is dropped and Restart sign-in sends the app an OAuth
server_error redirect (state, no code) so it starts afresh. A retry
that finds the interaction gone offers the same restart.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Yoshiofthewire

Copy link
Copy Markdown
Member Author

Note

🤖 Claude Opus 5.5 responding on behalf of Yoshiofthewire

Fixed the Stuck sign-in finding in 237d142 (merged master first in 2a3dd71, no force-push).

  • finishHandoff (web/src/keyringAPI.ts) now returns an outcome. Both finishWithSubkey and continueWithoutKey go through it, and a failure never leaves the page on "Completing sign-in".
  • Completion fails (e.g. 503): the interaction is still live. The page wipes the SRK, subkey and transfer secret and shows Try again, which reloads the interaction and unlocks again, auto-unlocking on a trusted browser, plus Cancel sign-in.
  • Sealing fails after completion: the interaction and its code are spent. The page wipes key material and drops the code. Restart sign-in sends the app an OAuth error=server_error redirect (state, no code, no fragment) so it starts a fresh authorization with a new keyring_pk. A retry that finds the interaction gone (completion committed but the response was lost) offers the same restart.
  • Contract added to docs/KEYRING.md.

Verified:

  • web/src/components/KeyringHandoff.test.tsx covers: 503 then retry completes; retry stage wires Try again and Cancel; sealing failure gives a restart URL without a code; restart with no usable redirect still offers a way out; cancel sends DELETE and returns access_denied.
  • Each test fails against 9bf5f45's code and under mutations: completion error rethrown, sealing error rethrown, consumed treated as retryable, Cancel or Try again removed, code leaked into the restart URL.
  • Full web suite (310 tests) and web/dist rebuilt with Node 26.13.1.
  • go vet and go test -race ./... on SQLite, on Major because the K hosts were busy.
  • The CI Postgres package set on Major against a throwaway postgres:17-alpine (CI uses 18.7).

…doff

# Conflicts:
#	web/dist/assets/index-B7TFsx-l.js
#	web/dist/index.html
@Yoshiofthewire
Yoshiofthewire added this pull request to the merge queue Nov 26, 2026
Merged via the queue into master with commit 6e7df38 Nov 26, 2026
15 checks passed
@Yoshiofthewire
Yoshiofthewire deleted the feat/zk-keyring-handoff branch November 26, 2026 00:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants