-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathprocessLog.go
94 lines (82 loc) · 2.54 KB
/
processLog.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package main
import (
"context"
"log/slog"
"strings"
"sync"
"sync/atomic"
ct "github.com/google/certificate-transparency-go"
ctLog "github.com/google/certificate-transparency-go/loglist3"
)
var totalProcessed uint64
var currentlyProcessing bool
func ProcessDomainsFromEntries(entries []ct.LogEntry) {
for _, entry := range entries {
if entry.X509Cert != nil {
for _, dnsName := range entry.X509Cert.DNSNames {
if flags.hasSuffix != "" {
if strings.HasSuffix(dnsName, flags.hasSuffix) {
DomainToOutput(dnsName)
}
} else if !strings.HasSuffix(dnsName, "flowers-to-the-world.com") {
DomainToOutput(dnsName)
}
}
}
}
}
func ProcessDomainsFromEntriesIncludingPrecerts(entries []ct.LogEntry) {
ProcessDomainsFromEntries(entries)
for _, entry := range entries {
if entry.Precert != nil {
for _, dnsName := range entry.Precert.TBSCertificate.DNSNames {
if flags.hasSuffix != "" {
if strings.HasSuffix(dnsName, flags.hasSuffix) {
DomainToOutput(dnsName)
}
} else if !strings.HasSuffix(dnsName, "flowers-to-the-world.com") {
DomainToOutput(dnsName)
}
}
}
}
}
func ProcessLog(wg *sync.WaitGroup, log *ctLog.Log, operator *ctLog.Operator) {
defer wg.Done()
slog.Debug("Querying log ", "url", log.URL, "operator", operator.Name)
client := CreateLogClient(log)
STH, err := client.GetSTH(context.Background())
if err != nil {
Abort(err.Error())
}
finalEntryIndex := STH.TreeSize
currentIndexInt, _ := mep.Get(log.URL)
lookupSize := flags.lookUpSizeFlag
currentIndex := uint64(currentIndexInt)
lastPercent := uint64(999)
for currentIndex < finalEntryIndex {
if currentIndex+lookupSize > finalEntryIndex {
lookupSize = finalEntryIndex - currentIndex
}
prcnt := currentIndex / finalEntryIndex
if lastPercent == 999 || prcnt > lastPercent {
slog.Info("Progress", "log", log.URL, "prcnt", prcnt)
lastPercent = prcnt
}
slog.Debug("Querying", "url", log.URL, "startIndex", currentIndex, "endIndex", currentIndex+lookupSize, "endIndex", finalEntryIndex)
entries := GetX509CertLogEntries(client, int64(currentIndex), int64(currentIndex+lookupSize))
if !flags.includePrecert {
ProcessDomainsFromEntries(entries)
} else {
ProcessDomainsFromEntriesIncludingPrecerts(entries)
}
currentIndex += uint64(len(entries))
atomic.AddUint64(&totalProcessed, uint64(len(entries)))
if atomic.LoadUint64(&totalProcessed) >= 10000 {
SaveResume()
atomic.StoreUint64(&totalProcessed, 0)
}
mep.Set(log.URL, int(currentIndex))
//time.Sleep(550 * time.Millisecond)
}
}