Security keys and smart cards
People add keys and cards in Settings, or a key during the first start, and sign in with them on the login and lock screens, as Security describes. This page is how that works.
The pieces
Section titled “The pieces”luft-sign-in is a root service, started by D-Bus as com.lantharos.SignIn1 and by its socket /run/luft-sign-in/verify, which only root can open. It does everything that touches a key or a card, so neither greetd nor kestrel-authenticate loads a USB or smart card library:
- FIDO2 keys go through libfido2, opened at run time. Each enrolled key holds a credential for the relying party
com.lantharos.sign-inthat isn’t stored on the key, made with thehmac-secretextension, and signing in always needs user verification: the key’s PIN, or its own fingerprint reader. - Smart cards go through PKCS #11, by way of p11-kit’s proxy, so OpenSC’s drivers for PIV, CAC and many national and company cards work, and so does a vendor’s own module registered with p11-kit. Only removable slots count, which leaves out the system’s trusted certificates. pcscd owns the readers; a card reader only counts when it speaks CCID, so readers that type a badge’s number as a keyboard never sign anyone in.
pam_luft_sign_in.so is a small client of that socket, which has an SELinux type of its own that greetd may connect to. It relays the service’s questions, such as Security key PIN: , and notices, such as Touch your security key, through the PAM conversation, which is how the login and lock screens show them.
Proving it’s the key or card
Section titled “Proving it’s the key or card”For a security key, the service first asks every plugged-in key, without a touch, whether it holds one of the person’s credentials. On the one that does, it asks for the PIN, then for an assertion over 32 fresh random bytes with user presence and user verification required, and checks the signature itself against the public key kept from enrolment. libfido2 encrypts the PIN and the hmac-secret exchange between the computer and the key.
For a card, the service looks for a certificate the person enrolled, logs in to the card with its PIN, has it sign 32 fresh random bytes with the key of that certificate, PKCS #1 v1.5 with SHA-256 for RSA and ECDSA over the SHA-256 digest for P-256 and P-384, and checks the signature against the enrolled certificate. A card that only replays an earlier answer can’t pass.
Proving the model of key
Section titled “Proving the model of key”A key says which model it is with its AAGUID, and a key someone built could claim any model. With key-attestation in the organization’s policy, adding a key checks its attestation: the certificates it signs a new credential with, which its maker put on it. libfido2 checks that signature, in the packed, fido-u2f or tpm format; a key that only signs with the credential’s own key, or sends no attestation, isn’t taken. The service then checks that the certificate names the same AAGUID when it names one, and that the chain, each certificate signed by the next and current, leads to a root the FIDO Alliance’s Metadata Service lists for that AAGUID, or to one of the organization’s key-attestation-roots. Models whose status reports say they were revoked, or that their keys or user verification can be broken into, are refused, and so is an attestation certificate reported as leaked. The service remembers the SHA-256 of the key’s own certificate, and checks it and the model against the Metadata Service again at every request, so a model reported later stops counting with the next image. Keys added before the policy asked carry no such proof, so they stop counting, Methods gives them as add-again, and adding the same key again replaces the old one, keeping its Lock when this key is taken out.
Without key-attestation, the service never reads or keeps a key’s attestation.
The Metadata Service blob comes in with every image build. A weekly workflow keeps a copy on get.luft.computer, since the Metadata Service turns away repeated downloads, and the build fetches that copy, checks its JWT signature, made by the certificate for mds.fidoalliance.org, through its chain to the GlobalSign Root CA R3 that Luft pins, and keeps only each FIDO2 model’s roots and refusals, one file per AAGUID in /usr/share/luft-sign-in/key-models. Checking a key reads only its own model’s file.
What’s kept
Section titled “What’s kept”Everything enrolled is in /var/lib/luft-sign-in/users/UID.json, which only root can read or change, never in the home folder: each key’s credential ID, public key and hmac-secret salt, the SHA-256 of the certificate it proved its model with when the policy asked, each card’s certificate and its keyring wrap, whether the person signs in with their password, and the USB identity of each key or reader. /var/lib/luft-sign-in/devices lists those identities for USB protection. A person with nothing enrolled and the password on has no file at all.
Unlocking Luft Keyring
Section titled “Unlocking Luft Keyring”With a TPM, any sign-in unlocks Luft Keyring through the key the TPM seals, so a key or card unlocks it as a fingerprint does. Keys and cards also unlock it without a TPM, or with a TPM PIN:
- A key’s secret is its
hmac-secretoutput for the enrolled salt, after its PIN. - A card’s secret is either 32 random bytes encrypted to the card’s RSA key, which only the card decrypts, or, for an elliptic curve key, an ECDH agreement between the card’s key and a key made at enrolment, run through HKDF-SHA256. Cards whose key may do neither still sign in, and unlock the keyring through the TPM.
The keyring keeps its master key wrapped by each of these secrets in its vault header, with XChaCha20-Poly1305, next to the password and TPM wraps. After a sign-in, pam_luft_sign_in.so leaves the secret as PAM data, and pam_luft_keyring.so hands it with its grant to the unlock service, which passes it only to the person’s own luft-keyring. The keyring adds a wrap the first time a secret arrives while it’s open, which enrolment arranges at once, drops wraps of keys and cards that are no longer enrolled, and, when a sign-in couldn’t open it, adds the wrap as soon as the password does. The secret never reaches a program of the person’s.
The login and lock screens
Section titled “The login and lock screens”com.lantharos.SignIn1.Ways(uid) says how an account signs in, best first: security key, smart card, fingerprint, then password. Anyone may ask, and the login screen asks for everyone listed as soon as it shows them, so it opens on the right way without showing the password first. It opens on the way used last unless that was the password, and on the best way otherwise. While fprintd gets the reader ready, the prompt says so in the fingerprint’s place.
greetd’s rules ask the login screen which way to use through pam_kestrel_sign_in.so, then run pam_luft_sign_in.so, which signs in with the key or card, turns password sign-in back on with the recovery key, or decides whether the password may be checked. The lock screen asks kestrel-authenticate for the security-key, smart-card or lock-screen rules, which do the same.
Taking it out locks
Section titled “Taking it out locks”After a card signs in or unlocks, the service watches its reader through pcscd. Taking the card out, or the reader with it, has logind lock every session of that person at the computer. A key does the same when its Lock when this key is taken out switch is on, which SetLockOnRemoval keeps with the key: the service watches /dev with inotify until the key’s hidraw node goes away. Turning the switch on while signed in with that key watches it at once.
What each person last signed in or unlocked with is kept in /run/luft-sign-in/signed-in/UID.json: which card and reader, or which key, its hidraw node and the HID device behind it, whose name the kernel never reuses for a key plugged in again. systemd starts the service again when it crashes, and every start watches each of these again for people still signed in at the computer. A card or chosen key that came out while nothing watched locks their sessions right away.
Administrator prompts and sudo
Section titled “Administrator prompts and sudo”polkit and sudo run their own PAM rules, which Luft replaces, /usr/lib/pam.d/polkit-1 and /etc/pam.d/sudo. Neither unlocks the keyring, so a key confirms without its hmac-secret and a card without opening its wrap.
- polkit’s rules start with
pam_luft_sign_in.so confirm, which asksluft-sign-inthe ways the administrator may use from where the request comes, and, when there’s more than one, asksConfirm with (security-key/smart-card/fingerprint/password):. Kestrel’s prompt answers it with the way the person chose, and runs the fingerprint’s rules beside the password’s, as the lock screen does. A key or card is checked right there;unless-fingerprintskipspam_fprintd.sofor every way but the fingerprint, and then the password. sudocan’t show a choice, soconfirm-pluggeduses a key or enrolled card that’s plugged in already: it asks for the PIN, then says to touch the key. An empty PIN goes on to the fingerprint and the password. With nothing plugged in it goes on too, unless neither may confirm, and then it waits for a key or card.
Both end with pam_luft_sign_in.so password before password-auth, so a person who turned the password off is never asked for it. The recovery key isn’t offered here: it turns the password back on, which only the login screen does, before anything of the person’s runs, and Rescue does.
Keys and cards count only for someone at the computer. The service takes the process that connected, polkit’s helper or sudo, from the socket, and asks logind which session it belongs to: one on a seat, in front and not remote counts. Programs the user manager starts, the desktop and its terminals among them, belong to no session; like polkit, the service counts them for the person’s graphical session, but only while none of that person’s sessions is remote or without a seat, since something started over SSH could run there too. Over SSH, only the password confirms, and only while it’s on; the fingerprint reader refuses remote sessions by itself.
Adding a key during the first start
Section titled “Adding a key during the first start”Adding a key or card asks polkit (com.lantharos.sign-in.enroll) to confirm it’s the caller. During the first start the person just chose their password, so Install Luft asks its installer service instead, which only answers for the account setup is pending for, signed in at the computer, outside a sandbox, while setup is open. The installer then calls AddSecurityKeyFor(uid, pin), which luft-sign-in answers only for the program that owns com.lantharos.Installer1, a name only root may take.
Turning off the password
Section titled “Turning off the password”The password stays allowed unless the person turned it off and a security key, a smart card or a fingerprint in /var/lib/fprint can sign them in. This is checked at every sign-in, so removing the last of them, even a fingerprint removed with fprintd-delete, brings the password back by itself. Turning it off asks polkit (com.lantharos.sign-in.password-off) to confirm it’s the person, and is refused while nothing else is enrolled. When the service can’t answer, the password stays allowed.
The same goes for administrator prompts and sudo. Kestrel’s own confirmations and text consoles, which only exist with Developer tools on, still take the password.
A lost key or card has two ways back, both needing what already opens the computer. At the login screen, Lost your key? asks for the disk’s recovery key, which trustd checks against the disk Luft started from, and turns password sign-in back on. From Rescue, which asks for the recovery key itself, /usr/libexec/luft-sign-in allow-password NAME does the same.
USB protection
Section titled “USB protection”While nobody is signed in or the screen is locked, USB protection lets in an enrolled key or reader, on any port, when its vendor, product, serial number and the full list of its parts match what was enrolled. It then connects only the part that signs in: the HID part outside the boot protocol for a key, which carries FIDO, or the CCID part for a reader. Other parts wait for the unlock as before. When nobody enrolled anything, nothing more connects while locked. YubiKeys don’t report a serial number over USB, so another YubiKey of the same model counts as the same device; it still can’t sign anyone in without its own credential.
An organization’s rules
Section titled “An organization’s rules”An organization’s policy can narrow all of this: which ways sign anyone in and which confirm administrators, which models of key and whose cards may be added, whether keys must prove their model, whether the password can be turned off, and whether taking out a card signs out instead of locking. The service reads the policy at every request, and what the policy leaves out stops counting at once, keys and cards added earlier included. The rule that the password comes back when nothing else is left holds here too, so a person who hasn’t added the key or card their organization asks for yet still gets in with their password, and adds one. How policy is enforced has the details.
Testing
Section titled “Testing”cargo test -p luft-sign-in -p luft-sign-in-certificates -p portguard covers what’s kept, the order of ways, USB matching, attestation chains and reading the Metadata Service. security/vm/sign-in/run.sh checks the whole path in a VM with SELinux enforcing: a FIDO2 key made in software on /dev/uhid with PIN protocol 1 and hmac-secret, and QEMU’s emulated CCID reader with a CAC card. It enrolls both, turns the password off, signs in through greetd with each, checks that the keyring unlocks without a TPM, that a wrong PIN is refused, that taking the card out locks the session, also after the service crashed and started again, and that the reader is held back while locked until it’s enrolled. From the session, pkexec confirms with the key and with the card, sudo with the key’s PIN and a touch, sudo never takes the password while it’s off, and taking the key out locks once its switch is on. In a session logind counts as remote, sudo and pkexec offer no key or card, and take the password only while it’s on. With key-attestation on, the software key, which proves its model with packed attestation from test certificates, must be added again before it signs in, and adding it again replaces the old one; a self-signed certificate, a model listed as compromised, an organization’s key before its root is in the policy and a model security-keys leaves out are refused, while the same organization’s key is taken once its root is listed. With the policy off, a key is added without its attestation being read.