~kisom/goutils

ref: v1.5.0 goutils/cmd/readchain/chain.go -rw-r--r-- 637 bytes
69256281Kyle Isom clean README 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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)
		}
	}
}