Face unlock: a Howdy-style PAM module, shown in the password dialog and set up in Settings
CI / test (push) Successful in 2m6s
CI / test (push) Successful in 2m6s
- face/pam_chandra_face.so (`-auth sufficient`): runs `chandra-face compare` as root with a clean
environment, forwards what it says as PAM_TEXT_INFO / PAM_ERROR_MSG, and maps its exit status
to success / auth error / unavailable, so the password always still works. Skips remote
sessions (PAM_RHOST, SSH_CONNECTION), a closed lid and users without faces; refuses a helper
that isn't root's; kills one that hangs (timeout + 6 s).
- face/chandra-face (Python + OpenCV): YuNet finds the face, SFace embeds it, cosine similarity
against the enrolled embeddings (threshold 0.42, two matching frames, dark IR warm-up frames
skipped, optional require_ir). enroll / list / remove / clear / test / status / pam
enable|disable / fetch-models (sha256-pinned opencv_zoo models). Embeddings only, in
/var/lib/chandra-face/USER/faces.json (root, 0600); labels in faces.list (0644). Store, config
and models must be root's and not writable by others. Root commands re-run through run0 (or
pkexec), so polkit asks first. Settings in /etc/chandra/face.conf.
- `just install-face [--pam]`, `just uninstall-face [--purge]` (face/install.py; uninstall takes
the module out of every PAM service first). `pam enable` inserts before the first auth or
@include line (Debian's sudo has only @include common-auth), keeping a .bak.
- Password dialog: a face row ("Looking for your face…" with a sweeping ring, "Face
recognized", or why not, "Type your password instead"); typing and Enter during the scan go in
when PAM asks for the password. Howdy's pam_howdy.so messages are understood too.
- Settings > Session > Face unlock: "Use my face for passwords" (polkit-1 + sudo), the enrolled
faces (Remove takes a second click), "Add a face…", and the tool's progress. New `face-unlock`
capability: tables 24 (status) and 25 (faces), request 44, in the wasmer/wasmtime stub, the Rust
host, the MoonBit wasmhost and chandra:host/plasmoids. compositor/shell/face.mbt runs the tool
on a socket so the compositor never waits.
- Tests: face/test_face.py (fake camera of PGM frames + fake recognizer; --pam builds the module
and runs it through pamtester), dialog states and message parsing (polkit_test), the dialog via
a mock helper (auth_test, shots 14/15), Settings against a fake chandra-face (face_test).
scripts/test.sh runs them (compositor/polkit was missing from its native list), CI installs
libpam0g-dev + pamtester. Also regenerated two stale desktop-module bindings (doc comments).
- docs/face-unlock.md, including the limits of 2D face recognition.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hhiJfJNAYqWzQiuKMf
This commit is contained in:
47 files changed
+2781
-29
No files matched your search
@@ -8,6 +8,7 @@ import {
|
||||
"chandra/desktop/interface/chandra/desktop/system" @system,
|
||||
"chandra/desktop/interface/chandra/desktop/shortcuts" @shortcuts,
|
||||
"chandra/desktop/interface/chandra/desktop/default-apps" @default_apps,
|
||||
"chandra/desktop/interface/chandra/desktop/face-unlock" @face_unlock,
|
||||
"chandra/desktop/lib/ui" @ui,
|
||||
}
|
||||
|
||||
|
||||
@@ -94,6 +94,27 @@ enum Row {
|
||||
AppKind(Int, String, @default_apps.AppChoice?, String, Int)
|
||||
/// One of a kind's apps, listed under it while it is expanded: the kind, its index there, the app.
|
||||
AppOption(Int, Int, @default_apps.AppChoice)
|
||||
/// Face unlock's switch: the password dialog and sudo try the face first.
|
||||
FaceUse
|
||||
/// An enrolled face: its index, label and when it was added (a second click removes it).
|
||||
FaceRow(Int, String, String)
|
||||
/// "Add a face..."
|
||||
FaceAdd
|
||||
}
|
||||
|
||||
///| An on/off switch at the right end of a row centred on `mid`: an accent track with the knob
|
||||
/// on the right when on, a muted outline when off.
|
||||
fn switch_ops(w : Int, mid : Int, on : Bool, p : @theme.Palette, ops : Array[@types.DrawOp]) -> Unit {
|
||||
let sx = w - margin - 10 - switch_w
|
||||
let sy = mid - switch_h / 2
|
||||
let knob = switch_h / 2 - 3
|
||||
if on {
|
||||
ops.push(@ui.fill_rect(@ui.rect(sx, sy, switch_w, switch_h), p.accent, radius=switch_h / 2))
|
||||
ops.push(@ui.circle(sx + switch_w - switch_h / 2, mid, knob, p.accent_foreground))
|
||||
} else {
|
||||
ops.push(@ui.stroke_rect(@ui.rect(sx, sy, switch_w, switch_h), p.foreground_muted, width=1, radius=switch_h / 2))
|
||||
ops.push(@ui.circle(sx + switch_h / 2, mid, knob, p.foreground_muted))
|
||||
}
|
||||
}
|
||||
|
||||
///| Width of the "Reset" button at the end of a changed shortcut's row.
|
||||
@@ -190,6 +211,7 @@ fn rows() -> Array[Row] {
|
||||
for i = 0; i < names.length(); i = i + 1 {
|
||||
rs.push(Setting(i, names[i]))
|
||||
}
|
||||
face_rows(rs)
|
||||
}
|
||||
1 => {
|
||||
rs.push(Heading("On the desktop"))
|
||||
@@ -282,6 +304,36 @@ fn rows() -> Array[Row] {
|
||||
rs
|
||||
}
|
||||
|
||||
///| Face unlock's rows on the Session tab (docs/face-unlock.md): the switch, the enrolled faces,
|
||||
/// "Add a face..." and what the last change said. Changes ask for the password first.
|
||||
fn face_rows(rs : Array[Row]) -> Unit {
|
||||
let st = @face_unlock.status()
|
||||
rs.push(Heading("Face unlock"))
|
||||
if !st.installed {
|
||||
rs.push(Info("Not installed: see docs/face-unlock.md"))
|
||||
return
|
||||
}
|
||||
if st.problem != "" {
|
||||
rs.push(Info("! " + st.problem))
|
||||
}
|
||||
if st.howdy != "" {
|
||||
rs.push(Info("Howdy also unlocks " + st.howdy))
|
||||
}
|
||||
rs.push(FaceUse)
|
||||
for i, f in @face_unlock.faces() {
|
||||
rs.push(FaceRow(i, f.label, f.added))
|
||||
}
|
||||
rs.push(FaceAdd)
|
||||
if st.message != "" {
|
||||
rs.push(Info(st.message))
|
||||
}
|
||||
}
|
||||
|
||||
///| `armed` value for "click again to remove" on face `i`.
|
||||
fn face_armed(i : Int) -> Int {
|
||||
100 + i
|
||||
}
|
||||
|
||||
///| Whether row `i` of `rs` can be highlighted and acted on (headings can't).
|
||||
fn active(rs : Array[Row], i : Int) -> Bool {
|
||||
i >= 0 && i < rs.length() && !(rs[i] is (Heading(_) | Info(_) | Category(_) | NothingToAdd))
|
||||
@@ -403,6 +455,10 @@ let hover_btn : Ref[Int] = { val: -1 }
|
||||
fn set_tab(i : Int) -> Unit {
|
||||
cancel_capture()
|
||||
expanded.val = -1
|
||||
if i == 0 {
|
||||
// Faces may have been added or removed elsewhere (chandra-face, another session).
|
||||
@face_unlock.refresh()
|
||||
}
|
||||
if i == 5 && tab.val != 5 {
|
||||
// Another program may have changed a default since the tab was last open.
|
||||
@default_apps.refresh()
|
||||
@@ -457,6 +513,17 @@ fn act(rs : Array[Row], i : Int, btn~ : Int = -1, x~ : Int = 0) -> Unit {
|
||||
armed.val = a
|
||||
}
|
||||
Info(_) => ()
|
||||
FaceUse =>
|
||||
if !@face_unlock.status().busy {
|
||||
@face_unlock.set_in_use(!@face_unlock.status().in_use)
|
||||
}
|
||||
FaceRow(k, _, _) =>
|
||||
if was_armed == face_armed(k) {
|
||||
@face_unlock.remove(k.reinterpret_as_uint())
|
||||
} else {
|
||||
armed.val = face_armed(k)
|
||||
}
|
||||
FaceAdd => if !@face_unlock.status().busy { @face_unlock.enroll() }
|
||||
Shortcut(k, sc) =>
|
||||
if sc.capturing {
|
||||
@shortcuts.cancel_capture()
|
||||
@@ -600,7 +667,7 @@ pub fn popup() -> PopupSurface? {
|
||||
match rs[i] {
|
||||
Heading(_) | Category(_) | NothingToAdd | Browse => ()
|
||||
// Rows with their own buttons get the soft fill, so the buttons stand out.
|
||||
Setting(_, _) | Loaded(_, _, _, _) | Available(_, _, _, _) =>
|
||||
Setting(_, _) | FaceUse | Loaded(_, _, _, _) | Available(_, _, _, _) =>
|
||||
if hot {
|
||||
ops.push(@ui.fill_rect(@ui.rect(margin, y, w - 2 * margin, rh - 2), p.surface_hover, radius=r))
|
||||
}
|
||||
@@ -616,18 +683,30 @@ pub fn popup() -> PopupSurface? {
|
||||
NothingToAdd => ops.push(@ui.text(margin + 10, mid, "Everything is in the panel", fs - 2, p.foreground_muted))
|
||||
Setting(k, name) => {
|
||||
ops.push(@ui.text(margin + 10, mid, name, fs - 1, p.foreground))
|
||||
// The switch: an accent track with the knob on the right when on, a muted outline when off.
|
||||
let on = @settings.is_on(k.reinterpret_as_uint())
|
||||
let sx = w - margin - 10 - switch_w
|
||||
let sy = mid - switch_h / 2
|
||||
let knob = switch_h / 2 - 3
|
||||
if on {
|
||||
ops.push(@ui.fill_rect(@ui.rect(sx, sy, switch_w, switch_h), p.accent, radius=switch_h / 2))
|
||||
ops.push(@ui.circle(sx + switch_w - switch_h / 2, mid, knob, p.accent_foreground))
|
||||
} else {
|
||||
ops.push(@ui.stroke_rect(@ui.rect(sx, sy, switch_w, switch_h), p.foreground_muted, width=1, radius=switch_h / 2))
|
||||
ops.push(@ui.circle(sx + switch_h / 2, mid, knob, p.foreground_muted))
|
||||
}
|
||||
switch_ops(w, mid, @settings.is_on(k.reinterpret_as_uint()), p, ops)
|
||||
}
|
||||
FaceUse => {
|
||||
let st = @face_unlock.status()
|
||||
ops.push(@ui.text(margin + 10, mid, "Use my face for passwords", fs - 1, p.foreground))
|
||||
switch_ops(w, mid, st.in_use, p, ops)
|
||||
}
|
||||
FaceRow(k, label, added) => {
|
||||
// A face glyph, the label and date; "Remove" at the right (a second click removes).
|
||||
let gx = margin + 18
|
||||
ops.push(@ui.circle(gx, mid, 7, list_fg, filled=false))
|
||||
ops.push(@ui.circle(gx - 3, mid - 2, 1, list_fg))
|
||||
ops.push(@ui.circle(gx + 3, mid - 2, 1, list_fg))
|
||||
ops.push(@ui.line(gx - 3, mid + 3, gx + 3, mid + 3, list_fg, width=1))
|
||||
ops.push(@ui.text(margin + 32, mid, label, fs - 1, list_fg))
|
||||
let lw = @ui.text_width(label, fs - 1)
|
||||
ops.push(@ui.text(margin + 40 + lw, mid, "added " + added, fs - 3, if hot { list_fg } else { p.foreground_muted }))
|
||||
let armed_here = armed.val == face_armed(k)
|
||||
let rlabel = if armed_here { "Click again to remove" } else { "Remove" }
|
||||
ops.push(@ui.text(w - margin - 10, mid, rlabel, fs - 2, if hot { list_fg } else { p.accent }, align=RIGHT, bold=armed_here))
|
||||
}
|
||||
FaceAdd => {
|
||||
let busy = @face_unlock.status().busy
|
||||
ops.push(@ui.text(margin + 10, mid, if busy { "Working…" } else { "Add a face…" }, fs - 1, if busy && !hot { p.foreground_muted } else { list_fg }, bold=true))
|
||||
}
|
||||
DesktopChoice(k, name) => {
|
||||
if k == cur_desk {
|
||||
|
||||
Reference in new issue
Block a user