Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions bin/omarchy-hw-fingerprint
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,42 @@
fingerprint_vendors=" 27c6 138a 06cb 08ff 1c7a 147e "
usb_devices_path="${OMARCHY_USB_DEVICES_PATH:-/sys/bus/usb/devices}"

# libfprint's hwdb lists every USB id it knows, grouped under the driver that
# claims it or under "Known unsupported devices". ELAN 04f3:0c00 on the HP
# Pavilion Aero 13 matches ELAN:ARM-M4 below and was offered for setup, which
# then failed with NoSuchDevice although the installed libfprint lists that id
# as unsupported (#17672). Read the installed file instead of copying ids: a
# libfprint fork that drives a reader ships a hwdb with the id under its driver,
# and the reader counts again. Before libfprint is installed there is no file,
# and every match counts as it did.
libfprint_hwdb="${OMARCHY_LIBFPRINT_HWDB_PATH:-/usr/lib/udev/hwdb.d/60-autosuspend-libfprint-2.hwdb}"
supported_ids=" "
unsupported_ids=" "
if [[ -r $libfprint_hwdb ]]; then
section=""
while IFS= read -r line; do
case $line in
"# Known unsupported devices") section="unsupported" ;;
"# "*) section="driver" ;;
usb:v????p????\*)
id="${line:5:4}:${line:10:4}"
if [[ $section == "unsupported" ]]; then
unsupported_ids+="${id,,} "
else
supported_ids+="${id,,} "
fi
;;
esac
done <"$libfprint_hwdb"
fi

# An id under a driver wins, so a hwdb that lists one in both places still
# offers the reader.
libfprint_cannot_drive() {
local id="$1"
[[ $unsupported_ids == *" $id "* && $supported_ids != *" $id "* ]]
}

# A reader the kernel drives without USB (a Mac's Touch ID, behind its Secure
# Enclave) is the platform's to name: each line of its fingerprint-readers file
# is a file (a shell glob) and the value that file reads once the reader is
Expand Down Expand Up @@ -48,6 +84,12 @@ has_kernel_driver() {
}

