netkeys

package
v0.1.22 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package netkeys holds a network's Ed25519 signing identity and its durable trust store of pinned peer keys.

v1 has no key rotation: losing or leaking the private key means a new network identity, and every peer has to re-trust it explicitly (`moltnet keys forget <id>` then `moltnet keys trust <id> <fingerprint>`).

Index

Constants

View Source
const (
	PinSourceInvite   = "invite"
	PinSourcePairing  = "pairing"
	PinSourceOperator = "operator"
	// PinSourceRoom is a key a room home introduced (trust introduced).
	PinSourceRoom = "room"
)

Pin sources.

Variables

View Source
var ErrPinConflict = errors.New("network is already pinned to a different key")

ErrPinConflict means a network id is already pinned to a different key. It is never resolved automatically: an operator must forget the old pin.

Functions

func DirForConfig

func DirForConfig(configPath string) string

DirForConfig is the keys directory for a network config file.

Types

type Identity

type Identity struct {
	// contains filtered or unexported fields
}

Identity is a network's signing key. It never exposes the private key: there is no accessor, and String/JSON render only public data.

func LoadIdentity

func LoadIdentity(dir string) (*Identity, error)

LoadIdentity loads an existing dir/network.key without creating one.

func LoadOrCreateIdentity

func LoadOrCreateIdentity(dir string) (identity *Identity, created bool, err error)

LoadOrCreateIdentity loads dir/network.key, creating it on first use. Creation is exclusive, so a server and a CLI racing on first start agree on one key. created reports whether this call generated it.

func NewEphemeralIdentity

func NewEphemeralIdentity() (*Identity, error)

NewEphemeralIdentity generates an in-memory identity for servers with no durable keys directory (and for tests).

func (*Identity) Fingerprint

func (i *Identity) Fingerprint() string

func (*Identity) MarshalJSON

func (i *Identity) MarshalJSON() ([]byte, error)

func (*Identity) Public

func (i *Identity) Public() protocol.NetworkIdentity

Public is the identity as published on GET /v1/network.

func (*Identity) PublicKey

func (i *Identity) PublicKey() ed25519.PublicKey

func (*Identity) Sign

func (i *Identity) Sign(message []byte) []byte

func (*Identity) String

func (i *Identity) String() string

String and MarshalJSON keep accidental logging to public data only.

type Pin

type Pin struct {
	NetworkID   string `json:"network_id"`
	Fingerprint string `json:"fingerprint"`
	PublicKey   string `json:"public_key,omitempty"`
	// Trust is protocol.KeyTrustVerified, KeyTrustIntroduced or
	// KeyTrustUnconfirmed.
	Trust string `json:"trust"`
	// Source records how the pin was learned: invite, pairing, operator.
	Source string `json:"source"`
	// SourceID is the pairing id for invite/pairing pins.
	SourceID string `json:"source_id,omitempty"`
	// IntroducedBy is the vouching room home's network id (chunk B).
	IntroducedBy string    `json:"introduced_by,omitempty"`
	PinnedAt     time.Time `json:"pinned_at"`
}

Pin binds a human-readable network id to a key fingerprint.

type PinStore

type PinStore struct {
	// contains filtered or unexported fields
}

PinStore is the durable trust store. With an empty path it is in-memory (tests and keyless servers) but enforces the same rules.

func NewMemoryPinStore

func NewMemoryPinStore() *PinStore

func OpenPinStore

func OpenPinStore(dir string) *PinStore

OpenPinStore uses dir/pins.json; the file is created on the first pin.

func (*PinStore) BindPairing

func (s *PinStore) BindPairing(pairingID, networkID string) error

BindPairing records that pairingID's credential speaks for networkID.

func (*PinStore) Forget

func (s *PinStore) Forget(networkID string) (bool, error)

Forget removes a pin, reporting whether one existed.

func (*PinStore) ForgetExact

func (s *PinStore) ForgetExact(pin Pin) error

ForgetExact removes networkID's pin only if it is still exactly pin (same key, trust, source and time), undoing one PinKeyCreated and nothing newer.

func (*PinStore) ForgetPairing

func (s *PinStore) ForgetPairing(pairingID string) error

ForgetPairing drops every binding of pairingID (its credential is gone).

func (*PinStore) List

func (s *PinStore) List() ([]Pin, error)

List returns every pin ordered by network id.

func (*PinStore) Lookup

func (s *PinStore) Lookup(networkID string) (Pin, bool, error)

Lookup reads the current pin for networkID. File-backed stores re-read the file so `moltnet keys trust/forget` take effect without a restart.

func (*PinStore) PairingNetworks

func (s *PinStore) PairingNetworks(pairingID string) ([]string, error)

PairingNetworks returns the networks pairing pairingID's credential has spoken for: its durable bindings (which survive a pin being re-sourced, e.g. by `moltnet keys trust`) plus any pin still sourced through it.

func (*PinStore) PinKey

func (s *PinStore) PinKey(pin Pin) (Pin, error)

PinKey records pin unless the network is already pinned. Pinning the same fingerprint again returns the stored pin, upgrading it to verified when the new pin is verified. A different fingerprint is ErrPinConflict, except that a verified pin replaces an unconfirmed or introduced one.

func (*PinStore) PinKeyCreated

func (s *PinStore) PinKeyCreated(pin Pin) (Pin, bool, error)

PinKeyCreated is PinKey that also reports whether this call stored a new pin or replaced a different key, so a caller whose own write then fails can undo exactly its pin (ForgetExact) and nothing else.

Jump to

Keyboard shortcuts

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