Files
connector-popos/configure.d/71-fingerprint.sh
T
davidandClaude Opus 5.5 7185d6cb3e Sign in to sudo and polkit with a security key or fingerprint
Ports configure security-key and configure fingerprint from CoreDesktop's
9dc5eb1: touch a FIDO2 key or a finger instead of typing your password for
sudo and polkit, falling back to the password. Each shows only when the
hardware is there. The fingerprint skips to the password with the lid shut.

lib/pam.sh is CoreDesktop's, but also takes Ubuntu's "@include
common-auth" as the start of a stack's auth part, which is how sudo's and
polkit's begin. Only those two stacks change, not common-auth, which
pam-auth-update owns and every sign-in includes. libpam-fprintd's
pam-auth-update profile is off by default, so installing it changes no
sign-in by itself. The login and lock screens keep asking for the
password, unlike on GNOME.

Smoketest: 70-sign-in, on copies of Ubuntu's sudo and polkit stacks.
TEST.md: with a real key and reader.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-28 19:03:41 -07:00

127 lines
4.2 KiB
Bash

#!/bin/bash
# configure reads TITLE and DESCRIPTION
# shellcheck disable=SC2034
TITLE="Fingerprint"
# shellcheck disable=SC2034
DESCRIPTION="Use your fingerprint instead of typing your password for sudo"
source "$CONNECTOR/configure.d/lib/pam.sh"
# With the lid shut the reader can't be touched, and sudo would wait for it to
# time out. This skips the fingerprint then, straight to the password.
LID_CLOSED="${LID_CLOSED:-/usr/local/lib/federated-connector/lid-closed}"
FPRINT_LINES=(
"auth [success=1 default=ignore] pam_exec.so quiet $LID_CLOSED"
"auth sufficient pam_fprintd.so"
)
# fprintd and its PAM module. The module's pam-auth-update profile is off
# unless you turn it on, so installing it changes no sign-in by itself.
FPRINT_PACKAGES=(fprintd libpam-fprintd)
# For the tests
USB_DEVICES="${USB_DEVICES:-/sys/bus/usb/devices}"
# Vendors whose USB devices are fingerprint readers (Goodix, Validity,
# Synaptics, AuthenTec, Upek, LighTuning), adapted from Omarchy. Elan and FPC
# readers name themselves instead.
FPRINT_VENDORS=" 27c6 138a 06cb 08ff 1c7a 147e "
# libfprint drives a reader from userspace, so no kernel driver claims it. The
# same vendors' touchpads and cameras have one (usbfs is libusb's own).
has_kernel_driver() {
local interface driver
for interface in "$1"/*:*; do
[ -e "$interface/driver" ] || continue
driver="$(readlink -f "$interface/driver")"
[ "${driver##*/}" = usbfs ] || return 0
done
return 1
}
reader_present() {
local device product vendor
for device in "$USB_DEVICES"/*; do
if [ -r "$device/product" ]; then
product="$(< "$device/product")"
product="${product,,}"
[[ "$product" == *fingerprint* || "$product" == *biometric* \
|| "$product" == *elan:arm-m4* || "$product" == "fpc "* ]] && return 0
fi
if [ -r "$device/idVendor" ]; then
vendor="$(< "$device/idVendor")"
[[ "$FPRINT_VENDORS" == *" $vendor "* ]] && ! has_kernel_driver "$device" && return 0
fi
done
return 1
}
fingers_enrolled() {
fprintd-list "$USER" 2> /dev/null | grep -qE '^[[:space:]]*- #[0-9]+:'
}
# Shown on computers with a reader
is_installed() {
pam_has sudo pam_fprintd.so || reader_present
}
is_configured() {
pam_has sudo pam_fprintd.so && fingers_enrolled
}
install_lid_check() {
sudo install -d -m 755 "$(dirname "$LID_CLOSED")" || return 1
sudo tee "$LID_CLOSED" > /dev/null << 'EOF' || return 1
#!/bin/sh
# Federated Connector: true when the laptop's lid is shut, so PAM skips the
# fingerprint reader, which can't be touched then (configure fingerprint)
for state in /proc/acpi/button/lid/*/state; do
grep -q closed "$state" 2> /dev/null && exit 0
done
exit 1
EOF
sudo chmod 755 "$LID_CLOSED"
}
use_fingerprint() {
local service
install_lid_check || return 1
for service in "${PAM_SERVICES[@]}"; do
pam_add "$service" pam_fprintd.so "${FPRINT_LINES[@]}" || return 1
done
}
stop_using_fingerprint() {
local service
for service in "${PAM_SERVICES[@]}"; do
pam_remove "$service" "[[:space:]](pam_fprintd\.so|${LID_CLOSED//./\\.})([[:space:]]|$)" || return 1
done
echo "sudo and the password prompts ask for your password only. Your enrolled fingers"
echo "stay in fprintd; to delete them: fprintd-delete $USER"
}
run_configure() {
local choice
if is_configured; then
echo "sudo and the password prompts take your fingerprint. To add a finger:"
echo "fprintd-enroll -f left-index-finger (or another), and to list them: fprintd-list $USER"
echo
echo " 1) Stop using your fingerprint for sudo and the password prompts"
echo " q) Leave it as it is"
echo
read -rp "Choose: " choice
[ "$choice" = 1 ] && stop_using_fingerprint
return
fi
pkg_ensure "Fingerprints" "${FPRINT_PACKAGES[@]}" || return 1
# Enrolled already, e.g. with fprintd-enroll
if ! fingers_enrolled; then
echo "Touch the fingerprint reader with your right index finger, again and again until"
echo "it says it's done."
fprintd-enroll "$USER" || { echo "Your finger wasn't enrolled."; return 1; }
fi
use_fingerprint || return 1
echo "Done. sudo and the password prompts take your fingerprint, and your password as"
echo "before. The login and lock screens still ask for your password."
}