File: chain.go

package info (click to toggle)
golang-github-kisom-goutils 0.0~git20161101.0.858c9cb-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 396 kB
  • sloc: makefile: 6
file content (40 lines) | stat: -rw-r--r-- 637 bytes parent folder | download | duplicates (4)
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)
		}
	}
}