Skip to content

Go: package webbotauth

Generated from the Go source by scripts/gen-docs.sh — do not edit; run it to regenerate. Canonical deep reference: pkg.go.dev/github.com/dnsid-ai/dnsid-go/webbotauth. Guides and account setup: https://docs.dnsid.ai.

import "github.com/dnsid-ai/dnsid-go/webbotauth"

Package webbotauth implements the constrained DNSid Web Bot Auth profile targeting draft-ietf-webbotauth-httpsig-protocol-01, using package httpsig. It signs and verifies requests and signed key directories using Ed25519. This is not a generic WBA verifier or a partner interoperability claim.

The main entry type is Profile. A Profile holds the agent’s domain and its dnsid.KeyProvider; Config controls the Signature-Agent header, the key directory URL, and signature lifetimes, and its zero value applies the profile defaults. Requests must cover the Signature-Agent dictionary member, which contains a direct HTTPS directory URL and has no parameters. Trusted caller policy does not replace signed discovery. Directory creation times cannot be in the future, even within the configured request clock skew.

A typical caller signs a request and lets the origin discover its key through the Signature-Agent header:

profile := webbotauth.NewFromIdentityManager(idm, webbotauth.Config{})
req, _ := http.NewRequest(http.MethodGet, "https://target.example/search?q=dnsid", nil)
signed, err := profile.CreateWebBotAuthSignedRequest(req, webbotauth.SigningOptions{})
// signed carries Signature-Agent, Signature-Input, and Signature headers.

ServeHttpMessageSignaturesDirectory produces the signed key directory response that origins fetch from DirectoryPath to obtain the agent’s public key. Request signing preserves existing Authorization fields. Directories are backdated by min(5, TTL-1) seconds without extending their lifetime, and emit bounded max-age with must-revalidate. Disable CDN stale serving, stale-while-revalidate, and stale-if-error for this endpoint. Only the current DNSid operational key is accepted, without rotation overlap. After both signatures pass, a key mismatch permits one DNSid refresh per domain per five seconds. Failed attempts consume the allowance. Suppressed, failed, or still-mismatched refreshes reject; caches can still delay rotation.

VerifyWebBotAuthSignedRequest authenticates both signatures and binds the directory key to the current DNSid ku key through a RefreshingIdentityResolver, including its configured accountable-entity acceptance. NewVerifier requires no local identity. Discovery uses public-address-only, Web-PKI HTTPS with no redirects, content coding, or directory caching. Each invocation sends an unconditional no-cache GET; fresh directory key misses are not retried. Discovery must not identify authenticated ku, including query variants. Discovery availability failures are transient; invalid evidence and unsafe destinations are not. Supply a trusted SignerDomain or explicitly permit the signed discovery host to identify it; cross-host delegation is unsupported. Pass the current application peer’s verified certificate chains for fl=mtls, not the directory server’s certificate.

Verification has a finite shared deadline, bounded content and directory inputs, and a caller-supplied ReplayPolicy hook. Without a replay policy, valid signatures can be reused until expiry. Required @authority coverage alone does not bind the method or path. Signers can cover additional components; recipients require them through VerificationOptions.RequiredComponents. Extra signing coverage does not make a recipient require it.

WBA reuses ku, which also authorizes KEY_ROTATION. Unrestricted signing-node key access therefore permits identity rotation, not just forged requests; keeping ek off the fleet does not remove rotation authority. Use the shared managed rotation/recovery flow, pause request and directory signing during recovery, and revoke/reissue suspected compromised keys rather than rotate. Without fl=mtls, validated HTTPS retrieval of ku supplies agent-domain TLS evidence; the crawler itself need not accept inbound connections. With fl=mtls, hosted resource certificates do not replace current application-peer evidence.

See https://docs.dnsid.ai for protocol guides and account setup.

Example

Example creates a Web Bot Auth signed request. The signing key must be Ed25519.

package main
import (
"fmt"
"net/http"
dnsid "github.com/dnsid-ai/dnsid-go"
"github.com/dnsid-ai/dnsid-go/webbotauth"
)
func main() {
key := dnsid.GenerateEd25519KeyProvider()
profile := webbotauth.New("bot.example", key, webbotauth.Config{})
req, err := http.NewRequest(http.MethodGet, "https://target.example/search?q=dnsid", nil)
if err != nil {
panic(err)
}
signed, err := profile.CreateWebBotAuthSignedRequest(req, webbotauth.SigningOptions{})
if err != nil {
panic(err)
}
// Signature-Input and Signature vary per run; Signature-Agent tells the
// origin where to fetch this agent's key directory.
fmt.Println("Signature-Agent:", signed.Header.Get("Signature-Agent"))
fmt.Println("signature present:", signed.Header.Get("Signature") != "")
}
Signature-Agent: sig1="https://bot.example/.well-known/http-message-signatures-directory"
signature present: true

const (
// DirectoryPath is the well-known HTTP path where a Web Bot Auth key
// directory is served.
DirectoryPath = "/.well-known/http-message-signatures-directory"
// DirectoryContentType is the media type of a Web Bot Auth key
// directory response.
DirectoryContentType = "application/http-message-signatures-directory+json"
)

Config contains Web Bot Auth profile defaults. The zero value applies the profile defaults.

