Documentation
¶
Overview ¶
Package botauth implements IETF RFC 9421 HTTP Message Signatures (`web-bot-auth`), `draft-meunier-http-message-signatures-directory` self-signed JWKS responses, 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
- func ComputeJWKThumbprint(pub ed25519.PublicKey) (string, error)
- func ParsePrivateKey(encoded string) (ed25519.PrivateKey, error)
- func ParsePublicKey(encoded string) (ed25519.PublicKey, error)
- func VerifyDirectoryResponse(req *http.Request, respHdr http.Header, body []byte, pub ed25519.PublicKey, ...) error
- func VerifyRequest(req *http.Request, pub ed25519.PublicKey, now time.Time) error
- type DirectoryDocument
- type KeyPair
- type PublicJWK
- type Signer
- func (s *Signer) DirectoryJSON() ([]byte, error)
- func (s *Signer) KeyID() string
- func (s *Signer) PublicJWK() PublicJWK
- func (s *Signer) SetKeyValidity(nbf, exp int64)
- func (s *Signer) SignDirectoryResponse(hdr http.Header, req *http.Request, body []byte, now time.Time) error
- func (s *Signer) SignRequest(req *http.Request, now time.Time) error
Constants ¶
const DefaultKeyNotBefore int64 = 1_767_225_600
DefaultKeyNotBefore (`2026-01-01T00:00:00Z`) is the deterministic default `nbf` (Unix seconds) on published JWKs.
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 ¶
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":"..."}` (optional metadata fields such as `nbf` and `exp` are never included in the canonical thumbprint input).
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 ¶
ParsePublicKey decodes a base64url or standard base64 Ed25519 public key (32 bytes).
func VerifyDirectoryResponse ¶ added in v2.5.2
func VerifyDirectoryResponse(req *http.Request, respHdr http.Header, body []byte, pub ed25519.PublicKey, now time.Time) error
VerifyDirectoryResponse verifies a `draft-meunier-http-message-signatures-directory` response (`Content-Digest` + `directory` signature).
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 ¶
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"`
Nbf int64 `json:"nbf,omitempty"`
Exp int64 `json:"exp,omitempty"`
}
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"`) and signs directory responses per `draft-meunier-http-message-signatures-directory` (`tag="http-message-signatures-directory"`).
func NewSigner ¶
NewSigner constructs an RFC 9421 Ed25519 request signer from an encoded seed/key and optional directory URL.
func (*Signer) DirectoryJSON ¶
DirectoryJSON serializes the `/.well-known/http-message-signatures-directory` JSON document for this signer.
func (*Signer) KeyID ¶
KeyID returns the RFC 7638 JWK thumbprint identifying this signer's public key.
func (*Signer) PublicJWK ¶
PublicJWK returns the public OKP JWK for publishing at `/.well-known/http-message-signatures-directory`.
func (*Signer) SetKeyValidity ¶ added in v2.5.2
SetKeyValidity configures the JWK `nbf` (not-before) and optional `exp` (expiration) Unix timestamps.
func (*Signer) SignDirectoryResponse ¶ added in v2.5.2
func (s *Signer) SignDirectoryResponse(hdr http.Header, req *http.Request, body []byte, now time.Time) error
SignDirectoryResponse attaches RFC 9530 `Content-Digest` and RFC 9421 `directory` self-signature headers (`tag="http-message-signatures-directory"`) to an HTTP response writer per Cloudflare Verified Bots requirements.