Watch
1
0
Fork
You've already forked keylib
0
mirror of https://codeberg.org/r4gus/keylib.git synced 2026-11-17 03:10:49 +00:00
8 Home
David Sugar edited this page 2026-01-23 20:58:14 +01:00

Authentication, especially on the web, is a tricky thing. For a long time, passwords were all we had and if we were lucky, service providers would actually store only the hash and not the whole password in their databases. Then later on, we got salts, peppers and with that even proper hash algorithms explicitly designed for passwords. But malicious actors got creative and up to this day, fishing attacks are one of the main reason for leaked passwords. Even second factors like OTPs changed little but at least made it somewhat harder for attackers to breach accounts.

When the Fido Alliance announced the second revision of the Fast Identity Online Protocol (FIDO2), they promised nothing more but to revolutionize the way we authenticate online. But to be honest, the core idea was not revolutionary at all! They just took another authentication method, already battle tested on the web: digital signatures. The revolutionary aspect was to bring browser developers (Mozilla, Google, Microsoft and Apple), hardware vendors like Yubico and service providers on board and convince them to implement their envisioned FIDO protocol.

You may ask: what is FIDO2 exactly? Well, imagine digital signatures for authentication on the web, i.e. instead of entering a password to gain access to your account, the service provider (e.g. Github) sends you (well... not really you but still you) a nonce, a number used once, which is signed with your private key. The signature is then send back to the service, which can verify the signature using a corresponding public key. If the signature matches, you gain access to your account.

You might say: Hey! This is how I always authenticate when I access my remote server using SSH! and you'd be correct. The difference lies in the protocol used and not in the core principles.

FIDO2 is actually a meta protocol, i.e. it consists of two protocols called Client to Authnenticator Protocol two (CTAP2) and Web Authentication (WebAuthn). You may ask yourself: why two protocols? The answer is simple, because FIDO2 envisions three parties. On the one side you have your service provider and on the opposite side you have a tool or application managing your private keys: a authenticator. In the middle sits the client which is usually your browser but in reality it can be any application on your computer. From now on lets call the (web) service Relying Party (RP) as this is the term used in the FIDO specifications.

The client sits, as already mentioned, between relying party and authenticator. The authenticator is responsible for managing private keys used for authentication. Just imagine a password manager. Every authenticator is either roaming, meaning you can carry it with you, or a platform authenticator, i.e. an application that acts as authenticator and sits on the same machine as the client. The prime example and probably the best known roaming authenticator is a YubiKey.

And how do Passkeys fit into all this? Good question! Come closer, I gonna tell you a little secret. You can think of passkeys as a tuple (rpId, userId, kpriv) where rpId is the relying party ID (e.g. zigtoberfest.de), userId is the ID of the user assigned by the relying party, and kpriv is the private key used for signatuers. Passkeys are not this mythical creature the Fido Alliance wants you to believe in but something known by the CTAP2 specification as Resident Key, i.e. a key that resides on the authenticator. There is nothing more to it (except for the fact that Google, Apple and WIndows removed the CTAP2 protocol for their own platform authenticators -- which they also call passkey -- in favor of their own proprietary procols, but this is a rant for another day...)!

When you click on "sign in with passkey", the following happens (this is just one of many possible user journeys but probably the most common):

  1. The relying party calls a JS API to say: hey please sign in the user sitting in front of the PC. BTW... here is a nonce for signing
  2. The browser enumerates all available authenticators (e.g. a YubiKey connected via USB)
  3. The user is prompted to select an authenticator
  4. For the selected authenticator, the browser enumerates all credentials bound to the reyling party (e.g. zigtoberfest.de)
  5. The browser lets the user choose one of the detected accounts/ credentials
  6. After selecting an account the browser sends the nonce (its actually a little bit more complicated) to the authenticator, asking it to make a assertion (generate a signature over the nonce using the selected credential)
  7. The signature is then send back, over the browser, to the relying party which can then verify the signature by looking up the public key and on success, signing in the corresponding user.

Why do I tell you all this? Because this package is all about FIDO2. This Zig package allows you to do two things:

  1. Create your own authenticator (yes that's totally possible)
  2. Create your own clients with FIDO2 support.

The only things you need are some programming experience, a Zig compiler, and some time. To get started, head to the examples folder and start ziggin.