diff --git a/default/polkit/org.omarchy.setup-security-fingerprint-enroll.policy b/default/polkit/org.omarchy.setup-security-fingerprint-enroll.policy new file mode 100644 index 000000000000..f1119c6f08fc --- /dev/null +++ b/default/polkit/org.omarchy.setup-security-fingerprint-enroll.policy @@ -0,0 +1,24 @@ + + + + + Omarchy + https://omarchy.org + + Set up fingerprint authentication + Set up fingerprint authentication + + auth_admin + auth_admin + auth_admin + + /usr/bin/omarchy-setup-security-fingerprint-enroll + enroll + + diff --git a/shell/plugins/panels/fingerprint/Enrollment.qml b/shell/plugins/panels/fingerprint/Enrollment.qml index e74e2cc176d7..1c9c857e56f3 100644 --- a/shell/plugins/panels/fingerprint/Enrollment.qml +++ b/shell/plugins/panels/fingerprint/Enrollment.qml @@ -21,6 +21,8 @@ Item { property string reason: "" readonly property string helper: "omarchy-setup-security-fingerprint-enroll" + readonly property string packagedHelper: "/usr/bin/" + helper + readonly property string policyPath: "/usr/share/polkit-1/actions/org.omarchy.setup-security-fingerprint-enroll.policy" // Everything the last run's commands said, for a failure that takes more // than a line to explain. readonly property string logPath: Quickshell.env("HOME") + "/.local/state/omarchy/fingerprint.log" @@ -89,11 +91,24 @@ Item { } cancelling = false phase = demo ? "setup" : "auth" - var command = demo ? [helper, demoFails ? "demo-fail" : "demo", finger] : ["pkexec", helper, "enroll", finger] - // The polkit agent labels the prompt for this exact command line with the - // reason. The helper's stderr, and pkexec's own, is the log of this run. - run.command = ["bash", "-c", 'mkdir -p "${0%/*}"; [[ -z $1 ]] || omarchy-shell -q omarchy.polkit expect "$1" "$2"; shift 2; exec "$@" 2>"$0"', - logPath, demo ? "" : helper + " enroll " + finger, reason].concat(command) + // The helper's stderr, and pkexec's own, is the log of this run. + if (demo) { + run.command = ["bash", "-c", 'mkdir -p "${0%/*}"; exec "$@" 2>"$0"', + logPath, helper, demoFails ? "demo-fail" : "demo", finger] + } else { + // The polkit policy for packagedHelper gives the prompt its reason + // without showing the command line. On a dev checkout before that policy + // is installed, fall back to the helper on PATH with a polkit label. + run.command = ["bash", "-c", + 'mkdir -p "${0%/*}"\n' + + 'if [[ -f $1 && -x $2 ]]; then\n' + + ' exec pkexec "$2" enroll "$4" 2>"$0"\n' + + 'else\n' + + ' omarchy-shell -q omarchy.polkit expect "$3 enroll $4" "$5"\n' + + ' exec pkexec "$3" enroll "$4" 2>"$0"\n' + + 'fi', + logPath, policyPath, packagedHelper, helper, finger, reason] + } run.running = true } diff --git a/shell/plugins/polkit/PolkitModel.js b/shell/plugins/polkit/PolkitModel.js index 34ddd7541c98..27a358dec985 100644 --- a/shell/plugins/polkit/PolkitModel.js +++ b/shell/plugins/polkit/PolkitModel.js @@ -42,9 +42,14 @@ function matchesProgram(shown, want) { var clean = want.replace(/^\.\//, "") var bare = "/" + clean if (shown.slice(-bare.length) === bare && shown.slice(0, shown.length - bare.length).indexOf(" ") === -1) return true + if (shown.length !== 80 || shown.indexOf(" ... ") !== 38) return false + var head = shown.slice(0, 38) + var tail = shown.slice(-37) + if (bare.length < 37 || tail !== bare.slice(-37)) return false var wantExe = "/" + clean.split(" ")[0] - var shownExe = shown.split(" ")[0] - return shown.length === 80 && shown.indexOf(" ... ") === 38 && shownExe.slice(-wantExe.length) === wantExe && shown.slice(-37) === bare.slice(-37) + if (head.indexOf(" ") !== -1) return head.split(" ")[0].slice(-wantExe.length) === wantExe + var lastSlash = head.lastIndexOf("/") + return lastSlash !== -1 && wantExe.indexOf(head.slice(lastSlash)) === 0 } // A label a command asked for its next prompt (omarchy.polkit expect), when @@ -88,6 +93,9 @@ function authorizationLabel(message, tr, agentName) { // udisks formatting a drive, named as udisks names it. match = clean.match(/^Authentication is required to format (.+)$/i) if (match) return t("polkit.authorizeFormatting", "Authorize formatting of %1").replace("%1", function() { return match[1] }) + // Fingerprint setup policy message, translated through the shell catalog. + if (clean === "Set up fingerprint authentication") + return t("fingerprint.authorize", "Set up fingerprint authentication") return clean } diff --git a/test/shell.d/polkit-test.sh b/test/shell.d/polkit-test.sh index 40f86342b219..fbed79ef5049 100644 --- a/test/shell.d/polkit-test.sh +++ b/test/shell.d/polkit-test.sh @@ -36,6 +36,16 @@ assertEqual( 'Authentication is required to change system settings', 'polkit preserves custom authorization messages' ) +assertEqual( + polkit.authorizationLabel('Set up fingerprint authentication', key => key === 'fingerprint.authorize' ? 'Opsæt fingeraftryksgodkendelse' : key), + 'Opsæt fingeraftryksgodkendelse', + 'polkit translates the fingerprint setup policy message through the shell catalog' +) +assertEqual( + polkit.promptProgram('Set up fingerprint authentication'), + '', + 'fingerprint setup policy message hides the command line' +) const multilineSh = "Authentication is needed to run `/usr/bin/sh -c\nfor f in /sys/device ... [ -w \"$f\" ] && echo 1 > \"$f\"\ndone\n' as the super user" assertEqual( polkit.authorizationLabel(multilineSh), @@ -73,6 +83,20 @@ assertEqual(polkit.expectedLabel(cutPrompt, { program: longLine, label: 'Claude assertEqual(polkit.expectedLabel("Authentication is needed to run `/usr/bin/pacman -S valkey' as the super user", { program: 'pacman -S valkey', label: 'Install Valkey', until: 1000 }, 500), 'Install Valkey', 'a bare program name matches the resolved path in the prompt') assertEqual(polkit.expectedLabel("Authentication is needed to run `/usr/bin/unpacman -S valkey' as the super user", { program: 'pacman -S valkey', label: 'Install Valkey', until: 1000 }, 500), '', 'a bare program name does not match a different program suffix') assertEqual(polkit.expectedLabel("Authentication is needed to run `/usr/bin/echo /usr/bin/pacman -S valkey' as the super user", { program: 'pacman -S valkey', label: 'Install Valkey', until: 1000 }, 500), '', 'a bare program name does not match when appearing inside arguments') +const longExe = '/usr/share/omarchy/bin/omarchy-setup-security-fingerprint-enroll enroll right-index-finger' +const cutExePrompt = "Authentication is needed to run `" + longExe.slice(0, 38) + ' ... ' + longExe.slice(-37) + "' as the super user" +assertEqual( + polkit.expectedLabel(cutExePrompt, { program: 'omarchy-setup-security-fingerprint-enroll enroll right-index-finger', label: 'Set up fingerprint authentication', until: 1000 }, 500), + 'Set up fingerprint authentication', + 'a bare program name matches even when pkexec cuts inside the executable name' +) +const badPrefixExe = '/usr/share/omarchy/bin/unomarchy-setup-security-fingerprint-enroll enroll right-index-finger' +const cutBadPrefixPrompt = "Authentication is needed to run `" + badPrefixExe.slice(0, 38) + ' ... ' + badPrefixExe.slice(-37) + "' as the super user" +assertEqual( + polkit.expectedLabel(cutBadPrefixPrompt, { program: 'omarchy-setup-security-fingerprint-enroll enroll right-index-finger', label: 'Set up fingerprint authentication', until: 1000 }, 500), + '', + 'a bare program name cut inside the executable still rejects a different program prefix' +) assertEqual(polkit.promptProgram(pacman), '/usr/bin/pacman', 'a pkexec prompt names the program it runs, which a label never hides') assertEqual(polkit.promptProgram("Authentication is needed to run `/usr/bin/sh -c echo it's' as the super user"), "/usr/bin/sh -c echo it's", 'a command line holding a quote is read up to the quote that closes it') assertEqual(JSON.stringify(polkit.parseRequester('claude\tClaude\t0\n')), JSON.stringify({ mark: 'claude', name: 'Claude', light: false }), 'parseRequester reads mark, display name, and light flag')