Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
certchk
13 changes: 10 additions & 3 deletions certchk.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,22 @@ import (

var (
dialer = &net.Dialer{Timeout: 5 * time.Second}
config = &tls.Config{}
file = flag.String("f", "", "read server names from `file`")
skipHostVerify = flag.Bool("skip-host-verify", false, "If set, will ensure that the certificate chain(s) retrieved from the specified hosts are not verified")
)

func check(server string, width int) {
conn, err := tls.DialWithDialer(dialer, "tcp", server+":443", nil)
conn, err := tls.DialWithDialer(dialer, "tcp", server+":443", config)
if err != nil {
fmt.Printf("%*s | %v\n", width, server, err)
return
}
defer conn.Close()
valid := conn.VerifyHostname(server)

var valid error = nil
if !*skipHostVerify {
valid = conn.VerifyHostname(server)
}
for _, c := range conn.ConnectionState().PeerCertificates {
if valid == nil {
fmt.Printf("%*s | valid, expires on %s (%s)\n", width, server,
Expand All @@ -71,6 +75,9 @@ func main() {
os.Exit(1)
}

// Create TLS config based on supplied options
config = &tls.Config{InsecureSkipVerify: *skipHostVerify}

// collect list of server names
names := getNames()

Expand Down