Karta.Auth.DKIM.Verifier (Karta v1.0.0)

Verifies the DKIM signatures of a message (RFC 6376 §6, RFC 8463, RFC 8301) on the message's bytes as received.

Every DKIM-Signature field is evaluated on its own, from the top, and gets a Karta.Auth.DKIM.Result; a message without signatures gets an empty list (DKIM result "none").

Rules beyond the RFC's minimum:

  • RSA keys under 1024 bits are never accepted (RFC 8301); keys between 1024 bits and :min_rsa_bits verify but give :policy/:weak_key.
  • A signature whose l= leaves part of the body unsigned gives :policy/:partial_body: content could have been appended.
  • rsa-sha1 is unsupported (:permerror).
  • A t= more than :clock_skew seconds in the future, or an x= more than :clock_skew seconds in the past, is a :permerror.
  • At most :max_signatures signatures are evaluated; the rest are :neutral. Each needs one DNS lookup, so this bounds the work a message can cause.

Options:

  • :dns - options for Karta.DNS.lookup/3 (:resolver, :cache)
  • :now - the time in Unix seconds (default: now)
  • :min_rsa_bits - default 1024
  • :clock_skew - seconds, default 3600
  • :max_signatures - default 8
  • :deadline - a System.monotonic_time(:millisecond) value after which no key is looked up: the signature gets :temperror/:timeout
  • :header_limits - options for Karta.Mail.Headers.split/2

Summary

Functions

Verifies every DKIM signature in message. Returns an error only when the header block itself cannot be read within the limits.

Functions

verify(message, opts \\ [])

@spec verify(binary(), keyword()) ::
  {:ok, [Karta.Auth.DKIM.Result.t()]} | {:error, Karta.Mail.Headers.error()}

Verifies every DKIM signature in message. Returns an error only when the header block itself cannot be read within the limits.