Documentation
¶
Overview ¶
Package remotework is the Remote Work extension (SPEC §10.18): one workspace of an Emetos on laptop A can be used from an Emetos on laptop B. This package is the part that runs on A, with the login of step 15.2: the page "Remote Work" (the per-workspace switch, the port, the idle timeout, the allowed keys, the host fingerprint and the security notes), the listener that exists only while a workspace has Remote Work on, the SSH server of extensions/internal/sshlogin that lets the listed keys in, the session token and the banner "Remote Work: <key comment> connected" with its Disconnect button. The conversation on the channel is package login, the messages are package protocol and the pictures are package tiles.
The extension is made once for the process (NewFactory) and activated in every workspace; the instances share one Hub, which holds the listener, the sessions and remote-work.json.
Index ¶
- Constants
- func CheckIdle(minutes int) error
- func CheckPort(port int) error
- func FactoryOf(hub *Hub) extension.Factory
- func NewFactory(opts HubOptions) extension.Factory
- type Config
- type Hub
- func (h *Hub) AddKey(line string) (sshlogin.AllowedKey, error)
- func (h *Hub) Addr() net.Addr
- func (h *Hub) Addresses() []string
- func (h *Hub) Cameras() keyqr.Source
- func (h *Hub) Close()
- func (h *Hub) EnsureHostKey() (string, error)
- func (h *Hub) HostKey() (ssh.Signer, error)
- func (h *Hub) Hosting() sharing.Host
- func (h *Hub) HostingState(folder string) sharing.State
- func (h *Hub) HostsPath() (string, error)
- func (h *Hub) OnChange(fn func()) (stop func())
- func (h *Hub) Register(api extension.API) (unregister func())
- func (h *Hub) RemoveKey(fingerprint string) error
- func (h *Hub) SessionByToken(token []byte) (*Session, bool)
- func (h *Hub) Sessions() []*Session
- func (h *Hub) SetCameras(src keyqr.Source)
- func (h *Hub) SetIdleMinutes(minutes int) error
- func (h *Hub) SetPort(port int) error
- func (h *Hub) SetWorkspace(folder string, on bool) error
- func (h *Hub) Snapshot(folder string) Snapshot
- type HubOptions
- type KeyEntry
- type Reason
- type Session
- type SessionInfo
- type Snapshot
- type TabOptions
Constants ¶
const ( // DefaultPort is the port of the SSH listener (and of the UDP port of step 15.3), and DefaultIdleMinutes the idle timeout. DefaultPort = 47123 DefaultIdleMinutes = 30 // MinIdleMinutes and MaxIdleMinutes bound the idle timeout; there is no way to turn it off. MinIdleMinutes = 1 MaxIdleMinutes = 24 * 60 // MaxKeys is the most keys the list holds and MaxWorkspaces the most workspaces the file names. MaxKeys = 256 MaxWorkspaces = 256 )
The defaults and limits of the settings of the page.
const ( // DevFakeCameraCommand is dev.keyqr.fakeCamera: it puts a camera that plays pictures from memory in place of the real ones, so // that a proof or a test of the Scan QR Code dialog never opens a real device. Arguments: {"comment", "text", "nothing", // "cameras"}. Run it before the page is opened: the page looks for cameras when it is made. DevFakeCameraCommand = "dev.keyqr.fakeCamera" // DevScanQRCommand is dev.remotework.scanQR: it opens the Scan QR Code dialog of the Remote Work page that is open. DevScanQRCommand = "dev.remotework.scanQR" )
The dev commands of step 15.5, registered in a workspace in debug builds and builds with the emetos_dev tag (SPEC §15.2).
const ( // HostCommand turns Remote Work on for the workspace of the window, or opens the page at the guide when no key is listed. HostCommand = "emetos.remotework.host" // StopCommand turns it off and ends the sessions of the workspace. StopCommand = "emetos.remotework.stopHosting" )
The ids of the commands that host a workspace (SPEC §10.29). They start with "emetos.remotework.", so a client of a shared workspace may not run them (command.ClientRefusal).
const ( // ID is the id of the extension (SPEC §10.18: "emetos.remotework" on the Extensions page). ID = "emetos.remotework" // KindID is the kind of the editor tab that is the page, and ManageCommand the command that opens it. KindID = "emetos.remotework.page" ManageCommand = "emetos.remotework.manage" )
The ids of the extension.
const DevBindEnv = "EMETOS_DEV_REMOTEWORK_BIND"
DevBindEnv is the environment variable that makes the listeners of a debug build (or a build with the emetos_dev tag) listen on one address instead of every interface: the real-input tests of step 17e.4 set it to 127.0.0.1 so that nothing is exposed on the network (SPEC §15.2). A release build never reads it: its listeners are always on every interface.
const DevConnectCommand = "dev.remotework.connect"
DevConnectCommand is the dev command of the proofs (debug builds and builds with the emetos_dev tag only): in a Remote Work tab it fills the form and presses Connect. Arguments: {"host", "port", "keyFile", "workspace"}, or {"host", "port", "agent": true, "fingerprint"}.
const DevInterfacesEnv = sharing.DevInterfacesEnv
DevInterfacesEnv is the environment variable that replaces the network interfaces of this computer by a list (debug and emetos_dev builds only; see sharing.DevInterfacesEnv): the real-input tests set it so that no address of the machine they run on is on a screenshot.
const TabKindID = "emetos.remotework.tab"
TabKindID is the kind of the window tab "Remote Work..." (SPEC §10.18 "As built (step 15.4)").
Variables ¶
This section is empty.
Functions ¶
func CheckPort ¶
CheckPort and CheckIdle validate what the page sets. They fail with RemoteWorkSettingInvalid.
func FactoryOf ¶
FactoryOf makes the Factory of the extension over a hub the caller made and keeps (the tests of two windows on loopback turn Remote Work on and read the address from it).
func NewFactory ¶
func NewFactory(opts HubOptions) extension.Factory
NewFactory makes the Factory of the extension: the instances it makes, one for each workspace, share one Hub made here, which holds the listener, the sessions and remote-work.json. extensions.All calls it once; a test passes the options of its own (a loopback listener, a clock).
Types ¶
type Config ¶
type Config struct {
// Version is the version of the file.
Version int `json:"version"`
// Port is the TCP port of the listener.
Port int `json:"port"`
// IdleMinutes is the idle timeout of a session in minutes.
IdleMinutes int `json:"idleMinutes"`
// Workspaces are the folders of the workspaces that have Remote Work on.
Workspaces []string `json:"workspaces"`
// Keys are the allowed keys.
Keys []KeyEntry `json:"keys"`
}
Config is the content of remote-work.json: what the page sets.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig is the configuration of a machine that never used Remote Work: off everywhere.
func (Config) AllowedKeys ¶
func (c Config) AllowedKeys() []sshlogin.AllowedKey
AllowedKeys parses the keys of the list; the file was checked when it was read, so an entry that does not parse is left out.
func (Config) IdleTimeout ¶
IdleTimeout is the idle timeout as a duration.
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
Hub is what the instances of the extension share: remote-work.json, the host key, the listener, the sessions. It is made once for the process. Its methods may be called from any goroutine; what it shows in a workspace it posts to the UI thread of that workspace.
func NewHub ¶
func NewHub(opts HubOptions) *Hub
NewHub makes a hub that listens on nothing until a workspace has Remote Work on.
func (*Hub) AddKey ¶
func (h *Hub) AddKey(line string) (sshlogin.AllowedKey, error)
AddKey adds the key of an authorized_keys line to the list. It fails with the tags of sshlogin.ParseAuthorizedKey and with RemoteWorkKeyDuplicate and RemoteWorkTooManyKeys.
func (*Hub) Addresses ¶
Addresses lists the addresses another computer connects to: the non-loopback addresses of this computer with the port of Remote Work (the one the listener is on, else the configured one).
func (*Hub) Cameras ¶
Cameras is the Source that Scan QR Code reads, or nil when the hub has none (HubOptions.Camera).
func (*Hub) Close ¶
func (h *Hub) Close()
Close ends every session and stops the listener; the process calls it when it quits.
func (*Hub) EnsureHostKey ¶
EnsureHostKey makes the host key if there is none yet and returns its fingerprint. The page calls it when it opens, so that the user can read the fingerprint before the first client asks for it.
func (*Hub) HostKey ¶
HostKey returns the host key of this machine, made the first time it is needed and kept with mode 0600. It fails with the tags of sshlogin.LoadOrCreateHostKey.
func (*Hub) HostingState ¶
HostingState reads how Remote Work hosts the workspace with the folder, for the Sharing status item and the banner. It touches no file.
func (*Hub) HostsPath ¶
HostsPath is the file where a client pins host keys (remote-work-hosts.json), for the tab of step 15.4.
func (*Hub) OnChange ¶
func (h *Hub) OnChange(fn func()) (stop func())
OnChange calls fn, from any goroutine and with no lock held, after the state the page shows changed; the function it returns stops the calls.
func (*Hub) Register ¶
Register tells the hub that the extension is active in the workspace, so that it can show a banner and notifications there, and starts the listener when the workspace has Remote Work on. The function it returns undoes it: it ends the sessions of the workspace and stops the listener when no workspace is left. A workspace with no folder is not registered.
func (*Hub) RemoveKey ¶
RemoveKey takes the key with the fingerprint out of the list and ends the sessions it logged in. It fails with RemoteWorkKeyUnknown.
func (*Hub) SessionByToken ¶
SessionByToken finds the live session that has the token, comparing in constant time; the transport of step 15.3 calls it with the token a client presents. A token of an ended session is not found: it expired with the session.
func (*Hub) SetCameras ¶
SetCameras replaces the Source of the cameras. The dev command dev.keyqr.fakeCamera uses it to put a camera that plays a picture of a QR code in place of the real ones (debug builds only), and the tests use it. Dialogs that are open keep the Source they were made with.
func (*Hub) SetIdleMinutes ¶
SetIdleMinutes sets the idle timeout of the sessions that start or have traffic from now on. It fails with RemoteWorkSettingInvalid.
func (*Hub) SetPort ¶
SetPort sets the port of the listener (the listener moves to it at once, and the sessions end). It fails with RemoteWorkSettingInvalid.
func (*Hub) SetWorkspace ¶
SetWorkspace turns Remote Work on or off for the workspace with the folder. Turning it on makes the host key if it is missing and opens the listener; turning it off ends the sessions of the workspace and closes the listener when no workspace is left.
type HubOptions ¶
type HubOptions struct {
// StateDir gives the folder of the state files ($XDG_STATE_HOME/emetos); the default reads the environment each time.
StateDir func() (string, error)
// Listen opens the TCP listener of the SSH server on the port; the default listens on every interface. Tests listen on the
// loopback with an ephemeral port.
Listen func(port int) (net.Listener, error)
// Cert overrides the SHA-256 fingerprint of the QUIC certificate that the grant carries. The default is the fingerprint of the
// certificate the hub's transport made at start, empty when the hub has no QUIC (the session then runs over the SSH channel).
// A test gives a stand-in.
Cert func() []byte
// OnSession is called, on the goroutine that serves the SSH channel, after the grant was sent. Session.Conn is the session's
// transport, to which the headless view is attached (step 15.4). It must not block; the session ends with the channel.
OnSession func(*Session)
// NoTransport leaves the SSH channel to the caller: no transport is attached to a session and nothing reads the channel (the
// tests of the login use it).
NoTransport bool
// NoView leaves the messages of a session to the caller: no headless view is made for it and nothing reads its transport (the
// tests of the transport read the host's side themselves).
NoView bool
// Interfaces lists the network interfaces whose addresses the guide of the page shows as the places to connect to (SPEC §10.29);
// the default reads the operating system's. Tests pass a fake list, so that they are the same on every machine.
Interfaces sharing.Interfaces
// Tab are the knobs of the remote window tab (step 15.4); every field has a default.
Tab TabOptions
// Camera finds and opens the cameras that Scan QR Code reads (step 15.5). The editor passes the Source of the real cameras
// (extensions.All); nil means there is no way to read a camera, and the button says so. A test passes a keyqr.FakeSource: nothing
// in the tests of this package opens a real camera.
Camera keyqr.Source
// NoQUIC makes the transport use the SSH channel only: the hub opens no UDP socket and the grant has no fingerprint.
NoQUIC bool
// ListenUDP opens the UDP socket of QUIC on the port the SSH listener got; the default listens on every interface. When it
// fails the hub logs it and runs without QUIC.
ListenUDP func(port int) (net.PacketConn, error)
// Transport, if not nil, changes the options of the hub's transport host before it starts (tests shorten its timeouts).
Transport func(*transport.HostOptions)
// Limiter counts the failed attempts of each address; the default is 5 a minute.
Limiter *sshlogin.Limiter
// Logger is the log of the hub; slog.Default() when nil.
Logger *slog.Logger
// Now is the clock of the times and of the throttle of notifications; time.Now when nil.
Now func() time.Time
// After calls f after d and returns the function that stops it (the idle timeouts); the default uses time.AfterFunc.
After func(d time.Duration, f func()) (stop func() bool)
// Random is the source of the session tokens; crypto/rand.Reader when nil.
Random io.Reader
// HandshakeTimeout and ChannelTimeout are the deadlines of the SSH server (10 s each by default).
HandshakeTimeout, ChannelTimeout time.Duration
}
HubOptions are what NewHub takes; every field has a default, so the editor passes none and the tests pass their own.
type KeyEntry ¶
type KeyEntry struct {
// Line is the authorized_keys line (type, base64 and comment).
Line string `json:"line"`
// Added is when the key was added, RFC 3339.
Added string `json:"added"`
}
KeyEntry is an allowed key in the file: its authorized_keys line and when it was added.
type Session ¶
type Session struct {
// Key is the key the client logged in with and Remote its address.
Key sshlogin.AllowedKey
Remote string
// Workspace is the name the client was granted and Started when the session began.
Workspace string
Started time.Time
// contains filtered or unexported fields
}
Session is a client that logged in and was granted a workspace: the key that did it, the token of the session, and the SSH channel. It lives until the client disconnects, the user presses Disconnect, the idle timeout passes, the key is taken out of the list, Remote Work is turned off or the workspace closes.
func (*Session) Channel ¶
Channel is the SSH channel of the session. After the grant it carries the messages of package protocol when the session runs over SSH (the TCP fallback); the transport reads and writes it, and the hub writes the Disconnect message on it when it ends the session. A session with a transport is used through Conn, not this.
func (*Session) Conn ¶
Conn is the transport of the session: what the headless view of step 15.4 sends and receives the messages of package protocol through, over QUIC or the SSH channel. It is nil when the hub was made with HubOptions.NoTransport. It ends with the session.
func (*Session) Done ¶
func (s *Session) Done() <-chan struct{}
Done is closed when the session is over: it was asked to end, or its connection closed.
func (*Session) End ¶
End ends the session: the token is no longer valid, the client is told why with a Disconnect message, the connection is closed and the banner goes. It does nothing the second time.
func (*Session) Reason ¶
Reason is why the session ended, and the text that went with it; false while it lives.
type SessionInfo ¶
type SessionInfo struct {
// Key is the name of the key (its comment, or its fingerprint) and Fingerprint its fingerprint.
Key, Fingerprint string
// Remote is the address of the client and Started when the session began.
Remote string
Started time.Time
// contains filtered or unexported fields
}
SessionInfo is a live session as the page shows it.
func (SessionInfo) Disconnect ¶
func (s SessionInfo) Disconnect()
Disconnect ends a session of the page's list, as the banner's button does.
type Snapshot ¶
type Snapshot struct {
// Config is the configuration (a copy) and Keys its keys, parsed.
Config Config
Keys []sshlogin.AllowedKey
// On says that the workspace has Remote Work on.
On bool
// Listening says that the SSH listener is open, and Addr where.
Listening bool
Addr string
// ListenErr is why the listener could not be opened, LoadErr why remote-work.json is not used and HostKeyErr why the host key
// cannot be read; empty when all is well.
ListenErr, LoadErr, HostKeyErr string
// HostFingerprint is the fingerprint of the host key (SHA256:...), or empty while there is none.
HostFingerprint string
// Sessions are the live sessions of the workspace.
Sessions []SessionInfo
}
Snapshot is what the page shows for one workspace.
type TabOptions ¶
type TabOptions struct {
// Backoff is how long to wait before the reconnection attempt n (counted from 1) after a connection dropped; the default is 1 s,
// doubling to 30 s.
Backoff func(attempt int) time.Duration
// AgentSocket gives the socket of the ssh-agent; the default is the value of SSH_AUTH_SOCK.
AgentSocket func() string
// ResizeDelay is how long the size of the tab must stay as it is before the new size is sent (150 ms by default).
ResizeDelay time.Duration
// Transport, if not nil, changes the options of the client's transport before it connects (tests shorten its timeouts).
Transport func(*transport.ClientOptions)
// HandshakeTimeout bounds the connection and the login (the default of sshlogin).
HandshakeTimeout time.Duration
}
TabOptions are the knobs of the remote window tab; every field has a default, and the tests set their own.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package login is the conversation that Remote Work holds on the SSH channel after the key has been accepted (SPEC §10.18 "As built (step 15.2)"): the client opens the channel "emetos-remotework" with a request (the workspace it wants), and the host answers with one grant: the 256-bit session token and the SHA-256 fingerprint of the QUIC certificate (step 15.3), or the reason there is none.
|
Package login is the conversation that Remote Work holds on the SSH channel after the key has been accepted (SPEC §10.18 "As built (step 15.2)"): the client opens the channel "emetos-remotework" with a request (the workspace it wants), and the host answers with one grant: the 256-bit session token and the SHA-256 fingerprint of the QUIC certificate (step 15.3), or the reason there is none. |
|
Package protocol is the message format of Remote Work (SPEC §10.18): the messages the host and the client send each other once the login is done, in a binary form that is versioned, length-prefixed and limited in size.
|
Package protocol is the message format of Remote Work (SPEC §10.18): the messages the host and the client send each other once the login is done, in a binary form that is versioned, length-prefixed and limited in size. |
|
Package tiles cuts the picture of a view into 64x64 tiles, sends the ones that changed since the picture the client confirmed, and puts them together again on the client (SPEC §10.18 "As built (step 15.1)").
|
Package tiles cuts the picture of a view into 64x64 tiles, sends the ones that changed since the picture the client confirmed, and puts them together again on the client (SPEC §10.18 "As built (step 15.1)"). |
|
Package transport carries the messages of package protocol between the two machines of a Remote Work session (SPEC §10.18 "As built (step 15.3)"): over QUIC on UDP, or, when UDP does not get through, over the SSH channel the login opened.
|
Package transport carries the messages of package protocol between the two machines of a Remote Work session (SPEC §10.18 "As built (step 15.3)"): over QUIC on UDP, or, when UDP does not get through, over the SSH channel the login opened. |