lib

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2025 License: MIT Imports: 45 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultValidity = time.Hour * 24 * 7

DefaultValidity TODO: adjust

Variables

This section is empty.

Functions

func GetLoggerForRequest

func GetLoggerForRequest(r *http.Request, clientHeader string) *slog.Logger

Types

type ChallengeCallback added in v0.2.0

type ChallengeCallback func(result challenge.VerifyResult)

type ChallengeInformation

type ChallengeInformation struct {
	Name   string `json:"name"`
	Key    []byte `json:"key"`
	Result []byte `json:"result"`

	Expiry    *jwt.NumericDate `json:"exp,omitempty"`
	NotBefore *jwt.NumericDate `json:"nbf,omitempty"`
	IssuedAt  *jwt.NumericDate `json:"iat,omitempty"`
}

type RequestData

type RequestData struct {
	Id         [16]byte
	ProgramEnv map[string]any
	Expires    time.Time
	Challenges map[challenge.Id]challenge.VerifyResult
}

func RequestDataFromContext

func RequestDataFromContext(ctx context.Context) *RequestData

func (*RequestData) HasValidChallenge

func (d *RequestData) HasValidChallenge(id challenge.Id) bool

func (*RequestData) Headers

func (d *RequestData) Headers(state *State, headers http.Header)

type RuleState

type RuleState struct {
	Name string
	Hash string

	Host *string

	Program    cel.Program
	Action     policy.RuleAction
	Challenges []challenge.Id
}

type State

type State struct {
	Client   *http.Client
	Settings StateSettings
	UrlPath  string
	Mux      *http.ServeMux

	Networks map[string]cidranger.Ranger

	Wasm *wasm.Runner

	Challenges map[challenge.Id]challenge.Challenge

	RulesEnv *cel.Env

	Rules []RuleState

	Poison map[string][]byte

	ChallengeSolve sync.Map
	// contains filtered or unexported fields
}

func NewState

func NewState(p policy.Policy, settings StateSettings) (state *State, err error)

func (*State) AwaitChallenge added in v0.2.0

func (state *State) AwaitChallenge(key []byte, ctx context.Context) challenge.VerifyResult

func (*State) GetChallengeByName

func (state *State) GetChallengeByName(name string) (challenge.Challenge, bool)

func (*State) GetChallengeKeyForRequest

func (state *State) GetChallengeKeyForRequest(challengeName string, until time.Time, r *http.Request) []byte

func (*State) ServeHTTP

func (state *State) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*State) SolveChallenge added in v0.2.0

func (state *State) SolveChallenge(key []byte, result challenge.VerifyResult)

type StateSettings

type StateSettings struct {
	Backends               map[string]http.Handler
	PrivateKeySeed         []byte
	Debug                  bool
	PackageName            string
	ChallengeTemplate      string
	ChallengeTemplateTheme string
	ClientIpHeader         string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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