mirror of
https://blitiri.com.ar/repos/chasquid
synced 2025-12-23 15:37:01 +00:00
Support submission (directly) over TLS (submissions/smtps/port 465)
This patch adds support for TLS-wrapped submission connections. Instead of clients establishing a connection over plain text and then using STARTTLS to switch over a TLS connection, this new mode allows the clients to connect directly over TLS, like it's done in HTTPS. This is not an official standard yet, but it's reasonably common in practice, and provides some advantages over the traditional submission port. The default port is 465, commonly used for this; chasquid defaults to systemd file descriptor passing as for the other protocols (for now).
This commit is contained in:
@@ -55,12 +55,31 @@ var (
|
||||
|
||||
// Mode for a socket (listening or connection).
|
||||
// We keep them distinct, as policies can differ between them.
|
||||
type SocketMode string
|
||||
type SocketMode struct {
|
||||
// Is this mode submission?
|
||||
IsSubmission bool
|
||||
|
||||
// Is this mode TLS-wrapped? That means that we don't use STARTTLS, the
|
||||
// connection is directly established over TLS (like HTTPS).
|
||||
TLS bool
|
||||
}
|
||||
|
||||
func (mode SocketMode) String() string {
|
||||
s := "SMTP"
|
||||
if mode.IsSubmission {
|
||||
s = "submission"
|
||||
}
|
||||
if mode.TLS {
|
||||
s += "+TLS"
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
// Valid socket modes.
|
||||
const (
|
||||
ModeSMTP SocketMode = "SMTP"
|
||||
ModeSubmission SocketMode = "submission"
|
||||
var (
|
||||
ModeSMTP = SocketMode{IsSubmission: false, TLS: false}
|
||||
ModeSubmission = SocketMode{IsSubmission: true, TLS: false}
|
||||
ModeSubmissionTLS = SocketMode{IsSubmission: true, TLS: true}
|
||||
)
|
||||
|
||||
// Incoming SMTP connection.
|
||||
@@ -137,6 +156,7 @@ func (c *Conn) Handle() {
|
||||
|
||||
c.tr = trace.New("SMTP.Conn", c.conn.RemoteAddr().String())
|
||||
defer c.tr.Finish()
|
||||
c.tr.Debugf("Connected, mode: %s", c.mode)
|
||||
|
||||
c.tc.PrintfLine("220 %s ESMTP chasquid", c.hostname)
|
||||
|
||||
@@ -314,7 +334,7 @@ func (c *Conn) MAIL(params string) (code int, msg string) {
|
||||
if !strings.HasPrefix(strings.ToLower(params), "from:") {
|
||||
return 500, "unknown command"
|
||||
}
|
||||
if c.mode == ModeSubmission && !c.completedAuth {
|
||||
if c.mode.IsSubmission && !c.completedAuth {
|
||||
return 550, "mail to submission port must be authenticated"
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user