How to implement PassKeys in your application

azilian 65 views 33 slides May 11, 2024
Slide 1
Slide 1 of 33
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33

About This Presentation

PassKeys is relatively new way of authentication. This presentation aims to provide a bit of guidance on how you can implement them in your own application.


Slide Content

PassKeys
How to implement them
Presenter:
Marian Marinov
Organization:
Director of Engineering
Web Hosting Canada

What are passkeys?
The idea behind them is to replace username
and password combinations with something
more secure and generally unique per
application/website.

Are passkeys more secure?
➢ Randomly generated long string
➢ Cryptographically signed
➢ Cryptographically verifiable
➢ Unique passkey pair for each site/application
➢ Eliminating the possibility to reuse either usernames
or passwords

Reality
➢ Usernames are still required
➢ Computer generated strings are hard
➢ Usage is cumbersome
➢ Adoption is low
➢ Reports for problems with major vendors

Reality
➢ Usernames are still required
➢ Computer generated strings are hard
➢ Usage is cumbersome
➢ Adoption is low
➢ Reports for problems with major vendors
➢ Why I decided to speak about this topic?

Reality
➢ Usernames are still required
➢ Computer generated strings are hard
➢ Usage is cumbersome
➢ Adoption is low
➢ Reports for problems with major vendors
➢ Why I decided to speak about this topic?

https://www.peeringdb.com/

Implementation
Handling of PassKeys on the client side

Implementation
Handling of PassKeys on the client side
➢ You can use HW device (i have examples)

Implementation
Handling of PassKeys on the client side
➢ You can use HW device (i have examples)
➢ You can also use iPhone or Android

Implementation
iPhone/Android situation
➢ Your authentication keys are stored on their cloud
➢ You have limited control
➢ The vendor can delete those without your concent
➢ The vendor can limit your access to your creds at any
given time

PassKeys process

PassKeys process
Credit Yubico

PassKeys process
Credit Yubico

On the backend
Registrations
➢ Generate random challenge with expiration time
(CSRF)
➢ Generate new user_id based on the username +
challenge
➢ Enrol passkey (pubkey + user_id)
➢ Store the generated pair on the backend

On the frontend
➢ Most of the work is here
➢ Support for devices in Browsers

All major browsers support it
➢ Annoying and large frontend libraries

Fronted implementation
➢ I decided to ride the wave of AI
➢ I asked ChatGPT to assist me

Fronted implementation
➢ I decided to ride the wave of AI
➢ I asked ChatGPT to assist me
➢ Big mistake!

Fronted implementation
Once it was clear it will not build it for me...

Fronted implementation
I shamelessly stole the web interface from
https://webauthn.io

Backend implementation
I used PostgreSQL
I needed two tables:
➢ challenges
➢ credentials
Challenges would probably be better with
Redis/DragonFly auto expiring keys

Backend implementation
I used PostgreSQL
table: challenges
id
username
challenge
created

Backend implementation
I used PostgreSQL
sign_count, if implemented allows prevention of
replay attacks
table: challenges
id
username
challenge
created
table: credentials
id
sign_count
user_handle
credential_id
public_key

Backend implementation
I tried initially writing it in PHP with
web-auth/webauthn-lib
It did not work. Their example returned:
PHP Fatal error:
Uncaught Error: Class "Webauthn\Server" not found

Backend implementation
Then I switched to my favourite
I found Authen::WebAuthn ...
But I decided to try to build it from scratch.

My basic Mojolicious app
I ended up creating the following
endpoints in my app:
get '/' Login form
post '/auth-options' Challenge generation
post '/auth-verify' Authentication
validation
post '/register' User ID generation
post '/reg-verify' Registering the user

Important definitions
➢ rp_id - Relying Party (hostname of your app)
➢ credential_id - ID that is stored on the backend
➢ allowCredentials - the server may request specific
credentials

Backend- Registration
1. /auth-options - get supported options from the
backend
2. /register - register the client and return passkey
data
3. /reg-verify - validate the credentials

Problems with passkeys?
➢ Multiple reports that Apple has completely erased
the passkey store for users
➢ Not fully supported everywhere.
➢ Cumbersome with HW devices
➢ Device missing
➢ Requiring restart of browsers in order to recognize
a device

HW Security keys

➢ YubiKey
➢ NitroKey
➢ Thetis Fido U2F Security Key (only U2F, no OTP)
➢ CryptoTrust OnlyKey
➢ Feitian ePass K9 USB Security Key

YubiKey on Ubuntu

apt-get install \
yubico-piv-tool \
yubikey-personalization-gui \
yubioath-desktop \
ykcs11 \
opensc

Resources
https://passkeys.dev
https://www.passkeys.io/technical-details
https://developer.apple.com/passkeys/
https://developers.google.com/identity/
passkeys
https://developers.yubico.com/Passkeys/
Quick_overview_of_WebAuthn_FIDO2_and_CTAP.h
tml

Questions?
Marian Marinov
[email protected]