Skip to content

App: lock tinyclient behind Touch ID, Windows Hello, a fingerprint or a passcode - #836

Closed
itz4blitz wants to merge 1 commit into
mainfrom
issue/751-screen-lock
Closed

itz4blitz wants to merge 1 commit into
mainfrom
issue/751-screen-lock

Conversation

@itz4blitz

Copy link
Copy Markdown
Collaborator

What changed and why

Settings › Privacy can lock the window after it has been left for a minute, five minutes, or an hour, and when the screen locks. While that lock is held the window draws only the lock screen. A message notification says "New message" with no sender or text, and Reply is refused. A ring can still be answered. Unlock uses the device-approval prompt. On Linux, where that prompt is not available, a passphrase is kept as a hash in the window prefs. Android sets FLAG_SECURE while the lock is armed. iOS draws an opaque cover when the scene resigns active. The caption says this covers the window and does not encrypt messages or sign-ins.

Tested with cargo test -p tinyclient --features gui --bins (646 passed, 2 ignored). One test failed because a named pipe was unavailable. That test is not in this diff. cargo test -p chatd --lib an_app_lock_names passed. cargo clippy -p tinyclient --features gui --all-targets still fails in composer/edit.rs on an empty range this change does not touch. The prove runs in the desktop binary when TINYCLIENT_PROVE=screen-lock is set. A build without that arm opens the window and the driver fails.

Not tested: a live fingerprint, face, or PIN prompt; a live notification; the lock screen drawn in a window. Android and iOS sources are in this diff and were not compiled here.

Type

  • feature
  • fix
  • perf
  • refactor
  • chore
  • docs

Platforms

  • windows
  • macos
  • linux
  • android
  • ios

Proof

Scenario: e2e/scenarios/screen-lock

Lab run:

Compatibility

No protocol change. shell.prefs may grow lock_away, lock_screen, lock_salt, and lock_hash lines. An older build keeps lines it does not know. Chatd reads a file named shell-lock that the window writes while the lock is held.

Risk and rollback

The lock only hides the window. The caption says so. Turning the setting off clears the cover. Revert this change to remove it.

Release note

The window can cover itself after you leave it, or when the screen locks, and a notification then says only "New message".

Closes #751

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Tiny Code Review

⚠️ Code review unavailable · run

the AI provider rate-limited the request

This is advice, not a gate. Re-run with the agent:review label or a /review comment.

@unRekable unRekable left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

🟡 4 findings (3 blocking).

The lock covers the Shell window, redacts chatd's notifications behind a shell-lock file, and keeps the honest 'this does not encrypt' caption; the notification and reply gating in chatd is right. It fails as an authentication gate: a policy change from the separate Settings window clears a held lock with no prompt, and the keyboard still reaches the composer and the action bindings while the cover is up. With 'When the screen locks' on, every rendered frame also blocks the main thread on a loginctl subprocess. The design is worth keeping; the gate around it is not closed yet.

Residual risk

  • The Linux passphrase verifier is a single SHA-256 over a 16-byte hex salt in shell.prefs; anyone who can read that file can brute-force a weak passphrase at full hash speed. A memory-hard KDF would slow that, though the same read access could also delete the hash, and the lock claims no encryption.
  • fresh_salt() falls back to SystemTime nanos when both /dev/urandom and BCryptGenRandom fail, which makes that launch's salt predictable.
  • The desktop_helper child killed at the 120-second deadline is never waited on after the kill, so a long-lived Unix session collects one zombie per timeout.
  • chatd trusts a shell-lock file in the support dir, so any process running as the same user can set or clear the lock bit; that is within the cover-only threat model the caption states.

