Karta. RFC2136. TSIG
(Karta v1.0.0)
TSIG (RFC 8945): the signature of a DNS message with a shared secret, HMAC-SHA256 or HMAC-SHA512.
sign/3 signs an encoded message and returns it with the TSIG record
last in its additional section, and the MAC (which verify/3 needs to
check the answer: a response's MAC covers the request's). verify/3
checks one received message: the TSIG record is last, its key and
algorithm are ours, its time is within the fudge, and its MAC matches.
The MAC covers the message without the TSIG record and with the
additional count decremented, the request's MAC (for a response), and
the TSIG variables of RFC 8945 §4.3.3. Names are compared as DNS names
(without case) and hashed in canonical (lower-case) wire form. The
record's owner name is read in the context of the whole packet, so a
compression pointer (RFC 1035 §4.1.4) is followed; the algorithm name
must not be compressed (RFC 8945 §4.2) and is read on its own. Nothing
here reads the clock twice: now (Unix seconds) is an option, read
once by the caller.
Summary
Types
Why a message could not be signed or verified.
A shared secret: the key's name, its bytes and the algorithm.
Functions
The algorithm's DNS name, as its TSIG record carries it.
The TSIG error code and Other Data of a received message that carries a
TSIG record, whether or not its signature verifies; :error when it
carries none. An answer may report why it refused in these fields
(RFC 8945 §5.2), such as BADTIME.
Signs an encoded message. Returns it with the TSIG record and the MAC;
options: now (Unix seconds), fudge (default 300), request_mac
(when the message answers one, so that its MAC covers it), and error
and other (the TSIG error code and Other Data an answer reports, as
an error response does).
Verifies one received message. Returns the decoded message and the MAC
the signature carried; options: now (Unix seconds) and request_mac
(the MAC of the request this message answers).
Types
@type error() :: :no_tsig | :bad_tsig | :bad_key | :bad_algorithm | :bad_mac | :bad_time | :bad_message | :truncated | Karta.DNS.Wire.error()
Why a message could not be signed or verified.
A shared secret: the key's name, its bytes and the algorithm.
Functions
@spec algorithm_name(:hmac_sha256 | :hmac_sha512) :: String.t()
The algorithm's DNS name, as its TSIG record carries it.
@spec error(binary()) :: {:ok, non_neg_integer(), binary()} | :error
The TSIG error code and Other Data of a received message that carries a
TSIG record, whether or not its signature verifies; :error when it
carries none. An answer may report why it refused in these fields
(RFC 8945 §5.2), such as BADTIME.
Signs an encoded message. Returns it with the TSIG record and the MAC;
options: now (Unix seconds), fudge (default 300), request_mac
(when the message answers one, so that its MAC covers it), and error
and other (the TSIG error code and Other Data an answer reports, as
an error response does).
Verifies one received message. Returns the decoded message and the MAC
the signature carried; options: now (Unix seconds) and request_mac
(the MAC of the request this message answers).