Safari can't approve: its stored device key doesn't sign after a reload #94

Open
opened 2026-10-03 05:56:53 +00:00 by jhgaylor · 1 comment
Owner

What happened

A new user on Safari on Mac couldn't add a machine with hosted control (2026-10-03):

  • GitHub sign-in worked. Safari enrolled as the account's first device: its self-signed certificate passed control's signed_by check, and it signed both recovery codes fine.
  • illogicald join printed a code. The code was valid: recomputing it from the request's keys gives the same code, so the browser's "doesn't match its code" check passes.
  • Approving it in Safari failed with control's that approval doesn't check out (signed by a device this account trusts?) (approval_ok, crates/control/src/api.rs). The join stayed unapproved. The account has no revocations, no pending second browser, and Safari is its root.

So the device approving is the right one and is trusted, but its signature on the daemon's certificate doesn't verify.

Suspected cause (unconfirmed)

The browser's Ed25519 key is a non-extractable CryptoKey kept in IndexedDB (web/src/e2e/keys.ts). Every signature that worked was made in the page load that generated the key, with the in-memory key. The approval came after opening the #join= link, a new page load, so with the key read back from IndexedDB. If Safari doesn't round-trip Ed25519 (and maybe X25519) CryptoKeys through structured clone correctly, every later signature fails. If the X25519 key is affected too, connecting to machines from that Safari would fail as well.

This hasn't been reproduced on Safari: geek has no Safari, and control doesn't keep rejected approvals.

Fix

  1. Confirm. Make a small page that generates a non-extractable Ed25519 key and an X25519 key, puts them in IndexedDB, reloads, signs and derives with them, and verifies the results. Run it in Safari on jake-mini (and iOS Safari). Note the Safari version.
  2. Self-check before enrolling. After generateKeys() stores the keys, read them back from IndexedDB and check a sign→verify (and an X25519 agreement) against the public keys. Enroll only once that passes, so a browser can never become a trusted device with keys it can't use after a reload.
  3. Store keys in a form that survives the round trip where the check fails, e.g. generate extractable and keep the raw/pkcs8 key (or wrap it with a non-extractable AES-GCM key, if Safari round-trips those). Write down what this gives up compared with non-extractable keys.
  4. Already-enrolled Safari devices whose stored keys are broken: detect it at boot (the same probe) and say so plainly. Offer to forget this browser and re-enroll (approved by another device or a recovery code) rather than failing later with an approval error.
  5. Control logs rejected approvals and enrolments (approval_ok, join_approve, approve, enroll) with the reason, account and device ids, so fly logs shows the cause next time. No signatures or bodies in the logs beyond ids.
  6. Test: Playwright WebKit for the round trip and an e2e join approved after a reload, plus the manual Safari check from step 1.

Workaround for affected users

Sign in from Chrome or Firefox, let that browser in with a recovery code (it signs with the code's key, not Safari's), then approve the illogicald join link there.