type Config struct {
// DirectoryURL is the HTTPS JWKS endpoint advertised in Signature-Agent.
// Empty uses the well-known directory URL at the local domain.
DirectoryURL string
// SignatureTTL is the default request signature lifetime (the distance
// from the created to the expires parameter). Zero means the default of
// 1 minute; WithSignatureTTL records explicit presence and rejects zero.
// Nonzero values below 1 second or above 5 minutes are invalid.
SignatureTTL time.Duration
// Deprecated: Signature-Agent is required. Nil and true are accepted;
// false is invalid.
IncludeSignatureAgent *bool
// DirectorySignatureTTL is the signature lifetime for key directory
// responses. Zero means the default of 5 minutes; WithDirectorySignatureTTL
// records explicit presence and rejects zero. Nonzero values below 1 second
// or above 5 minutes are invalid.
DirectorySignatureTTL time.Duration
// ClockSkew is the request creation and signature expiry tolerance.
// Directory creation times never permit future timestamps. Negative values
// are invalid. Zero means omitted (5 seconds); WithClockSkew(0) sets strict zero.
ClockSkew time.Duration
// contains filtered or unexported fields
}

func (c Config) WithClockSkew(skew time.Duration) Config

WithClockSkew specifies verification tolerance, including explicit zero.

func (c Config) WithDirectorySignatureTTL(ttl time.Duration) Config

WithDirectorySignatureTTL specifies an explicit positive directory lifetime.

func (c Config) WithSignatureTTL(ttl time.Duration) Config

WithSignatureTTL specifies an explicit positive request signature lifetime.

Profile signs and verifies DNSid Web Bot Auth requests and serves signed key directories. The signing key must be Ed25519. Verification requires an RefreshingIdentityResolver, supplied through NewVerifier or NewFromIdentityManager.

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

func New(domain string, kp dnsid.KeyProvider, cfg Config) *Profile

New constructs a Web Bot Auth profile that signs as domain using kp. The domain is normalized to a FQDN when possible. Signing fails unless kp’s active key is Ed25519.

func NewFromIdentityManager(manager identityManager, cfg Config) *Profile

NewFromIdentityManager constructs a Web Bot Auth profile from an IdentityManager-like core manager, using its domain and KeyProvider. A nil manager yields a profile whose signing operations fail.

func NewVerifier(resolver dnsid.IdentityResolver, cfg Config) (*Profile, error)

NewVerifier constructs a verification-only profile with public-address-only, Web-PKI HTTPS discovery. Redirects are rejected. No local key is required. Construction fails unless resolver implements dnsid.RefreshingIdentityResolver.

func (p *Profile) CreateWebBotAuthSignedRequest(req *http.Request, opts SigningOptions) (*http.Request, error)

CreateWebBotAuthSignedRequest returns a signed clone of req carrying Signature-Input and Signature headers tagged “web-bot-auth”, plus a covered Signature-Agent header. Requests with a body also gain a covered Content-Digest header. The profile’s active key must be Ed25519.

func (p *Profile) ServeHttpMessageSignaturesDirectory(req *http.Request) (*http.Response, error)

ServeHttpMessageSignaturesDirectory builds the signed key directory response containing the profile’s active public key. req is recorded as the response’s originating request so the signature can cover @authority.

func (p *Profile) VerifyWebBotAuthSignedRequest(ctx context.Context, req *http.Request, opts VerificationOptions) (*dnsid.VerifiedDomain, error)

VerifyWebBotAuthSignedRequest verifies a request, its signed directory, and current DNSid ku binding and acceptance. It does not grant permissions. The operation has the shared verification deadline, 1 MiB request metadata, 8 MiB request content, 1 MiB directory, 64 directory keys, and 64 JSON nesting levels. Directories are not cached; DNSid acceptance and current key binding run on every call. Supplied body readers must unblock on Close; resolver and replay callbacks must honor ctx. Signature fields use the shared parser’s 64 KiB and 128-label limits, with at most 128 components per signature.

ReplayPolicy must atomically reject a repeated (domain, keyID, nonce), retain it until retainUntil, and fail closed on store errors.

type ReplayPolicy func(ctx context.Context, domain, keyID, nonce string, retainUntil time.Time) error

SigningOptions configures Web Bot Auth request signing.

type SigningOptions struct {
// AdditionalComponents lists extra component names to cover beyond the
// profile's defaults. Unknown names cause signing to fail.
AdditionalComponents []string
// AdditionalComponentIDs lists extra components, with parameters, to
// cover beyond the profile's defaults. Nested signing is unsupported:
// signature and signature-input components are rejected.
AdditionalComponentIDs []httpsig.ComponentIdentifier
// Deprecated: Signature-Agent is required. Nil and true are accepted;
// false is invalid.
SignatureAgent *bool
// TTL overrides Config.SignatureTTL. Zero means omitted; WithTTL records
// explicit presence and rejects zero.
TTL time.Duration
// contains filtered or unexported fields
}

func (o SigningOptions) WithTTL(ttl time.Duration) SigningOptions

WithTTL specifies an explicit positive request signature lifetime.

VerificationOptions supplies trusted discovery and current application-peer evidence. Cross-host delegation is not supported.

type VerificationOptions struct {
SignerDomain string
// Deprecated: discovery requires a covered Signature-Agent. This field
// has no effect; SignerDomain constrains the signed discovery host.
DirectoryURL string
// AllowSignatureAgentDomain permits the signed discovery origin host to
// identify the signer when SignerDomain is absent. Default is false.
AllowSignatureAgentDomain bool
Peer dnsid.VerifyDomainOpts
// RequiredComponents requires exact coverage, including parameter values,
// beyond the profile minimum. Nil adds no requirements. Policy is validated
// before content reads or discovery; request-only components are required.
RequiredComponents []httpsig.ComponentIdentifier
// Replay is optional. Without it, valid requests can be reused until expiry.
Replay ReplayPolicy
}

Generated by gomarkdoc