Extensions
Second factors: codes and passkeys
A code from an authenticator app (totp),
and passkeys (passkey), checked on the
back end and fitted into the accounts and sessions of
auth: an account that has one is not signed in
by its password alone, and a call can ask for a factor shown lately.
Back to the map.
use "pkg:totp/totp.mote"use "pkg:passkey/passkey.mote"// Money leaves only for someone who showed a second factor in the last ten minutes.server fn payout(cents: number): string requires secondFactor(10) …action enter auth.signIn(email, password) else err => (err.kind == "second" ? askForCode = true : none)In auth#
Codes from an app: totp#
Passkeys#
What a program may say of its passkeys#
Attestation checked#
The FIDO Metadata Service#
In the page: passkey#
A key from a passkey: the PRF extension#
Passkeys with no back end#
Examplea whole program
app "Vault"// (The salt and the ids are not secrets: they are kept with the wrapped key.)state salt = ""state ids: string[] = []state said = ""// What the vault would wrap its device key under. It is not kept, and not shown.fn wrapKey(out: bytes?): bytes if out == none fail("That passkey gives no key (it has no PRF).", {kind: "invalid"})? return crypto.hkdf(out, {salt: "vault/v1", info: "device-wrap", length: 32})?// One more authenticator: verification required, nothing left on a security key, never the// same authenticator twice.action enroll if salt == "" salt = (bytes.hex(crypto.random(32))?).base64url() let made = passkey.create({user: {name: "Vault key"}, userVerification: "required", residentKey: "discouraged", attestation: "none", excludeCredentials: ids.map(id => ({id})), extensions: {prf: {eval: {first: salt}}}})? if !made.prf.enabled fail("This authenticator cannot protect a key (it has no PRF).", {kind: "invalid"})? // (Some give the output as the passkey is made; the others at a first touch.) let out = made.prf.first ?? (passkey.get({allowCredentials: [{id: made.id}], userVerification: "required", extensions: {prf: {eval: {first: salt}}}})?).prf.first let key = wrapKey(out)? ids = [...ids, made.id] said = `${ids.length} registered (${made.attachment == "cross-platform" ? "a security key" : "this device"}), a key of ${key.length} bytes`// One touch of any of them.action unlock let got = passkey.get({allowCredentials: ids.map(id => ({id})), userVerification: "required", extensions: {prf: {eval: {first: salt}}}})? let key = wrapKey(got.prf.first)? said = `unlocked by passkey ${ids.indexOf(got.id) + 1}, a key of ${key.length} bytes`column gap=8 padding=16 button "Add a passkey" press=enroll button "Unlock" press=unlock text `${said}${failure(enroll) ?? ""}${failure(unlock) ?? ""}`Tested#
Previous
Signing in with other services: oauthExtensionsNext
A public API: API keys and tokensExtensionsEdit this page:
docs/second-factor.md