for dev in "$usb_devices_path"/*; do
# Checked before either match, since the product string is trusted outright.
if [[ -r $dev/idVendor && -r $dev/idProduct ]] &&
libfprint_cannot_drive "$(<"$dev/idVendor"):$(<"$dev/idProduct")"; then
continue
Comment on lines +87 to +90

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Setup blocks the newer driver

If stock libfprint lists a reader as unsupported but libfprint-git supports it, this exclusion makes setup's first hardware check fail. Setup reports “No fingerprint sensor detected” and exits before it can install the replacement library. The user cannot enroll through setup without replacing the library themselves.

Keep the initial check about hardware presence, and apply the unsupported-device check after package installation.

fi

# The device's own product descriptor usually names it, e.g. "Goodix
# Fingerprint USB Device" — driver-independent and vendor-agnostic.
if [[ -r $dev/product ]]; then
Expand Down
9 changes: 9 additions & 0 deletions bin/omarchy-setup-security-fingerprint
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,15 @@ if omarchy-pkg-missing libfprint-git fprintd usbutils; then
sudo pacman -S --needed --noconfirm --ask 4 -- libfprint-git fprintd usbutils
fi

# Detection can only rule out a reader libfprint lists as unsupported once
# libfprint's hwdb is installed, which on a fresh machine is the step above.
# Ask again so a reader like ELAN 04f3:0c00 stops here, not at an enrollment
# that fails with NoSuchDevice (#17672).
if ! omarchy-hw-fingerprint; then
echo -e "\e[31mThe installed libfprint lists this fingerprint reader as unsupported, so it can't be enrolled.\e[0m"
exit 1
fi

# Enroll first fingerprint
# Authenticate sudo first, and say so: with fingerprint sudo already set up it
# asks for a touch of its own, which must not pass for the first sample.
Expand Down
11 changes: 11 additions & 0 deletions test/shell.d/fingerprint-package-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ mkdir -p "$scratch/bin"
export CALL_LOG="$scratch/calls"
export PATH="$scratch/bin:$ROOT/bin:$PATH"

# HARDWARE_STATUS_AFTER_INSTALL is the answer once pacman has run, as it
# changes when the newly installed libfprint lists the reader as unsupported.
cat > "$scratch/bin/omarchy-hw-fingerprint" <<'STUB'
#!/bin/bash
if grep -q '^pacman -S' "$CALL_LOG"; then
exit "${HARDWARE_STATUS_AFTER_INSTALL:-${HARDWARE_STATUS:-0}}"
fi
exit "${HARDWARE_STATUS:-0}"
STUB
cat > "$scratch/bin/sudo" <<'STUB'
Expand Down Expand Up @@ -140,6 +145,12 @@ HARDWARE_STATUS=1 run_setup
[[ ! -s $CALL_LOG ]] || fail "missing hardware stops before package operations"
pass "missing hardware performs no package operations"

HARDWARE_STATUS_AFTER_INSTALL=1 run_setup
if grep -Eq '^(enroll|sudo authenticated)$' "$CALL_LOG"; then
fail "a reader the installed libfprint cannot drive stops before enrollment"
fi
pass "a reader the installed libfprint cannot drive stops before enrollment"

# Successful setup must reuse the same lock/recovery installer as updates.
: > "$CALL_LOG"
OMARCHY_PATH="$scratch" ENROLL_STATUS=0 VERIFY_STATUS=0 \
Expand Down
31 changes: 30 additions & 1 deletion test/shell.d/hw-fingerprint-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ platform_root="$tmp_dir/platform"
mkdir -p "$platform_root" "$tmp_dir/bin"
platform_root_copy "$ROOT/bin/omarchy-hw-fingerprint" "$tmp_dir/bin/omarchy-hw-fingerprint" "$platform_root"

# No libfprint hwdb unless a case writes one, whatever the host has installed.
libfprint_hwdb="$tmp_dir/libfprint.hwdb"

hw_fingerprint() {
OMARCHY_USB_DEVICES_PATH="$tmp_dir/devices" "$tmp_dir/bin/omarchy-hw-fingerprint"
OMARCHY_USB_DEVICES_PATH="$tmp_dir/devices" OMARCHY_LIBFPRINT_HWDB_PATH="$libfprint_hwdb" \
"$tmp_dir/bin/omarchy-hw-fingerprint"
}

assert_detects() {
Expand Down Expand Up @@ -110,6 +114,31 @@ assert_detects "a self-named reader is detected with a driver bound"
write_usb_devices '1234:5678:Generic USB Device'
assert_rejects "a machine with no matching USB devices detects nothing"

# The shape fprint-list-udev-hwdb generates: ids under the driver that claims
# them, then the ones libfprint knows and cannot drive.
write_libfprint_hwdb() {
local driver_id="$1" unsupported_id="$2"
printf '%s\n' '# SPDX-License-Identifier: LGPL-2.1-or-later' '' \
'# Supported by libfprint driver elanmoc' "usb:v${driver_id}*" ' ID_AUTOSUSPEND=1' '' \
'# Known unsupported devices' "usb:v${unsupported_id}*" ' ID_AUTOSUSPEND=1' >"$libfprint_hwdb"
}

# ELAN 04f3:0c00 (HP Pavilion Aero 13) names itself ELAN:ARM-M4, which the
# product match trusts, but stock libfprint has no driver for it (#17672).
write_usb_devices '04f3:0c00:ELAN:ARM-M4'
assert_detects "an ELAN:ARM-M4 reader is detected while libfprint is not installed"
write_libfprint_hwdb 04F3p0C7D 04F3p0C00
assert_rejects "a reader libfprint lists as unsupported is not detected"

write_usb_devices '04f3:0c00:ELAN:ARM-M4' '27c6:1234'
assert_detects "an unsupported reader does not hide another reader"

# A fork that drives the reader lists its id under a driver.
write_libfprint_hwdb 04F3p0C00 04F3p0C00
write_usb_devices '04f3:0c00:ELAN:ARM-M4'
assert_detects "a reader a libfprint driver claims is detected"
rm -f "$libfprint_hwdb"

# A reader the platform names: a file and the value it reads once usable, as a
# Mac's Secure Enclave reports Touch ID. No USB device takes part.
write_platform_readers() {
Expand Down