Add Remote relay library and secure settings storage

Add bounded NVDA-v2 framing, TLS transport, peer validation, speech and Braille decoding, and private transport fixtures. Store settings and explicitly remembered endpoint-bound keys using owner-only atomic files.

Include the implementation plan and status records. Remote remains a source library without an installable package or desktop integration.
This commit is contained in:
ak47 committed 2026-11-03 22:33:26 -05:00
1 parent bc305993b8
commit 63e84e9ac7
20 files changed
+3984

No files matched your search

+138
View File
@@ -0,0 +1,138 @@
# Remote relay contract, first implementation increment
This describes the implemented relay library, not a promise of usable desktop
control. The host streaming API remains unimplemented. All payloads stay in the
external Tentacle; no reader internals or output backends are imported here.
## Sources and provenance
Reference heads were checked on 2026-11-03:
- Cthulhu `testing`: `a47253d697c1aa44dea80646cad99a4fe163c7f1`.
- Cthulhu Tentacles `master`: `bc305993b8ad5c2374c8fc2c8b886c9cd6697b52`.
- NVDA current head: `84756356cd19a57cfeb4ef265619e54850e06568`.
- NVDA local reference: `2843e703ce19757711e976ebb6e9c5b689fc2017`.
- NVDA Remote add-on: `301248945481e462601248c5e423731bd58d5e0a`.
- churst90/orca-remote: `391f0c52044071e7cd34e3900fc13474826c312d`.
- serrebidev/orca-remote: `9260d8284bb9f0761633dca958f5e1d9ccc37485`.
The current NVDA
[serializer](https://github.com/nvaccess/nvda/blob/84756356cd19a57cfeb4ef265619e54850e06568/source/_remoteClient/serializer.py),
[session](https://github.com/nvaccess/nvda/blob/84756356cd19a57cfeb4ef265619e54850e06568/source/_remoteClient/session.py),
[transport](https://github.com/nvaccess/nvda/blob/84756356cd19a57cfeb4ef265619e54850e06568/source/_remoteClient/transport.py),
[server](https://github.com/nvaccess/nvda/blob/84756356cd19a57cfeb4ef265619e54850e06568/source/_remoteClient/server.py)
and [input adapter](https://github.com/nvaccess/nvda/blob/84756356cd19a57cfeb4ef265619e54850e06568/source/_remoteClient/input.py)
were downloaded for source review. Speech command fields and priorities were
also inspected in the local NVDA reference. The current serializer, session and
input adapter matched that local revision; the server now bounds incoming
messages but retains the reviewed membership fields.
No implementation, mapping table or test fixture was copied from NVDA or Orca.
`src/testdata/nvda-v2.jsonl` contains independently authored synthetic examples
of reviewed field shapes, with generic IDs and text. The optional `scan_code`
example exercises a documented optional field, not an observed NVDA emission.
Private test certificates are generated in memory, never distributed. No Windows
NVDA process, standalone add-on or Orca plugin has been run against this code.
Live captured fixtures and versioned interoperability results remain required.
## Framing and validation
TLS is mandatory. Each frame is a UTF-8 JSON object followed by LF. A relay frame
may contain at most 1 MiB before LF. EOF with a partial frame fails. Parsing
rejects invalid UTF-8, duplicate keys at every depth, trailing values, nesting
beyond 24, more than 4,096 members per collection or more than 16,384 values.
Additional fields are allowed but still undergo structural validation.
The `type` is a nonempty printable ASCII string of at most 64 bytes. `origin`,
when present, is a positive 32-bit integer. Boolean and numeric types are not
interchangeable. Required values cannot be null. Errors contain fixed local
messages; they never include channel keys, remote output or server text.
| Message | Implemented representation and limits |
| --- | --- |
| `protocol_version`, `join` | Outbound authentication only: version 2, channel and `connection_type` of `master` or `slave`. |
| `channel_joined` | Matching channel required. Missing `clients` means empty. A maximum of 16 peers may be parsed; session policy accepts at most one. `user_ids`, if present, must exactly match typed peers. Nonempty legacy IDs without roles fail. The echoed key is removed from returned membership. |
| `client_joined`, `client_left` | Typed `client` requires positive `id` and known `connection_type`. Optional `user_id` must agree. ID-only legacy membership is unsupported. |
| `speak` | Up to 1,024 sequence entries. Strings preserve whitespace and order. Numeric priority 0, 1 or 2; absence defaults to 0. Null and string priorities fail. |
| `cancel`, `pause_speech` | Typed cancel or required boolean `switch`. No output backend is called. |
| `key` | Required integer `vk_code` 1–255 and booleans `extended`, `pressed`. Optional integer `scan_code` 0–65,535. No VK/XKB mapping or injection yet. |
| `set_braille_info` | Name at most 256 UTF-8 bytes; width 0–4,096. Absent fields permit the controlled peer's geometry request. Zero means no display. |
| `set_display_size` | Required `sizes` array, at most 16 widths, each 0–4,096. |
| `display` | Required array of at most 4,096 integer cells, each 0–255. Null cells and base64 strings fail. |
| `braille_input` | Only the fixed global-command pan/route paths described below produce actions. Other gestures remain inert. |
| `set_clipboard_text` | Required string, at most 8,192 UTF-8 bytes. No clipboard access is performed. |
| `ping`, `motd` | Relay-only housekeeping. Required `motd` text is bounded and discarded; optional boolean `force_display` cannot authorize an action. |
| `error`, `version_mismatch`, `nvda_not_connected` | Terminal session failures; no automatic reconnect. Server error text is discarded. |
| Other types | Structurally validated and inert. Post-join peer extensions require the selected peer origin. Includes `tone`, `wave`, `send_SAS` and `index`; no path is opened or script executed. |
NVDA speech commands use `[name, fields]` arrays. The parser recognizes
`CharacterModeCommand.state`, `LangChangeCommand.lang` (null restores the
default language) and `EndUtteranceCommand`. Extra fields such as `isDefault`
are tolerated. Unsupported command arrays increment an utterance-local bounded
count without retaining their names or executing them. Dictionary-shaped command
objects are rejected. Backend language, priority and character-mode conversion,
UTF-8 splitting into host operations, cancellation ownership and cancel-on-pause
policy still need reader integration. The 1 MiB relay limit is not permission to
send a 1 MiB host presentation.
Braille scripts must have exactly the form
`["globalCommands", "GlobalCommands", name]`. The only recognized names are
`braille_scrollBack`, `braille_scrollForward` and `braille_routeTo`. Routing
accepts a single `cellIndexes` item or legacy `routingIndex`, each 0–4,095.
When both are supplied they must agree. Multiple routing cells are unsupported.
Unknown modules, plugins, arbitrary script names and `kb:` commands are inert.
Actual viewport width and generation must still be checked in core.
## Session policy and ownership
The external `session` state has one owner and no locks or background workers.
It starts `joining`, becomes `waiting` after an empty channel acknowledgement,
and becomes `ready` only with one opposite-role peer. Additional/repeated joins,
same-role peers, peer departure, ambiguous origins and wrong-direction effects
suspend it and clear peer identity. A suspended or closed session cannot resume;
a local action must create a new connection and core-issued epoch. Stale-epoch
events are rejected without changing the current state.
Speech/cancel/pause/display travel from controlled to controller. Keys, Braille
input and display sizes travel from controller to controlled. Clipboard and
Braille information can travel both ways. None of this grants desktop access.
Core consent and per-operation grants must be checked separately at delivery.
`relayConn` owns one reader, a serialized writer and a lifetime context. Its
context remains active after `connect` returns. Read/decode failure closes the
socket. Explicit close and cancellation interrupt blocked I/O. Writes have a
five-second deadline covering queue wait and transmission, at most 32 admitted
calls and a 256 KiB aggregate byte ceiling. Overflow closes the connection;
cleanup does not wait for writer admission. Concurrent writes cannot interleave
frames; their relative order is unspecified, so the session owner must sequence
speech/cancel and key transitions before submitting them.
The future coordinator must close the transport immediately when `session`
returns a terminal error, revoke the core lease on transport failure, and reject
late network-worker results. The current tests exercise these layers separately;
there is not yet a running Tentacle/coordinator. Transport write capacity does
not replace the proposed separate host control/input/output queues.
## Timeouts, trust and liveness
Dial plus TLS has a 15-second bound. Join has a separate 15-second bound and at
most 32 pre-join notices. Unexpected pre-join peer effects fail. Disconnect
cancels the entire connection lifetime. No reconnect/backoff is implemented;
authentication/trust failures require a fresh explicit attempt.
CA mode uses normal system roots and hostname/IP checks. Pin mode accepts only
the exact SHA-256 leaf certificate digest previously approved for that exact
host string and port, replacing CA/name validation for that endpoint. Even a
CA-valid replacement certificate fails an existing pin. Pin approval, display,
fingerprint discovery and persistence are not implemented; callers cannot obtain
consent merely by constructing a pin. There is no plaintext or generic insecure
mode. Host names are separate from ports; bare IPv6 literals use `JoinHostPort`.
NVDA's embedded relay sends one-way `ping` every 300 seconds. Accordingly the
initial read deadline is six minutes; receiving a complete next frame resets it.
TCP keepalive requests idle 10 seconds, interval 3 seconds and three probes.
These are development transport settings, **not a proven desktop recovery
bound**. A relay process can hang while its kernel still acknowledges probes;
the separate core one-second heartbeat/three-second lease expiry and remote-peer
liveness design remain required. Idle/dead relay trials, abrupt network loss,
IPv6 connections and installed-package behavior have not been verified.