lanid

package
v0.60.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: GPL-3.0 Imports: 13 Imported by: 2 modules, 1 package

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 lanid manages this device's persistent LAN identity (an Ed25519 keypair) and the trusted-devices store, shared by the `s2u` CLI and the desktop GUI. Both store under os.UserConfigDir()/share2us (the same base cli-core uses for credentials/config), so a device's identity and the devices it trusts are shared across the CLI and GUI on one machine.

Trust is keyed by the peer's verified public-key fingerprint (never its name or IP), so a device recognised once needs no per-transfer verify code — and can be revoked.

Index

Constants

View Source
const (
	// ModeAsk: trusted, but every transfer still needs a one-tap approval (no
	// verify code, no anti-spam caps). The default.
	ModeAsk = "ask"
	// ModeAuto: trusted and its transfers are saved without asking.
	ModeAuto = "auto"
)

Trust modes.

View Source
const TrustKeysEnv = "SHARE2US_TRUST_KEYS"

TrustKeysEnv lists extra accepted server keys, comma-separated hex, for self-hosted and development servers. Setting it is an explicit act by the operator of the machine; it is never read from a file the CLI writes.

Variables

View Source
var (
	// ErrTrustKeyChanged means the server presented a different signing key than
	// the one pinned locally. Refused rather than silently re-pinned; the user
	// clears the cache (ResetTrust) if the server really rotated its key.
	ErrTrustKeyChanged = errors.New("lanid: server trust-signing key changed; run `lan trusted reset` if this is expected")
	// ErrLocalTrustDisabled is returned by the retired local writers.
	ErrLocalTrustDisabled = errors.New("lanid: trusting a device requires verification through your account (ADR-034); local trust is disabled")
)
View Source
var BuiltinTrustKeys = []string{
	"fdce17424db15bee0a7f859e93f31f732296870a4209f639e02ec6286c6d327c",
	"87be5b415b53731efbc0fd79e79797c055ea9a9474264acf4965f118028a5e44",
}

