Created
March 6, 2019 18:41
-
-
Save WGH-/d7f90fab9e2385f348aaba3bae4896a8 to your computer and use it in GitHub Desktop.
Checks X509 certificate subjects and SANs for given domain's MX servers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"crypto/tls" | |
"crypto/x509" | |
"fmt" | |
"log" | |
"net" | |
"net/smtp" | |
"os" | |
) | |
func printCertificateInfo(cert *x509.Certificate) { | |
fmt.Printf(" Subject: %s\n", cert.Subject) | |
fmt.Printf(" DNSNames:\n") | |
for _, name := range cert.DNSNames { | |
fmt.Printf(" %s\n", name) | |
} | |
} | |
func main() { | |
mxs, err := net.LookupMX(os.Args[1]) | |
if err != nil { | |
log.Fatal(err) | |
} | |
for _, mx := range mxs { | |
fmt.Printf("%s\n", mx.Host) | |
client, err := smtp.Dial(mx.Host + ":25") | |
if err != nil { | |
log.Fatal(err) | |
} | |
err = client.StartTLS(&tls.Config{ | |
InsecureSkipVerify: true, | |
}) | |
if err != nil { | |
log.Fatal(err) | |
} | |
state, ok := client.TLSConnectionState() | |
if !ok { | |
log.Fatal("client.TLSConnectionState: !ok") | |
} | |
printCertificateInfo(state.PeerCertificates[0]) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment