Skip to main content

Module local_session

Module local_session 

Source
Expand description

The browser sessions of a headless srv that serves its own UI on loopback: one-time codes, the pending sessions a code makes, and the live sessions a person confirms.

The flow, from the person’s side: agentmux-srv open mints a code with the key, the browser enters it, the page shows a short check phrase, open shows the same phrase and asks the person to confirm. Only a confirmed session is live. Codes and pending sessions are memory only and a restart ends them. The live sessions are kept across a restart when a data root is given (SessionStore::keep_in, the file is in local_session_file.rs): only their digests, and only while they are inside their limits.

A live session is a pair: a cookie (sent by the browser to every port of the address, so it proves little alone) and a per-tab token the page keeps in sessionStorage (isolated by origin, port included). One record holds the hash of both, and a request needs both to name it (SessionStore::admit). Secrets are kept as SHA-256 digests; a code, handle, cookie or token never reaches a log.

StructsΒ§

Confirm πŸ”’
One confirm of a session, as status shows it. It holds no value of a code, cookie or token: the session is named by its check phrase, which the person saw.
Entered πŸ”’
What a code entry made.
Grant πŸ”’
What a session’s page was handed, once.
Inner πŸ”’
Pending πŸ”’
Persist πŸ”’
Where the live sessions are kept across a restart, once that is on.
Session πŸ”’
SessionId πŸ”’
Which session a request came from (the digest of its cookie), carried on the request so a WebSocket upgraded with it can be closed when the session ends.
SessionStore πŸ”’

EnumsΒ§

CodeState πŸ”’
Where a code stands, for the open that minted it.
Collected πŸ”’
The waiting page’s answer.
ConfirmHow πŸ”’
How a confirm was made: where the process that sent it stands.
Outcome πŸ”’
RouteClass πŸ”’
What a request to a route may present.

ConstantsΒ§

CODE_LIFE πŸ”’
A code can be entered for this long after it is minted.
LIVE_RECHECK πŸ”’
How often a socket re-checks that its session is still live (a logout is heard at once).
LOGGED_FAILURES πŸ”’
This many refusals in a minute are logged one by one; after them, one line says the rest are only counted.
MAX_CONFIRMS πŸ”’
Most confirms remembered at once; the oldest goes first.
MAX_FAILURES πŸ”’
Most refusals remembered at once (they are counted over a minute).
MAX_HELD πŸ”’
Most codes and most pending sessions held at once; the oldest goes first.
PENDING_LIFE πŸ”’
A pending session waits this long, from the moment its code was entered, for the person’s answer.
SESSION_IDLE_LIFE πŸ”’
A session ends after this long without a request.
SESSION_MAX_LIFE πŸ”’
A session ends this long after it was confirmed, however much it is used: a browser that is always open signs in again (with agentmux-srv open) once a week.

FunctionsΒ§

check_phrase πŸ”’
Two short pronounceable words from 1024 each (about 20 bits), e.g. kela-mivo: easy to compare by eye.
digest πŸ”’
end_pending πŸ”’
phrase_word πŸ”’
Word n (0..1024): consonant, vowel, consonant, vowel from 8 consonants and 4 vowels.
prune πŸ”’
Drop what has expired. A grant nobody collected ends its session too.
random_secret πŸ”’
256 random bits as 64 hex characters (a valid WebSocket subprotocol token and cookie value).
save πŸ”’
Write the live sessions to the file, or delete it when there are none. A write that fails is logged (its kind only) and the sessions stay in memory: nothing is lost but a sign-in surviving the next restart.
save_if_due πŸ”’
A use of a session is written at most every file::SAVE_EVERY.

Type AliasesΒ§

Digest32 πŸ”’