-
Notifications
You must be signed in to change notification settings - Fork 0
/
certy.go
68 lines (57 loc) · 1.21 KB
/
certy.go
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"net/http"
"os"
)
type CRTShCertificate struct {
NameValue string `json:"common_name"`
}
func main() {
domainPtr := flag.String("domain", "garthhumphreys.com", "a domain")
flag.Parse()
if len(os.Args) < 2 {
fmt.Println("expected 'domain'")
os.Exit(1)
}
if *domainPtr != "" {
// fmt.Println("site:", *domainPtr, "\n")
certSearch(*domainPtr)
} else {
flag.PrintDefaults()
os.Exit(1)
}
}
func certSearch(domain string) {
// domain := "example.com"
url := fmt.Sprintf("https://crt.sh/?q=%s.%s&output=json", "%", domain)
// fmt.Println("URL:", url)
resp, err := http.Get(url)
if err != nil {
fmt.Println("Error:", err)
return
}
defer resp.Body.Close()
// fmt.Println("RESP:", resp)
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println("Error:", err)
return
}
var certificates []CRTShCertificate
err = json.Unmarshal(body, &certificates)
if err != nil {
fmt.Println("Error:", err)
return
}
unique := make(map[string]bool)
for _, certificate := range certificates {
if _, ok := unique[certificate.NameValue]; !ok {
unique[certificate.NameValue] = true
fmt.Println(certificate.NameValue)
}
}
}