## What happened A new user on **Safari on Mac** couldn't add a machine with hosted control (2026-10-03): - GitHub sign-in worked. Safari enrolled as the account's first device: its self-signed certificate passed control's `signed_by` check, and it signed both recovery codes fine. - `illogicald join` printed a code. The code was valid: recomputing it from the request's keys gives the same code, so the browser's "doesn't match its code" check passes. - Approving it in Safari failed with control's `that approval doesn't check out (signed by a device this account trusts?)` (`approval_ok`, `crates/control/src/api.rs`). The join stayed unapproved. The account has no revocations, no pending second browser, and Safari is its root. So the device approving is the right one and is trusted, but its signature on the daemon's certificate doesn't verify. ## Suspected cause (unconfirmed) The browser's Ed25519 key is a non-extractable `CryptoKey` kept in IndexedDB (`web/src/e2e/keys.ts`). Every signature that worked was made in the page load that generated the key, with the in-memory key. The approval came after opening the `#join=` link, a new page load, so with the key read back from IndexedDB. If Safari doesn't round-trip Ed25519 (and maybe X25519) `CryptoKey`s through structured clone correctly, every later signature fails. If the X25519 key is affected too, connecting to machines from that Safari would fail as well. This hasn't been reproduced on Safari: geek has no Safari, and control doesn't keep rejected approvals. ## Fix 1. **Confirm.** Make a small page that generates a non-extractable Ed25519 key and an X25519 key, puts them in IndexedDB, reloads, signs and derives with them, and verifies the results. Run it in Safari on jake-mini (and iOS Safari). Note the Safari version. 2. **Self-check before enrolling.** After `generateKeys()` stores the keys, read them back from IndexedDB and check a sign→verify (and an X25519 agreement) against the public keys. Enroll only once that passes, so a browser can never become a trusted device with keys it can't use after a reload. 3. **Store keys in a form that survives the round trip** where the check fails, e.g. generate extractable and keep the raw/pkcs8 key (or wrap it with a non-extractable AES-GCM key, if Safari round-trips those). Write down what this gives up compared with non-extractable keys. 4. **Already-enrolled Safari devices** whose stored keys are broken: detect it at boot (the same probe) and say so plainly. Offer to forget this browser and re-enroll (approved by another device or a recovery code) rather than failing later with an approval error. 5. **Control logs rejected approvals and enrolments** (`approval_ok`, `join_approve`, `approve`, `enroll`) with the reason, account and device ids, so `fly logs` shows the cause next time. No signatures or bodies in the logs beyond ids. 6. **Test:** Playwright WebKit for the round trip and an e2e join approved after a reload, plus the manual Safari check from step 1. ## Workaround for affected users Sign in from Chrome or Firefox, let that browser in with a recovery code (it signs with the code's key, not Safari's), then approve the `illogicald join` link there.
Author
Owner

Merged into main (abb197b, from 54ddcca and 7febed0). CI passed on both runners.

Cause, reproduced in Playwright's WebKit (Safari 26.6 engine): IndexedDB gives back an X25519 CryptoKey, and any record that holds one, as null. Ed25519 and AES-GCM keys come back fine. So an enrolled Safari made new keys on every page load and signed approvals as a device the account doesn't trust. On main's old code, the new WebKit join-after-reload test reproduces the failure; with the fix it passes.

Fix:

  • Keys are read back and checked (sign/verify, an X25519 agreement, the device id) before enrolling and on every load.
  • Where that check fails, new keys are stored wrapped: PKCS#8 under a non-extractable AES-GCM key. What that gives up is in docs/control-e2e.md.
  • A browser enrolled with lost keys says so and offers to enroll again.
  • Control logs every refused enrolment and approval with the reason and ids.
  • WebKit e2e (device-keys.webkit.spec.ts) covers the round trip, a join approved after a reload, and re-enrolment.

Left: deploy control, then open /key-probe.html in real Safari on the Mac and on iOS and note the version and the verdict here. The affected user's Safari should then show the lost-key screen. They enroll again with a recovery code, then approve the join.

Merged into main (abb197b, from 54ddcca and 7febed0). CI passed on both runners. **Cause, reproduced in Playwright's WebKit (Safari 26.6 engine):** IndexedDB gives back an X25519 `CryptoKey`, and any record that holds one, as `null`. Ed25519 and AES-GCM keys come back fine. So an enrolled Safari made new keys on every page load and signed approvals as a device the account doesn't trust. On main's old code, the new WebKit join-after-reload test reproduces the failure; with the fix it passes. **Fix:** - Keys are read back and checked (sign/verify, an X25519 agreement, the device id) before enrolling and on every load. - Where that check fails, new keys are stored wrapped: PKCS#8 under a non-extractable AES-GCM key. What that gives up is in docs/control-e2e.md. - A browser enrolled with lost keys says so and offers to enroll again. - Control logs every refused enrolment and approval with the reason and ids. - WebKit e2e (`device-keys.webkit.spec.ts`) covers the round trip, a join approved after a reload, and re-enrolment. **Left:** deploy control, then open `/key-probe.html` in real Safari on the Mac and on iOS and note the version and the verdict here. The affected user's Safari should then show the lost-key screen. They enroll again with a recovery code, then approve the join.
Commenting is not possible because the repository is archived.
No milestone
No project
No assignees
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
jhgaylor/illogical#94
No description provided.