-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
77 lines (71 loc) · 1.91 KB
/
main.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
69
70
71
72
73
74
75
76
77
package main
import (
"context"
"log"
"os"
"os/signal"
"strings"
"syscall"
"github.com/santrancisco/certstream_screenshot/certstream-go"
"github.com/santrancisco/certstream_screenshot/screenshotworker"
"github.com/santrancisco/logutils"
)
var NEEDLES = []string{"tesla.com", "campaignmonitor.com", "tyro.com", "ebfe.pw", "cornmbank.com", "gov.au"}
func main() {
filter := &logutils.LevelFilter{
Levels: []logutils.LogLevel{"DEBUG", "INFO", "WARN", "ERROR"},
MinLevel: logutils.LogLevel("DEBUG"),
Writer: os.Stderr,
}
log.SetOutput(filter)
sigchan := make(chan os.Signal, 1)
signal.Notify(sigchan, os.Interrupt, syscall.SIGTERM)
// create context
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
log.Println("[INFO] Starting our Screenshot worker")
wp := screenshotworker.NewWorkerPool(ctx, 6)
wp.Start()
log.Println("[INFO] Monitor Certstream for needles")
stream, errStream := certstream.CertStreamEventStream(false)
MAINLOOP:
for {
select {
case _ = <-sigchan:
log.Print("[INFO] SIGTERM received, exiting app...")
cancel()
wp.Wg.Wait()
return
case jq := <-stream:
messageType, err := jq.String("message_type")
if err != nil {
log.Print("Error decoding jq string")
break
}
if messageType != "certificate_update" {
break
}
all_domains_array, err := jq.Array("data", "leaf_cert", "all_domains")
if err != nil {
log.Print("Error decoding jq string")
break
}
for _, element := range all_domains_array {
if element == nil {
continue
}
domain := element.(string)
// log.Printf("[DEBUG] Checking %s ", domain)
for _, needle := range NEEDLES {
if strings.HasSuffix(domain, needle) {
log.Printf("[INFO] New Cert for %s was requested", domain)
wp.URL <- "https://" + strings.TrimLeft(domain, "*.")
continue MAINLOOP
}
}
}
case err := <-errStream:
log.Printf("%v", err)
}
}
}