From bef04695dd3b84bc6eec6ac7811903617b144f1e Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Fri, 30 Oct 2026 08:43:04 -0400 Subject: [PATCH] omamobile-omarchy 0.1.19: fingerprint on the lock only when a finger is enrolled Omarchy 4.0.6's lock and omarchy-apply-lock decide fingerprint is set up with `fprintd-list "$USER" | grep -qi finger`, which also matches "User ... has no fingers enrolled ...". omamobile-fingerprint installs /etc/pam.d/omarchy-lock-fingerprint and pulls in fprintd, so on a phone with nothing enrolled only that grep decides, and it says yes. The lock then starts a pam_fprintd attempt that fails at once (PAM_AUTHINFO_UNAVAIL, code 9) and retries 250 ms later for as long as it is up: 130,164 failed attempts in one night on a Pixel 7 Pro, about 3.4 a second, each reaching fprintd and polkit, and 55-62 mA (roughly 12 % of the phone's draw) in an A/B run against the PAM file moved aside (#170). Upstream fixed this in 879d6583d ("Fix fingerprint enrollment and lock-screen recovery", omacom/omarchy#7158), which is only in the 4.5 pre-releases. Patch 0022 backports its probe half: - the lock's probe becomes `LC_ALL=C fprintd-list "$USER" 2>&1`, read by FingerprintModel.classifyProbe(): yes only for an enrolled-print row (" - #0: ..."), no for "has no fingers enrolled" (or no PAM file), unknown otherwise; an unknown answer never turns fingerprint off and is asked again after 1 s, doubling to 40 s, while the lock is up; - omarchy-apply-lock matches the same row, removes the fingerprint PAM file only on a definite no, and keeps it when the probe fails. The rest of 879d6583d (the attempt backoff and "reader unavailable" notice, the fprintd resume hook, the enrollment changes) is left out, so a phone with a finger enrolled behaves as before: a mismatch still retries at 250 ms. omamobile-fingerprint keeps owning the PAM file (TOUCH-PLAN 0.1); with the probe fixed, the file's presence no longer counts as setup on its own. test/patches.py runs the patched lock's own probe command against a fake fprintd-list with the issue's "has no fingers enrolled" text, an enrolled print and a failed call, and puts the output through classifyProbe; it runs the patched omarchy-apply-lock the same way. The series applies with --fuzz=0 to the real aarch64 omarchy 4.0.6-1. 0.1.13 and 0.1.14 are taken by open #134 and #162 (and patch 0021 by Fixes #170 Co-Authored-By: Claude Opus 5.5 --- ...print-only-when-a-finger-is-enrolled.patch | 186 ++++++++++++++++++ packages/omamobile-omarchy/test/patches.py | 119 +++++++++++ packages/omamobile-omarchy/version | 2 +- 3 files changed, 306 insertions(+), 1 deletion(-) create mode 100644 packages/omamobile-omarchy/patches/0022-lock-fingerprint-only-when-a-finger-is-enrolled.patch diff --git a/packages/omamobile-omarchy/patches/0022-lock-fingerprint-only-when-a-finger-is-enrolled.patch b/packages/omamobile-omarchy/patches/0022-lock-fingerprint-only-when-a-finger-is-enrolled.patch new file mode 100644 index 000000000..13c9da150 --- /dev/null +++ b/packages/omamobile-omarchy/patches/0022-lock-fingerprint-only-when-a-finger-is-enrolled.patch @@ -0,0 +1,186 @@ +# Lock: fingerprint only when a finger is enrolled. A backport of the probe +# half of upstream Omarchy's 879d6583d ("Fix fingerprint enrollment and +# lock-screen recovery", omacom/omarchy#7158, on quattro for 4.5; no stable +# release has it). The lock and omarchy-apply-lock took +# fprintd-list "$USER" | grep -qi finger as "fingerprint is set up", which +# also matches "User ... has no fingers enrolled ...". On a phone with +# omamobile-fingerprint installed (it ships the PAM file) and nothing +# enrolled, the lock then started a pam_fprintd attempt that failed at once +# (PAM_AUTHINFO_UNAVAIL) and retried every 250 ms for as long as it was up: +# 130,164 attempts in one night, about 55-62 mA (#170). +# +# As upstream: the probe is LC_ALL=C fprintd-list "$USER" 2>&1, and +# FingerprintModel.classifyProbe() reads it: "yes" only for an enrolled-print +# row (" - #0: ..."), "no" for "has no fingers enrolled" (or no PAM file or +# fprintd-list), "unknown" otherwise. Unknown never turns fingerprint off; it +# is asked again after 1 s, doubling to 40 s, while the lock is up. +# omarchy-apply-lock matches the same row, removes the PAM file only on a +# definite "no", and keeps it when the probe fails. +# +# Not taken: the rest of 879d6583d (the attempt backoff and the "reader +# unavailable" notice, the fprintd resume hook and its stop-timeout drop-in, +# the enrollment script changes), so a phone with a finger enrolled behaves +# as before: retries after a mismatch stay at 250 ms. FingerprintModel.js +# holds only upstream's probe functions, copied unchanged. +# +# Against Omarchy 4.0.6 (edge 4.0.6-1), after 0003 and 0009. Drop it once the +# phone's Omarchy has 879d6583d (the 4.5 line); its Service.qml and +# omarchy-apply-lock differ from 4.0.6's, so this will not apply there. +diff --git i/bin/omarchy-apply-lock w/bin/omarchy-apply-lock +--- i/bin/omarchy-apply-lock ++++ w/bin/omarchy-apply-lock +@@ -40,16 +40,24 @@ + account include system-local-login + EOF + +-if [[ -x /usr/bin/fprintd-list ]] && +- /usr/bin/fprintd-list "$target_user" 2>/dev/null | grep -qi finger; then ++# Keep the privileged probe pinned to /usr/bin; failure is not empty enrollment. ++if [[ -x /usr/bin/fprintd-list ]]; then ++ fingerprint_status=$(/usr/bin/fprintd-list "$target_user" 2>&1 || true) ++else ++ fingerprint_status="no" ++fi ++ ++if grep -qE '^[[:space:]]*-[[:space:]]*#[0-9]+:' <<< "$fingerprint_status"; then + echo "Configuring lock screen fingerprint authentication..." + as_root tee /etc/pam.d/omarchy-lock-fingerprint >/dev/null <<'EOF' + #%PAM-1.0 + auth required pam_fprintd.so + account include system-local-login + EOF +-else ++elif [[ $fingerprint_status == "no" ]] || grep -qi 'has no fingers enrolled' <<< "$fingerprint_status"; then + as_root rm -f /etc/pam.d/omarchy-lock-fingerprint ++else ++ echo "Could not check fingerprint enrollment; keeping the existing configuration." >&2 + fi + + # omarchy-shell can't reach a running shell during chroot install. The echo +diff --git i/shell/plugins/lock/FingerprintModel.js w/shell/plugins/lock/FingerprintModel.js +new file mode 100644 +--- /dev/null ++++ w/shell/plugins/lock/FingerprintModel.js +@@ -0,0 +1,33 @@ ++// The probe half of upstream's FingerprintModel.js (879d6583d): what ++// fprintd-list's answer means, and how often to ask again when it had none. ++var MATCH_RETRY_MS = 250 ++var ERROR_RETRY_BASE_MS = 1000 ++// Leave enough idle time for fprintd to exit and clear a wedged claim. ++var FPRINTD_IDLE_EXIT_MS = 30000 ++var ERROR_RETRY_CAP_MS = 40000 ++ ++function retryDelayMs(streak) { ++ if (streak <= 0) return MATCH_RETRY_MS ++ var delay = ERROR_RETRY_BASE_MS * Math.pow(2, streak - 1) ++ return Math.min(delay, ERROR_RETRY_CAP_MS) ++} ++ ++// A failed probe is unknown, so it cannot disable authentication for the lock. ++function classifyProbe(text) { ++ var s = String(text || "").trim() ++ if (/^[ \t]*-[ \t]*#[0-9]+:/m.test(s)) return "yes" ++ if (s === "no") return "no" ++ if (/has no fingers enrolled/i.test(s)) return "no" ++ return "unknown" ++} ++ ++if (typeof module !== "undefined") { ++ module.exports = { ++ MATCH_RETRY_MS: MATCH_RETRY_MS, ++ ERROR_RETRY_BASE_MS: ERROR_RETRY_BASE_MS, ++ ERROR_RETRY_CAP_MS: ERROR_RETRY_CAP_MS, ++ FPRINTD_IDLE_EXIT_MS: FPRINTD_IDLE_EXIT_MS, ++ classifyProbe: classifyProbe, ++ retryDelayMs: retryDelayMs ++ } ++} +diff --git i/shell/plugins/lock/Service.qml w/shell/plugins/lock/Service.qml +--- i/shell/plugins/lock/Service.qml ++++ w/shell/plugins/lock/Service.qml +@@ -5,6 +5,7 @@ + import Quickshell.Wayland + import qs.Commons + import qs.Commons as Commons ++import "FingerprintModel.js" as FingerprintModel + + Item { + id: root +@@ -23,6 +24,7 @@ + property bool fingerprintAuthenticating: false + property bool passwordPamConfigured: false + property bool fingerprintConfigured: false ++ property int fingerprintProbeStreak: 0 + property bool keypad: false + property bool previewVisible: false + property string enteredPassword: "" +@@ -119,6 +121,32 @@ + if (!fingerprintCheckProc.running) fingerprintCheckProc.running = true + } + ++ // Only definitive enrollment results may disable authentication. ++ function applyFingerprintProbe(text) { ++ var status = FingerprintModel.classifyProbe(text) ++ if (status === "unknown") { ++ if (fingerprintConfigured) return ++ fingerprintProbeStreak += 1 ++ if (lockRequested) { ++ fingerprintRecheckTimer.interval = FingerprintModel.retryDelayMs(fingerprintProbeStreak) ++ fingerprintRecheckTimer.restart() ++ } ++ return ++ } ++ fingerprintProbeStreak = 0 ++ fingerprintRecheckTimer.stop() ++ fingerprintConfigured = status === "yes" ++ if (lockRequested && fingerprintConfigured) { ++ // A pending retry already owns the next attempt. ++ if (!fingerprintRetryTimer.running) startFingerprint() ++ } else if (!fingerprintConfigured) { ++ // abort() delivers no completion signal, so close the attempt here. ++ if (fingerprintPam.active) fingerprintPam.abort() ++ fingerprintAuthenticating = false ++ fingerprintRetryTimer.stop() ++ } ++ } ++ + function logEvent(event) { + lastEvent = event + lastEventAt = new Date().toISOString() +@@ -132,6 +160,8 @@ + failedAttempts = 0 + authenticatingPassword = false + fingerprintAuthenticating = false ++ fingerprintProbeStreak = 0 ++ fingerprintRecheckTimer.stop() + fingerprintRetryTimer.stop() + if (passwordPam.active) passwordPam.abort() + if (fingerprintPam.active) fingerprintPam.abort() +@@ -390,15 +420,21 @@ + } + } + ++ // Keep fprintd errors distinguishable from an explicit empty enrollment. + Process { + id: fingerprintCheckProc +- command: ["bash", "-c", "if [[ -f /etc/pam.d/omarchy-lock-fingerprint ]] && command -v fprintd-list >/dev/null 2>&1 && fprintd-list \"$USER\" 2>/dev/null | grep -qi finger; then echo yes; else echo no; fi"] ++ command: ["bash", "-c", "if [[ -f /etc/pam.d/omarchy-lock-fingerprint ]] && command -v fprintd-list >/dev/null 2>&1; then LC_ALL=C fprintd-list \"$USER\" 2>&1; else echo no; fi"] + stdout: StdioCollector { id: fingerprintCheckStdout; waitForEnd: true } +- onExited: { +- root.fingerprintConfigured = String(fingerprintCheckStdout.text || "").trim() === "yes" +- if (root.lockRequested && root.fingerprintConfigured) root.startFingerprint() +- else if (!root.fingerprintConfigured && fingerprintPam.active) fingerprintPam.abort() +- } ++ onExited: root.applyFingerprintProbe(fingerprintCheckStdout.text) ++ } ++ ++ // Retries a probe that could not reach fprintd, paced like the attempt ++ // retries so a daemon that stays unreachable is asked about ever less often. ++ Timer { ++ id: fingerprintRecheckTimer ++ interval: FingerprintModel.ERROR_RETRY_BASE_MS ++ repeat: false ++ onTriggered: root.refreshFingerprintStatus() + } + + Process { diff --git a/packages/omamobile-omarchy/test/patches.py b/packages/omamobile-omarchy/test/patches.py index 26a4b1004..9c843f60e 100755 --- a/packages/omamobile-omarchy/test/patches.py +++ b/packages/omamobile-omarchy/test/patches.py @@ -392,6 +392,7 @@ def make_root(name, mtree_from): screensaver_launcher(t, os.path.join(root, "usr/bin/omarchy-launch-screensaver")) notification_phrasing(t, os.path.join(root, "usr/bin/omarchy-notification-send"), os.path.join(ex, "usr/bin/omarchy-notification-send")) + lock_fingerprint_probe(t, root) rc, out = run(root, "apply", series=SERIES) ok(rc == 0 and "already applied" in out, "real omarchy: already applied") rc, _ = run(root, "verify") @@ -609,6 +610,124 @@ def send(script, args, phrasing): % (" " + repr(bad_desktop) if bad_desktop else "")) +# fprintd-list's answers (fprintd 1.94), with a placeholder user +PROBE_NO_FINGERS = """found 1 devices +Device at /net/reactivated/Fprint/Device/0 +Using device /net/reactivated/Fprint/Device/0 +User tester has no fingers enrolled for Pixel 7 Pro under-display fingerprint sensor (Omarchy Mobile). +""" +PROBE_ENROLLED = """found 1 devices +Device at /net/reactivated/Fprint/Device/0 +Using device /net/reactivated/Fprint/Device/0 +Fingerprints for user tester on Pixel 7 Pro under-display fingerprint sensor (Omarchy Mobile) (press): + - #0: right-thumb +""" +PROBE_FAILED = """found 1 devices +Device at /net/reactivated/Fprint/Device/0 +Using device /net/reactivated/Fprint/Device/0 +ListEnrolledFingers failed: GDBus.Error:net.reactivated.Fprint.Error.Internal: Failed to open device +""" + + +def lock_fingerprint_probe(t, root): + """Patch 0022 (upstream's 879d6583d probe, #170): the lock's probe and + omarchy-apply-lock call fingerprint set up only for an enrolled print, not + for "has no fingers enrolled", and a failed probe never turns it off.""" + lock = "usr/share/omarchy/shell/plugins/lock/" + service = read(root, lock + "Service.qml") + ok("grep -qi finger" not in service and "onExited: root.applyFingerprintProbe(fingerprintCheckStdout.text)" in service + and 'import "FingerprintModel.js" as FingerprintModel' in service + and os.path.isfile(os.path.join(root, lock, "FingerprintModel.js")), + "real omarchy: the lock classifies fprintd-list's answer (0022)") + apply_fn = service.split("function applyFingerprintProbe(text) {", 1) + unknown = apply_fn[1].split('if (status === "unknown") {', 1)[1].split("\n }\n", 1)[0] if len(apply_fn) == 2 else "" + ok(unknown and "fingerprintConfigured =" not in unknown and "if (fingerprintConfigured) return" in unknown, + "real omarchy: an unknown probe never turns fingerprint off (0022)") + ok("interval: 250" in service.split("id: fingerprintRetryTimer", 1)[1].split("}", 1)[0], + "real omarchy: a mismatch still retries at 250 ms (0022)") + + d = os.path.join(t, "fp-probe") + fakes = os.path.join(d, "bin") + pam = os.path.join(d, "pam.d") + os.makedirs(fakes) + os.makedirs(pam) + answer = os.path.join(d, "answer") + with open(os.path.join(fakes, "fprintd-list"), "w") as f: + f.write('#!/bin/bash\n[[ $1 == tester ]] || exit 3\ncat "%s"\n[[ ! -e "%s.rc" ]] || exit "$(cat "%s.rc")"\n' + % (answer, answer, answer)) + with open(os.path.join(fakes, "sudo"), "w") as f: + f.write('#!/bin/bash\nexec "$@"\n') + # Never the laptop's running shell + with open(os.path.join(fakes, "omarchy-shell"), "w") as f: + f.write('#!/bin/bash\nexit 1\n') + for n in ("fprintd-list", "sudo", "omarchy-shell"): + os.chmod(os.path.join(fakes, n), 0o755) + env = dict(os.environ, PATH=fakes + ":/usr/bin:/bin", USER="tester", OMARCHY_INSTALL_USER="tester") + + def set_answer(text, rc=0): + with open(answer, "w") as f: + f.write(text) + if rc: + with open(answer + ".rc", "w") as f: + f.write(str(rc)) + elif os.path.exists(answer + ".rc"): + os.unlink(answer + ".rc") + + # The lock's own probe command, with the PAM path moved into the scratch + # tree, then its output through FingerprintModel.classifyProbe + cmd = service.split("id: fingerprintCheckProc", 1)[1].split('command: ["bash", "-c", "', 1)[1].split('"]\n', 1)[0] + cmd = cmd.replace('\\"', '"').replace("/etc/pam.d/", pam + "/") + node = shutil.which("node") + model = os.path.join(root, lock, "FingerprintModel.js") + cases = [("no fingers enrolled", PROBE_NO_FINGERS, 0, True, "no"), + ("an enrolled print", PROBE_ENROLLED, 0, True, "yes"), + ("a failed fprintd-list", PROBE_FAILED, 1, True, "unknown"), + ("no PAM file", PROBE_ENROLLED, 0, False, "no")] + if not node: + print("ok - real omarchy: the lock's probe end to end # SKIP no node") + else: + bad = [] + for what, text, rc, pam_file, want in cases: + set_answer(text, rc) + fpam = os.path.join(pam, "omarchy-lock-fingerprint") + if pam_file: + open(fpam, "w").close() + elif os.path.exists(fpam): + os.unlink(fpam) + out = subprocess.run(["bash", "-c", cmd], env=env, capture_output=True, text=True).stdout + got = subprocess.run([node, "-e", "process.stdout.write(require(process.argv[1]).classifyProbe(process.argv[2]))", + model, out], capture_output=True, text=True).stdout + if got != want: + bad.append((what, got)) + ok(not bad, "real omarchy: the lock's probe says yes only for an enrolled print (0022)%s" + % (" " + repr(bad) if bad else "")) + + # omarchy-apply-lock, with /etc/pam.d and /usr/bin/fprintd-list moved + script = read(root, "usr/bin/omarchy-apply-lock") + ok("grep -qi finger" not in script, "real omarchy: omarchy-apply-lock no longer greps for 'finger' (0022)") + script = script.replace("/usr/bin/fprintd-list", os.path.join(fakes, "fprintd-list")).replace("/etc/pam.d/", pam + "/") + tool = os.path.join(d, "omarchy-apply-lock") + with open(tool, "w") as f: + f.write(script) + fpam = os.path.join(pam, "omarchy-lock-fingerprint") + results = [] + for what, text, rc, want in (("no fingers enrolled", PROBE_NO_FINGERS, 0, False), + ("an enrolled print", PROBE_ENROLLED, 0, True), + ("a failed fprintd-list", PROBE_FAILED, 1, "kept")): + with open(fpam, "w") as f: + f.write("kept\n") + set_answer(text, rc) + r = subprocess.run(["bash", tool], env=env, capture_output=True, text=True) + there = os.path.exists(fpam) + got = (open(fpam).read() == "kept\n" and "kept") if there else False + if there and got != "kept": + got = "pam_fprintd.so" in open(fpam).read() + results.append(r.returncode == 0 and got == want) + ok(all(results), "real omarchy: omarchy-apply-lock removes the fingerprint PAM file for no fingers, writes it " + "for an enrolled print, keeps it when fprintd-list fails (0022) %s" % results) + + + def mod_patch(root, path): """A patch rewritten to real paths, for patch -d root (it touches no links).""" with open(path) as src, open(os.path.join(root, "p0000"), "w") as dst: diff --git a/packages/omamobile-omarchy/version b/packages/omamobile-omarchy/version index f8bc4c625..d8a023ec1 100644 --- a/packages/omamobile-omarchy/version +++ b/packages/omamobile-omarchy/version @@ -1 +1 @@ -0.1.18 +0.1.19