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

+10
View File
@@ -331,6 +331,10 @@ pub(all) enum HostTable {
AppChoices
/// What can fill the desktop (s: name), served by `wallpaper.desktops`.
Desktops
/// Face unlock status (sssiii: problem howdy message installed in-use busy; one row).
FaceStatus
/// Enrolled faces (ss: label added).
Faces
}
///|
@@ -359,6 +363,8 @@ pub fn publish(which : HostTable, t : Table) -> Unit {
AppCategories => 11U
AppChoices => 12U
Desktops => 20U
FaceStatus => 24U
Faces => 25U
}
// Most tables are republished every frame unchanged: skip the copy into the host then.
let slot = id.reinterpret_as_int()
@@ -446,6 +452,9 @@ pub(all) enum HostRequest {
ReloadSession
/// The wallpaper capability's `set-desktop`: an index into the Desktops table.
SetDesktop(Int)
/// The face-unlock capability: a face index removes it; -1 refresh, -2 enroll, -3 / -4 stop /
/// start using it for the password dialog and sudo.
FaceUnlock(Int)
} derive(Eq, Debug)
///|
@@ -472,6 +481,7 @@ pub fn next_request() -> HostRequest? {
Some(DefaultApp(code)) => Some(DefaultApp(code))
Some(ReloadSession) => Some(ReloadSession)
Some(SetDesktop(i)) => Some(SetDesktop(i))
Some(FaceUnlock(i)) => Some(FaceUnlock(i))
}
}
+10
View File
@@ -739,6 +739,10 @@ pub(all) enum HostTable {
AppChoices
/// What can fill the desktop (s: name), served by `wallpaper.desktops`.
Desktops
/// Face unlock status (sssiii: problem howdy message installed in-use busy; one row).
FaceStatus
/// Enrolled faces (ss: label added).
Faces
}
///| Publish `t` as the data behind `which` for every module's next call.
@@ -758,6 +762,8 @@ pub fn publish(which : HostTable, t : Table) -> Unit {
AppCategories => 11
AppChoices => 12
Desktops => 20
FaceStatus => 24
Faces => 25
}
let out : Array[Byte] = []
for k = 0; k < 4; k = k + 1 {
@@ -844,6 +850,9 @@ pub(all) enum HostRequest {
ReloadSession
/// The wallpaper capability's `set-desktop`: an index into the Desktops table.
SetDesktop(Int)
/// The face-unlock capability: a face index removes it; -1 refresh, -2 enroll, -3 / -4 stop /
/// start using it for the password dialog and sudo.
FaceUnlock(Int)
} derive(Eq, Debug)
///|
@@ -886,6 +895,7 @@ pub fn next_request() -> HostRequest? {
18 => Some(Shortcut(c_host_req_int()))
19 => Some(DefaultApp(c_host_req_int()))
40 => Some(SetDesktop(c_host_req_int()))
44 => Some(FaceUnlock(c_host_req_int()))
_ => None
}
}
+18 -2
View File
@@ -66,7 +66,8 @@ enum {
K_NET_SET_AIRPLANE,
K_SC_LIST, K_SC_CAPTURE, K_SC_CANCEL, K_SC_RESET, K_SC_RESET_ALL,
K_DA_CATS, K_DA_APPS, K_DA_SET, K_DA_REFRESH,
K_DESKTOPS, K_DESKTOP_CUR, K_SET_DESKTOP
K_DESKTOPS, K_DESKTOP_CUR, K_SET_DESKTOP,
K_FU_STATUS, K_FU_FACES, K_FU_ENROLL, K_FU_REMOVE, K_FU_SET_IN_USE, K_FU_REFRESH
};
typedef struct Env { Inst *inst; int kind; } Env;
@@ -75,7 +76,7 @@ typedef struct Env { Inst *inst; int kind; } Env;
enum { T_APPS, T_WINDOWS, T_LAYOUTS, T_MODULES, T_INSTANCES, T_WALLPAPERS, T_SESSION_SETTINGS, T_ICONS,
T_NET_STATUS, T_NET_NETWORKS, T_SHORTCUTS, T_APP_CATS, T_APP_CHOICES,
/* fixed numbers from here (wit/host/plasmoids.wit publish-table) */
T_DESKTOPS = 20, T_N = 32 };
T_DESKTOPS = 20, T_FACE_STATUS = 24, T_FACES = 25, T_N = 32 };
typedef struct { uint8_t *data; size_t len; } Blob;
static Blob tables[T_N];
static int32_t host_ints[24] = {[7] = -1}; /* 0 layout mode, 1 inspector on, 2 current wallpaper, 3 session settings on (bit i: row i),
@@ -387,6 +388,15 @@ static wasm_trap_t *host_import(void *env, const wasm_val_vec_t *args, wasm_val_
if (results->size >= 1) results->data[0] = (wasm_val_t)WASM_I32_VAL(host_ints[20]);
break;
case K_SET_DESKTOP: push_req(40, a0, NULL); break;
/* Face unlock: status from table 24 (problem howdy message installed in-use busy), faces from
* table 25 (label added); request 44 is a face index to remove, or -1 refresh, -2 enroll,
* -3 / -4 stop / start using it. */
case K_FU_STATUS: build_record(in, T_FACE_STATUS, "sssbbb", a0); break;
case K_FU_FACES: build_list(in, T_FACES, "ss", a0); break;
case K_FU_ENROLL: push_req(44, -2, NULL); break;
case K_FU_REMOVE: if (a0 >= 0 && a0 < 1000) push_req(44, a0, NULL); break;
case K_FU_SET_IN_USE: push_req(44, a0 ? -4 : -3, NULL); break;
case K_FU_REFRESH: push_req(44, -1, NULL); break;
case K_SESSION_SET: push_req(a1 ? 11 : 10, a0, NULL); break; /* 10 off, 11 on */
/* Request 12 carries the screenshot code: 0-3 take, 10-12 record, 20 stop, 30/31 pointer. */
case K_SHOT_TAKE: if (a0 >= 0 && a0 <= 3) push_req(12, a0, NULL); break;
@@ -604,6 +614,12 @@ static int classify_import(const wasm_name_t *m, const wasm_name_t *f) {
if (!strcmp(iface, "wallpaper") && !strcmp(fn, "desktops")) return K_DESKTOPS;
if (!strcmp(iface, "wallpaper") && !strcmp(fn, "current-desktop")) return K_DESKTOP_CUR;
if (!strcmp(iface, "wallpaper") && !strcmp(fn, "set-desktop")) return K_SET_DESKTOP;
if (!strcmp(iface, "face-unlock") && !strcmp(fn, "status")) return K_FU_STATUS;
if (!strcmp(iface, "face-unlock") && !strcmp(fn, "faces")) return K_FU_FACES;
if (!strcmp(iface, "face-unlock") && !strcmp(fn, "enroll")) return K_FU_ENROLL;
if (!strcmp(iface, "face-unlock") && !strcmp(fn, "remove")) return K_FU_REMOVE;
if (!strcmp(iface, "face-unlock") && !strcmp(fn, "set-in-use")) return K_FU_SET_IN_USE;
if (!strcmp(iface, "face-unlock") && !strcmp(fn, "refresh")) return K_FU_REFRESH;
if (!strcmp(iface, "session-settings") && !strcmp(fn, "settings")) return K_SESSION_SETTINGS;
if (!strcmp(iface, "session-settings") && !strcmp(fn, "is-on")) return K_SESSION_IS_ON;
if (!strcmp(iface, "session-settings") && !strcmp(fn, "set-setting")) return K_SESSION_SET;
+1
View File
@@ -243,6 +243,7 @@ test "the settings module's Panel tab lists host modules and asks to load, move,
ignore(p.on_event(true, PointerDown(20, 190))) // add the moon
ignore(p.on_event(true, PointerDown(160, 285))) // browse
assert_eq(drain(), [
FaceUnlock(-1), // opening on the Session tab reads the face unlock status
MoveInstance("w1", 1),
UnloadInstance("w2"),
LoadModule("/m/moon-disc.wasm"),