I was attempting to build a function to grab certificate information. When utilizing the top-level domain with "www" everyone works well, yet when excluding that or querying a third-level domain it provides incorrect "Not After" and "Not Before" dates.
I was wondering if anyone had a remedy or advice. Thank you!
package main
import (
"crypto/tls"
"fmt"
"log"
)
func main() {
conf := &tls.Config{
InsecureSkipVerify: true,
}
conn, err := tls.Dial("tcp", "www.google.com:443", conf)
if err != nil {
log.Println("Error when Dialing", err)
return
}
defer conn.Close()
certs := conn.ConnectionState().PeerCertificates
for _, cert := range certs {
fmt.Printf("FQDNs: %s\n\n", cert.DNSNames)
fmt.Printf("Issuer Name: %s\n\n", cert.Issuer)
fmt.Printf("Issued: %v\n\n", cert.NotBefore.Format("Jan 2, 2006 3:04 PM"))
fmt.Printf("Expires: %s\n\n", cert.NotAfter.Format("Jan 2, 2006 3:04 PM"))
fmt.Printf("Issuer Common Name: %s\n\n", cert.Issuer.CommonName)
fmt.Println("-----------------------------------------")
}
}