Karta. Webhooks. Mailgun
(Karta v1.0.0)
Webhook requests in Mailgun's format, for receivers written for Mailgun's webhooks. The body is a JSON object:
{
"signature": {
"timestamp": "1796378400",
"token": "<50 random hexadecimal digits>",
"signature": "<hex HMAC-SHA256 of timestamp and token>"
},
"event-data": {"id": ..., "event": "delivered", ...}
}Signature. signature is the hexadecimal HMAC-SHA256 of the
timestamp (seconds, as written) followed by the token, keyed with the
webhook's signing key as it is written (64 hexadecimal digits, shown
once, like Mailgun's HTTP webhook signing key). Receivers compare it,
refuse old timestamps, and may refuse a token they saw before
(verify/3 is that check, as Rails' Action Mailbox makes it for
Mailgun). The body itself is not signed, as with Mailgun. Each request
has a timestamp and token of its own; a rotated key signs at once (there
is room for one signature only).
Events (event-data.event), from Karta's types:
message.accepted-accepted;message.delivered-delivered, withdelivery-status;message.deferred-failed,severitytemporary,reasongeneric, withdelivery-status(and itsretry-seconds);message.bounced-failed,severitypermanent,reasonbounce(oroldwhen the retry period ran out);message.suppressed-failed,severitypermanent,reasonsuppress-bounce,suppress-unsubscribeorsuppress-complaint(codes 605, 606, 607);message.opened,message.clicked-opened,clicked, withip(the client's network, as Karta keeps it),client-info.user-agentand for clicksurl;message.unsubscribed-unsubscribed;message.complained-complained,severitypermanent, with the reason Mailgun gives a complaint about a suppressed address (suppress-complaint). Mailgun's own complained events carry no delivery status; the two fields say the same as thefailedevents Karta sends for a suppressed recipient.
Every event has id (from Karta's event id: the same on every attempt
and replay), timestamp (seconds, with microseconds), log-level,
recipient, recipient-domain, tags, user-variables, flags,
envelope and message (headers to, message-id, from,
subject; size). Karta does not keep the message's To header for
each event: message.headers.to is the recipient's address. Not sent:
geolocation, the client's type and system, storage and attachments
(always []). webhook.test has id, event webhook.test,
timestamp, log-level, webhook-id and description.
Summary
Functions
The body of a request about event (a stored Karta.Webhooks.Event)
made at now, signed with key; token is new for every request.
A new signing key: 64 hexadecimal digits.
A token for one request: 50 random hexadecimal digits.
The body without its signature: what every request about event has in common.
The hexadecimal HMAC-SHA256 of timestamp and token, keyed with key.
Karta's event types that have a Mailgun event.
A receiver's check of the signature object of a request, as Rails'
Action Mailbox checks Mailgun's: the signature equals the HMAC of the
timestamp and token under key (compared in constant time), and the
timestamp is at most two minutes old at now (option, seconds; default
the clock's). A token seen before is the receiver's to refuse.
Functions
@spec body(map(), String.t(), DateTime.t(), String.t()) :: String.t()
The body of a request about event (a stored Karta.Webhooks.Event)
made at now, signed with key; token is new for every request.
@spec new_key() :: String.t()
A new signing key: 64 hexadecimal digits.
@spec new_token() :: String.t()
A token for one request: 50 random hexadecimal digits.
The body without its signature: what every request about event has in common.
The hexadecimal HMAC-SHA256 of timestamp and token, keyed with key.
@spec types() :: [String.t()]
Karta's event types that have a Mailgun event.
A receiver's check of the signature object of a request, as Rails'
Action Mailbox checks Mailgun's: the signature equals the HMAC of the
timestamp and token under key (compared in constant time), and the
timestamp is at most two minutes old at now (option, seconds; default
the clock's). A token seen before is the receiver's to refuse.