Karta.Inbound.SRS (Karta v1.0.0)

The Sender Rewriting Scheme: the envelope sender of a forwarded message is rewritten to an address in Karta's SRS domain, so that the receiving server checks SPF against that domain (which names Karta), not against the original sender's (which does not). The original sender can be read back from the address, so a bounce sent to it can be checked.

  • SRS0=HHHHHHHH=TT=example.org=ann@srs.example.net - a message from ann@example.org. TT is the day (two base32 characters, days since 1970 modulo 1024); HHHHHHHH an HMAC-SHA256 tag of the day, domain and local part (eight base32 characters, 40 bits), under a key derived from the vault key.
  • SRS1=HHHHHHHH=fwd.example==HHH=TT=example.org=ann@srs.example.net - a message that another forwarder (fwd.example) rewrote to an SRS0 address already: a bounce goes straight back to that forwarder's SRS0 address, which it can check itself. An SRS1 sender is rewritten keeping its first forwarder.

reverse/2 checks an address: the tag must have been made with a key of the vault (the active one or a retired one, so a key rotation leaves the addresses of mail in flight valid) and the day must be at most 21 days ago. Tags and days are compared without case, as mail systems may change the case of local parts.

The SRS domain is config :karta, Karta.Inbound, srs_domain: (KARTA_SRS_DOMAIN), by default the return path domain (KARTA_RETURN_PATH_DOMAIN). Its MX records must lead to Karta and its SPF record must name Karta's sending addresses.

Options of forward/2, reverse/2 and ours?/2, for tests: :domain (the SRS domain), :now, :key (the active vault key) and :keys (all vault keys).

Summary

Functions

The SRS domain, or nil when none is configured.

The rewritten sender of a message from sender ("", the null reverse path, stays ""). {:error, :no_domain} without an SRS domain.

True for an SRS address (SRS0=, SRS1=) in Karta's SRS domain.

The original sender named by an SRS address of ours: {:ok, sender}; {:error, :not_srs} for another address, :invalid for a tag no vault key made (or a damaged address), :expired for one older than 21 days. The domain is not checked (see ours?/2).

Functions

domain()

@spec domain() :: String.t() | nil

The SRS domain, or nil when none is configured.

forward(sender, opts \\ [])

@spec forward(String.t(), keyword()) :: {:ok, String.t()} | {:error, :no_domain}

The rewritten sender of a message from sender ("", the null reverse path, stays ""). {:error, :no_domain} without an SRS domain.

ours?(address, opts \\ [])

@spec ours?(String.t(), keyword()) :: boolean()

True for an SRS address (SRS0=, SRS1=) in Karta's SRS domain.

reverse(address, opts \\ [])

@spec reverse(String.t(), keyword()) ::
  {:ok, String.t()} | {:error, :not_srs | :invalid | :expired}

The original sender named by an SRS address of ours: {:ok, sender}; {:error, :not_srs} for another address, :invalid for a tag no vault key made (or a damaged address), :expired for one older than 21 days. The domain is not checked (see ours?/2).