git » chasquid » commit 7005398

smtp-check: Add a -skip_tls_check flag

author Alberto Bertogli
2017-01-04 16:36:28 UTC
committer Alberto Bertogli
2017-01-04 16:37:26 UTC
parent 6479138c579f3d270ccd9d3a784a8d47911ffa66

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 +24 -17

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")