Documentation
¶
Overview ¶
Package quick is RemoHop's quick-support experience: `remohop quick` (and the RemoHop.exe / RemoHop.app builds of cmd/remohop-quick, which run it when started without arguments). A person who was asked to "open RemoHop" double-clicks one file and sees this machine's ID and a temporary password, approves each incoming connection, sees who is connected and can end it. No terminal is involved.
Design ¶
The process is a normal host (internal/hostd) plus a small UI server on 127.0.0.1. The page it serves is the whole user interface; it is opened in an app-style browser window where one is available (Microsoft Edge on Windows) and in the default browser otherwise. The two things that must reach the user even when that window is buried are native: the "allow this connection?" question (a system dialog on Windows and macOS, in addition to the page) and fatal start-up errors.
Product code has to stay pure Go and cross-compile, so there is no native toolkit here: no cgo, no window or tray code that could only be tested on the real system. Everything the user sees is exercised by the tests in this package, in a real browser where one is installed.
What a quick-support host allows ¶
Whatever the config file says, a host started here
- asks for approval on every login, pairings and authorised keys included, and refuses when nobody answers within a minute;
- accepts only the temporary password generated for this run (a fixed password in the config file is ignored) and mints no pairings;
- offers the screen, and by the user's choice in the page: mouse and keyboard, files and clipboard (both on at start), and the terminal, port forwarding, VPN, serial and USB (off at start). Features switched off with `remohop config feature` stay off.
Security model of the UI ¶
The UI server follows the loopback mode of internal/web. It listens on 127.0.0.1 only; every URL starts with a 128-bit random token, which is the login; the Host header must name the loopback address (DNS rebinding); a request that says where it comes from (Origin, Sec-Fetch-Site) must come from the page itself; and everything that changes state is a JSON POST carrying a second secret the page obtains over that same checked channel. The UI is never reachable from another machine and there is no remote API for approving: a client that is waiting for approval has no session, hence no way to move this machine's mouse. (A client the user has already allowed and given mouse control can click anything on this screen, this page included. That is what allowing remote control means.)
Index ¶
- Constants
- func SystemLang() string
- type App
- func (a *App) Configure(mode, server string) error
- func (a *App) Decide(n int, allow bool) error
- func (a *App) Disconnect(id int) error
- func (a *App) Done() <-chan struct{}
- func (a *App) InstallFFmpeg() error
- func (a *App) Regenerate() error
- func (a *App) SetOption(name string, on bool) error
- func (a *App) Start()
- func (a *App) State() State
- func (a *App) Stop()
- func (a *App) Subscribe() (<-chan struct{}, func())
- type AppConfig
- type Controller
- type Options
- type Presence
- type Request
- type Server
- type SessionInfo
- type State
Constants ¶
const ( PhaseSetup = "setup" // the rendezvous server has not been chosen yet PhaseConnecting = "connecting" // host running, no ID yet PhaseReady = "ready" // ID known PhaseError = "error" // the host could not start PhaseStopped = "stopped" // sharing has ended; the process is about to exit )
Phases of the app, as the page shows them.
const ( ErrAlreadyRunning = "already_running" ErrStartFailed = "start_failed" )
Error codes of PhaseError.
const AskTimeout = 60 * time.Second
AskTimeout is how long a connection request waits for the user's answer before it is refused. Longer than `remohop host`'s: the person answering is not sitting at a terminal waiting for it.
Variables ¶
This section is empty.
Functions ¶
func SystemLang ¶
func SystemLang() string
SystemLang is the language of the user's session: "zh", "en" or "" when it is neither (the page then follows the browser).
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
App runs the quick-support host and answers the UI.
func (*App) Configure ¶
Configure stores the user's choice of rendezvous server and starts the host with it: mode "official" (signal.OfficialAddr), "custom" (server, as typed; also the default for an empty mode) or "none" (no server: helpers on this network connect by address). The choice is the same setting the desktop app and `remohop config` use, so it is asked once.
It is accepted in the setup phase, and also while the host is still trying to reach its server (or could not start), so that a mistyped address can be corrected: the host is then restarted with the new choice, which also wins over a --signal given at start. Once the host is registered, the choice stays.
func (*App) Done ¶
func (a *App) Done() <-chan struct{}
Done is closed when sharing has stopped for good.
func (*App) InstallFFmpeg ¶
InstallFFmpeg downloads and installs ffmpeg in the background (the button under "Screen sharing needs ffmpeg"); State follows it. Sessions started after it has finished can share the screen.
func (*App) Regenerate ¶
Regenerate replaces the temporary password. Sessions stay; whoever has the old password can no longer log in with it.
func (*App) SetOption ¶
SetOption switches one of Options ("input", "files", "advanced"). It applies at once, also to helpers already connected, before SetOption returns: nothing new of what is switched off can be opened, and what they have open with it ends (terminals, file transfers, forwards, ...; see hostd.WatchFeature). Switching "input" off leaves the screen showing: an open desktop stream lets go of any key or button the helper holds, takes no more input and tells the helper's viewer so.
func (*App) Start ¶
func (a *App) Start()
Start resolves the rendezvous server and starts the host. The outcome is in State: the setup phase when no server is configured, the error phase when the host cannot start.
type AppConfig ¶
type AppConfig struct {
// Dir is the remohop config directory; empty means the default.
Dir string
// Signal overrides the configured rendezvous server.
Signal string
// AskTimeout defaults to the package's AskTimeout.
AskTimeout time.Duration
// Prompt, if set, also asks the user about a request outside the page
// (a native dialog). It returns ok false when it has no answer: the
// dialog could not be shown, or ctx ended because the request was
// answered elsewhere or went away.
Prompt func(ctx context.Context, r Request) (allow, ok bool)
Logger *slog.Logger
// Host adjusts the host configuration before it starts; tests bind
// loopback and run without a server with it.
Host func(*hostd.Config)
// NoSignal runs without a rendezvous server (tests).
NoSignal bool
// FFmpeg finds and installs ffmpeg; nil means the real one (tests
// replace it).
FFmpeg *ffmpeg.Installer
}
AppConfig configures an App.
type Controller ¶
type Controller interface {
State() State
Subscribe() (changed <-chan struct{}, cancel func())
Regenerate() error
Decide(n int, allow bool) error
Disconnect(id int) error
SetOption(name string, on bool) error
Configure(mode, server string) error
// InstallFFmpeg starts the one-click install of ffmpeg (State.FFmpeg).
InstallFFmpeg() error
Stop()
}
Controller is what the UI server shows and drives; *App implements it.
type Options ¶
type Options struct {
// Input: control the mouse and keyboard (otherwise the helper only watches).
Input bool `json:"input"`
// Files: transfer files and share the clipboard.
Files bool `json:"files"`
// Advanced: terminal, port forwarding, VPN, serial ports, USB devices.
Advanced bool `json:"advanced"`
}
Options are the user's switches for what an allowed helper may do.
func DefaultOptions ¶
func DefaultOptions() Options
DefaultOptions is what a quick-support host starts with.
type Presence ¶
type Presence struct {
// Viewers is the number of pages showing the UI now.
Viewers int
// Seen: a page has shown the UI at some point.
Seen bool
// Gone is when the last page went away (meaningful when Viewers is 0
// and Seen).
Gone time.Time
// Bye: the last page announced that it was being closed, as opposed to
// vanishing (a crashed or suspended browser).
Bye bool
}
Presence says whether the UI is on screen.
type Request ¶
type Request struct {
N int `json:"n"`
// Name is the pairing or authorised-key name the host knows the
// client by; empty for a password login.
Name string `json:"name,omitempty"`
// Device is what the client calls itself: a claim, not verified.
Device string `json:"device,omitempty"`
// Identity is the fingerprint of the client's key.
Identity string `json:"identity"`
From string `json:"from"`
Auth string `json:"auth"`
// Action is set when this is not a login but something a connected,
// granted client asks to do ("exec: git push"); Grant names its grant.
Action string `json:"action,omitempty"`
Grant string `json:"grant,omitempty"`
// Left is the number of seconds until the request is refused.
Left int `json:"left"`
}
Request is a connection waiting for the user's answer.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the local UI server. See the package comment for its security model.
func NewServer ¶
NewServer listens on a free loopback port. lang is the language the page starts in ("zh", "en", or "" to let the browser's language decide).
func (*Server) OnLang ¶
OnLang sets what runs when the user picks a language in the page: the caller saves the choice for the next start and uses it for the native dialogs. Set it before Serve.
func (*Server) PresenceChanged ¶
func (s *Server) PresenceChanged() <-chan struct{}
PresenceChanged receives when Presence may have changed.
type SessionInfo ¶
type SessionInfo struct {
ID int `json:"id"`
Name string `json:"name,omitempty"`
Device string `json:"device,omitempty"`
Identity string `json:"identity"`
From string `json:"from"`
// Path is lan, direct, punched, relayed or "relayed (websocket)".
Path string `json:"path"`
// Seconds is how long the session has been open.
Seconds int `json:"seconds"`
}
SessionInfo is a connected helper.
type State ¶
type State struct {
Phase string `json:"phase"`
ErrorCode string `json:"error_code,omitempty"`
Error string `json:"error,omitempty"`
// ID is the 9-digit ID formatted in groups of three; OtherID is the ID
// of the host that is already running (ErrAlreadyRunning).
ID string `json:"id,omitempty"`
OtherID string `json:"other_id,omitempty"`
Password string `json:"password,omitempty"`
// Online: registered with the rendezvous server right now.
Online bool `json:"online"`
Server string `json:"server,omitempty"`
// Transport is "udp" or "websocket" (helpers then arrive relayed).
Transport string `json:"transport,omitempty"`
// Relay: this machine accepts a relayed connection when no direct
// one is possible.
Relay bool `json:"relay"`
// Waited is how many seconds the host has been trying to register.
Waited int `json:"waited,omitempty"`
// Addresses are where helpers on this network reach this computer
// when it runs without a rendezvous server (the user chose none).
// (null when it has a server; empty when none was found).
Addresses []string `json:"addresses"`
Device string `json:"device,omitempty"`
Requests []Request `json:"requests"`
Sessions []SessionInfo `json:"sessions"`
Options Options `json:"options"`
AskTimeout int `json:"ask_timeout"`
Version string `json:"version"`
// NoFFmpeg: this computer has no ffmpeg, so helpers cannot see the
// screen live (screenshots, files and commands still work).
NoFFmpeg bool `json:"no_ffmpeg,omitempty"`
// FFmpeg is the one-click install of ffmpeg (InstallFFmpeg), where
// RemoHop can download it.
FFmpeg ffmpeg.UIState `json:"ffmpeg"`
}
State is everything the page shows.