Initial import.
This commit is contained in:
20
cmd/readchain/README
Normal file
20
cmd/readchain/README
Normal file
@@ -0,0 +1,20 @@
|
||||
readchain
|
||||
|
||||
This is a small utility to read a chain of PEM-encoded X.509 certificates
|
||||
and print their common names. It was written to quickly see what certificates
|
||||
were in a bundle.
|
||||
|
||||
It is called with the files containing chains to read passed in as an
|
||||
argument. The program has no knobs or widgets to adjust.
|
||||
|
||||
Examples:
|
||||
|
||||
$ readchain google.com.pem microsoft.com.pem
|
||||
[+] google.com.pem:
|
||||
*.google.com
|
||||
Google Internet Authority G2
|
||||
GeoTrust Global CA
|
||||
[+] microsoft.com.pem:
|
||||
microsoft.com
|
||||
MSIT Machine Auth CA 2
|
||||
Microsoft Internet Authority
|
||||
40
cmd/readchain/chain.go
Normal file
40
cmd/readchain/chain.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"crypto/x509"
|
||||
"encoding/pem"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
for _, fileName := range flag.Args() {
|
||||
data, err := ioutil.ReadFile(fileName)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "[!] %s: %v\n", fileName, err)
|
||||
continue
|
||||
}
|
||||
|
||||
fmt.Printf("[+] %s:\n", fileName)
|
||||
rest := data[:]
|
||||
for {
|
||||
var p *pem.Block
|
||||
p, rest = pem.Decode(rest)
|
||||
if p == nil {
|
||||
break
|
||||
}
|
||||
|
||||
cert, err := x509.ParseCertificate(p.Bytes)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "[!] %s: %v\n", fileName, err)
|
||||
break
|
||||
}
|
||||
|
||||
fmt.Printf("\t%+v\n", cert.Subject.CommonName)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user