provider

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package provider decides whether an inbound request really came from the provider it claims to be.

Nothing here knows a vendor's name. A vendor is a set of parameters, and a preset is a name for such a set. Adding support for one is registration or configuration, never a new branch.

Index

Constants

View Source
const (
	Simple   = "simple"
	Advanced = "advanced"
)

How the signature header is laid out.

View Source
const (
	SHA1   = "sha1"
	SHA256 = "sha256"
	SHA512 = "sha512"
)
View Source
const (
	Hex    = "hex"
	Base64 = "base64"
)
View Source
const (
	SharedToken = "shared-token"
	BasicAuth   = "basic-auth"
)

Proof that carries no signature: the caller only shows it knows the secret. It says nothing about the body, and is what a provider that does not sign leaves you with.

View Source
const HMAC = "hmac"

Variables

View Source
var (
	ErrNoProof       = errors.New("the request carried no proof of origin")
	ErrMalformed     = errors.New("the proof is malformed")
	ErrMismatch      = errors.New("the proof does not match")
	ErrStale         = errors.New("the proof is outside the tolerance window")
	ErrNoSecret      = errors.New("no secret is configured")
	ErrUnknownKind   = errors.New("unknown verifier")
	ErrUnknownOption = errors.New("unknown option")
)

Functions

func Algorithms

func Algorithms() []string

func Encodings

func Encodings() []string

func PresetNames

func PresetNames() []string

func Schemes

func Schemes() []string

Types

type Build

type Build func(Settings) (Verifier, error)

Build turns settings into a verifier, or fails if they do not describe one.

type Cache

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

Cache holds a built verifier per tenant and provider, so checking a request costs no query and no construction. A provider that is absent gets the verifier that checks nothing, which is why a cold or failed load can never keep a request from being recorded.

func NewCache

func NewCache(source Source, registry *Registry, refresh time.Duration, logger *slog.Logger) *Cache

func (*Cache) Verifier

func (c *Cache) Verifier(tenant uuid.UUID, name string) Verifier

func (*Cache) VerifyToken added in v0.2.0

func (c *Cache) VerifyToken(tenant uuid.UUID, name string) (string, bool)

VerifyToken is the token a provider must offer before its callback address is confirmed, and whether one was ever asked for. A provider that asked and whose variable is not set here answers ("", true): nothing can be compared, and nothing in this process can put it there either, which is a different answer from an address that confirms nothing.

func (*Cache) Watch

func (c *Cache) Watch(ctx context.Context)

Watch loads the settings and keeps them current: at once when a change is announced, and on the refresh interval regardless, so a missed announcement cannot leave verification stale.

type Preset

type Preset struct {
	Name            string
	Description     string
	Settings        Settings
	ConfirmsAddress bool
}

A preset is a name for a set of parameters. It adds no behaviour: everything it fills in could be typed by hand, and nothing reads the name at runtime.

func PresetByName

func PresetByName(name string) (Preset, bool)

func Presets

func Presets() []Preset

type Registry

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

Registry maps a kind of proof to the code that builds it. Supporting a new kind is a call to Register, not an edit to a conditional.

func Default

func Default() *Registry

Default is the registry this project ships with: the kinds of proof a provider can offer, and nothing about who offers them.

func NewRegistry

func NewRegistry() *Registry

func (*Registry) Kinds

func (r *Registry) Kinds() []string

func (*Registry) Knows

func (r *Registry) Knows(kind string) bool

func (*Registry) Register

func (r *Registry) Register(kind string, build Build)

func (*Registry) Verifier

func (r *Registry) Verifier(settings Settings) (Verifier, error)

Verifier for these settings. Empty settings produce a verifier that checks nothing, so a caller never has to test for absence.

type Request

type Request struct {
	Headers http.Header
	Body    []byte
	Now     time.Time
}

Request is what a verifier is allowed to look at. The body is the exact bytes received, because that is what was signed.

type Settings

type Settings struct {
	Verifier string
	Secret   string
	// VerifyToken is what a provider that confirms its callback address before
	// sending anything offers when it does. Resolved, like Secret, so a preset
	// must never set either: a preset is parameters, and these are credentials.
	VerifyToken string
	// VerifyTokenNamed is whether a variable was named for that token, which
	// is a fact about the row and not its location: it names nothing and
	// resolves nothing. A resolved token cannot tell a provider that asked for
	// no confirmation from one whose variable is not set in this process, and
	// those two are owed different answers.
	VerifyTokenNamed bool
	Header           string
	Scheme           string
	Algorithm        string
	Encoding         string
	TimestampKey     string
	SignatureKey     string
	Tolerance        time.Duration
}

Settings are the parameters as an operator stores them.

type Source

type Source interface {
	AllVerification(ctx context.Context) (map[uuid.UUID]map[string]Settings, error)
	ProviderChanges(ctx context.Context) <-chan struct{}
}

Source is where the settings come from. Declared here, by the side that consumes it, so this package depends on no storage.

type State

type State string
const (
	// Unchecked: nothing is configured for the provider.
	Unchecked State = "unchecked"
	// Valid: the proof held.
	Valid State = "valid"
	// Invalid: a proof was offered and did not hold.
	Invalid State = "invalid"
	// Missing: a proof was required and none was offered.
	Missing State = "missing"
)

type Unverified

type Unverified struct{}

Unverified stands for a provider nobody configured. It is a verifier so that the inbound port has one path, not two.

func (Unverified) Verify

func (Unverified) Verify(Request) (State, error)

type Verifier

type Verifier interface {
	Verify(Request) (State, error)
}

Verifier is one way of proving a request's origin.

Jump to

Keyboard shortcuts

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