BuiltinTrustKeys are the server trust-signing public keys (hex Ed25519) this build accepts. They are compiled in because the cache file is the thing being verified: a pin READ FROM THAT FILE proves nothing (§AJ #10: any local process could write a self-signed list with its own device on "auto", and the ADR-034 gate was bypassed offline). A key rotation ships as a client release that lists both keys. Self-hosted or development servers add theirs through SHARE2US_TRUST_KEYS.

View Source
var CurrentAccountID func() string

CurrentAccountID reports the account the saved login belongs to. A cached list is honoured only for THAT account: the server signs lists for every account, so without this binding a list the attacker obtained for their own account (their device on "auto") would verify under the genuine key. The root package wires this at init from the credential file; nil or "" means no cache is ever trusted.

View Source
var ErrTrustKeyNotPinned = errors.New("lanid: server trust-signing key is not one this build accepts (set " + TrustKeysEnv + " for a self-hosted server)")

ErrTrustKeyNotPinned means the server's signing key is not one this build knows. A list under an unknown key is never cached and never honoured.

Functions

func ActivityAppend

func ActivityAppend(e ActivityEntry)

ActivityAppend records an event, keeping the newest maxActivity entries.

func ActivityClear

func ActivityClear()

ActivityClear empties the log.

func Code

func Code() string

Code is the short human-verifiable code for this device's fingerprint.

func Fingerprint

func Fingerprint() string

Fingerprint / Code identify this device to peers.

func GetScanInterval

func GetScanInterval() int

GetScanInterval returns the broadcast-discovery scan interval in seconds (default 60; 0 = manual refresh only).

func Identity

func Identity() (ed25519.PrivateKey, error)

Identity returns this device's persistent Ed25519 identity, creating and saving it (0600) on first use.

func NormalizeMode added in v0.12.0

func NormalizeMode(v string) (string, error)

NormalizeMode maps user input to a mode constant ("" -> ModeAsk).

func PinnedTrustKey added in v0.13.0

func PinnedTrustKey() string

PinnedTrustKey returns the pinned server key ("" if none yet).

func RemoveLegacyTrustFile added in v0.13.0

func RemoveLegacyTrustFile()

RemoveLegacyTrustFile deletes the pre-ADR-034 local trust file if present. Its entries were never verified by a second factor, so they are not migrated; the user re-trusts each device with MFA. Best-effort.

func ResetTrust added in v0.13.0

func ResetTrust() error

ResetTrust drops the cached list and the pinned key.

func SafetyNumber added in v0.14.0

func SafetyNumber() string

SafetyNumber is this device's long comparison number (lanshare.SafetyNumber), shown at trust time next to the 6-digit Code.

func SaveSignedTrust added in v0.13.0

func SaveSignedTrust(list SignedTrustList, publicKeyHex string) error

SaveSignedTrust verifies a freshly fetched list and caches it. The server key is pinned on the first save; a different key later is refused.

func SetMode added in v0.12.0

func SetMode(string, string) error

func SetScanInterval

func SetScanInterval(sec int) error

SetScanInterval persists the scan interval (seconds; 0 = manual only).

func Trust

func Trust(string, string) error

Trust, TrustWithMode, SetMode and Untrust were the local writers of the pre-ADR-034 trust file. Trust is now granted, changed and revoked through the account API (with MFA for anything that widens it); these remain only so old callers fail loudly instead of silently writing a file nobody reads.

func TrustCacheStatus added in v0.13.0

func TrustCacheStatus() (ok bool, expires time.Time)

TrustCacheStatus reports whether a verified cache exists and when it expires.

func TrustWithMode added in v0.12.0

func TrustWithMode(string, string, string) error

func Untrust

func Untrust(string) error

Types

type ActivityEntry

type ActivityEntry struct {
	Kind string `json:"kind"` // sent | received | downloaded | broadcast | link
	Peer string `json:"peer"`
	Name string `json:"name"`
	Size int64  `json:"size"`
	Link string `json:"link,omitempty"` // for kind "link": the share URL (re-copyable)
	TS   int64  `json:"ts"`             // unix seconds
}

ActivityEntry is one logged transfer/broadcast event. Metadata only — never file contents.

func ActivityList

func ActivityList() []ActivityEntry

ActivityList returns the log, newest first.

type SignedTrustList added in v0.13.0

type SignedTrustList struct {
	KeyID     string `json:"kid"`
	Payload   string `json:"payload"`   // base64url JSON of TrustListPayload
	Signature string `json:"signature"` // base64url Ed25519 over the raw payload
}

SignedTrustList is the server's signed list as returned by GET /v1/lan/trusted (and by the challenge verify / mode / revoke endpoints).

type TrustListPayload added in v0.13.0

type TrustListPayload struct {
	Version   int             `json:"v"`
	AccountID string          `json:"account_id"`
	IssuedAt  time.Time       `json:"issued_at"`
	ExpiresAt time.Time       `json:"expires_at"`
	Devices   []TrustedDevice `json:"devices"`
}

TrustListPayload is the signed content.

func VerifyTrustList added in v0.13.0

func VerifyTrustList(list SignedTrustList, publicKeyHex string, now time.Time) (TrustListPayload, error)

VerifyTrustList checks a signed list against a public key (hex) at time now.

type TrustedDevice

type TrustedDevice struct {
	Fingerprint string `json:"fingerprint"`
	Name        string `json:"name"`
	// Mode is ModeAsk or ModeAuto. Empty (records written before modes existed)
	// means ModeAsk: the safer reading, never fewer prompts than the user expects.
	Mode string `json:"mode,omitempty"`
}

TrustedDevice is a device we've trusted, keyed by its verified Ed25519 key fingerprint. Trust skips the verify-code compare and the anti-spam caps; what happens next depends on Mode: ModeAsk (the default) still asks the receiver to approve each transfer, ModeAuto lets its transfers land without a prompt. Untrusted devices always go through the full prompt. Revocable.

func List

func List() []TrustedDevice

List returns the trusted devices from the verified cache, sorted by name.

func Lookup

func Lookup(fingerprint string) (TrustedDevice, bool)

Lookup returns the trusted device for a fingerprint from the VERIFIED server- signed cache (ok=false if untrusted, anonymous, or no valid cache).

func (TrustedDevice) AutoAccept added in v0.12.0

func (d TrustedDevice) AutoAccept() bool

AutoAccept reports whether transfers from this device may land without asking.

func (TrustedDevice) EffectiveMode added in v0.12.0

func (d TrustedDevice) EffectiveMode() string

EffectiveMode returns the device's mode with the legacy empty value read as ask.

Jump to

Keyboard shortcuts

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