Skip to content

Instantly share code, notes, and snippets.

@girokon
Created October 24, 2017 16:26
Show Gist options
  • Save girokon/7f0c85b8f3cf3261b8a4b7857959d220 to your computer and use it in GitHub Desktop.
Save girokon/7f0c85b8f3cf3261b8a4b7857959d220 to your computer and use it in GitHub Desktop.
package main
import (
"crypto/tls"
"log"
"fmt"
"os"
"time"
)
func main() {
if len(os.Args) != 2 {
log.Fatal("Addres is required")
}
addr := os.Args[1]
conn, err := tls.Dial("tcp", addr, &tls.Config{
InsecureSkipVerify: false,
})
if err!=nil {
log.Fatal(err)
}
ceritificates := conn.ConnectionState().PeerCertificates;
for _, cert := range ceritificates {
//str, _ := json.MarshalIndent(cert, "", " ")
now := time.Now()
expire := cert.NotAfter.Sub(now).Hours()
fmt.Printf("Subject: %s\n", cert.Subject.CommonName)
fmt.Printf("Issuer: %s\n", cert.Issuer.CommonName)
fmt.Printf("NotBefore: %s\n", cert.NotBefore)
fmt.Printf("NotAfter: %s\n", cert.NotAfter)
if expire > 24 {
fmt.Printf("Expire in: %v days\n", int(expire/24+0.5))
} else if (expire > 0) {
fmt.Printf("Expire in: %v hours\n", int(expire+0.5))
} else {
fmt.Println("Expired!")
}
fmt.Println()
}
conn.Close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment