Documentation
¶
Overview ¶
Package account is the client side of RemoHop accounts: `remohop login`, `remohop logout`, `remohop account`, the account part of `remohop devices`, and the host-side "account-trust" that lets a host accept the account's other devices. The server side is in internal/signal (accounts are an optional service of a rendezvous server); the signed membership log both sides verify is internal/account/ledger.
What an account is ¶
An account groups devices under an email address, on one rendezvous server. Every device of the account can list the others with their 9-digit ID, name, platform, whether they are online and when they were last seen. That is all: an account never grants access to a device. Connecting still takes a credential the host accepts (its password, a pairing, or a key its owner authorised).
One host setting changes that, on that host only: with `remohop config account-trust on`, a host accepts the identity keys of its account's devices like authorised keys. It is off by default.
Threat model ¶
The rendezvous server is not trusted (see docs/security.md), and the operator who enables accounts is the party best placed to attack them: it sends the login codes, so it can log in to any account on its server as far as the server is concerned. Account-trust must therefore not rest on anything the server says. It rests on two things:
Membership is a log of entries each signed by the identity key of a device that is already a member (ledger). The first entry is signed by the device that created the account, and its hash is the account ID. The server stores and relays the log but holds no member key, so it cannot write an entry.
A device that joins an existing account has no way to tell the real log from one the server made up with its own keys, and an existing device cannot tell a real new device from the server's key. So joining takes two comparisons by the person who owns both devices: the existing device approves the new one only by its full identity fingerprint (`remohop account approve FINGERPRINT`, which the new device prints), and the new device accepts the account only after its owner has confirmed the account fingerprint shown by an existing device (asked at `remohop login`, or --account-fingerprint). Both fingerprints are 80 bits of SHA-256: the server cannot grind a key that matches.
A host with account-trust on accepts a client when the client proves its identity key in the TLS handshake of the session (as for any key login) and that key is a member in the log the host verified from the account ID it confirmed. The host keeps the longest log it has verified and accepts only extensions of it, so a server cannot roll a removal back once the host has seen it. What a malicious server can do: refuse service; withhold new entries from a host, which delays a removal from taking effect there (a host that cannot refresh the log for MaxStale stops trusting the account until it can; `remohop config account-trust off` on the host takes effect at once); see which devices belong together; and, by the login codes, show itself as "pending" in the account, which nobody should approve. It cannot add a device, log in to a host, or read a session.
Mechanically, a host keeps its account's member keys in its own list of authorised keys (paired.json), named "account:NAME". The host's normal key login then accepts them, `remohop host paired` lists them, and removing a device from the account (or turning account-trust off) removes them and ends their sessions within seconds. `remohop host revoke` of such an entry keeps that device out of this host until account-trust is turned off and on again.
Index ¶
- Constants
- Variables
- func CachedDevices(dir string) ([]Device, *State, error)
- func CheckLog(dir string, log []ledger.Entry) error
- func Delete(ctx context.Context, opts Options) error
- func DeviceName(values map[string]string) string
- func Devices(ctx context.Context, opts Options) ([]Device, *State, error)
- func HostKey(ctx context.Context, opts Options, id string, refresh bool) (ed25519.PublicKey, bool)
- func IsTrustEntry(name string) bool
- func Logout(ctx context.Context, opts Options) error
- func Reject(ctx context.Context, opts Options, fingerprint string) error
- func RequestCode(ctx context.Context, opts Options, email string) error
- func RunHost(ctx context.Context, dir string, log *slog.Logger)
- func SyncTrust(dir string) (added, removed int, err error)
- func TrustEnabled(dir string) bool
- type Device
- type JoinRequest
- type LoginRequest
- type LoginResult
- type Options
- type State
- type Summary
Constants ¶
const ( // StatusPending: logged in, waiting for an existing device to approve. StatusPending = "pending" // StatusMember: a device of the account. StatusMember = "member" // StatusLoggedOut: the server no longer accepts the session (the // device was removed, logged out elsewhere, or the account deleted). StatusLoggedOut = "logged_out" )
Statuses of this device in its account.
const File = "account.json"
File is the account session inside the config directory (mode 0600: it holds the session token).
const MaxStale = 7 * 24 * time.Hour
MaxStale is how long a host keeps trusting its account's devices without being able to fetch the account's log. A rendezvous server can withhold a removal from a host; past this the host trusts nobody from the account until it can check again.
const SettingTrust = "account-trust"
SettingTrust is the host setting that makes it accept its account's devices like authorised keys.
const TrustFile = "account-trust.json"
TrustFile records which authorised keys account-trust put in the host's paired.json, so that it only ever removes its own.
Variables ¶
var ErrConfirmAccount = errors.New("joining an existing account needs its fingerprint confirmed: " +
"pass --account-fingerprint with the fingerprint `remohop account` shows on one of your other devices")
ErrConfirmAccount: joining an existing account needs its fingerprint to be confirmed.
var ErrNotLoggedIn = errors.New("not logged in to an account (log in with `remohop login EMAIL`)")
ErrNotLoggedIn is returned when this device has no account session.
Functions ¶
func CachedDevices ¶
CachedDevices is the device list as last fetched, without asking the server; presence is as it was then.
func CheckLog ¶
CheckLog reports whether this device would accept log as its account's log: valid signatures from members all the way, the account it confirmed, and an extension of what it verified before. Nothing is stored.
func Delete ¶
Delete deletes the account on the server: every device's session ends and the account is gone. Only a member can.
func DeviceName ¶
DeviceName is the name a device joins its account with: the "name" setting from values, or else the computer's host name (as hostd.DeviceName).
func Devices ¶
Devices lists the account's devices with their presence. Only devices in the verified log are listed, whatever the server says; ID, name, platform and presence are the server's word.
func HostKey ¶
HostKey returns the identity key of the account device registered under id, if this device is a member and the device is in the verified log. The key is what a client pins for that host: the account's own devices vouch for it, not the rendezvous server. With refresh, a device that is not in the cached list is looked up on the server.
func IsTrustEntry ¶
IsTrustEntry reports whether an authorised key's name marks it as one account-trust manages.
func Logout ¶
Logout removes this device from the account (an entry signed by itself), ends its session and forgets the account here, including the keys account-trust had authorised. If the server cannot be reached the account is forgotten here anyway and the error says so: the device then stays in the account's list until another device removes it.
func RequestCode ¶
RequestCode asks the rendezvous server to mail a login code to email.
func RunHost ¶
RunHost keeps a host's account up to date for as long as ctx lasts: it reports the device's name to the account, fetches and verifies the log, and keeps account-trust's authorised keys in line (SyncTrust). It is meant to run beside `remohop host`. Registration itself needs nothing from here: the rendezvous server knows which registered keys belong to which account, so a host shows as online in its account as soon as it is.
func SyncTrust ¶
SyncTrust brings the host's authorised keys in dir in line with its account, from the log this device last verified (it does not contact the server; RunHost does that). With account-trust off, not a member, or a log older than MaxStale, every key it added is removed. It reports how many keys were added and removed.
func TrustEnabled ¶
TrustEnabled reports whether account-trust is on in dir's config.
Types ¶
type Device ¶
type Device struct {
// ID is its 9-digit ID, if it has ever registered as a host on the
// account's rendezvous server.
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Platform string `json:"platform,omitempty"`
// Identity is the fingerprint of its identity key; Key the key.
Identity string `json:"identity"`
Key string `json:"key"`
// Online: registered with the rendezvous server right now, so it can
// be connected to (if it accepts this device's credential).
Online bool `json:"online"`
LastSeen *time.Time `json:"last_seen,omitempty"`
// This is the device running the command.
This bool `json:"this_device,omitempty"`
}
Device is a device of the account.
type JoinRequest ¶
type JoinRequest struct {
Identity string `json:"identity"`
Key string `json:"key"`
Name string `json:"name,omitempty"`
Platform string `json:"platform,omitempty"`
From string `json:"from,omitempty"`
At time.Time `json:"at"`
}
JoinRequest is a device waiting to be approved.
type LoginRequest ¶
type LoginRequest struct {
Email string
// Code is the login code from the mail.
Code string
// AccountFingerprint, if set, is the account fingerprint an existing
// device of the account shows (`remohop account`); joining an account
// with another fingerprint fails.
AccountFingerprint string
// ConfirmAccount is asked otherwise, when this device joins an
// existing account: does the fingerprint match what an existing
// device of the account shows? With neither, joining fails with
// ErrConfirmAccount.
ConfirmAccount func(fingerprint string) (bool, error)
}
LoginRequest is the input of Login.
type LoginResult ¶
type LoginResult struct {
// Status is "created" (this device created the account), "member"
// (it was already a member) or "pending" (an existing device has to
// approve it: `remohop account approve DeviceFingerprint` there).
Status string `json:"status"`
Email string `json:"email"`
// Account is the account fingerprint.
Account string `json:"account"`
// Device is this device's identity fingerprint.
Device string `json:"device"`
}
LoginResult describes a successful login.
func Login ¶
func Login(ctx context.Context, opts Options, req LoginRequest) (*LoginResult, error)
Login proves a login code and joins this device to the account.
type Options ¶
type Options struct {
// Dir is the config directory; empty means the default.
Dir string
// Signal is the rendezvous server for Login and RequestCode (empty:
// the configured one). Everything after login uses the server, and
// the server key, recorded at login.
Signal string
// Listen opens the UDP socket for one exchange with the server;
// default an ephemeral port on all interfaces.
Listen func() (net.PacketConn, error)
// Logger receives debug output; nil discards it.
Logger *slog.Logger
}
Options configures the functions of this package.
type State ¶
type State struct {
// Server is the rendezvous server the account lives on, and ServerKey
// its key, pinned at login.
Server string `json:"server"`
ServerKey string `json:"server_key"`
// ServerWS is the server's websocket bridge as configured at login,
// for networks without UDP; Server is empty when it was the only way
// configured.
ServerWS string `json:"server_ws,omitempty"`
Email string `json:"email"`
Token []byte `json:"token"`
Status string `json:"status"`
// AccountID is the account this device created or whose fingerprint
// its owner confirmed. Every log is checked against it.
AccountID []byte `json:"account_id,omitempty"`
// Log is the longest membership log verified so far.
Log []ledger.Entry `json:"log,omitempty"`
// Devices is the device list as last fetched.
Devices []Device `json:"devices,omitempty"`
// Verified is when a log was last fetched from the server and
// verified.
Verified time.Time `json:"verified,omitzero"`
LoggedIn time.Time `json:"logged_in"`
}
State is what this device keeps about its account.
func Refresh ¶
Refresh fetches the account's state from the server and verifies its log; for a pending device it reports whether it has been approved.
func WaitForApproval ¶
WaitForApproval polls the server until this pending device has been approved, ctx ends, or the session fails.
func (*State) Fingerprint ¶
Fingerprint is the account fingerprint people compare.
type Summary ¶
type Summary struct {
Email string `json:"email"`
Server string `json:"server"`
Account string `json:"account"`
// Status is this device's: member, pending or logged_out.
Status string `json:"status"`
ThisDevice string `json:"this_device"`
AccountTrust bool `json:"account_trust"`
Devices []Device `json:"devices"`
Pending []JoinRequest `json:"pending,omitempty"`
// Error is set when the server could not be asked; Devices is then
// what was fetched last.
Error string `json:"error,omitempty"`
}
Summary is `remohop account --json`.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package ledger is the signed membership log of a RemoHop account: the one piece of account state that does not depend on trusting the rendezvous server.
|
Package ledger is the signed membership log of a RemoHop account: the one piece of account state that does not depend on trusting the rendezvous server. |