ADR 0050 — Biometric unlock with device keys, and finding a gateway on the local network
Status: accepted (2026-11-14, owner request); gateway and wyrmd built 2026-11-14, Studio after it. The decisions taken while building are in the last section. Design: canvas rows Log in, part 2 (Unlock*, UnlockApp, UnlockPlatforms, Discover*). Studio side: studio/docs/design/specs/unlock-discover.md. Closes docs/studio.md §10 item 13 (gateway info before login).
Context
Studio logs in to a gateway with a user and a password (POST /api/login, a session of session_ttl). It remembers the gateway URLs and the user, never the password, so every start asks for it. The owner asks (2026-11-14) for:
- Biometric login, covering every case: Touch ID, Face ID, Windows Hello, Android fingerprint or face, computers with no biometrics, fingerprints that change, a device that is lost, and so on.
- Finding a broker on the local network from the log-in page.
Two constraints come from the platform rules. First, biometrics must not become a weaker password: the gateway decides who is in, not the client (principle 6). Second, nothing on the wire carries secrets or opens the broker to people who could not reach it before. A cached password or a long session token in the OS keychain behind a biometric check would also work, but the gateway could not see or revoke it, and a copied keychain item would replay it. So both are refused.
Decision
1. Device keys: the gateway checks a signature, the device checks the person
-
Registration. With a session that used the password within the last 5 minutes, Studio makes a P-256 key pair in the device’s secure hardware: the Secure Enclave on macOS and iOS (access control
biometryCurrentSet), the TPM through Windows Hello, or the Android Keystore withBIOMETRIC_STRONG,setInvalidatedByBiometricEnrollmentand StrongBox when the device has it. Studio then callsPOST /api/devices {name, platform, public_key, attestation?}. The gateway stores the record{id, user, user_generation, name, platform, public_key, added, last_used, password_at}in the users store (users SCHEMA 5), which the standby replicates (ADR 0036). It answers{device}. -
Unlock.
POST /api/device/challenge {device}→{nonce, exp ≤ 60 s}(single use, in memory). The OS prompt unlocks the key and Studio signswyrm-device-login/1 ‖ site ‖ gateway origin ‖ user ‖ device ‖ nonce. ThenPOST /api/device/login {device, nonce, signature}→ the same session as/api/login. The gateway refuses when:- the device is unknown or removed;
- the user’s generation moved (a password change signs every device out);
password_atis older thanpassword_every_days;- devices are off.
Each refusal is a distinct code (
device_removed,password_changed,password_due,devices_off), so Studio can say why (boardUnlockSignedOut).
-
Step-up. When
step_up: config, every request atconfiglevel needs a session confirmed in the last 5 minutes.POST /api/device/confirm {nonce, signature over the request hash}confirms with the device key;POST /api/confirm {password}confirms with the password. A refused request answersconfirm_requiredand Studio showsUnlockStepUp, then sends the request again. -
Idle lock. Local to Studio: after
lock_after_min(the gateway’sidle_lock_max_mincaps it), Studio hides the tree and values. Unlocking signs a fresh challenge withPOST /api/device/login {…, session}, which keeps the session. Without a device key it asks for the password. -
Visible and revocable.
GET /api/deviceslists the user’s own devices.DELETE /api/devices/<id>removes one, for the user or an admin./api/users/<u>/devicesgives an admin everyone’s.- Studio shows the user’s devices in Account › Security and everyone’s in Access › Users.
- Audit records:
device_added,device_login,device_refused,step_up,device_removed.
-
Policy (
wyrmd.json5gateway.devices):{ enabled: true, max_per_user: 5, password_every_days: 30, idle_lock_max_min: 30, step_up: "config" | "none", allow_device_credential: false }GET /api/infocarries it so the log-in page knows what to offer before login. Withallow_device_credential: false, an Android screen PIN or a Mac’s login password never stands in for biometrics; Windows Hello PIN counts as Hello.enabled: falsedoes not delete records; it refuses device logins, and Studio removes its key after the refusal. -
Never offered: Linux (no system prompt binds a key), kiosk sessions (no person), and devices whose biometrics are weak (class 2 face on Android) or not enrolled. A future web build uses passkeys (WebAuthn) against the same records: the record format leaves room for that.
-
Downstream sites are reached through the gateway of the upstream site, as today. A device key is per gateway, user and device. A standby gateway accepts it because the users store is replicated, and its origin is listed with the main one.
2. The gateway announces itself; the log-in page finds it
-
Announce.
wyrmdadvertises its gateway by DNS-SD on every non-loopback interface the gateway listens on: service_wyrm._tcp, instance name = site. Configgateway.announce: {enabled: true, interfaces?: [...]}; hardened sites turn it off. The TXT record has no users and no secrets:TXT key Value vwyrmd version sitesite name tls1or0fpfirst 16 bytes, in hex, of the SHA-256 of the CA certificate the gateway’s certificate chains to roleactiveorstandby(ADR 0036)pairthe other host’s host:portupupstream site, when this broker is a downstream The crate is
mdns-sd(pure Rust, no Avahi or Bonjour dependency). The announcement stops on SIGTERM and moves with a takeover (the new active announcesrole=active). -
GET /api/info(public, rate-limited like/api/login):{site, version, tls, ca_fp, role, pair, devices: {enabled, step_up}, min_studio}. It serves the probe oflogin.md§6, the trust step and the range probe. -
Studio finds.
- Find on this network browses
_wyrm._tcpfor 8 s. It shows one row per site: an active and its standby merge into one row, andupshows downstream sites. Each row is checked with/api/info. - Rows Studio cannot use are shown greyed with the reason: plain
httpoff loopback (insecure_plaintext), or a wyrmd version older thanmin_studio. - Picking a row fills the gateway and its standby.
- Trust. A gateway whose CA the device does not know shows its CA code (
ca_fpin 8 groups of 4). The person compares it with System › Gateway › Certificate code on the broker, or withwyrmd ca fingerprint(a new subcommand). Only after that does Studio pin that CA for that origin. Anything on the network can announce a name, so finding never means trusting. - Nothing found. Studio says why it may be: multicast blocked, local-network permission off, announce off. It offers Probe a range: an opt-in
GET /api/infoper address of a CIDR on one port, 16 at a time, at most 1 024 addresses. It also offers typing the address, or a code from the broker’s System page.
- Find on this network browses
-
Platform permissions:
- iOS:
NSLocalNetworkUsageDescriptionandNSBonjourServices = [_wyrm._tcp]. - macOS 15: the Local Network prompt.
- Android:
CHANGE_WIFI_MULTICAST_STATEand a multicast lock while browsing. - Windows and Linux: none (browsing is outbound).
Flutter package:
bonsoir(all five platforms). - iOS:
Consequences
- Gateway:
devices.rs(records, challenge cache, verify P-256 ECDSA withring::signature::ECDSA_P256_SHA256_ASN1,ringis already in the tree), routes inhttp.rs, users SCHEMA 5,inforoute,confirm_requiredon config requests whenstep_upis on, audit records. wyrmd:gateway.devices,gateway.announcewithmdns-sd,wyrmd ca fingerprint; System › Gateway shows the certificate code and a QR (wyrm://<host:port>?fp=…).- Studio: a platform channel per OS for the key (the
local_authpackage alone cannot bind a key; Studio uses a thin plugin over Security.framework,KeyCredentialManagerandBiometricPrompt+ Keystore),bonsoir, pinned CAs per origin instorage. - Tests:
- device register and login, plus every refusal code;
- a password change signs devices out;
- step-up refused, then confirmed;
- challenge reuse refused;
- announce TXT content and its absence with
enabled: false; /api/infowithout a session;- a standby accepts a device registered on the active.
Not decided here
- Hardware attestation checks (Apple App Attest, Android Key Attestation) as a policy option: recorded when sent, not required.
- Passkeys for a web build.
- Discovery across subnets (an mDNS reflector is the network’s job).
Decisions taken while building (2026-11-14, ADR 0029)
The owner’s request was the decision to build this ADR as written. Where it left a point open, the rule below is the one built; Studio follows it.
-
Refusals on the wire. No new spec-04 status: a refusal has
status: permission_denied(0x21) and a textcode, in the HTTP error body{status, message, code}and in the WebSocketerrormap. Codes:device_removed,password_changed(the user’s generation moved: a new password, Sign out everywhere, or a disable),password_due,devices_off,confirm_required, and three a client acts on:password_required(register needs a fresh password),too_many_devices,bad_password(/api/confirm). An unknown device, a bad signature, an origin the gateway does not serve and a nonce that is unknown, used or older than 60 s all get one bare401without acode, counted by the login limiter (5 per device and address a minute, 20 per address): they tell nobody which device ids exist. A coded refusal comes only after a good signature by the stored key. Rate limits answer429 rate_limited. -
What is signed. Canonical CBOR arrays, the label first, the nonce and hashes as byte strings:
- login:
["wyrm-device-login/1", site, origin, user, device, nonce]; - register:
["wyrm-device-register/1", site, origin, user, nonce, public_key](the key bytes as sent); - step-up:
["wyrm-device-confirm/1", site, origin, user, device, nonce, request].
Test vector (
devices::tests::messages_are_canonical_cbor_arrays): siteplant, originhttps://gw:8443, userolena, deviced1, nonce07070707→86737779726d2d6465766963652d6c6f67696e2f3165706c616e746f68747470733a2f2f67773a38343433656f6c656e616264314407070707. - login:
-
Origins. The gateway checks the signed origin against a list, never against the
Hostheader (a relay sets that).gateway.devices.originslists them; by default they are the DNS and IP names of the gateway’s own certificate on the port it listens on (https), or127.0.0.1,localhostand::1for plain HTTP on loopback. A standby gateway with its own certificate covers its own names; a standby reached under other names lists them. -
Keys. The record carries
alg.es256: ECDSA P-256 with SHA-256, signature in ASN.1 DER, key kept as the 65-byte uncompressed point (SPKI DER, as Android exports it, is accepted and normalised).rs256: RSASSA-PKCS1-v1_5 with SHA-256, at least 2048 bits, key kept as PKCS#1 DER (SPKI accepted): Windows Hello’sKeyCredentialManagermakes RSA-2048 keys only, so Windows uses it. Registration proves the key:POST /api/devicescarries aregisternonce of the same session signed by the new key, so an invalid key or one the device does not hold is refused (401). On Apple and Android platforms that is the person’s first biometric prompt, when they turn the unlock on. -
Calls.
POST /api/device/challenge {device}→{nonce, exp}answers for any id. With a bearer session,{purpose: "register"}gives a nonce bound to that session. A step-up nonce comes only with itsconfirm_requiredrefusal, bound by its MAC to the session and to the hash of the refused request, so a device signs, and the audit keeps, exactly the request the gateway named (review of PR 86, L3). Adevicethat is not a device id (32 lower-case hex digits) is refused with400before any limiter or audit record (review H1). A nonce is 56 opaque bytes,random(16) ‖ exp(8) ‖ HMAC(key, purpose ‖ random ‖ exp), under a key the gateway process makes when it opens. Issuing one stores nothing, so nobody can evict or crowd out another caller’s nonce, and a nonce for an unknown device looks like one for a known device (security review of PR 86). Only a spent nonce is remembered until it would have expired (single use; at most 100 000, thenbusy, which the login limiter does not count; review L2). Every limit counts an IPv6 address by its /64, and a full table of the request limiter drops its oldest record instead of refusing new addresses (review L1). A nonce is good only on the gateway process that made it. 30 challenges per address a minute.POST /api/devices {name, platform, alg, public_key, attestation?, origin, nonce, signature}→{device}(a random 128-bit id in hex).POST /api/device/login {device, origin, nonce, signature, session?}→{session, exp}.POST /api/device/confirm {device, origin, nonce, request, signature},POST /api/confirm {password},GET /api/devices,DELETE /api/devices/{id},GET /api/users/{name}/devices, andPOST /api/me/sign-out(Sign out everywhere: user store opEndSessions, a new generation).GET /api/usersrows gaindevices(the count that can log in). -
password_atmoves when a password login names its device:POST /api/login {user, password, device}.password_duethen clears without a new key. -
Removing. The owner’s
DELETE(Turn off, Forget) deletes the record. An admin’sDELETEof another user’s device leaves a tombstone withremoved_byandremoved_at, so the device hearsdevice_removedand its owner sees who; aDELETEof a tombstone deletes it. A user keeps at most 32 records; past that, the oldest that cannot log in go first. Removing a user removes their devices. A session made by a device login ends when its device is removed, forgotten or signed out. -
Sessions carry
amr(pwd,dev,oauth),auth_at(when the password or the key was last checked at login) anddev(the device of a device login). Tokens from before this ADR read as password logins atiat. Registering needs a session whose password was checked in the last 5 minutes: a password login or/api/confirm. A device session or an MCP token never registers. -
Step-up. Confirmations are kept in memory per session (a restart asks again). A session is confirmed for 5 minutes after its login (password or device), a device confirm or a password confirm; an idle unlock (
/api/device/loginwithsession) confirms the kept session.confirm_requiredcarriesrequestandnonce(aconfirmnonce of that session) to sign.requestis an HMAC-SHA256, under the gateway process’s own key, of the canonical CBOR of the refused request ({op, key, value?, action?, args?}over the WebSocket,{method, path, body}over HTTP) with the fieldspassword,secret,tokenandpassphraseleft out at any depth. So the hash the device signs and the audit keeps cannot test a guessed password (security review of PR 86). Config level is: aseton a point whosewritableisconfig; aninvokewhose actionlevelisconfig(also/api/invokeand flow deploys); user management changes; an admin removing another user’s device; anapproveof an agent’s plan in which a step to be signed is atconfig, and every flow deploy (the gateway signs tokens for both, so the step-up holds before anything is signed; security review of PR 86). A node whose~metacannot be read counts asconfig. Only users who holdconfigthere are asked (the responder refuses the others). An MCP token never passes a step-up: withstep_up: "config", the MCP endpoint gets noconfig. The tokens the gateway mints for a session that is not confirmed reachwriteat most, so a responder that does more for aconfigtoken (a DQL sink query,publish) gets none from it (review M1). Defaultstep_up: "none", so existing clients keep working; hardened sites turn it on. -
/api/infocarries{site, version, tls, role, devices: {enabled, max_per_user, password_every_days, idle_lock_max_min, step_up, allow_device_credential}, min_studio, up, pair?, ca_fp?, ca?, names?}.ca(the CA certificate’s DER, public data) is beyond the list above. It is there because a client only sees the leaf certificate in the handshake, so it cannot pin the CA without it. Studio never trustsca_fpor thefpTXT key, which an untrusted server sends (review M2). It shows the code it computes itself, SHA-256 of the receivedcaDER, first 16 bytes. It then reads/api/infoonce more under that CA alone, so the handshake’s leaf must chain to it, and only then pins it. Whenca_fporfpdiffer from the computed code, Studio refuses the row.names(over TLS) are the DNS and IP names of the gateway’s certificate. A row found by DNS-SD gives an address, and the certificate rarely nameswyrm-<site>.local. So Studio builds the gateway URL from the first ofnames: the address itself when it is listed, else a DNS name. When that name does not resolve, Studio connects to the address and checks the certificate against the name (the pinned CA, the name’s origin for device keys). A certificate that names neither cannot be used from a row; the person types its address instead.min_studiois the oldest Studio the gateway serves (1.0.0). 60 requests per address a minute. ADR 0051 §3 addssetup: truewhile a setup code waits for the first admin (absent otherwise). -
The CA and its code. One function,
wyrmd::gateway_ca, gives the code for/api/info, thefpTXT key andwyrmd ca fingerprint(which prints it in 8 groups of 4 and creates nothing). It takesgateway.tls_ca(new, a PEM path), else the last certificate oftls_certwhen that holds a chain, else the site CA when it issued the gateway’s certificate. Otherwise there is no code. System › Gateway in Studio reads the code from/api/info; nosysvalue was added. -
Updates. The users SCHEMA moves from 4 to 5 and the WAL gains ops 6–11. An update through ADR 0048 restores the users store from its pre-update backup if it rolls back (the guard’s rule for a moved SCHEMA); with
state_anchor_dirset it is an update by hand. In a standby pair, update the standby first: an older standby cannot read the new ops. -
Announce. On by default when the gateway listens off loopback (§2.1: hardened sites turn it off), never on loopback.
gateway.announce {enabled, interfaces, pair}. Only the broker that serves announces, soroleisactive. A following standby runs no gateway; Studio fills the standby frompair, which isannounce.pairor the host ofstandby.peerwith this gateway’s port.uplists every upstream site, joined with commas. A takeover starts the new active’s announcement; a step down and SIGTERM end it with a goodbye. A multicast failure is logged and the broker runs without an announcement.