account

package
v1.0.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2026 License: AGPL-3.0 Imports: 25 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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.

View Source
const File = "account.json"

File is the account session inside the config directory (mode 0600: it holds the session token).

View Source
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.

View Source
const SettingTrust = "account-trust"

SettingTrust is the host setting that makes it accept its account's devices like authorised keys.

View Source
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

View Source
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.

View Source
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

func CachedDevices(dir string) ([]Device, *State, error)

CachedDevices is the device list as last fetched, without asking the server; presence is as it was then.

func CheckLog

func CheckLog(dir string, log []ledger.Entry) error

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

func Delete(ctx context.Context, opts Options) error

Delete deletes the account on the server: every device's session ends and the account is gone. Only a member can.

func DeviceName

func DeviceName(values map[string]string) string

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

func Devices(ctx context.Context, opts Options) ([]Device, *State, error)

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

func HostKey(ctx context.Context, opts Options, id string, refresh bool) (ed25519.PublicKey, bool)

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

func IsTrustEntry(name string) bool

IsTrustEntry reports whether an authorised key's name marks it as one account-trust manages.

func Logout

func Logout(ctx context.Context, opts Options) error

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 Reject

func Reject(ctx context.Context, opts Options, fingerprint string) error

Reject drops the join request of the device with that fingerprint.

func RequestCode

func RequestCode(ctx context.Context, opts Options, email string) error

RequestCode asks the rendezvous server to mail a login code to email.

func RunHost

func RunHost(ctx context.Context, dir string, log *slog.Logger)

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

func SyncTrust(dir string) (added, removed int, err error)

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

func TrustEnabled(dir string) bool

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.

func Remove

func Remove(ctx context.Context, opts Options, ref string) (*Device, error)

Remove takes a device out of the account: ref is its identity fingerprint, 9-digit ID or name (if unique). Its session ends, and hosts with account-trust stop accepting it once they see the change.

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.

func Approve

func Approve(ctx context.Context, opts Options, fingerprint string) (*JoinRequest, error)

Approve adds the waiting device whose identity fingerprint is exactly fingerprint. The fingerprint has to be the one the new device printed: that comparison is what keeps the rendezvous server from slipping its own key into the account.

func Pending

func Pending(ctx context.Context, opts Options) ([]JoinRequest, error)

Pending lists the devices waiting for approval.

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 Load

func Load(dir string) (*State, error)

Load returns this device's account state, or ErrNotLoggedIn.

func LoadOpts

func LoadOpts(opts Options) (*State, error)

LoadOpts is Load on the directory of opts.

func Refresh

func Refresh(ctx context.Context, opts Options) (*State, error)

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

func WaitForApproval(ctx context.Context, opts Options, every time.Duration) (*State, error)

WaitForApproval polls the server until this pending device has been approved, ctx ends, or the session fails.

func (*State) Fingerprint

func (st *State) Fingerprint() string

Fingerprint is the account fingerprint people compare.

func (*State) Ledger

func (st *State) Ledger() (*ledger.State, error)

Ledger verifies the stored log.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL