Face unlock: a Howdy-style PAM module, shown in the password dialog and set up in Settings
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:
Claude committed 2026-11-26 01:19:29 +00:00
1 parent 0f71779819
commit 932fca627e
47 files changed
+2781 -29

No files matched your search

+1
View File
@@ -295,6 +295,7 @@ impl chandra::host::plasmoids::Host for State {
Req::Shortcut(code) => R::Shortcut(code),
Req::DefaultApp(code) => R::DefaultApp(code),
Req::SetDesktop(i) => R::SetDesktop(i),
Req::FaceUnlock(code) => R::FaceUnlock(code),
})
}
+53 -1
View File
@@ -73,6 +73,9 @@ pub enum Req {
DefaultApp(i32),
/// `wallpaper.set-desktop`: an index into the desktops table.
SetDesktop(i32),
/// A face-unlock request: a face index removes it; -1 refresh, -2 enroll, -3 / -4 stop /
/// start using it.
FaceUnlock(i32),
}
pub const T_APPS: usize = 0;
@@ -96,11 +99,15 @@ pub const T_APP_CATS: usize = 11;
pub const T_APP_CHOICES: usize = 12;
/// What can fill the desktop (s): name, behind `wallpaper.desktops`.
pub const T_DESKTOPS: usize = 20;
/// Face unlock status, one row (sssiii): problem howdy message installed in-use busy.
pub const T_FACE_STATUS: usize = 24;
/// Enrolled faces (ss): label added.
pub const T_FACES: usize = 25;
/// Host data every module reads from, shared by all loaded modules.
#[derive(Default)]
pub struct Shared {
pub tables: [Vec<u8>; 21],
pub tables: [Vec<u8>; 26],
pub layout_mode: i32,
pub wallpaper: i32,
/// What fills the desktop (an index into the desktops table).
@@ -366,6 +373,51 @@ impl d::wallpaper::Host for PState {
}
}
impl d::face_unlock::Host for PState {
fn status(&mut self) -> d::face_unlock::FaceStatus {
let rows = self.rows(T_FACE_STATUS, "sssiii");
match rows.first() {
Some(r) if r.len() == 6 => d::face_unlock::FaceStatus {
problem: s(&r[0]),
howdy: s(&r[1]),
message: s(&r[2]),
installed: i(&r[3]) != 0,
in_use: i(&r[4]) != 0,
busy: i(&r[5]) != 0,
},
_ => d::face_unlock::FaceStatus {
problem: String::new(),
howdy: String::new(),
message: String::new(),
installed: false,
in_use: false,
busy: false,
},
}
}
fn faces(&mut self) -> Vec<d::face_unlock::Face> {
self.rows(T_FACES, "ss")
.iter()
.filter(|r| r.len() == 2)
.map(|r| d::face_unlock::Face { label: s(&r[0]), added: s(&r[1]) })
.collect()
}
fn enroll(&mut self) {
self.shared.borrow_mut().requests.push_back(Req::FaceUnlock(-2));
}
fn remove(&mut self, index: u32) {
if index < 1000 {
self.shared.borrow_mut().requests.push_back(Req::FaceUnlock(index as i32));
}
}
fn set_in_use(&mut self, on: bool) {
self.shared.borrow_mut().requests.push_back(Req::FaceUnlock(if on { -4 } else { -3 }));
}
fn refresh(&mut self) {
self.shared.borrow_mut().requests.push_back(Req::FaceUnlock(-1));
}
}
impl d::power::Host for PState {
fn screen_off_minutes(&mut self) -> u32 {
self.shared.borrow().screen_off_min