Documentation
¶
Overview ¶
Package dkim implements DKIM signing and verification according to RFC 6376. It provides support for both simple and relaxed canonicalization algorithms as well as support for RSA and ED25519 signature algorithms.
This package only supports RSA-SHA256 and ED25519-SHA256 signature algorithms. RSA-SHA1 is not supported since it's deprecated and prohibited by RFC 8301.
See: https://datatracker.ietf.org/doc/html/rfc6376 and: https://datatracker.ietf.org/doc/html/rfc8301#section-3.1
Index ¶
- Variables
- type Canonicalization
- type SignatureAlgo
- type Signer
- func (s *Signer) AUID(auid string)
- func (s *Signer) BodyCanonicalization(mode Canonicalization)
- func (s *Signer) Bodylength(length int64)
- func (s *Signer) ExpiresIn(expiration time.Duration)
- func (s *Signer) HeaderCanonicalization(mode Canonicalization)
- func (s *Signer) OversignHeaders(headers ...string)
- func (s *Signer) Sign(rawHeaders, body []byte) (string, error)
- func (s *Signer) SignHeaders(headers ...string)
- func (s *Signer) ValidateConfig() error
Constants ¶
This section is empty.
Variables ¶
var ( // ErrDKIMNoDomain is returned when no DKIM domain is set ErrDKIMNoDomain = errors.New("a DKIM domain must be set") // ErrDKIMNoSelector is returned when no DKIM selector is set ErrDKIMNoSelector = errors.New("a DKIM selector must be set") // ErrDKIMNoSigner is returned when no DKIM crypto signer is provided ErrDKIMNoSigner = errors.New("a DKIM crypto signer must be provided") // ErrDKIMInvalidSigner is returned when the provided crypto signer is not // supported by DKIM ErrDKIMInvalidSigner = errors.New("the provided crypto signer is not supported by DKIM") // ErrDKIMMissingFrom is returned when the FROM header is missing ErrDKIMMissingFrom = errors.New("FROM is a required DKIM header") // ErrDKIMUnsupportedSigner is returned when the DKIM signer type is // unsupported ErrDKIMUnsupportedSigner = errors.New("unsupported DKIM signer type") )
Functions ¶
This section is empty.
Types ¶
type Canonicalization ¶
type Canonicalization string
Canonicalization defines the DKIM canonicalization algorithm
const ( // CanonicalizationSimple is the simple canonicalization algorithm CanonicalizationSimple Canonicalization = "simple" // CanonicalizationRelaxed is the relaxed canonicalization algorithm CanonicalizationRelaxed Canonicalization = "relaxed" )
type SignatureAlgo ¶
type SignatureAlgo string
SignatureAlgo defines the DKIM signature algorithm
const ( // SignatureAlgoRSA is the RSA SHA-256 signature algorithm SignatureAlgoRSA SignatureAlgo = "rsa-sha256" // SignatureAlgoED25519 is the ED25519 SHA-256 signature algorithm SignatureAlgoED25519 SignatureAlgo = "ed25519-sha256" )
type Signer ¶
type Signer struct {
// Domain represents the DKIM Signing Domain Identifier (SDID). It is
// d single domain name that is the mandatory payload output of DKIM
// and that refers to the identity claiming some responsibility for
// the message by signing it.
//
// Domain MUST not be empty
//
// See: https://datatracker.ietf.org/doc/html/rfc6376#section-2.5
Domain string
// Selector represents the DKIM domain selectors
//
// To support multiple concurrent public keys per signing domain, the
// key namespace is subdivided using "selectors". For example,
// selectors might indicate the names of office locations (e.g.,
// "sanfrancisco", "coolumbeach", and "reykjavik"), the signing date
// (e.g., "january2005", "february2005", etc.), or even an individual
// user.
//
// Selector MUST not be empty
//
// See: https://datatracker.ietf.org/doc/html/rfc6376#section-3.1
Selector string
// Signer is the crypto.Signer used to sign the message.
Signer crypto.Signer
// NowFunc represents a function that is used to determine the signature's
// time field (t=). It can be overridden for deterministic tests.
NowFunc func() time.Time
// contains filtered or unexported fields
}
Signer represents a DKIM signer that holds all signing parameters
func NewSigner ¶
NewSigner creates a new DKIM signer with the given domain, selector, and crypto.Signer
func (*Signer) BodyCanonicalization ¶
func (s *Signer) BodyCanonicalization(mode Canonicalization)
BodyCanonicalization sets the canonicalization mode for the message body
func (*Signer) Bodylength ¶
Bodylength sets the length of the message body to be signed by DKIM (via the l= tag)
It is highly discouraged to set this value as it means that only a portion of the message body would be appropriately signed, including it allows malicious actors to send phishing emails, alter content or otherwise exploit emails and still pass DKIM.
Only use this option if you are sure what you are doing
func (*Signer) HeaderCanonicalization ¶
func (s *Signer) HeaderCanonicalization(mode Canonicalization)
HeaderCanonicalization sets the canonicalization mode for the message headers
func (*Signer) OversignHeaders ¶
OversignHeaders sets the headers to be oversigned for the DKIM signature
func (*Signer) Sign ¶
Sign returns the DKIM-Signature header line for the given raw headers and body
func (*Signer) SignHeaders ¶
SignHeaders sets the headers to be signed for the DKIM signature
func (*Signer) ValidateConfig ¶
Validate validates the DKIM configuration for required settings