You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

25 lines
527 B

package main
import (
"crypto/tls"
"time"
)
func hostCheck(host string) (secondsTillExpiry int, err error) {
conn, err := tls.Dial("tcp", host, nil)
if err != nil {
return
}
// secondsTillExpiry gets initalized to 0.
var seconds int
for _, chain := range conn.ConnectionState().VerifiedChains {
for _, certificate := range chain {
seconds = int(certificate.NotAfter.Sub(time.Now()).Seconds())
if secondsTillExpiry == 0 || secondsTillExpiry > seconds {
secondsTillExpiry = seconds
}
}
}
return
}