From 700539876bc816204a7a2eeb3c2fff6eba984452 Mon Sep 17 00:00:00 2001 From: Alberto Bertogli Date: Wed, 4 Jan 2017 13:36:28 -0300 Subject: [PATCH] smtp-check: Add a -skip_tls_check flag This patch adds a -skip_tls_check flag, so smtp-check can still be used from places where outgoing SMTP connections are blocked. --- cmd/smtp-check/smtp-check.go | 41 +++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/cmd/smtp-check/smtp-check.go b/cmd/smtp-check/smtp-check.go index a9cc7af..c7f03a7 100644 --- a/cmd/smtp-check/smtp-check.go +++ b/cmd/smtp-check/smtp-check.go @@ -17,6 +17,8 @@ import ( var ( port = flag.String("port", "smtp", "port to use for connecting to the MX servers") + skipTLSCheck = flag.Bool("skip_tls_check", false, + "skip TLS check (useful if connections are blocked)") ) func main() { @@ -56,27 +58,32 @@ func main() { } } - c, err := smtp.Dial(mx.Host + ":" + *port) - if err != nil { - log.Fatal(err) - } + if *skipTLSCheck { + log.Printf("TLS check skipped") + } else { + c, err := smtp.Dial(mx.Host + ":" + *port) + if err != nil { + log.Fatal(err) + } - config := &tls.Config{ - // Expect the server to have a certificate valid for the MX - // we're connecting to. - ServerName: mx.Host, - } - err = c.StartTLS(config) - if err != nil { - log.Fatalf("TLS error: %v", err) - } + config := &tls.Config{ + // Expect the server to have a certificate valid for the MX + // we're connecting to. + ServerName: mx.Host, + } + err = c.StartTLS(config) + if err != nil { + log.Fatalf("TLS error: %v", err) + } - cstate, _ := c.TLSConnectionState() - log.Printf("TLS OK: %s - %s", tlsconst.VersionName(cstate.Version), - tlsconst.CipherSuiteName(cstate.CipherSuite)) + cstate, _ := c.TLSConnectionState() + log.Printf("TLS OK: %s - %s", tlsconst.VersionName(cstate.Version), + tlsconst.CipherSuiteName(cstate.CipherSuite)) + + c.Close() + } log.Printf("") - c.Close() } log.Printf("=== Success")