Sub topic 8
Passkeys and WebAuthn: registering and signing in
Assume you understand passwords and two-factor authentication, can use a centralized exchange, and can change its security settings. This chapter focuses on the browser and server steps behind passkeys, not on implementing a complete exchange.
What a passkey is
A passkey is a WebAuthn credential. WebAuthn is a browser standard that lets a website authenticate you with a cryptographic key pair.
During registration:
- The authenticator creates a private key and a public key.
- The private key remains protected by your phone, computer, password manager, or security key.
- The exchange receives the public key and a credential identifier.
- The exchange stores those values with your account.
The exchange cannot use the public key to create a valid login signature. Your authenticator must use the private key, usually after you unlock it with a fingerprint, face scan, device PIN, or security-key touch.
Registration and sign-in
Each operation uses a challenge. A challenge is a fresh, unpredictable value generated by the server. The authenticator signs the challenge, and the server verifies the signature with the stored public key.
At registration, the server also specifies the relying party identifier, or RP ID. For an exchange at exchange.example, the RP ID might be exchange.example. The browser and authenticator bind the credential to that site.
At sign-in, the server sends another fresh challenge. The browser asks the authenticator for an assertion, which contains a signature and metadata. The server checks:
- The challenge matches the one it issued.
- The RP ID hash is correct.
- The origin is the expected website.
- The signature verifies with the stored public key.
- The credential belongs to the claimed account.
- User verification was performed when required.
- The challenge has not expired or been reused.
The browser-side calls look like this:
const credential = await navigator.credentials.create({
publicKey: {
challenge: challengeBytes,
rp: { id: "exchange.example", name: "Example Exchange" },
user: { id: userIdBytes, name: "[email protected]", displayName: "Alice" },
pubKeyCredParams: [
{ type: "public-key", alg: -7 },
{ type: "public-key", alg: -257 }
],
authenticatorSelection: {
residentKey: "preferred",
userVerification: "required"
},
attestation: "none",
timeout: 60000
}
});
const assertion = await navigator.credentials.get({
publicKey: {
challenge: newChallengeBytes,
rpId: "exchange.example",
userVerification: "required"
}
});challengeBytes, userIdBytes, and newChallengeBytes come from the exchange. They must be encoded as binary data, commonly ArrayBuffer values, rather than ordinary JSON strings. The server must validate the returned data with a WebAuthn library. Parsing fields without checking their cryptographic relationships is unsafe.
Common implementation choices
| Choice | Benefit | Trade-off |
|---|---|---|
| `userVerification: "required"` | Requires a local unlock step | Some older devices may not support it |
| Synced passkey | Easier recovery across devices | Depends on the credential manager's account security |
| Hardware security key | Strong device separation | Can be lost and needs a backup |
Exercise
Exercise
Why does a phishing site usually fail to use your passkey even if you approve a login prompt?
Show answer
The passkey is bound to the legitimate site's origin and RP ID. The phishing site's browser request does not match those values, so the authenticator will not produce a signature usable by the exchange.