botauth

package
v2.5.1 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 12 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 botauth implements IETF RFC 9421 HTTP Message Signatures (`web-bot-auth`) and RFC 7638 Ed25519 JWK Thumbprints using only the Go standard library (`crypto/ed25519`, `crypto/sha256`, `encoding/base64`).

When configured via `EDGEFETCH_BOT_SIGNING_KEY` (base64url 32-byte Ed25519 seed or 64-byte private key) and optional `EDGEFETCH_BOT_DIRECTORY_URL` (`https://<hub>/.well-known/http-message-signatures-directory`), EdgeFetch attaches cryptographic `Signature-Input`, `Signature`, and `Signature-Agent` headers so origins and Cloudflare Verified Bots can cryptographically authenticate the crawler without relying on static IP allowlists.

Index

Constants

View Source
const DefaultSignatureTTL = 5 * time.Minute

DefaultSignatureTTL is the validity window (`expires - created`) stamped on outbound RFC 9421 signatures.

Variables

This section is empty.

Functions

func ComputeJWKThumbprint

func ComputeJWKThumbprint(pub ed25519.PublicKey) (string, error)

ComputeJWKThumbprint computes the RFC 7638 SHA-256 thumbprint (`base64url`, unpadded) of an Ed25519 public key. Per RFC 7638 Section 3.2, members of an OKP JWK are ordered lexicographically: `{"crv":"Ed25519","kty":"OKP","x":"..."}`.

func ParsePrivateKey

func ParsePrivateKey(encoded string) (ed25519.PrivateKey, error)

ParsePrivateKey decodes a base64url or standard base64 Ed25519 seed (32 bytes) or full private key (64 bytes).

func ParsePublicKey

func ParsePublicKey(encoded string) (ed25519.PublicKey, error)

ParsePublicKey decodes a base64url or standard base64 Ed25519 public key (32 bytes).

func VerifyRequest

func VerifyRequest(req *http.Request, pub ed25519.PublicKey, now time.Time) error

VerifyRequest verifies an RFC 9421 `sig1` Ed25519 signature on `req` against `pub` at timestamp `now`.

Types

type DirectoryDocument

type DirectoryDocument struct {
	Keys    []PublicJWK `json:"keys"`
	Purpose string      `json:"purpose,omitempty"`
}

DirectoryDocument is the JSON body served at `/.well-known/http-message-signatures-directory`.

type KeyPair

type KeyPair struct {
	PrivateKeySeedB64URL string    `json:"privateKeySeed"`
	PublicKeyB64URL      string    `json:"publicKey"`
	KeyID                string    `json:"kid"`
	JWK                  PublicJWK `json:"jwk"`
}

KeyPair bundles a freshly generated Ed25519 keypair, its RFC 7638 JWK thumbprint (`kid`), and ready-to-serve JWK.

func GenerateKeyPair

func GenerateKeyPair() (KeyPair, error)

GenerateKeyPair mints a new cryptographically random Ed25519 keypair for RFC 9421 Web Bot Auth.

type PublicJWK

type PublicJWK struct {
	Kty string `json:"kty"`
	Crv string `json:"crv"`
	Kid string `json:"kid,omitempty"`
	X   string `json:"x"`
}

PublicJWK represents an OKP Ed25519 public key entry inside `/.well-known/http-message-signatures-directory`.

type Signer

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

Signer signs outbound HTTP requests per IETF RFC 9421 (`tag="web-bot-auth"`).

func NewSigner

func NewSigner(encodedPrivKey, directoryURL string) (*Signer, error)

NewSigner constructs an RFC 9421 Ed25519 request signer from an encoded seed/key and optional directory URL.

func (*Signer) DirectoryJSON

func (s *Signer) DirectoryJSON() ([]byte, error)

DirectoryJSON serializes the `/.well-known/http-message-signatures-directory` JSON document for this signer.

func (*Signer) KeyID

func (s *Signer) KeyID() string

KeyID returns the RFC 7638 JWK thumbprint identifying this signer's public key.

func (*Signer) PublicJWK

func (s *Signer) PublicJWK() PublicJWK

PublicJWK returns the public OKP JWK for publishing at `/.well-known/http-message-signatures-directory`.

func (*Signer) SignRequest

func (s *Signer) SignRequest(req *http.Request, now time.Time) error

SignRequest attaches RFC 9421 `Signature-Input`, `Signature`, and (when DirectoryURL is set) `Signature-Agent` headers.

Jump to

Keyboard shortcuts

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