Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

Passkeys and WebAuthn

After this lesson: I can explain why a passkey resists phishing by checking what a site verifies.

60 min lesson4 commandsPassword lab: John the Ripper, MFA and passkeys

A quick check that you are not a bot, then your own lab opens on the interactive lesson.

Already have an account? Sign in

A fake page that gets nothing

A member of staff gets an email: their account will close unless they sign in. The link opens a perfect copy of the college's page at a look-alike address. A password, or even a one-time code, typed there goes straight to the attacker.

With a passkey, the phone has nothing to give that page. This lesson shows why.

By the end of this lesson

Note

I can explain why a passkey resists phishing by checking what a site verifies.

Key words

WordWhat it meansExample
Passkeya key pair that signs you in to one site
Relying partythe site a passkey belongs torp id site
Authenticatorthe phone, laptop or key that holds the private key
Challengerandom bytes the site asks to have signed
Originthe address the browser is really on
Sign counta number that rises with every use

The cells students fill in are left blank in this preview.

Starter

Have a go

Starter

4 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

The rule for this lesson

Warning

The look-alike site in this lesson is a script inside your own lab. Never build a copy of a real organisation's sign-in page without written permission, even as a test. Using what it collects is a crime under the Computer Misuse Act 1990.

A passkey is one site's key pair

When you add a passkey, your authenticator makes a new key pair for that site alone. The private key never leaves it. The site stores only the public key, which is useless to a thief.

To sign in, the site sends a random challenge. The authenticator checks you are there, often with a fingerprint or PIN that stays on the device, and signs. The site checks the signature with the public key.

Add a passkey to amira's account

Command
docker exec john python3 steps/passkey.py register

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Sign in with the passkey

Command
docker exec john python3 steps/passkey.py login

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Worked example: register and sign in

What passkey.py printedWhat happened
new key pair for rp id site, credential 48235ee546c6c10dA key pair just for the site
public key x starts cd1563f3d39e4c31Only the public half went to the site
challenge from the site: 16 random bytesA fresh challenge each time
signed ... with sign count 1, site says: okThe signature checked out

The cells students fill in are left blank in this preview.

Check

Have a go

Check

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

The browser says where it really is

Two things beat the fake page. The authenticator picks a key by the site's name, the relying party id, so a look-alike name finds no key at all.

And the browser writes the real origin into what is signed. A look-alike that forwards the real site's challenge still gets an origin the site refuses. The user never has to spot the fake address.

Play the look-alike site

Command
docker exec john python3 steps/passkey.py phish

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Send an old signature again

Command
docker exec john python3 steps/passkey.py replay

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

A common mistake

Warning

Many people think a passkey is a password kept on the phone. Nothing secret is sent or stored by the site: the phone proves it holds a private key by signing a fresh challenge. A stolen copy of the site's table holds only public keys.

Check

Have a go

Check

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Try it: a key chosen by name

Code: python
# A passkey is chosen by the site's name, never by what a page looks like.
passkeys = {"site": "key 48235ee5"}
for page in ["site", "site-login.example", "slte"]:
    if page in passkeys:
        print(page, "->", passkeys[page])
    else:
        print(page, "-> no passkey, nothing signed")
# Add a passkey for "college.example", then ask for it, and press Run.

Make a free account to save your work and track your progress.

Synced passkeys, recovery and roll-out

Most passkeys sync across a person's devices through their phone or browser maker's account, so losing one phone loses nothing. NIST allows synced passkeys for most accounts, and device-bound security keys for the highest assurance.

Roll out by offering passkeys beside the password first, with recovery codes or a second key. Then turn passwords off for staff who have one.

The fix, and how to detect phishing

Fix: offer passkeys, and for admins and staff with access to student data, require them. A site must check the type, challenge, origin, relying party, user presence, signature and sign count every time.

Detect: log every refused assertion with its reason. Bursts of "wrong origin" show a look-alike in use, and a sign count that goes back suggests a cloned key.

Check

Have a go

Check

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Assignment: check an assertion

Write the checks a site makes on a passkey sign-in, before the signature. rp_hash(rp_id) returns the SHA-256 of the relying party id as lowercase hex. check(client, auth, expected) takes three dictionaries: client with "type", "challenge" and "origin"; auth with "rp_id_hash", "flags" and "count"; expected with "challenge", "origin", "rp_id" and "count" (the last sign count stored). Return the first problem found, in this order: "wrong type" unless the type is "webauthn.get"; "wrong challenge"; "wrong origin"; "wrong rp id"; "no user presence" when flags is even; "sign count went back" when the count is not above the stored one, unless both are 0. Otherwise return "ok".

Code: python
import hashlib


def rp_hash(rp_id):
    return ""


def check(client, auth, expected):
    return "ok"

Make a free account to save your work and track your progress.

Exit quiz

Have a go

Exit quiz

5 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Teaching a class? Set this module for your students with a teacher guide, marked assignments and a lab for every student.