goutils/cmd/certchain/certchain.go

40 lines
595 B
Go
Raw Permalink Normal View History

2015-06-10 23:29:52 +00:00
package main
import (
"crypto/tls"
"encoding/pem"
"flag"
"fmt"
"regexp"
2020-11-27 04:09:37 +00:00
"git.sr.ht/~kisom/goutils/die"
2015-06-10 23:29:52 +00:00
)
var hasPort = regexp.MustCompile(`:\d+$`)
func main() {
flag.Parse()
for _, server := range flag.Args() {
if !hasPort.MatchString(server) {
server += ":443"
}
var chain string
conn, err := tls.Dial("tcp", server, nil)
die.If(err)
details := conn.ConnectionState()
for _, cert := range details.PeerCertificates {
p := pem.Block{
Type: "CERTIFICATE",
Bytes: cert.Raw,
}
chain += string(pem.EncodeToMemory(&p))
}
fmt.Println(chain)
}
}