Documentation ¶
Index ¶
- Variables
- func NormalizeFQDN(name string) string
- type DNSResolver
- func (r *DNSResolver) Exists(name string) (bool, error)
- func (r *DNSResolver) LookupTXT(name string) ([]string, error)
- func (r *DNSResolver) LookupTXTStrict(name string) ([]string, error)
- func (r *DNSResolver) MatchIP(name string, matcher IPMatcherFunc) (bool, error)
- func (r *DNSResolver) MatchMX(name string, matcher IPMatcherFunc) (bool, error)
- type IPMatcherFunc
- type LimitedResolver
- func (r *LimitedResolver) Exists(name string) (bool, error)
- func (r *LimitedResolver) LookupTXT(name string) ([]string, error)
- func (r *LimitedResolver) LookupTXTStrict(name string) ([]string, error)
- func (r *LimitedResolver) MatchIP(name string, matcher IPMatcherFunc) (bool, error)
- func (r *LimitedResolver) MatchMX(name string, matcher IPMatcherFunc) (bool, error)
- type MiekgDNSResolver
- func (r *MiekgDNSResolver) Exists(name string) (bool, error)
- func (r *MiekgDNSResolver) LookupTXT(name string) ([]string, error)
- func (r *MiekgDNSResolver) LookupTXTStrict(name string) ([]string, error)
- func (r *MiekgDNSResolver) MatchIP(name string, matcher IPMatcherFunc) (bool, error)
- func (r *MiekgDNSResolver) MatchMX(name string, matcher IPMatcherFunc) (bool, error)
- type Resolver
- type Result
- type SyntaxError
Constants ¶
This section is empty.
Variables ¶
var ( ErrDNSTemperror = errors.New("temporary DNS error") ErrDNSPermerror = errors.New("permanent DNS error") ErrInvalidDomain = errors.New("invalid domain name") ErrDNSLimitExceeded = errors.New("limit exceeded") ErrSPFNotFound = errors.New("SPF record not found") )
Errors could be used for root couse analysis
Functions ¶
func NormalizeFQDN ¶
NormalizeFQDN appends a root domain (a dot) to the FQDN.
Types ¶
type DNSResolver ¶
type DNSResolver struct{}
DNSResolver implements Resolver using local DNS
func (*DNSResolver) Exists ¶
func (r *DNSResolver) Exists(name string) (bool, error)
Exists is used for a DNS A RR lookup (even when the connection type is IPv6). If any A record is returned, this mechanism matches.
func (*DNSResolver) LookupTXT ¶
func (r *DNSResolver) LookupTXT(name string) ([]string, error)
LookupTXT returns the DNS TXT records for the given domain name.
func (*DNSResolver) LookupTXTStrict ¶
func (r *DNSResolver) LookupTXTStrict(name string) ([]string, error)
LookupTXTStrict returns DNS TXT records for the given name, however it will return ErrDNSPermerror upon NXDOMAIN (RCODE 3)
func (*DNSResolver) MatchIP ¶
func (r *DNSResolver) MatchIP(name string, matcher IPMatcherFunc) (bool, error)
MatchIP provides an address lookup, which should be done on the name using the type of lookup (A or AAAA). Then IPMatcherFunc used to compare checked IP to the returned address(es). If any address matches, the mechanism matches
func (*DNSResolver) MatchMX ¶
func (r *DNSResolver) MatchMX(name string, matcher IPMatcherFunc) (bool, error)
MatchMX is similar to MatchIP but first performs an MX lookup on the name. Then it performs an address lookup on each MX name returned. Then IPMatcherFunc used to compare checked IP to the returned address(es). If any address matches, the mechanism matches
type IPMatcherFunc ¶
IPMatcherFunc returns true if ip matches to implemented rules. If IPMatcherFunc returns any non nil error, the Resolver must stop any further processing and use the error as resulting error.
type LimitedResolver ¶
type LimitedResolver struct {
// contains filtered or unexported fields
}
LimitedResolver wraps a Resolver and limits number of lookups possible to do with it. All overlimited calls return ErrDNSLimitExceeded.
func (*LimitedResolver) Exists ¶
func (r *LimitedResolver) Exists(name string) (bool, error)
Exists is used for a DNS A RR lookup (even when the connection type is IPv6). If any A record is returned, this mechanism matches. Returns false and ErrDNSLimitExceeded if total number of lookups made by underlying resolver exceed the limit.
func (*LimitedResolver) LookupTXT ¶
func (r *LimitedResolver) LookupTXT(name string) ([]string, error)
LookupTXT returns the DNS TXT records for the given domain name. Returns nil and ErrDNSLimitExceeded if total number of lookups made by underlying resolver exceed the limit.
func (*LimitedResolver) LookupTXTStrict ¶
func (r *LimitedResolver) LookupTXTStrict(name string) ([]string, error)
LookupTXTStrict returns the DNS TXT records for the given domain name. Returns nil and ErrDNSLimitExceeded if total number of lookups made by underlying resolver exceed the limit. It will also return ErrDNSPermerror upon DNS call return error NXDOMAIN (RCODE 3)
func (*LimitedResolver) MatchIP ¶
func (r *LimitedResolver) MatchIP(name string, matcher IPMatcherFunc) (bool, error)
MatchIP provides an address lookup, which should be done on the name using the type of lookup (A or AAAA). Then IPMatcherFunc used to compare checked IP to the returned address(es). If any address matches, the mechanism matches Returns false and ErrDNSLimitExceeded if total number of lookups made by underlying resolver exceed the limit.
func (*LimitedResolver) MatchMX ¶
func (r *LimitedResolver) MatchMX(name string, matcher IPMatcherFunc) (bool, error)
MatchMX is similar to MatchIP but first performs an MX lookup on the name. Then it performs an address lookup on each MX name returned. Then IPMatcherFunc used to compare checked IP to the returned address(es). If any address matches, the mechanism matches.
In addition to that limit, the evaluation of each "MX" record MUST NOT result in querying more than 10 address records -- either "A" or "AAAA" resource records. If this limit is exceeded, the "mx" mechanism MUST produce a "permerror" result.
Returns false and ErrDNSLimitExceeded if total number of lookups made by underlying resolver exceed the limit.
type MiekgDNSResolver ¶
type MiekgDNSResolver struct {
// contains filtered or unexported fields
}
MiekgDNSResolver implements Resolver using github.com/miekg/dns
func (*MiekgDNSResolver) Exists ¶
func (r *MiekgDNSResolver) Exists(name string) (bool, error)
Exists is used for a DNS A RR lookup (even when the connection type is IPv6). If any A record is returned, this mechanism matches.
func (*MiekgDNSResolver) LookupTXT ¶
func (r *MiekgDNSResolver) LookupTXT(name string) ([]string, error)
LookupTXT returns the DNS TXT records for the given domain name.
func (*MiekgDNSResolver) LookupTXTStrict ¶
func (r *MiekgDNSResolver) LookupTXTStrict(name string) ([]string, error)
LookupTXTStrict returns DNS TXT records for the given name, however it will return ErrDNSPermerror upon NXDOMAIN (RCODE 3)
func (*MiekgDNSResolver) MatchIP ¶
func (r *MiekgDNSResolver) MatchIP(name string, matcher IPMatcherFunc) (bool, error)
MatchIP provides an address lookup, which should be done on the name using the type of lookup (A or AAAA). Then IPMatcherFunc used to compare checked IP to the returned address(es). If any address matches, the mechanism matches
func (*MiekgDNSResolver) MatchMX ¶
func (r *MiekgDNSResolver) MatchMX(name string, matcher IPMatcherFunc) (bool, error)
MatchMX is similar to MatchIP but first performs an MX lookup on the name. Then it performs an address lookup on each MX name returned. Then IPMatcherFunc used to compare checked IP to the returned address(es). If any address matches, the mechanism matches
type Resolver ¶
type Resolver interface { // LookupTXT returns the DNS TXT records for the given domain name. LookupTXT(string) ([]string, error) // LookupTXTStrict returns DNS TXT records for the given name, however it // will return ErrDNSPermerror upon returned NXDOMAIN (RCODE 3) LookupTXTStrict(string) ([]string, error) // Exists is used for a DNS A RR lookup (even when the // connection type is IPv6). If any A record is returned, this // mechanism matches. Exists(string) (bool, error) // MatchIP provides an address lookup, which should be done on the name // using the type of lookup (A or AAAA). // Then IPMatcherFunc used to compare checked IP to the returned address(es). // If any address matches, the mechanism matches MatchIP(string, IPMatcherFunc) (bool, error) // MatchMX is similar to MatchIP but first performs an MX lookup on the // name. Then it performs an address lookup on each MX name returned. // Then IPMatcherFunc used to compare checked IP to the returned address(es). // If any address matches, the mechanism matches MatchMX(string, IPMatcherFunc) (bool, error) }
Resolver provides abstraction for DNS layer
func NewLimitedResolver ¶
NewLimitedResolver returns a resolver which will pass up to lookupLimit calls to r. In addition to that limit, the evaluation of each "MX" record will be limited to mxQueryLimit. All calls over the limit will return ErrDNSLimitExceeded.
func NewMiekgDNSResolver ¶
NewMiekgDNSResolver returns new instance of Resolver
type Result ¶
type Result int
Result represents result of SPF evaluation as it defined by RFC7208 https://tools.ietf.org/html/rfc7208#section-2.6
const ( // None means either (a) no syntactically valid DNS // domain name was extracted from the SMTP session that could be used // as the one to be authorized, or (b) no SPF records were retrieved // from the DNS. None Result // Neutral result means the ADMD has explicitly stated that it // is not asserting whether the IP address is authorized. Neutral // Pass result is an explicit statement that the client // is authorized to inject mail with the given identity. Pass // Fail result is an explicit statement that the client // is not authorized to use the domain in the given identity. Fail // Softfail result is a weak statement by the publishing ADMD // that the host is probably not authorized. It has not published // a stronger, more definitive policy that results in a "fail". Softfail // Temperror result means the SPF verifier encountered a transient // (generally DNS) error while performing the check. // A later retry may succeed without further DNS operator action. Temperror // Permerror result means the domain's published records could // not be correctly interpreted. // This signals an error condition that definitely requires // DNS operator intervention to be resolved. Permerror )
func CheckHost ¶
CheckHost is a main entrypoint function evaluating e-mail with regard to SPF and it utilizes DNSResolver as a resolver. As per RFC 7208 it will accept 3 parameters: <ip> - IP{4,6} address of the connected client <domain> - domain portion of the MAIL FROM or HELO identity <sender> - MAIL FROM or HELO identity All the parameters should be parsed and dereferenced from real email fields. This means domain should already be extracted from MAIL FROM field so this function can focus on the core part.
CheckHost returns result of verification, explanations as result of "exp=", and error as the reason for the encountered problem.
func CheckHostWithResolver ¶
func CheckHostWithResolver(ip net.IP, domain, sender string, resolver Resolver) (Result, string, error)
CheckHostWithResolver allows using custom Resolver. Note, that DNS lookup limits need to be enforced by provided Resolver.
The function returns result of verification, explanations as result of "exp=", and error as the reason for the encountered problem.
func (Result) String ¶
String returns string form of the result as defined by RFC7208 https://tools.ietf.org/html/rfc7208#section-2.6
type SyntaxError ¶
type SyntaxError struct {
// contains filtered or unexported fields
}
SyntaxError represents parsing error, it holds reference to faulty token as well as error describing fault
func (SyntaxError) Error ¶
func (e SyntaxError) Error() string