mirror of
https://github.com/mjl-/mox.git
synced 2024-12-26 16:33:47 +03:00
893a6f8911
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.
108 lines
2.9 KiB
Go
108 lines
2.9 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"time"
|
|
|
|
"github.com/mjl-/mox/dmarcdb"
|
|
"github.com/mjl-/mox/dns"
|
|
"github.com/mjl-/mox/http"
|
|
"github.com/mjl-/mox/imapserver"
|
|
"github.com/mjl-/mox/mlog"
|
|
"github.com/mjl-/mox/mox-"
|
|
"github.com/mjl-/mox/mtastsdb"
|
|
"github.com/mjl-/mox/queue"
|
|
"github.com/mjl-/mox/smtpserver"
|
|
"github.com/mjl-/mox/store"
|
|
"github.com/mjl-/mox/tlsrptdb"
|
|
"github.com/mjl-/mox/tlsrptsend"
|
|
)
|
|
|
|
func shutdown(log *mlog.Log) {
|
|
// We indicate we are shutting down. Causes new connections and new SMTP commands
|
|
// to be rejected. Should stop active connections pretty quickly.
|
|
mox.ShutdownCancel()
|
|
|
|
// Now we are going to wait for all connections to be gone, up to a timeout.
|
|
done := mox.Connections.Done()
|
|
second := time.Tick(time.Second)
|
|
select {
|
|
case <-done:
|
|
log.Print("connections shutdown, waiting until 1 second passed")
|
|
<-second
|
|
|
|
case <-time.Tick(3 * time.Second):
|
|
// We now cancel all pending operations, and set an immediate deadline on sockets.
|
|
// Should get us a clean shutdown relatively quickly.
|
|
mox.ContextCancel()
|
|
mox.Connections.Shutdown()
|
|
|
|
second := time.Tick(time.Second)
|
|
select {
|
|
case <-done:
|
|
log.Print("no more connections, shutdown is clean, waiting until 1 second passed")
|
|
<-second // Still wait for second, giving processes like imports a chance to clean up.
|
|
case <-second:
|
|
log.Print("shutting down with pending sockets")
|
|
}
|
|
}
|
|
err := os.Remove(mox.DataDirPath("ctl"))
|
|
log.Check(err, "removing ctl unix domain socket during shutdown")
|
|
}
|
|
|
|
// start initializes all packages, starts all listeners and the switchboard
|
|
// goroutine, then returns.
|
|
func start(mtastsdbRefresher, sendDMARCReports, sendTLSReports, skipForkExec bool) error {
|
|
smtpserver.Listen()
|
|
imapserver.Listen()
|
|
http.Listen()
|
|
|
|
if !skipForkExec {
|
|
// If we were just launched as root, fork and exec as unprivileged user, handing
|
|
// over the bound sockets to the new process. We'll get to this same code path
|
|
// again, skipping this if block, continuing below with the actual serving.
|
|
if os.Getuid() == 0 {
|
|
mox.ForkExecUnprivileged()
|
|
panic("cannot happen")
|
|
} else {
|
|
mox.CleanupPassedFiles()
|
|
}
|
|
}
|
|
|
|
if err := mtastsdb.Init(mtastsdbRefresher); err != nil {
|
|
return fmt.Errorf("mtasts init: %s", err)
|
|
}
|
|
|
|
if err := tlsrptdb.Init(); err != nil {
|
|
return fmt.Errorf("tlsrpt init: %s", err)
|
|
}
|
|
|
|
done := make(chan struct{}, 1)
|
|
if err := queue.Start(dns.StrictResolver{Pkg: "queue"}, done); err != nil {
|
|
return fmt.Errorf("queue start: %s", err)
|
|
}
|
|
|
|
// dmarcdb starts after queue because it may start sending reports through the queue.
|
|
if err := dmarcdb.Init(); err != nil {
|
|
return fmt.Errorf("dmarc init: %s", err)
|
|
}
|
|
if sendDMARCReports {
|
|
dmarcdb.Start(dns.StrictResolver{Pkg: "dmarcdb"})
|
|
}
|
|
|
|
if sendTLSReports {
|
|
tlsrptsend.Start(dns.StrictResolver{Pkg: "tlsrptsend"})
|
|
}
|
|
|
|
store.StartAuthCache()
|
|
smtpserver.Serve()
|
|
imapserver.Serve()
|
|
http.Serve()
|
|
|
|
go func() {
|
|
store.Switchboard()
|
|
<-make(chan struct{})
|
|
}()
|
|
return nil
|
|
}
|