From 722e9f7848fef267643c73b0c55c4b453db03c30 Mon Sep 17 00:00:00 2001 From: Christian Joergensen Date: Tue, 10 Oct 2017 10:10:59 +0200 Subject: [PATCH] Also set Peer.TLS connection state on raw TLS connections. Fix double underscore typo. --- smtpd.go | 10 +++++++++- smtpd_test.go | 7 ++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/smtpd.go b/smtpd.go index a705ff3..797ad8e 100644 --- a/smtpd.go +++ b/smtpd.go @@ -113,7 +113,15 @@ func (srv *Server) newSession(c net.Conn) (s *session) { // Check if the underlying connection is already TLS. // This will happen if the Listerner provided Serve() // is from tls.Listen() - __, s.tls = c.(*tls.Conn) + + var tlsConn *tls.Conn + + tlsConn, s.tls = c.(*tls.Conn) + + if s.tls { + state := tlsConn.ConnectionState() + s.peer.TLS = &state + } s.scanner = bufio.NewScanner(s.reader) diff --git a/smtpd_test.go b/smtpd_test.go index e60cb19..3b7a5b7 100644 --- a/smtpd_test.go +++ b/smtpd_test.go @@ -1209,7 +1209,12 @@ func TestTLSListener(t *testing.T) { addr := ln.Addr().String() server := &smtpd.Server{ - Authenticator: func(peer smtpd.Peer, username, password string) error { return nil }, + Authenticator: func(peer smtpd.Peer, username, password string) error { + if peer.TLS == nil { + t.Error("didn't correctly set connection state on TLS connection") + } + return nil + }, } go func() {