Path to the ACCEPTOR daemon user’s authorized_keys ($HOME/.ssh/authorized_keys).
Deliberately rooted at $HOME (NOT the config dir), that is where sshd reads
it. Tests sandbox the write by running the acceptor with HOME set to a temp.
The cached login for device if its bootstrap is still fresh, else None
(None = do a full bootstrap). Outer Some = fresh cache hit; the inner Option
is the login account the acceptor last reported (None when it reported none).
Ensure the managed ed25519 keypair exists; generate it on demand via
ssh-keygen if absent. Returns the PUBLIC key line (one line, no trailing
newline). The private key NEVER leaves disk and is never printed.
Read the acceptor’s real public host keys. Prod reads /etc/ssh/ssh_host_*.pub;
the gate points FILAMENT_SSH_HOSTKEY at a throwaway sshd’s hostkey pubfile so
it never needs to touch the system’s. Returns the raw pubkey lines (e.g.
“ssh-ed25519 AAAA…”).
Install (or replace) pubkey in a marked block for device in
authorized_keys. Idempotent: a re-grant replaces that device’s block rather
than appending a duplicate. Creates ~/.ssh (0700) and the file (0600) if
absent. SECURITY: the caller MUST have verified the trusted channel + shell
cap before calling this. The pubkey is re-validated here (M-3), defense in
depth, so a bad key is NEVER written even if a caller forgot to check.
Pin the acceptor’s host keys into our private known_hosts, keyed by the EXACT
destination token ssh will use (so the pin is not silently inert). Replaces
any prior pins for that token (host keys can rotate). Each hostkeys entry is
a pubkey line like “ssh-ed25519 AAAA…”.
Return content with the # BEGIN/END filament-managed <device> block (and
the lines between) removed. Lines outside any such block are preserved
verbatim. Path-pure (testable), the file I/O wrappers call this.
M-3 (authorized_keys injection): validate that pubkey is a SINGLE, well-
formed ssh public-key line before it is ever written. A trusted+shell peer
could otherwise send a pubkey containing an interior \n (which .trim()
does NOT strip) to inject EXTRA authorized_keys lines, extra keys, a
command=/from= forced-command, etc. We reject anything with a control
character (newline, CR, tab, …) or more than one whitespace-separated key
line, and require the shape <key-type> <base64-blob> [single-line comment].