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

@@ -0,0 +1,4 @@
Face unlock (docs/face-unlock.md): the session user's enrolled faces and whether the password
dialog and sudo try the face first. Every change runs chandra-face through run0 or pkexec, so
polkit asks for an administrator's password before anything happens; the module never sees a
camera picture or any face data, only labels.
@@ -0,0 +1,46 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
fn wasmImportStatus(p0 : Int) = "chandra:desktop/face-unlock@0.1.0" "status"
///|
fn wasmImportFaces(p0 : Int) = "chandra:desktop/face-unlock@0.1.0" "faces"
///|
fn wasmImportEnroll() = "chandra:desktop/face-unlock@0.1.0" "enroll"
///|
fn wasmImportRemove(p0 : Int) = "chandra:desktop/face-unlock@0.1.0" "remove"
///|
fn wasmImportSetInUse(p0 : Int) = "chandra:desktop/face-unlock@0.1.0" "set-in-use"
///|
fn wasmImportRefresh() = "chandra:desktop/face-unlock@0.1.0" "refresh"
///|
extern "wasm" fn mbt_ffi_load8_u(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load8_u)
///|
extern "wasm" fn mbt_ffi_free(position : Int) =
#|(func (param i32) local.get 0 call $moonbit.decref)
///|
extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
#|(func (param i32) (result i32) (local i32)
#| local.get 0 i32.const 4 i32.add call $moonbit.gc.malloc
#| local.tee 1 i32.const 0 call $moonbit.init_array8
#| local.get 1)
///|
extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load)
///|
extern "wasm" fn mbt_ffi_ptr2str(ptr : Int, len : Int) -> String =
#|(func (param i32) (param i32) (result i32)
#| local.get 0
#| local.get 1 call $moonbit.init_array16
#| local.get 0)
@@ -0,0 +1 @@
warnings = "-44"
@@ -0,0 +1,36 @@
// Generated using `moon info`, DON'T EDIT IT
package "chandra/desktop/interface/chandra/desktop/face-unlock"
// Values
pub fn enroll() -> Unit
pub fn faces() -> Array[Face]
pub fn refresh() -> Unit
pub fn remove(UInt32) -> Unit
pub fn set_in_use(Bool) -> Unit
pub fn status() -> FaceStatus
// Errors
// Types and methods
pub(all) struct Face {
label : String
added : String
}
pub(all) struct FaceStatus {
problem : String
howdy : String
message : String
installed : Bool
in_use : Bool
busy : Bool
}
// Type aliases
// Traits
@@ -0,0 +1,77 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
pub(all) struct FaceStatus {
problem : String; howdy : String; message : String; installed : Bool; in_use : Bool; busy : Bool
}
///|
pub(all) struct Face {
label : String; added : String
}
///|
pub fn status() -> FaceStatus {
let return_area = mbt_ffi_malloc(28)
wasmImportStatus(return_area);
let result = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 0), mbt_ffi_load32((return_area) + 4))
let result0 = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 8), mbt_ffi_load32((return_area) + 12))
let result1 = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 16), mbt_ffi_load32((return_area) + 20))
let ret = FaceStatus::{problem : result, howdy : result0, message : result1, installed : (mbt_ffi_load8_u((return_area) + 24) != 0), in_use : (mbt_ffi_load8_u((return_area) + 25) != 0), busy : (mbt_ffi_load8_u((return_area) + 26) != 0)}
mbt_ffi_free(return_area)
return ret
}
///|
/// The enrolled faces, oldest first.
pub fn faces() -> Array[Face] {
let return_area = mbt_ffi_malloc(8)
wasmImportFaces(return_area);
let array : Array[Face] = [];
for index = 0; index < (mbt_ffi_load32((return_area) + 4)); index = index + 1 {
let iter_base = (mbt_ffi_load32((return_area) + 0)) + (index * 16)
let result = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4))
let result0 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12))
array.push(Face::{label : result, added : result0})
}
mbt_ffi_free(mbt_ffi_load32((return_area) + 0))
let ret = array
mbt_ffi_free(return_area)
return ret
}
///|
/// Add a face: after the password, the camera looks for about ten seconds.
pub fn enroll() -> Unit {
wasmImportEnroll();
}
///|
/// Forget face `index` of `faces`.
pub fn remove(index : UInt) -> Unit {
wasmImportRemove((index).reinterpret_as_int());
}
///|
/// Try the face first in the password dialog and sudo, or stop.
pub fn set_in_use(on : Bool) -> Unit {
wasmImportSetInUse((if on { 1 } else { 0 }));
}
///|
/// Read the status and the faces again.
pub fn refresh() -> Unit {
wasmImportRefresh();
}
@@ -122,6 +122,7 @@ pub(all) enum Request {
ReloadSession
DefaultApp(Int32)
SetDesktop(Int32)
FaceUnlock(Int32)
}
pub(all) struct SettingChange {
+5
View File
@@ -62,6 +62,7 @@ pub(all) enum Request {
ReloadSession
DefaultApp(Int)
SetDesktop(Int)
FaceUnlock(Int)
}
///|
/// A native file-chooser dialog (zenity on the host session) for "Add widget".
@@ -624,6 +625,10 @@ pub fn next_request() -> Request? {
Request::SetDesktop(mbt_ffi_load32((return_area) + 8))
}
20 => {
Request::FaceUnlock(mbt_ffi_load32((return_area) + 8))
}
_ => panic()
}