Comment thread crates/tinyclient/src/gui/lock.rs Outdated
with_live(|live| {
live.session.policy = policy;
if !live.session.policy.can_arm() {
live.session.held = false;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Blocker: A policy change unlocks a held lock with no authentication. The Settings window is a separate gpui window (cx.open_window in settings/mod.rs) that the Shell cover never covers, and the Settings keybinding still fires while held because the early-return root keeps its key listeners. So with the cover up, choosing Lock › Off — or Reset all — reaches set_lock/set_policy and this line clears held, dropping the cover and the chatd redaction without any prompt. Keep held when it is already set: only clear it when the session was not held, and let the new policy take effect at the next lock.

Comment thread crates/tinyclient/src/gui/layout.rs Outdated
super::phone::set_active(phone_form);
super::phone::tokens::set_landscape(phone_form && viewport.width > viewport.height);
super::lock::tick();
if super::lock::held() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Blocker: The cover blocks only the mouse. The root is still built with self.keys(...), so the window's key listeners and action bindings stay active in this early return, and nothing takes focus, so the composer or the sidebar keeps the focus it had when the lock engaged. Typed characters keep reaching the composer and Return still sends, and the Settings binding still opens the separate settings window; the lock stays drivable from the keyboard while it is held. When held, focus a FocusHandle on the cover here and swallow keys that are not the unlock input.


/// Covers the window once the policy says so. Called from the frame.
pub fn tick() {
let screen = screen_is_locked();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Blocker: tick() runs from the frame (Shell::render calls it on every redraw), and with 'When the screen locks' on this reaches os_screen_locked, which on Linux spawns loginctl and blocks until it exits — a subprocess wait per rendered frame on the window's main thread, and on macOS a WindowServer XPC round trip per frame. Poll the OS off the main thread at most about once a second and hand tick the cached answer.

Comment thread crates/tinyclient/src/gui/lock.rs Outdated
let path = protocol::support_dir().join("shell-lock");
if held {
let _ = std::fs::create_dir_all(protocol::support_dir());
let _ = std::fs::write(path, b"1\n");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Major: This file is the one bit chatd reads to redact notifications and refuse replies; if the write fails, notifications keep the sender and text and replies stay enabled while the window is covered, and nothing records why. At least surface the failure so it can be diagnosed.

Suggested change
let _ = std::fs::write(path, b"1\n");
if let Err(err) = std::fs::write(path, b"1\n") { tracing::warn!("tinyclient: the lock could not tell chatd: {err}"); }

@itz4blitz
itz4blitz force-pushed the issue/751-screen-lock branch from f4aea5e to e914526 Compare November 20, 2026 20:56
@itz4blitz

Copy link
Copy Markdown
Collaborator Author

Rebased onto \origin/main\ (\e914526e) and addressed all review findings and mobile CI failures:

  • Blocker 1 (policy change unlocks held session): \lock::set_policy\ no longer clears \session.held\ when the new policy cannot arm; a held lock stays up (and \hides_switcher()\ stays true) until unlocked, and the new policy takes effect after unlock. Added unit test \�_policy_change_does_not_unlock_a_held_session.
  • Blocker 2 (cover only blocked mouse): \Shell::render\ now builds a separate locked root without \self.keys(...), focuses \Shell::lock_focus\ (or the Linux passphrase input), swallows app-level window-opening actions (\Settings, \About, \KeyboardShortcuts, \ShowLogs, \CheckForUpdates, \NewMessage, \AddAccount), and stops key-down propagation on the cover.
  • Blocker 3 (\ ick()\ blocking main thread on \os_screen_locked()): \screen_is_locked()\ now returns a cached \AtomicBool\ and polls \os_screen_locked()\ on a background thread at most once per second.
  • Major (\publish()\ silent write failure): \publish()\ now logs a warning via \ racing::warn!\ if creating the support dir or writing \shell-lock\ fails.
  • Android CI (\E0603): Made \gui::lock\ \pub(crate)\ so \mobile/android/natives.rs\ can call \crate::gui::lock::hides_switcher().
  • iOS CI (\E0599): Imported \objc2::MainThreadOnly\ in \mobile/ios/cover.rs\ and called \UIView::alloc(mtm).

@itz4blitz

Copy link
Copy Markdown
Collaborator Author

Superseded by and merged in #903 (d387971 — Release 2026-11-20 combined PR).

@itz4blitz itz4blitz closed this Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

App: lock tinyclient behind Touch ID, Windows Hello, a fingerprint or a passcode

2 participants