Repository navigation
HUD login: PIN required for control, viewing stays open - #56
Draft
KoganTheDev wants to merge 7 commits into
Draft
KoganTheDev wants to merge 7 commits into
KoganTheDev wants to merge 7 commits into
Conversation
…and the viewer gate prov::SessionTable keeps up to 4 random 128-bit login tokens in RAM (LRU eviction, constant-time lookup), prov::session_cookie() reads vs_session=<32 hex> from a Cookie header, and remote::requires_auth()/gate() turn every control command from a viewer into a Poll. AuthLevel (viewer, authed, open when no PIN is set) is shared through ESP32/include/auth_level.h. Natively tested (new test_hud_session suite, test_remote).
POST /api/hud/login checks the WiFi PIN through WifiManager's PinGuard (lockouts shared with the WiFi API) and sets vs_session=<128-bit random token>; HttpOnly; SameSite=Strict; Path=/. POST /api/hud/logout ends that session. Both get the same IPv4-Host, origin, size and deadline rules as the WiFi POSTs and are registered before the catch-all. /commands keeps a live login token in the httpd session context at the handshake and asks WifiManager::auth_level() on every message (atomic + spinlock, never the manager mutex), so a logout or a new PIN takes control away from an open socket at once. A viewer's control commands reach the controller as a Poll (remote::gate); every message still gets its one reply, which now ends with "auth" (0 view only, 1 logged in, 2 no PIN set, control open). Sessions live in RAM, so a reboot ends them; setting the PIN and wifi-reset clear them. The joystick is unaffected. The mock board sends the new key and applies the same viewer gate (reply_keys.json contract).
An ACCESS chip (lock icon) shows VIEW ONLY, CONTROL or OPEN from the reply's auth key. While view only, the d-pad, mode segment, calibration, tap-to-aim, speed, FIRE and auto-fire are disabled with a "Log in" callout, and control keys only toast a login hint. The login dialog (numeric PIN, autocomplete off, Esc closes) POSTs /api/hud/login, shows wrong-PIN and lockout answers and on success reconnects /commands (App.restart, which also serves the stall watchdog and detaches the old socket's handlers so only one poll loop can run). The CONTROL chip offers log out. With no PIN set a dismissible hint points to the WiFi page. Login and logout are fetch() POSTs, never /commands messages.
The mock board now mirrors the firmware's control access: PIN 1234 through a PinGuard model shared by the WiFi API and POST /api/hud/login|logout (5th wrong PIN locks out, escalating), RAM-only session tokens (max 4, LRU) in an HttpOnly vs_session cookie, the cookie read at the /commands handshake and re-checked per message. --no-pin starts with no PIN (auth 2) and the first WiFi add sets one, ending every session, like the board. Unit tests cover the guard, cookie parsing, login, eviction and the per-socket behaviour (login needs a new socket, logout cuts an open one). hud_e2e.py adds an access scenario (viewer sees video and status with controls locked, M refused, wrong PIN error, Esc closes, right PIN unlocks and jogs, log out locks again) and a --no-pin scenario; the existing control scenarios log in through the HUD first. 48 checks on 10 mocks.
CLAUDE.md: the login routes, the per-message session check on /commands, the auth reply key, sessions owned by WifiManager and cleared on a new PIN or wifi-reset, App.restart for socket replacement. Notes s9: why the existing PIN and a cookie, why control only, why the check is per message, and what remains (plain HTTP: a LAN sniffer can capture the PIN or the cookie). README: how to log in. The HUD spec's reply table gains auth.
The click variant failed once in five full runs under the e2e's load (10 mocks); a key reaches the same pressDir guard without depending on where the d-pad sits after the login callout appears. The check now reports the toasts, link and access state when it fails.
…d on Linux Headless Chrome on Linux does not give the page focus, so element.focus() did nothing and Input.insertText typed into nothing: the PIN was submitted empty, the login failed in CI, and the wrong-PIN check passed for the wrong reason. Enable Emulation.setFocusEmulationEnabled and fail if the typed PIN is not in the field.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Tech debt item #8. Stacked on #55 (split HUD sources); I'll retarget it to
mainonce #55 merges. Draft until it has been tested on the board.Why
Notes s9: any device on the LAN could drive the turret. The Origin check only stops cross-site pages, not other clients on the LAN.
Decisions (made by the owner)
PinGuard, so the WiFi page and the HUD share one lockout.wifi-reset.How it works
POST /api/hud/login(form fieldpin; same Host, Origin, body-size and deadline rules as the WiFi POSTs):{"ok":true}andSet-Cookie: vs_session=<128-bit hex>; HttpOnly; SameSite=Strict; Path=/;locked_s; no PIN set yet: 400.POST /api/hud/logoutremoves the caller's session and clears the cookie.prov::SessionTable(pure, natively tested) holds 4 sessions with LRU eviction, and the token comparison takes the same time however much of it is right./commands: the handshake stores the session token in the httpd session context. Every message is then checked againstWifiManager::auth_level(), so a logout or PIN change takes effect at once.remote::gateturns a viewer's control commands into a Poll, which still gets exactly one reply. Every command needs a login except Poll, includingmove:stop.auth: 0 view only, 1 logged in, 2 no PIN (control open). Worst-case reply is 750 of 832 B.--no-pin). New checks cover view only, a wrong PIN, login then jog, and logout locking control again.Verification
Known limit
The board has no HTTPS, so anyone who can sniff the LAN can capture the PIN or the cookie. This is documented in notes s9.