identity

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: Apache-2.0 Imports: 23 Imported by: 2 modules, 4 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 identity is who the parties are: their keys and cards, how two parties come to trust each other, and how they sign and seal what they write.

Index

Constants

View Source
const ClockAllowance = 5 * time.Minute

ClockAllowance is how far two parties' clocks may differ. A receiver allows this much before it treats another party's time as passed.

Variables

View Source
var (
	// ErrAltered is a value whose signature does not hold, or that was
	// found under a name it was not signed for.
	ErrAltered = errors.New("the value has been altered or moved")
	// ErrNotForUs is a sealed value this identity cannot open.
	ErrNotForUs = errors.New("the value is not sealed to this party")
)

Functions

func CheckName

func CheckName(name string) error

CheckName says whether a party may have the name: it is one part of a store's names, of letters, digits, dots, dashes and underscores.

func Decode

func Decode(data []byte, into any) error

Decode reads JSON strictly: an unknown name, a repeated name or a name in the wrong case is an error.

func Encode

func Encode(v any) ([]byte, error)

Encode writes v as JSON in the one form signed and stored values have: the same value always gives the same bytes.

func Exists

func Exists(path string) bool

Exists says whether there is an identity file at path.

func WriteTrust

func WriteTrust(ctx context.Context, s store.Store, ctl *Identity, t Trust) error

WriteTrust writes what a controller holds about a party into its store.

Types

type Card

type Card struct {
	Name string
	Kind Kind
	// contains filtered or unexported fields
}

A Card is the public side of an identity: a name, a kind and two public keys, signed by itself. Its text form is one line.

func ParseCard

func ParseCard(line string) (Card, error)

ParseCard reads a card from its line of text and checks its signature.

func (Card) Fingerprint

func (c Card) Fingerprint() string

Fingerprint is a short mark of the card, made from its name, its kind and both of its keys, for two people to compare.

func (Card) IsZero

func (c Card) IsZero() bool

IsZero says whether the card is no card at all.

func (Card) MarshalText

func (c Card) MarshalText() ([]byte, error)

func (Card) Same

func (c Card) Same(o Card) bool

Same says whether two cards hold the same keys.

func (Card) SignKey

func (c Card) SignKey() ed25519.PublicKey

SignKey is the key a card's signatures are checked with.

func (Card) String

func (c Card) String() string

String is the card as one line of text.

func (*Card) UnmarshalText

func (c *Card) UnmarshalText(text []byte) error

type Config

type Config struct {
	Dir string
}

A Config is the directory that holds a machine's parties: a place each for a controller, a runner and a client.

<config>/controller/identity      the controller's keys
<config>/controller/store         the address of its store
<config>/runner/identity          the runner's keys
<config>/runner/trust/<name>      a controller the runner serves
<config>/client/identity          the client's keys
<config>/client/trust/<name>      the client's controller

func DefaultConfig

func DefaultConfig() (Config, error)

DefaultConfig is where a machine's parties live unless it is told otherwise.

func (Config) ControllerStore

func (c Config) ControllerStore() (string, error)

ControllerStore is the address of the controller's store.

func (Config) Has

func (c Config) Has(kind Kind) bool

Has says whether the config holds an identity of the kind.

func (Config) Load

func (c Config) Load(kind Kind) (*Identity, error)

Load reads the identity of the kind.

func (Config) Make

func (c Config) Make(kind Kind, name string) (*Identity, error)

Make gives the identity of the kind, making it with the name if there is none. A name once chosen is never changed: an identity that exists is given as it is.

func (Config) Served

func (c Config) Served() (string, error)

Served is where the controller's computer serves its directory to other machines, as host:port, or nothing where it does not.

func (Config) SetControllerStore

func (c Config) SetControllerStore(address string) error

SetControllerStore notes the address of the controller's store.

func (Config) SetServed

func (c Config) SetServed(at string) error

SetServed notes where the controller's computer serves its directory, or with nothing given that it does not.

func (Config) SetTrust

func (c Config) SetTrust(kind Kind, t Trust) error

SetTrust writes what the runner or the client holds about a controller.

func (Config) Trust

func (c Config) Trust(kind Kind, controller string) (*Trust, error)

Trust reads what the runner or the client of this config holds about a controller.

func (Config) TrustList

func (c Config) TrustList(kind Kind) ([]Trust, error)

TrustList reads every controller the runner or the client holds, removed ones included.

type Identity

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

An Identity is a party's two private keys, with its card.

func Load

func Load(path string) (*Identity, error)

Load reads an identity from its file. A file that anyone but its owner can read is refused. No error it gives holds anything from the file.

func New

func New(name string, kind Kind) (*Identity, error)

New makes an identity with new keys.

func (*Identity) Proof

func (id *Identity) Proof() (tls.Certificate, error)

Proof is what the identity shows of itself to the other end of a served directory's wire: that it holds its signing key.

func (*Identity) Save

func (id *Identity) Save(path string) error

Save writes the identity to a file only its owner can read, whole or not at all.

func (*Identity) Write

func (id *Identity) Write(at string, now, until time.Time, body any, to ...Card) ([]byte, error)

Write signs body as a value that belongs under the name at, sent now and good until the time given (for ever, if zero). With cards, the body is sealed to them and nobody else can read it.

type Kind

type Kind string

Kind is what a party is.

const (
	Controller Kind = "controller"
	Runner     Kind = "runner"
	Client     Kind = "client"
)

type Trust

type Trust struct {
	Card    Card             `json:"card"`
	Ceiling permission.Layer `json:"ceiling,omitzero"`
	Tags    []string         `json:"tags,omitzero"`
	Store   string           `json:"store,omitzero"`
	Removed bool             `json:"removed,omitzero"`
}

Trust is what one party holds about another it has taken the card of: the card, and the limit trust was given with. A controller gives a client a ceiling and a runner its tags; a runner gives a controller a ceiling, and notes the address of that controller's store, as a client does.

A removed party stays on record with its key, so its name stays tied to that key.

func ListTrust

func ListTrust(ctx context.Context, s store.Store, ctl Card) ([]Trust, error)

ListTrust reads everything a controller holds about other parties.

func ReadTrust

func ReadTrust(ctx context.Context, s store.Store, ctl Card, party string) (*Trust, error)

ReadTrust reads what a controller holds about a party from its store. It is read afresh each time it is asked for.

func Take

func Take(old *Trust, card Card, want Kind, replace bool) (Trust, error)

Take is what trusting a card gives, given what is on record under its name. A name stays tied to the key it was first taken with, also after the party was removed: a different key is refused unless replace says it takes the old one's place. What the old key was given is not carried over.

func (Trust) HasTags

func (t Trust) HasTags(tags []string) bool

HasTags says whether the party was given every one of the tags.

func (*Trust) Trusted

func (t *Trust) Trusted() bool

Trusted says whether anything from the party is accepted.

type Value

type Value struct {
	By     string    `json:"by"`
	At     string    `json:"at"`
	Sent   time.Time `json:"sent"`
	Until  time.Time `json:"until,omitzero"`
	Sealed bool      `json:"sealed,omitzero"`
	// contains filtered or unexported fields
}

A Value is something a party signed: three lines of text. The first is the frame, which says who signed it, which name in the store it belongs under, when it was written and when it stops being good. The second is the body, as JSON, or sealed so that only the parties it was sealed to can read it. The third is the signature over the first two.

The frame is bound into the sealing, so nobody can wrap a sealed body in a frame of their own.

func Parse

func Parse(data []byte) (Value, error)

Parse reads a value's frame. Nothing is checked: until Check has passed, the frame is whatever its writer chose.

func Read

func Read(data []byte, at string, signer Card, id *Identity, into any) (Value, error)

Read is Parse, Check and Open together, for a value whose signer is known before it is read.

func (Value) Check

func (v Value) Check(signer Card, at string) error

Check says whether the value was signed by the card and belongs under the name it was found at.

func (Value) Good

func (v Value) Good(now time.Time) bool

Good says whether the value is still good at now, by the reader's own clock, allowing for clocks that differ.

func (Value) Open

func (v Value) Open(id *Identity, into any) error

Open reads the body into a Go value, opening it first if it is sealed. Call it only after Check.

Jump to

Keyboard shortcuts

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