senderconstraint

package
v1.0.310 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 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 senderconstraint is the listener-independent MCP sender-constraint core: DPoP proof parsing/verification, a bounded partitioned replay cache, and mTLS certificate-thumbprint binding. It receives request-binding metadata (HTTP method/URI, observed certificate thumbprint) and token confirmation values as explicit inputs; it performs no TLS handshake, no certificate-chain verification, and no network I/O.

The zero Profile fails closed: a required sender-constrained profile that cannot safely admit a proof (missing constraint, replay, cache full) is rejected — there is no best-effort path.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PartitionKey

func PartitionKey(issuer, client, thumbprint string) string

PartitionKey builds the replay partition key from the identity-bearing dimensions. jti is the per-request entry within the partition.

func VerifyMTLS

func VerifyMTLS(in MTLSInput) (string, error)

VerifyMTLS compares the observed certificate thumbprint with the token's cnf.x5t#S256 in constant time. It requires both to be present and canonically encoded; a missing binding, missing observation, malformed value, or mismatch is rejected. There is no ambiguity with DPoP here — the caller selects mTLS.

Types

type DPoPInput

type DPoPInput struct {
	Capability  protocol.Capability
	ProofJWT    string // the DPoP proof compact JWS
	HTTPMethod  string // expected htm (exact)
	HTTPURI     string // expected htu (exact, canonical)
	AccessToken string // to compute ath; NEVER stored
	ExpectedJKT string // the access token's cnf.jkt; the proof key must match
	Issuer      string // for the replay partition
	Client      string // for the replay partition
	Nonce       string // required server nonce; empty ⇒ no nonce required
}

DPoPInput is the explicit material for one DPoP verification. The access token is supplied only to compute and compare `ath`; it is never retained. All request binding (method/URI/nonce) and the token's confirmation thumbprint (cnf.jkt) are caller-supplied — no network I/O.

type DPoPResult

type DPoPResult struct {
	Thumbprint string
}

DPoPResult carries the verified proof-key thumbprint (jkt) for the identity context. It contains no key material and no token.

func VerifyDPoP

func VerifyDPoP(in DPoPInput, cache *ReplayCache, lim limits.AuthLimits, now time.Time) (DPoPResult, error)

VerifyDPoP verifies a DPoP proof against the request and the access token, and records the proof jti in the replay cache. It validates: proof type dpop+jwt; supported asymmetric alg; embedded PUBLIC jwk (no private material); signature; exact htm/htu; iat within the configured window; non-empty jti; ath == the hash of the presented access token; the proof-key thumbprint == the token's cnf.jkt; and the optional nonce. A replayed jti (or a full cache) fails closed.

type MTLSInput

type MTLSInput struct {
	ObservedThumbprint string // base64url SHA-256 of the observed peer certificate
	TokenX5TS256       string // the token's cnf.x5t#S256
}

MTLSInput is the material for an mTLS certificate-binding check. The caller supplies the OBSERVED peer certificate SHA-256 thumbprint (base64url) — PR-3 performs no TLS handshake and no certificate-chain verification — and the token's confirmation thumbprint (cnf.x5t#S256).

type Profile

type Profile uint8

Profile is a deployment sender-constraint requirement.

const (
	// ProfileUnset — the zero value. FAILS CLOSED: not a usable profile.
	ProfileUnset Profile = iota
	// BearerControlled — a controlled/low-risk deployment where an unconstrained
	// bearer token is acceptable. The ONLY profile that permits bearer fallback.
	BearerControlled
	// DPoPRequired — every request must carry a valid, non-replayed DPoP proof bound
	// to the access token.
	DPoPRequired
	// MTLSRequired — the access token must be mTLS-bound (cnf.x5t#S256) and match the
	// observed peer certificate.
	MTLSRequired
	// DPoPOrMTLSRequired — either DPoP or mTLS binding is required (no bearer fallback).
	DPoPOrMTLSRequired
)

func (Profile) AllowsBearer

func (p Profile) AllowsBearer() bool

AllowsBearer reports whether the profile permits an unconstrained bearer token. Only BearerControlled does; the zero profile and every constrained profile do not.

func (Profile) RequiresDPoP

func (p Profile) RequiresDPoP() bool

RequiresDPoP reports whether the profile can be satisfied by a DPoP proof.

func (Profile) RequiresMTLS

func (p Profile) RequiresMTLS() bool

RequiresMTLS reports whether the profile can be satisfied by an mTLS binding.

func (Profile) String

func (p Profile) String() string

String returns the profile label.

type ReplayCache

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

ReplayCache is a bounded, time-expiring, race-safe, per-capability DPoP-proof replay cache. Keys are partitioned by (capability, issuer, client, proof-key thumbprint) with the proof jti as the entry within a partition, so no partition can grow unbounded from attacker-controlled input and one capability can never exhaust the other (each capability has its own total budget). There are no per-entry goroutines: expired entries are swept opportunistically on access, amortizing cleanup. Full-capacity behavior is explicit and FAILS CLOSED.

func NewReplayCache

func NewReplayCache(lim limits.AuthLimits, clk func() time.Time) *ReplayCache

NewReplayCache builds a replay cache bounded by lim, using clk (nil ⇒ time.Now).

func (*ReplayCache) CheckAndAdd

func (c *ReplayCache) CheckAndAdd(capb protocol.Capability, partKey, jti string, ttl time.Duration) error

CheckAndAdd records a fresh proof jti in its partition and returns nil, or ReasonDPoPReplay if the jti was already seen within its (unexpired) window. It fails closed (also ReasonDPoPReplay) when the partition or the capability cache is at capacity and no expired room can be reclaimed — a required sender-constrained profile never admits on best-effort.

func (*ReplayCache) Size

func (c *ReplayCache) Size(capb protocol.Capability) int

Size returns the entry count for a capability (for tests/metrics).

func (*ReplayCache) Sweep

func (c *ReplayCache) Sweep() int

Sweep removes all expired entries across both capabilities and returns the count reclaimed. Callers may invoke it on a cadence; access-time sweeping already keeps hot partitions bounded, so this is a background convenience, not a requirement.

Jump to

Keyboard shortcuts

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