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
- Variables
- func ActivityAppend(e ActivityEntry)
- func ActivityClear()
- func Code() string
- func Fingerprint() string
- func GetScanInterval() int
- func Identity() (ed25519.PrivateKey, error)
- func NormalizeMode(v string) (string, error)
- func PinnedTrustKey() string
- func RemoveLegacyTrustFile()
- func ResetTrust() error
- func SaveSignedTrust(list SignedTrustList, publicKeyHex string) error
- func SetMode(string, string) error
- func SetScanInterval(sec int) error
- func Trust(string, string) error
- func TrustCacheStatus() (ok bool, expires time.Time)
- func TrustWithMode(string, string, string) error
- func Untrust(string) error
- type ActivityEntry
- type SignedTrustList
- type TrustListPayload
- type TrustedDevice
Constants ¶
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.
Variables ¶
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") )
Functions ¶
func ActivityAppend ¶
func ActivityAppend(e ActivityEntry)
ActivityAppend records an event, keeping the newest maxActivity entries.
func Code ¶
func Code() string
Code is the short human-verifiable code for this device's fingerprint.
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
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 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 SetScanInterval ¶
SetScanInterval persists the scan interval (seconds; 0 = manual only).
func Trust ¶
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
TrustCacheStatus reports whether a verified cache exists and when it expires.
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.
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.