Documentation
¶
Overview ¶
Package webhooksig signs and verifies webhook requests the way the services that send them do: GitHub, Stripe, Slack, and senders that follow Standard Webhooks.
Index ¶
- Constants
- Variables
- func CheckSecret(s Sender, secret string) error
- func Event(header http.Header, body []byte) string
- func Events(written []string) ([]string, error)
- func IsGitHubPing(header http.Header) bool
- func NewSecret() string
- func Sign(s Sender, secret string, body []byte, now time.Time) (http.Header, error)
- func StandardKey(secret string) ([]byte, error)
- func StandardSignature(key []byte, id string, timestamp int64, body []byte) string
- func Takes(events []string, event string) bool
- func Verify(s Sender, secret string, header http.Header, body []byte, received time.Time) error
- type Sender
Constants ¶
const ( // MaxEventLength bounds an event name a webhook takes or a log keeps. MaxEventLength = 120 // MaxEvents bounds how many events a webhook names. MaxEvents = 50 )
Variables ¶
var ( ErrMismatch = errors.New("the signature does not match the signing secret") ErrStale = errors.New("the signature was made more than 5 minutes before or after the request arrived") )
Senders lists every format, in the order a person chooses among them.
Functions ¶
func CheckSecret ¶
CheckSecret reports whether secret has the form the sender's signing secrets take.
func Event ¶
Event names what a request is about, as its sender labels it: an event header, with GitHub's action after a dot, or else the type or event the body names, as Stripe and Standard Webhooks senders do, or the type of the event Slack wraps. It is empty when the request names none.
func Events ¶
Events returns the events a webhook takes as written: trimmed, once each, in the order written, and nil when none is named.
func IsGitHubPing ¶
IsGitHubPing reports whether a request is the ping GitHub sends when a webhook is created.
func NewSecret ¶
func NewSecret() string
NewSecret returns a random signing secret for a sender, such as GitHub, that takes whatever secret it is given.
func Sign ¶
Sign returns the headers that carry the sender's signature over body, made with secret at now.
func StandardKey ¶
StandardKey is the key a Standard Webhooks signing secret holds: whsec_ followed by a base64 key of 24 to 64 bytes.
func StandardSignature ¶
StandardSignature signs one message as Standard Webhooks specifies: an HMAC-SHA256 over the message identifier, the timestamp, and the body.