Skip to content

Commit 428dc7f

Browse files
committed
json output
1 parent 2380f67 commit 428dc7f

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

certscan.go

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"crypto/tls"
66
"crypto/x509"
77
"encoding/pem"
8+
"encoding/json"
89
"flag"
910
"fmt"
1011
"net"
@@ -21,7 +22,6 @@ import (
2122

2223
/* TODO
2324
follow http redirects
24-
json output
2525
cert chain
2626
*/
2727

@@ -42,6 +42,7 @@ var starttls bool
4242
var sortCerts bool
4343
var savePath string
4444
var list bool
45+
var printJSON bool
4546

4647
// domain node conection status
4748
type domainStatus int
@@ -77,7 +78,7 @@ func (status domainStatus) String() string {
7778
// structure to store a domain and its edges
7879
type DomainNode struct {
7980
Domain string
80-
Depth uint
81+
Depth uint `json:"-"`
8182
Fingerprint []byte
8283
Neighbors []string
8384
Status domainStatus
@@ -108,13 +109,18 @@ func main() {
108109
flag.BoolVar(&starttls, "starttls", false, "connect without TLS and then upgrade with STARTTLS for SMTP, useful with -port 25")
109110
flag.BoolVar(&sortCerts, "sort", false, "visit and print domains in sorted order")
110111
flag.BoolVar(&list, "list", false, "only print the domains found and not the entire graph")
112+
flag.BoolVar(&printJSON, "json", false, "print the graph as json")
111113
flag.StringVar(&savePath, "save", "", "save certs to folder in PEM formate")
112114
flag.Usage = func() {
113115
fmt.Fprintf(os.Stderr, "Usage of %s: [OPTION]... HOST...\n", os.Args[0])
114116
flag.PrintDefaults()
115117
}
116118

117119
flag.Parse()
120+
if printJSON {
121+
// these arguments conflict
122+
sortCerts = true
123+
}
118124
if flag.NArg() < 1 {
119125
flag.Usage()
120126
return
@@ -141,9 +147,9 @@ func main() {
141147

142148
BFS(startDomains)
143149

144-
v("Done...")
145-
146-
if sortCerts {
150+
if printJSON {
151+
printJSONGraph()
152+
} else if sortCerts {
147153
printSortedGraph()
148154
}
149155

@@ -192,6 +198,16 @@ func directDomain(domain string) string {
192198
return domain
193199
}
194200

201+
// prnts the graph as a json object
202+
func printJSONGraph() {
203+
j, err := json.Marshal(domainGraph)
204+
if err != nil {
205+
fmt.Println(err)
206+
return
207+
}
208+
fmt.Println(string(j))
209+
}
210+
195211
// prints the adjacency list in sorted order
196212
func printSortedGraph() {
197213
domains := make([]string, 0, len(domainGraph))

0 commit comments

Comments
 (0)