我试图建立一个函数来获取证书信息。当使用带有"www"的顶级域时,每个人都工作得很好,但当排除它或查询三级域时,它提供了不正确的"不晚于"和"不早于"日期。
我想知道有没有人有补救或建议,谢谢!
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("-----------------------------------------")
}
}
1条答案
按热度按时间yzuktlbb1#