implement dnssec-awareness throughout code, and dane for incoming/outgoing mail delivery
the vendored dns resolver code is a copy of the go stdlib dns resolver, with
awareness of the "authentic data" (i.e. dnssec secure) added, as well as support
for enhanced dns errors, and looking up tlsa records (for dane). ideally it
would be upstreamed, but the chances seem slim.
dnssec-awareness is added to all packages, e.g. spf, dkim, dmarc, iprev. their
dnssec status is added to the Received message headers for incoming email.
but the main reason to add dnssec was for implementing dane. with dane, the
verification of tls certificates can be done through certificates/public keys
published in dns (in the tlsa records). this only makes sense (is trustworthy)
if those dns records can be verified to be authentic.
mox now applies dane to delivering messages over smtp. mox already implemented
mta-sts for webpki/pkix-verification of certificates against the (large) pool
of CA's, and still enforces those policies when present. but it now also checks
for dane records, and will verify those if present. if dane and mta-sts are
both absent, the regular opportunistic tls with starttls is still done. and the
fallback to plaintext is also still done.
mox also makes it easy to setup dane for incoming deliveries, so other servers
can deliver with dane tls certificate verification. the quickstart now
generates private keys that are used when requesting certificates with acme.
the private keys are pre-generated because they must be static and known during
setup, because their public keys must be published in tlsa records in dns.
autocert would generate private keys on its own, so had to be forked to add the
option to provide the private key when requesting a new certificate. hopefully
upstream will accept the change and we can drop the fork.
with this change, using the quickstart to setup a new mox instance, the checks
at internet.nl result in a 100% score, provided the domain is dnssec-signed and
the network doesn't have any issues.
2023-10-10 13:09:35 +03:00
|
|
|
package adns
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ExtendedError is an RFC 8914 Extended DNS Error (EDE).
|
|
|
|
type ExtendedError struct {
|
|
|
|
InfoCode ErrorCode
|
|
|
|
ExtraText string // Human-readable error message, optional.
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsTemporary indicates whether an error is a temporary server error, and
|
|
|
|
// retries might give a different result.
|
|
|
|
func (e ExtendedError) IsTemporary() bool {
|
|
|
|
return e.InfoCode.IsTemporary()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unwrap returns the underlying ErrorCode error.
|
|
|
|
func (e ExtendedError) Unwrap() error {
|
|
|
|
return e.InfoCode
|
|
|
|
}
|
|
|
|
|
|
|
|
// Error returns a string representing the InfoCode, and either the extra text or
|
|
|
|
// more details for the info code.
|
|
|
|
func (e ExtendedError) Error() string {
|
|
|
|
s := e.InfoCode.Error()
|
|
|
|
if e.ExtraText != "" {
|
|
|
|
return s + ": " + e.ExtraText
|
|
|
|
}
|
|
|
|
if int(e.InfoCode) >= len(errorCodeDetails) {
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
return s + ": " + errorCodeDetails[e.InfoCode]
|
|
|
|
}
|
|
|
|
|
|
|
|
// ErrorCode is an InfoCode from Extended DNS Errors, RFC 8914.
|
|
|
|
type ErrorCode uint16
|
|
|
|
|
|
|
|
const (
|
|
|
|
ErrOtherErrorCode ErrorCode = 0
|
|
|
|
ErrUnsupportedDNSKEYAlgorithm ErrorCode = 1
|
|
|
|
ErrUnsupportedDSDigestType ErrorCode = 2
|
|
|
|
ErrStaleAnswer ErrorCode = 3
|
|
|
|
ErrForgedAnswer ErrorCode = 4
|
|
|
|
ErrDNSSECIndeterminate ErrorCode = 5
|
|
|
|
ErrDNSSECBogus ErrorCode = 6
|
|
|
|
ErrSignatureExpired ErrorCode = 7
|
|
|
|
ErrSignatureNotYetValid ErrorCode = 8
|
|
|
|
ErrDNSKEYMissing ErrorCode = 9
|
|
|
|
ErrRRSIGMissing ErrorCode = 10
|
|
|
|
ErrNoZoneKeyBitSet ErrorCode = 11
|
|
|
|
ErrNSECMissing ErrorCode = 12
|
|
|
|
ErrCachedError ErrorCode = 13
|
|
|
|
ErrNotReady ErrorCode = 14
|
|
|
|
ErrBlocked ErrorCode = 15
|
|
|
|
ErrCensored ErrorCode = 16
|
|
|
|
ErrFiltered ErrorCode = 17
|
|
|
|
ErrProhibited ErrorCode = 18
|
|
|
|
ErrStaleNXDOMAINAnswer ErrorCode = 19
|
|
|
|
ErrNotAuthoritative ErrorCode = 20
|
|
|
|
ErrNotSupported ErrorCode = 21
|
|
|
|
ErrNoReachableAuthority ErrorCode = 22
|
|
|
|
ErrNetworkError ErrorCode = 23
|
|
|
|
ErrInvalidData ErrorCode = 24
|
|
|
|
)
|
|
|
|
|
|
|
|
// IsTemporary returns whether the error is temporary and has a chance of
|
|
|
|
// succeeding on a retry.
|
|
|
|
func (e ErrorCode) IsTemporary() bool {
|
|
|
|
switch e {
|
|
|
|
case ErrOtherErrorCode,
|
|
|
|
ErrStaleAnswer,
|
|
|
|
ErrCachedError,
|
|
|
|
ErrNotReady,
|
|
|
|
ErrStaleNXDOMAINAnswer,
|
|
|
|
ErrNoReachableAuthority,
|
|
|
|
ErrNetworkError:
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsAuthentication returns whether the error is related to authentication,
|
|
|
|
// e.g. bogus DNSSEC, missing DS/DNSKEY/RRSIG records, etc, or an other
|
|
|
|
// DNSSEC-related error.
|
|
|
|
func (e ErrorCode) IsAuthentication() bool {
|
|
|
|
switch e {
|
|
|
|
case ErrUnsupportedDNSKEYAlgorithm,
|
|
|
|
ErrUnsupportedDSDigestType,
|
|
|
|
ErrDNSSECIndeterminate,
|
|
|
|
ErrDNSSECBogus,
|
|
|
|
ErrSignatureExpired,
|
|
|
|
ErrSignatureNotYetValid,
|
|
|
|
ErrDNSKEYMissing,
|
|
|
|
ErrRRSIGMissing,
|
|
|
|
ErrNoZoneKeyBitSet,
|
|
|
|
ErrNSECMissing:
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// Error includes a human-readable short string for the info code.
|
|
|
|
func (e ErrorCode) Error() string {
|
|
|
|
if int(e) >= len(errorCodeStrings) {
|
|
|
|
return fmt.Sprintf("unknown error code from name server: %d", e)
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("error from name server: %s", errorCodeStrings[e])
|
|
|
|
}
|
|
|
|
|
implement outgoing tls reports
we were already accepting, processing and displaying incoming tls reports. now
we start tracking TLS connection and security-policy-related errors for
outgoing message deliveries as well. we send reports once a day, to the
reporting addresses specified in TLSRPT records (rua) of a policy domain. these
reports are about MTA-STS policies and/or DANE policies, and about
STARTTLS-related failures.
sending reports is enabled by default, but can be disabled through setting
NoOutgoingTLSReports in mox.conf.
only at the end of the implementation process came the realization that the
TLSRPT policy domain for DANE (MX) hosts are separate from the TLSRPT policy
for the recipient domain, and that MTA-STS and DANE TLS/policy results are
typically delivered in separate reports. so MX hosts need their own TLSRPT
policies.
config for the per-host TLSRPT policy should be added to mox.conf for existing
installs, in field HostTLSRPT. it is automatically configured by quickstart for
new installs. with a HostTLSRPT config, the "dns records" and "dns check" admin
pages now suggest the per-host TLSRPT record. by creating that record, you're
requesting TLS reports about your MX host.
gathering all the TLS/policy results is somewhat tricky. the tentacles go
throughout the code. the positive result is that the TLS/policy-related code
had to be cleaned up a bit. for example, the smtpclient TLS modes now reflect
reality better, with independent settings about whether PKIX and/or DANE
verification has to be done, and/or whether verification errors have to be
ignored (e.g. for tls-required: no header). also, cached mtasts policies of
mode "none" are now cleaned up once the MTA-STS DNS record goes away.
2023-11-09 19:40:46 +03:00
|
|
|
// String returns a short text string for known error codes, or "unknown".
|
|
|
|
func (e ErrorCode) String() string {
|
|
|
|
if int(e) >= 0 && int(e) < len(errorCodeStrings) {
|
|
|
|
return errorCodeStrings[e]
|
|
|
|
}
|
|
|
|
return "unknown"
|
|
|
|
}
|
|
|
|
|
implement dnssec-awareness throughout code, and dane for incoming/outgoing mail delivery
the vendored dns resolver code is a copy of the go stdlib dns resolver, with
awareness of the "authentic data" (i.e. dnssec secure) added, as well as support
for enhanced dns errors, and looking up tlsa records (for dane). ideally it
would be upstreamed, but the chances seem slim.
dnssec-awareness is added to all packages, e.g. spf, dkim, dmarc, iprev. their
dnssec status is added to the Received message headers for incoming email.
but the main reason to add dnssec was for implementing dane. with dane, the
verification of tls certificates can be done through certificates/public keys
published in dns (in the tlsa records). this only makes sense (is trustworthy)
if those dns records can be verified to be authentic.
mox now applies dane to delivering messages over smtp. mox already implemented
mta-sts for webpki/pkix-verification of certificates against the (large) pool
of CA's, and still enforces those policies when present. but it now also checks
for dane records, and will verify those if present. if dane and mta-sts are
both absent, the regular opportunistic tls with starttls is still done. and the
fallback to plaintext is also still done.
mox also makes it easy to setup dane for incoming deliveries, so other servers
can deliver with dane tls certificate verification. the quickstart now
generates private keys that are used when requesting certificates with acme.
the private keys are pre-generated because they must be static and known during
setup, because their public keys must be published in tlsa records in dns.
autocert would generate private keys on its own, so had to be forked to add the
option to provide the private key when requesting a new certificate. hopefully
upstream will accept the change and we can drop the fork.
with this change, using the quickstart to setup a new mox instance, the checks
at internet.nl result in a 100% score, provided the domain is dnssec-signed and
the network doesn't have any issues.
2023-10-10 13:09:35 +03:00
|
|
|
// short strings, always included in error messages.
|
|
|
|
var errorCodeStrings = []string{
|
|
|
|
"other",
|
|
|
|
"unsupported dnskey algorithm",
|
|
|
|
"unsupported ds digest type",
|
|
|
|
"stale answer",
|
|
|
|
"forged answer",
|
|
|
|
"dnssec indeterminate",
|
|
|
|
"dnssec bogus",
|
|
|
|
"signature expired",
|
|
|
|
"signature not yet valid",
|
|
|
|
"dnskey missing",
|
|
|
|
"rrsigs missing",
|
|
|
|
"no zone key bit set",
|
|
|
|
"nsec missing",
|
|
|
|
"cached error",
|
|
|
|
"not ready",
|
|
|
|
"blocked",
|
|
|
|
"censored",
|
|
|
|
"filtered",
|
|
|
|
"prohibited",
|
|
|
|
"stale nxdomain answer",
|
|
|
|
"not authoritative",
|
|
|
|
"not supported",
|
|
|
|
"no reachable authority",
|
|
|
|
"network error",
|
|
|
|
"invalid data",
|
|
|
|
}
|
|
|
|
|
|
|
|
// more detailed string, only included if there is no detail text in the response.
|
|
|
|
var errorCodeDetails = []string{
|
|
|
|
"unspecified error",
|
|
|
|
"only found unsupported algorithms in DNSKEY records",
|
|
|
|
"only found unsupported types in DS records",
|
|
|
|
"unable to resolve within deadline, stale data served",
|
|
|
|
"answer was forged for policy reason",
|
|
|
|
"dnssec validation ended in interderminate state",
|
|
|
|
"dnssec validation ended in bogus status",
|
|
|
|
"only expired dnssec signatures found",
|
|
|
|
"only signatures found that are not yet valid",
|
|
|
|
"ds key exists at a parent, but no supported matching dnskey found",
|
|
|
|
"dnssec validation attempted, but no rrsig found",
|
|
|
|
"no zone key bit found in a dnskey",
|
|
|
|
"dnssec validation found missing data without nsec/nsec3 record",
|
|
|
|
"failure served from cache",
|
|
|
|
"not yet fully functional to resolve query",
|
|
|
|
"domain is on blocklist due to internal security policy",
|
|
|
|
"domain is on blocklist due to external entity",
|
|
|
|
"domain is on client-requested blocklist",
|
|
|
|
"refusing to serve request",
|
|
|
|
"stale nxdomain served from cache",
|
|
|
|
"unexpected authoritativeness of query",
|
|
|
|
"query or operation not supported",
|
|
|
|
"no authoritative name server could be reached",
|
|
|
|
"unrecoverable network error",
|
|
|
|
"zone data not valid",
|
|
|
|
}
|