Categorygithub.com/willscott/go-dkim
modulepackage
0.0.0-20240117163537-77cb5174ba32
Repository: https://github.com/willscott/go-dkim.git
Documentation: pkg.go.dev

# README

go-dkim

DKIM package for Golang

GoDoc

Getting started

Install

 	go get github.com/toorop/go-dkim

Warning: you need to use Go 1.4.2-master or 1.4.3 (when it will be available) see https://github.com/golang/go/issues/10482 fro more info.

Sign email

import (
	dkim "github.com/toorop/go-dkim"
)

func main(){
	// email is the email to sign (byte slice)
	// privateKey the private key (pem encoded, byte slice )	
	options := dkim.NewSigOptions()
	options.PrivateKey = privateKey
	options.Domain = "mydomain.tld"
	options.Selector = "myselector"
	options.SignatureExpireIn = 3600
	options.BodyLength = 50
	options.Headers = []string{"from", "date", "mime-version", "received", "received"}
	options.AddSignatureTimestamp = true
	options.Canonicalization = "relaxed/relaxed"
	err := dkim.Sign(&email, options)
	// handle err..

	// And... that's it, 'email' is signed ! Amazing© !!!
}

Verify

import (
	dkim "github.com/toorop/go-dkim"
)

func main(){
	// email is the email to verify (byte slice)
	status, err := Verify(&email)
	// handle status, err (see godoc for status)
}

Todo

  • handle z tag (copied header fields used for diagnostic use)

# Functions

DNSOptLookupTXT sets the function to use to lookup TXT records.
GetHeader return a new DKIMHeader by parsing an email Note: according to RFC 6376 an email can have multiple DKIM Header in this case we return the last inserted or the last with d== mail from.
NewPubKeyResp parses DKIM record (usually from DNS).
NewPubKeyRespFromDNS retrieves the TXT record from DNS based on the specified domain and selector and parses it.
NewSigOptions returns new sigoption with some defaults value.
Sign signs an email.
Verify verifies an email an return state: SUCCESS or PERMFAIL or TEMPFAIL, TESTINGSUCCESS, TESTINGPERMFAIL TESTINGTEMPFAIL or NOTSIGNED error: if an error occurs during verification.

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

ErrBadDKimTagLBodyTooShort bad l tag.
ErrBadMailFormat unable to parse mail.
ErrBadMailFormatHeaders bad headers format (not DKIM Header).
ErrCandNotParsePrivateKey when unable to parse private key.
ErrDkimHeaderBadFormat when errors found in DKIM header.
ErrDkimHeaderBTagNotFound when there's no b tag.
ErrDkimHeaderDomainMismatch if i tag is not a sub domain of d tag.
ErrDkimHeaderMissingRequiredTag when a required tag is missing.
ErrDkimHeaderNoFromInHTag when from is missing in h tag.
ErrDkimHeaderNotFound when there's no DKIM-Signature header in an email we have to verify.
ErrDkimVersionNotsupported version not supported.
ErrSignBadAlgo Bad algorithm.
ErrSignBadCanonicalization If bad Canonicalization parameter.
ErrSignDomainRequired when there is no domain defined in config.
ErrSignHeaderShouldContainsFrom If Headers is specified it should at least contain 'from'.
ErrSignPrivateKeyRequired when there not private key in config.
ErrSignSelectorRequired when there is no Selcteir defined in config.
ErrVerifyBadKey when we can't parse pubkey.
ErrVerifyBadKeyType bad type for pub key (only rsa is accepted).
ErrVerifyBodyHash when body hash doesn't verify.
ErrVerifyInappropriateHashAlgo when h tag in pub key doesn't contain hash algo from a tag of DKIM header.
ErrVerifyKeyUnavailable when service (dns) is anavailable.
ErrVerifyNoKey when no key is found on DNS record.
ErrVerifyNoKeyForSignature no key.
ErrVerifyRevokedKey key(s) for this selector is revoked (p is empty).
ErrVerifySignatureHasExpired when signature has expired.
ErrVerifyTagVMustBeTheFirst if present the v tag must be the firts in the record.
ErrVerifyVersionMusBeDkim1 if présent flag v (version) must be DKIM1.

# Structs

No description provided by the author
DNSOptions holds settings for looking up DNS records.
PubKeyRep represents a parsed version of public key record.
sigOptions represents signing options.

# Interfaces

DNSOpt represents an optional setting for looking up DNS records.