The registration ceremony
Adding a passkey looks like one touch of a fingerprint reader, but behind it the server, the browser and the authenticator each add something the server will rely on at every later sign-in. This lesson opens the messages of a registration and the checks a server makes before it stores anything.
Adding a way back into an account
Ava is signed in to Lab Photos and opens her security page at https://auth.photos.example. She already has a security keyA small physical device, plugged in or held near a phone or computer, that holds credentials and uses them to prove you have it. It is an authenticator that resists phishing. there, and now she chooses Add a passkey so she can sign in from her phone and laptop without it. Her password manager asks for her fingerprint, and a moment later the page lists a new passkey. Security keys, passkeys, and biometrics described what happened in outline: her authenticator made a key pairA private key and a public key generated together and mathematically linked. The private key creates signatures and the public key checks them, but the private key cannot practically be worked out from the public one. and Lab Photos kept the public keyThe half of a key pair that can be shared freely. It checks signatures made with the matching private key and can encrypt data that only that private key can decrypt.. This lesson opens the messages that made it happen, because every check Lab Photos relies on later is set up here.
WebAuthn calls the exchange a ceremony, a word that includes the person as well as the software. There are three parties. Lab Photos' server is the relying party. Ava's browser is the client, and it is the only party that can see which website is asking. The authenticator holds the keys: a computer's or phone's built-in credential store, a password manager, or a security key. Ava's password manager is the authenticator this time.
Registration adds a new way into Ava's account, so Lab Photos treats it like a password change. It checks that the request comes from Ava's own sessionThe ongoing connection between later requests and an earlier sign-in, so you are not asked for your password on every click. It is often tracked with a cookie holding an unpredictable session identifier. and asks her to sign in again if her last sign-in was a while ago. Someone who borrowed her unlocked laptop for a minute should not be able to add their own key and walk away with lasting access.
The options the server sends
When Ava chooses Add a passkey, the page's script asks Lab Photos' server how to proceed. The server answers with the creation options, which the script passes to navigator.credentials.create(), the browser function that starts a registration. Here they are in the JSONA text format for structured information, written as named values inside curly braces. APIs, tokens, and discovery documents all use it. form browsers can read directly, with binary values written in base64urlA way of encoding data as ordinary text characters so it can travel safely in headers, URLs, and JSON. Anyone can decode it, so it hides nothing; Base64url is a variant safe for URLs, used in JWTs.:
{
"rp": { "id": "photos.example", "name": "Lab Photos" },
"user": {
"id": "P76oYjzHeIMH_he0IpY-elnmigO5e6ITTGrXPE5ttKY",
"name": "[email protected]",
"displayName": "Ava Archer"
},
"challenge": "pX4R1M8vUo0bmY3k2Ew7Qj6dTsL9fGh5aZcN0rKyVuI",
"pubKeyCredParams": [
{ "type": "public-key", "alg": -8 },
{ "type": "public-key", "alg": -7 },
{ "type": "public-key", "alg": -257 }
],
"timeout": 300000,
"excludeCredentials": [
{ "type": "public-key", "id": "Kq3w9xY2bVd1nRtE7uLs0A", "transports": ["usb", "nfc"] }
],
"authenticatorSelection": {
"residentKey": "required",
"userVerification": "required"
},
"attestation": "none",
"hints": ["client-device"]
}rp.id is the relying party ID, the domain the credential will belong to. It must be the page's own host or a parent of it that could be registered on its own, the registrable domain that Clients, servers, and addresses described. A page at https://auth.photos.example may use auth.photos.example or photos.example, but never the public suffix example and never an unrelated name such as photos-login.example. Lab Photos chooses photos.example, so the credential works on every site under that domain and on no other.
user describes the account. name and displayName are labels the authenticator shows when Ava later chooses between accounts. user.id is different. It is the user handle, the value the authenticator stores with the credential and hands back at sign-in to say whose account it is. The specification says it must not contain personal information such as a username or email address, because authenticators and password managers store it and may show or sync it. Lab Photos uses 32 random bytes made once for Ava's account; the limit is 64 bytes.
challenge is fresh random data for this one attempt. The server saves it together with the account it is for, its purpose (registration) and a deadline, five minutes here to match timeout, which is in milliseconds. pubKeyCredParams lists the signatureA value made with a private key that lets anyone holding the matching public key check that a message came from the key's holder and has not been changed. It proves origin and integrity; it does not hide the message. algorithms Lab Photos accepts, in order of preference. WebAuthn names them by number from COSE, a standard for signing and encrypting small binary messages that plays the part JOSE plays for JSON: -8 is EdDSA, here with Ed25519, -7 is ES256, ECDSA with the P-256 curve that Digital signatures used, and -257 is RS256. The authenticator uses the first one on the list that it supports. Ava's password manager makes ES256 keys, so her passkey will be -7.
excludeCredentials lists the credentials Ava already has, here her security key. An authenticator that recognizes one of them refuses to make a second credential for the same account, and the browser tells Ava that this device is already registered. Without the list she could fill her account with duplicates from one device and never be sure which one to remove. The transports beside each ID say how the browser can reach that authenticator: usb and nfc for a security key, internal for one built into the device, hybrid for a phone nearby.
authenticatorSelection states requirements. residentKey: "required" asks for a discoverable credential, one the authenticator can find without being told its ID, which is what later lets Ava sign in without typing her address. userVerification: "required" asks the authenticator to check a PIN or biometric. attestation says whether Lab Photos wants evidence about the authenticator's make and model: none means it does not, and Attestation and authenticator models covers the other values. hints suggests which kind of authenticator to offer first, and browsers may ignore it.
What the browser adds
Before involving the authenticator, the browser checks rp.id against the page's origin and refuses outright if it does not fit. Then it writes down what it knows in a small JSON document called clientDataJSON. The server never sends this; the browser builds it. Decoded from base64url, Ava's reads:
{
"type": "webauthn.create",
"challenge": "pX4R1M8vUo0bmY3k2Ew7Qj6dTsL9fGh5aZcN0rKyVuI",
"origin": "https://auth.photos.example",
"crossOrigin": false
}type separates a registration (webauthn.create) from a sign-in (webauthn.get), so an answer made for one cannot be passed off as the other. challenge is the server's challenge, copied back. origin is the scheme, host and port of the page that called the browser function, as the browser saw it. crossOrigin is true when the call came from an embedded frame of another origin, and then a topOrigin member names the page around it.
The origin is the heart of a passkey's phishing resistanceA property of an authentication method that binds sign-in to the real service, so evidence entered on a look-alike site cannot be passed on and used. Passkeys have it; passwords and one-time codes do not.. A lookalike page at https://photos-login.example could copy Lab Photos' options word for word, but the browser would refuse the relying party ID photos.example there, and any client data it did produce would name the wrong origin. Ava cannot be talked into getting the origin wrong, because she never types it.
The browser hands the authenticator a SHA-256 hashTurning data into a short, fixed-size value called a hash, in a way that cannot be reversed and where changing one character changes the result completely. Services store password hashes instead of passwords, and signatures are made over a hash. of clientDataJSON, together with the relying party ID, the user details and the requirements. The authenticator asks for Ava's fingerprint, makes a new P-256 key pair for this relying party and account, and keeps the private keyThe half of a key pair that its owner keeps to themselves and uses to create signatures or decrypt data. Anyone who obtains it can act as its owner..
Inside the authenticator data
The authenticator describes what it did in a compact binary structure called authenticator data. Its layout is fixed, so you can read it byte by byte, with each byte written as two hexadecimal digits:
| Bytes | Field | Ava's registration |
|---|---|---|
| 0 to 31 | rpIdHash, SHA-256 of the relying party ID | 6ddf25aa...3c58bfea, the hash of photos.example |
| 32 | Flags | 0x5d, binary 01011101 |
| 33 to 36 | signCount, a signature counter | 00000000, zero |
| 37 to 52 | AAGUID, the authenticator model's identifier | 16 bytes |
| 53 to 54 | Credential ID length | 0010, 16 bytes |
| 55 to 70 | Credential ID | 8ba26ae11c641a425d36a3fa8f79ab17 |
| 71 onward | Credential public key, as a COSE key | An EC2 key: kty 2, alg -7, curve P-256, and its x and y coordinates |
The flags byte packs six yes-or-no answers into single bits, numbered 0 to 7 from the right. A bit set to 1 means yes:
| Bit | Flag | Meaning | In 0x5d |
|---|---|---|---|
| 0 | UP, user present | Someone interacted with the authenticator, such as a touch | Set |
| 2 | UV, user verified | The authenticator checked a PIN or biometric | Set |
| 3 | BE, backup eligible | The credential's provider may copy it to other devices | Set |
| 4 | BS, backup state | The credential is currently backed up | Set |
| 6 | AT, attested credential data | The AAGUID, credential ID and public key follow | Set |
| 7 | ED, extension data | Extension results follow the credential data | Not set |
Bits 1 and 5 are reserved. 0x5d is bits 0, 2, 3, 4 and 6: the credential was made with presence and verification, Ava's password manager syncs it to her other devices and has already backed it up, and the credential data follows. A credential that stays on one device, such as a passkey on a security key, leaves BE and BS clear, and its flags byte reads 0x45. Synced passkeys, cross-device sign-in, and recovery explains what those two bits can and cannot tell a server.
The signCount starts at zero here; the next lesson explains what an authenticator does with it at sign-in. The credential ID names this credential from now on. In a sign-in, the browser reports which credential answered by its ID, and Lab Photos looks up the matching public key. The public key itself is written as a COSE key, a small map of numbered fields: the key type (kty 2 means an elliptic curve key), the algorithm number from pubKeyCredParams, the curve, and the two coordinates that make up a P-256 public key.
The attestation object
For a registration, the authenticator data travels inside an attestation object. It is encoded in CBOR, a binary format with the same building blocks as JSON (maps, lists, text and numbers) plus raw bytes, which keeps it small enough for a security key to produce. The COSE key above is CBOR too. Written in CBOR's text notation, where h'...' marks raw bytes in hexadecimal, the attestation object is a map with three entries:
{
"fmt": "none",
"attStmt": {},
"authData": h'6ddf25aa25cae088...' (the bytes in the table above)
}fmt names the format of the attestation statement, and attStmt holds the statement itself: a signature over the authenticator data by a key that belongs to the authenticator's maker, with the certificates needed to check it. Lab Photos asked for none, so the format is none and the statement is empty. The browser returns two base64url values to the page, clientDataJSON and attestationObject, along with the credential ID and the transports the authenticator supports.
Notice what is missing. Nothing in the response contains Ava's fingerprint, her phone's PIN or the private key. The UV flag is the only trace of the fingerprint check, and Lab Photos relies on that bit because the authenticator vouches for it, not because the server saw anything.
Store only after verification
Lab Photos' server now checks the response against what it saved before the browser was involved. Section 7.1 of the WebAuthn specification lists the steps. A maintained WebAuthn library performs them, and it helps to know what they are:
- Decode
clientDataJSON.typeiswebauthn.create,challengeequals the saved challenge of this account's pending registration, andoriginis one Lab Photos expects, herehttps://auth.photos.example. The deadline has not passed and the challenge has not been used. - Decode the attestation object.
rpIdHashequals SHA-256 ofphotos.example. - UP is set. UV is set, because Lab Photos required verification. BS is not set without BE.
- The public key's algorithm is one of those offered in
pubKeyCredParams. - The attestation statement is valid for its format and acceptable under Lab Photos' policy. With
nonethere is nothing to check, and nothing is learned about the model. - The credential ID is at most 1023 bytes and is not already registered to any account. If it is, the ceremony fails.
Only then does Lab Photos store a record: the credential ID, the public key, the signCount, the transports, the BE and BS flags, a label Ava can recognize and the link to her account. The challenge is marked as used in the same step, a single change that either happens completely or not at all, so a response submitted twice, even at the same moment, cannot add the credential twice.
Each check answers a different attack. The challenge and its deadline stop an old response from being replayed. The origin and the rpIdHash stop a response made for another site. The account saved with the challenge stops an attempt started in Ava's session from being finished in someone else's: if Cora signs in on the same browser before the response arrives, the challenge still belongs to Ava's account, and the server refuses to store a passkey for Cora with it. The duplicate check catches a credential ID that is already registered, which would leave two accounts claiming one key. And nothing is stored on any path that fails.
Registration gives Ava a way to authenticate. It does not prove who she is in the legal sense, and it grants her no new permission.
Check your understanding
Try these questions before moving on. If an answer isn't right, use the feedback and try again.
Try it in the Lab
- Enroll a passkey, decode what the browser sent, and see bad enrollments refusedRead the creation options, decode your own clientDataJSON and authenticator data flags, then see expired, reused, wrong-account and duplicate enrollments refused.