Passkeys & Security Keys
On this page
- Introduction
- The Two Profiles
- What a Key Proves
- Relying Party and Origins
- Signature Algorithms
- RS256 and Windows Hello
- Attestation and AAGUIDs
- Requiring Attestation
- Attestation and AAL3
- Allowing Only Certain Models
- Trusting Each Model Separately
- What Is Kept
- Counters and Cloned Keys
- Signing In Without a Username
- Laravel's Passkeys Client
- Signing In With It
- Adding a Passkey and Step-Up
- Customising a Profile
- Stored Data
- How It Works
Introduction
Keyring supports WebAuthn, the standard behind passkeys and security keys, through one factor class with two profiles. Register either or both:
use Keyring\Factors\WebAuthn; Keyring::factors([ Password::class, WebAuthn::passkeys(), WebAuthn::securityKeys(),]);WebAuthn resists phishing, because the browser binds each response to your site's origin. Keyring uses the web-auth/webauthn-lib package for the ceremonies.
The Two Profiles
WebAuthn::passkeys() |
WebAuthn::securityKeys() |
|
|---|---|---|
| Key | passkey |
security-key |
| Discoverable (resident key) | required | discouraged |
| User verification | required | preferred |
| Authenticator attachment | any (platform or roaming) | cross-platform only |
| Can start a sign-in | yes, without a username | no, only as a further factor |
| Priority | 100 | 90 |
Users add either through the authenticator routes. Keyring excludes credentials the user already has, and refuses any credential registered to any account.
What a Key Proves
Every WebAuthn verification proves possession. It also proves inherence when the key reports that it verified the user this time (the UV flag), with a PIN, fingerprint or face.
- A passkey always verifies the user, so it proves possession and inherence. That's enough alone for AAL2. Most passkeys sync between devices, and NIST caps synced passkeys at AAL2.
- A security key that doesn't verify the user proves possession only. With a password, that's AAL2.
- Whether a key can sync comes from its backup-eligible flag, which Keyring reads on every sign-in. A key that hasn't reported it counts as synced. A key that can't sync is "device bound".
Requirement::deviceBound()andkeyring:aal2,device-boundask for one. - AAL3 needs more, since the flag is the key's own word. The key must have a verified attestation, and its second factor must be its own user verification or a password.
Relying Party and Origins
WebAuthn options live under webauthn in config/keyring.php. These are the defaults, apart from the two signature algorithm options:
'webauthn' => [ 'relying_party' => [ 'id' => env('KEYRING_WEBAUTHN_RP_ID'), ], 'origins' => [], 'timeout' => '60s', 'login_options_for' => '5m', 'attestation_roots' => [],],relying_party.idis the domain your keys are bound to. It defaults to the host ofAPP_URL. Keys forexample.comalso work on its subdomains, so set your registrable domain if users sign in on several subdomains, and list each origin inorigins. Changing it later stops existing keys working.originslists the exact origins (scheme://host[:port]) allowed to complete a ceremony. When it's empty, only theAPP_URLorigin is allowed. If no entry is a full URL (a bare host, or anAPP_URLwithout a scheme), Keyring refuses every passkey and security key response. Entries that aren't URLs are ignored.timeoutis how long the browser waits, as a duration.login_options_foris how long an answer to a usernameless challenge is accepted. It's never less thantimeout.attestation_rootsholds the certificates a key's attestation must chain to.
WebAuthn only works on https and localhost, so in development APP_URL must match the address in your browser, such as http://localhost:8000.
Signature Algorithms
webauthn.algorithms lists the signature algorithms keys may use, in order of preference:
'webauthn' => [ 'algorithms' => ['ES256', 'EdDSA'], 'minimum_rsa_bits' => 2048,],| Name | Algorithm | |
|---|---|---|
ES256 |
ECDSA with P-256 and SHA-256 | Nearly every authenticator supports it. |
EdDSA |
Ed25519 | Only offered when PHP's sodium extension is loaded. |
RS256 |
RSASSA-PKCS1-v1_5 with SHA-256 | Off by default. See below. |
Keyring only offers and accepts these. A new key signing with another algorithm is refused, and so is a stored key whose algorithm you've since removed, which can lock its owner out. Check what your users have before you remove one. An empty list, or an unknown name, throws.
RS256 and Windows Hello
RS256 is off because OWASP ASVS 5.0.0 doesn't approve it. Its PKCS #1 v1.5 padding is disallowed (Appendix C), and a 2048-bit RSA key gives 112 bits, where ASVS 11.2.3 asks for 128. NIST SP 800-63B-4 accepts RS256 at 2048 bits (Sec. 3.1.6.2), so it meets NIST but not ASVS.
The cost falls on Windows. Some machines, such as older builds and those without a TPM, create Windows Hello passkeys with RS256 only. Without RS256 offered, those users are shown a phone or security key instead, or an error.
If those users matter more than ASVS conformance, add RS256 last, so other authenticators keep choosing stronger algorithms, and record it as a deviation from ASVS 11.6.1 and 11.2.3:
'algorithms' => ['ES256', 'EdDSA', 'RS256'],With RS256 on, Keyring refuses RSA keys under minimum_rsa_bits when a key is added and at every sign-in. It never accepts under 2048 bits (RFC 8812). Identity providers' RSA keys have their own 2048-bit floor, so raising the option doesn't affect Google or Microsoft.
Warning
Raising minimum_rsa_bits to 3072 would give RSA the 128 bits ASVS asks for, but Windows Hello's RSA keys are 2048 bits. That refuses the keys RS256 was enabled for. If you want 128 bits throughout, leave RS256 off.
Attestation and AAGUIDs
By default, Keyring asks for none attestation and accepts only none statements, so any authenticator is accepted, including synced passkeys. Each key's model identifier, its AAGUID, is stored in aaguid. Without attestation that's only what the key claims, so it's fine for a friendly name but can't limit which models are allowed.
Requiring Attestation
To accept only certain hardware keys, require each new key to prove who made it. Keyring only adds a key whose attestation statement chains to a root you trust:
Keyring::factors([ Password::class, WebAuthn::passkeys(), WebAuthn::securityKeys()->requireAttestation(),]);List the makers' root certificates in config/keyring.php, as PEM text or paths to PEM files. Keyring never downloads anything, so you keep them current:
'webauthn' => [ 'attestation_roots' => [ storage_path('attestation/yubico-fido-root-ca.pem'), ],],With that in place, Keyring asks for direct attestation, and a user who declines in the browser gets none. A key is added only when its statement is valid and its certificate chain reaches one of the roots, with every certificate in date, and no SHA-1 signatures or RSA keys under 2048 bits. Anything else, including none, self-attestation or another root, is refused with keyring::keyring.key_not_accepted. If no root is listed, or one can't be read, Keyring refuses every key and says which.
Keyring reads the packed and fido-u2f formats that hardware security keys send, and refuses platform formats (tpm, android-key, apple), compound and any other.
Set it per factor. Requiring attestation on WebAuthn::passkeys() would turn away nearly every synced passkey, so keep it on security keys, or on a second security key factor with its own key:
WebAuthn::securityKeys()->as('staff-key')->requireAttestation(),Keyring doesn't check revocation, since that needs the network. Remove a withdrawn root from the list. Keys added before then stay, because attestation is checked only when a key is added.
Attestation and AAL3
A key reaches AAL3 only when its factor uses requireAttestation() and the key was added with an attestation Keyring verified, recorded in the attestation column. Nothing else tells a hardware key apart from software reporting the same flags.
-
Keys added before the factor required attestation have no value there, so they stay at AAL2 until their owners add them again.
-
Removing
requireAttestation()from a factor stops its keys reaching AAL3. -
Narrowing
allowOnly, or removing a root, only stops new keys. To stop an existing model counting, for example once it's found weak, clear itsattestationcolumn. Its keys then count as AAL2 second factors:PHPKeyring::authenticatorModel()::query()->where('aaguid', $aaguid)->update(['attestation' => null]); -
Attestation applies to the key alone. Its second factor must still be its own user verification or a password, so an attested key used after a synced passkey sign-in reaches only AAL2.
NIST also requires AAL3 authenticators to be validated to FIPS 140 (Sec. 2.3.2), which attestation doesn't show. Use allowOnly to accept only models you've checked.
Allowing Only Certain Models
List the AAGUIDs of the models you accept, as their makers publish them:
WebAuthn::securityKeys() ->requireAttestation() ->allowOnly([ '2fc0579f-8113-47ea-b116-bb5a8db9202a', 'ee882879-721c-4913-9775-3dfcce97072a', ]),Each entry must be a UUID, or allowOnly throws an InvalidArgumentException. Without requireAttestation(), adding a key throws a LogicException, because the list would trust any AAGUID a key claims. U2F keys ask with an all-zero AAGUID, so the list leaves them out.
Every root in attestation_roots is trusted for every model. If you trust several makers, any of them could certify another's AAGUID. To prevent that, trust each model separately.
Trusting Each Model Separately
Keyring asks the Keyring\Contracts\TrustsAuthenticators contract for the roots a model's attestation may chain to. The default gives the same attestation_roots for every model. To answer per AAGUID, bind your own implementation. This is also how you use the FIDO Metadata Service: verify its blob, keep it current, and return roots only for models it doesn't mark as compromised.
use Keyring\Contracts\TrustsAuthenticators; class ModelRoots implements TrustsAuthenticators{ public function roots(string $aaguid): array { return match ($aaguid) { '2fc0579f-8113-47ea-b116-bb5a8db9202a' => [file_get_contents(storage_path('attestation/yubico-fido-root-ca.pem'))], default => [], }; }} $this->app->bind(TrustsAuthenticators::class, ModelRoots::class);Return PEM certificates, or the base64 certificates a metadata statement lists in attestationRootCertificates. A model with no roots is refused.
What Is Kept
A key that passes has its attestation column set to the kind checked, such as basic, which means a certificate the maker shares across a batch of keys. The certificates it sent are kept in public_key. The column is null for keys added without the check.
Counters and Cloned Keys
Each assertion carries a signature counter, stored in sign_count. A counter lower than the last one seen suggests a clone. Keyring refuses that sign-in, dispatches Keyring\Events\CloneSuspected, and can send the clone_suspected security email. Synced passkeys usually report zero, so this check doesn't apply to them.
Signing In Without a Username
- The browser fetches
GET /login/passkey/options, which answers{ "options": { ... } }with an emptyallowCredentialsand required user verification. Keyring keeps the challenge in the session. The request takes the session lock, so its response can't undo a password sign-in that finished first. See Requests That Overlap a Sign In. - The browser posts the user's response to
POST /login/passkeyascredential. - Keyring finds the passkey by its credential ID, among the model behind its guard, checks the signature, and continues with the policy.
Autofill uses the same options. Give the email field autocomplete="username webauthn", and the browser package's usePasskeyLogin({ autofill: true }) starts it (see Frontend).
A challenge works once, and only for this kind of sign-in, so it can't finish a password login's second factor or a step-up. See How It Works for how replays and expiry are handled.
These requests name no account, so only the per-IP rate limit applies. Fetching options has its own limit of 60 a minute per IP address. Security keys can't sign in this way, so their routes return 404.
Laravel's Passkeys Client
Laravel's starter kits ship @laravel/passkeys, written for the routes of the laravel/passkeys package. Its sign-in calls work against Keyring's login routes, because Keyring answers the same JSON shapes (this was checked against @laravel/passkeys 0.2.0 and 0.4.1, and laravel/passkeys 0.3.0). Its add-a-passkey calls don't match Keyring's enrollment routes, and step-up has no options route, so use @keyringjs/keyring for those.
Signing In With It
Pass Keyring's login routes to the client:
import { Passkeys } from '@laravel/passkeys' const { redirect } = await Passkeys.verify({ routes: { options: '/login/passkey/options', submit: '/login/passkey' }, remember: true,}) if (redirect) { window.location.href = redirect}The React and Vue usePasskeyVerify hooks accept the same routes, for the button and for autofill. Always send the user to redirect, since it may be the challenge page. A refused passkey answers 422 and a rate limit 429, and the client throws with that message. Autofill needs the email field's autocomplete to end in webauthn, and remember needs @laravel/passkeys 0.4 or later. If you changed the route prefix, add it to both paths.
Adding a Passkey and Step-Up
To add a passkey, use enroll from @keyringjs/keyring. For the challenge and confirm pages, use useChallenge. usePasskeyLogin signs in through the same routes if you'd rather use one package for everything. Passkeys made with laravel/passkeys keep working once you import them.
Customising a Profile
Register a profile again under another factor key, such as to treat one programme's keys separately:
WebAuthn::securityKeys()->as('backup-key'),Other profile options:
WebAuthn::securityKeys()->requireUserVerification(),WebAuthn::securityKeys()->requireAttestation()->allowOnly([$aaguid]),Each returns a new instance. A factor key other than passkey or security-key also needs a line in the frontend's factor map. The browser package's enroll helper runs the ceremony from the options the server sends, so it works with any key:
import { enroll } from '@keyringjs/keyring' await enroll('backup-key', { name: 'Spare key', password })To change more than the profile, subclass it. passkeys and securityKeys return static, so they build your subclass:
use Keyring\Factors\WebAuthn; class AuditedWebAuthn extends WebAuthn{ // ...} Keyring::factors([AuditedWebAuthn::passkeys(), AuditedWebAuthn::securityKeys()]);Stored Data
Each key is a row in keyring_authenticators:
| Column | Holds |
|---|---|
credential_id |
The credential ID, base64url without padding, up to 512 characters. Unique across users. Longer IDs are refused. |
public_key |
The full credential record as JSON, including the public key and counter. |
sign_count |
The last counter seen. |
aaguid |
The model identifier the key reported. |
attestation |
The attestation kind checked against your roots (basic). It's what vouches for aaguid, and null when none was checked. |
transports |
How the browser reaches the key (usb, nfc, internal...). |
meta.user_verified |
Whether the key verified the user when registered. |
meta.backup_eligible |
Whether the key can be synced. |
meta.backed_up |
Whether the key says it has been backed up. Recorded on every sign-in, but assurance depends only on whether the key can sync. |
The user handle is an HMAC of the user's morph class and ID, keyed from APP_KEY for that purpose alone, so it's never the real ID or email. The class is included because an authenticator keeps one passkey per handle. Without it, a User 7 and a Staff 7 would replace each other's passkeys. Once a user has a key, new ones reuse its handle, so rotating APP_KEY doesn't make password managers list the account twice.
To test passkeys without a browser, see the VirtualAuthenticator.
How It Works
Spending a challenge removes it from the session, and Keyring records in the cache store (cache.limiter) that the answer was used. That record refuses the same signed answer a second time, even when the session can't, such as with an earlier copy of the session on Laravel's cookie driver. It lasts until the challenge expires. See Known Limitations.
Challenges expire. An answer arriving more than webauthn.login_options_for after its challenge is refused. A second factor's or step-up's challenge ends with the pending login (pending_logins.keep_for, 10 minutes), and a new key's with the enrollment (enrollments.keep_for, 15 minutes).
With autofill, the login page fetches options on load, and the browser doesn't time out while it waits for a pick. A page left open longer than login_options_for gets an expired challenge, and that sign-in fails. The browser package then fetches new options, so picking the passkey again works. Raise login_options_for if users often leave the page open.