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
- func ComputeJWKThumbprint(pub ed25519.PublicKey) (string, error)
- func ParsePrivateKey(encoded string) (ed25519.PrivateKey, error)
- func ParsePublicKey(encoded string) (ed25519.PublicKey, error)
- func VerifyRequest(req *http.Request, pub ed25519.PublicKey, now time.Time) error
- type DirectoryDocument
- type KeyPair
- type PublicJWK
- type Signer
Constants ¶
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":"..."}`.
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).
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"`
}
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 ¶
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.