From: Robert Sesek Date: Mon, 2 Jan 2017 01:22:00 +0000 (-0500) Subject: Fix post-STARTTLS protocol bug. X-Git-Tag: v1.1.0~8 X-Git-Url: https://src.bluestatic.org/?a=commitdiff_plain;h=c83dcc2e3c0d291f8cf71dac6f900e72e630a554;p=mailpopbox.git Fix post-STARTTLS protocol bug. After the TLS handshake, the server should *not* reply with a greeting again, but it should wait for an EHLO, per RFC 3207 ยง 4.2 & 5. Previously the server would re-send the greeting, which un-syncs the protocol. --- diff --git a/smtp/conn.go b/smtp/conn.go index ca24c10..1837027 100644 --- a/smtp/conn.go +++ b/smtp/conn.go @@ -188,21 +188,17 @@ func (conn *connection) doSTARTTLS() { conn.log.Info("doSTARTTLS()") conn.writeReply(220, "initiate TLS connection") - newConn := tls.Server(conn.nc, tlsConfig) - tp := textproto.NewConn(newConn) - - err := tp.PrintfLine("220 %s ESMTPS [%s] (mailpopbox)", - conn.server.Name(), newConn.LocalAddr()) - if err != nil { + tlsConn := tls.Server(conn.nc, tlsConfig) + if err := tlsConn.Handshake(); err != nil { conn.log.Error("failed to do TLS handshake", zap.Error(err)) return } - conn.nc = newConn - conn.tp = tp + conn.nc = tlsConn + conn.tp = textproto.NewConn(tlsConn) conn.state = stateNew - connState := newConn.ConnectionState() + connState := tlsConn.ConnectionState() conn.tls = &connState conn.log.Info("TLS connection done", zap.String("state", conn.getTransportString()))