Cadence: Privacy-Preserving Continuous Authentication via Keystroke Dynamics
Traditional password-based authentication only verifies who you are at the exact moment of login. Once an active session is established, modern operating systems implicitly trust every input device until the screen is manually locked or a system timeout occurs.
Cadence is an open-source, continuous authentication system designed for Linux. Operating as a background daemon written in Rust, it analyzes behavioral typing rhythms in real time to ensure the active user matches the authenticated session profile—all while enforcing strict privacy invariants.
Technical Architecture & Threat Model
Unlike conventional telemetry collectors, Cadence treats keystroke logging as a primary security risk. The system is designed to operate under a strict Zero-Disk / Zero-Text invariant: raw key identity values are stripped at the kernel boundary, leaving only non-identifying temporal metadata.
+-------------------------------------------------------------+ | Linux Kernel Subsystem | | /dev/input/event* (evdev) | +------------------------------+------------------------------+ | Raw EV_KEY events v +-------------------------------------------------------------+ | Rust Background Daemon | | 1. Category Bucketing -> Strip ASCII values | | 2. Feature Extraction -> Measure Dwell ($D$) & Flight ($F$) | | 3. Streaming Engine -> Welford's Algorithm & Z-Scores | +------------------------------+------------------------------+ | Anomaly Threshold Exceeded v +-------------------------------------------------------------+ | Enforcement Pipeline | | - Progressive Alert -> Non-blocking D-Bus notification | | - Session Lock-Down -> Trigger PAM / loginctl | | - Out-of-Band Audit -> Send encrypted alert to Android | +-------------------------------------------------------------+
Core Design Rules
Low-Level Ingestion: Binds directly to Linux
/dev/input/event*nodes usingevdev.Category Mapping: Maps physical scancodes into generalized functional buckets (
ALPHA,NUMERIC,MODIFIER,SPACE_ENTER) to obscure actual text.In-Memory Volatility: All temporal feature vectors and streaming metrics reside exclusively in volatile RAM.
Statistical Modeling & Feature Extraction
Instead of training heavy black-box deep learning models locally, Cadence evaluates typing cadence using lightweight streaming statistics. The daemon calculates two primary timing variables across a rolling buffer of size :
Dwell Time (): The duration between a key press event and its corresponding release event .
Flight Time ( ): The duration between releasing key and pressing key .
To establish baseline statistics without storing entire timing histories in memory, Cadence implements Welford's Algorithm to update the running mean and variance in time:
An anomaly score is continually evaluated across the composite vector using normalized distance calculations:
Note on Noise Suppression: Pauses exceeding $2.0$ seconds (e.g., stopping to read or take a break) are automatically clamped by the pre-processor to prevent skewing the standard deviation of standard typing cadence.
Implementation Sample: Safe Ingestion
The snippet below illustrates how low-level input timing is decoupled from key identity inside the Rust ingestion task:
use evdev::{Device, InputEventKind, Key};
use std::time::Instant;
pub struct TimingSample {
pub category: KeyCategory,
pub duration_micros: u64,
}
pub fn process_event(event_kind: InputEventKind, last_press: &mut Option<Instant>) -> Option<u64> {
match event_kind {
InputEventKind::Key(_) => {
let now = Instant::now();
if let Some(press_time) = *last_press {
let flight_time = now.duration_since(press_time).as_micros() as u64;
*last_press = Some(now);
Some(flight_time)
} else {
*last_press = Some(now);
None
}
}
_ => None,
}
}Session Enforcement & Out-of-Band Audit
When the rolling anomaly score exceeds the established threshold across consecutive windows, Cadence initiates a progressive lockdown sequence:
User Verification Prompt: A localized system notification requests quick PAM authentication.
Fail-Closed Lockdown: If unverified within 10 seconds or if authentication fails,
loginctl lock-sessionis triggered immediately.Out-of-Band Push Notification: An encrypted payload is dispatched to a self-hostable relay, notifying an Android companion app that an unauthorized access attempt was blocked locally.
By enforcing authentication locally on the machine while using remote channels strictly for auditing, Cadence ensures physical security without introducing network-based bypass vectors.