Initial import.

This commit is contained in:
Kyle Isom
2015-06-10 16:29:52 -07:00
commit 7391da8567
12 changed files with 365 additions and 0 deletions

19
cmd/certchain/README Normal file
View File

@@ -0,0 +1,19 @@
certchain
This is a utility for printing the X.509 certificate chain from a TLS
connection.
Note: while this will accept more than one server, it will print all
of the chains without any indication where one chain ends and the next
begins. This was the intended behaviour for the use case, but it may
not be applicable in other cases.
There are no knobs.
Examples:
$ certchain www.kyleisom.net
-----BEGIN CERTIFICATE-----
MIIFUTCCBDmgAwIBAgIQaaTVw0yZFGAYvFDKAIo4BzANBgkqhkiG9w0BAQsFADCB
kDELMAkGA1UEBhMCR0IxGzAZBgNVBAgTEkdyZWF0ZXIgTWFuY2hlc3RlcjEQMA4G
A1UEBxMHU2FsZm9yZDEaMBgGA1UEChMRQ09NT0RPIENBIExpbWl0ZWQxNjA0BgNV
...

View File

@@ -0,0 +1,39 @@
package main
import (
"crypto/tls"
"encoding/pem"
"flag"
"fmt"
"regexp"
"github.com/kisom/goutils/die"
)
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)
}
}