-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlist.go
82 lines (70 loc) · 2.1 KB
/
list.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
package main
import (
"context"
"fmt"
"log/slog"
"os"
"strings"
ctLog "github.com/google/certificate-transparency-go/loglist3"
)
func doList(logList *ctLog.LogList) {
if flags.entryToList != 0 {
if flags.logToList == "" {
Abort("Both --log must be specified when using --entry")
}
for _, operator := range logList.Operators {
for _, log := range operator.Logs {
if strings.HasPrefix(strings.ToUpper(log.URL), strings.ToUpper(flags.logToList)) {
slog.Debug("Using", "log", log.URL, "operator", operator.Name)
client := CreateLogClient(log)
STH, err := client.GetSTH(context.Background())
if err != nil {
Abort(err.Error())
}
finalEntryIndex := STH.TreeSize
if finalEntryIndex < flags.entryToList {
slog.Error("Entry is larger than final entry in log", "entry", flags.entryToList, "finalEntry", finalEntryIndex)
os.Exit(1)
}
entries := GetX509CertLogEntries(client, int64(flags.entryToList), int64(flags.entryToList))
slog.Debug("Entries", "len()", len(entries))
for _, entry := range entries {
var dnsNames []string
if entry.X509Cert != nil {
// Not a precert
dnsNames = entry.X509Cert.DNSNames
} else if !flags.includePrecert && entry.Precert != nil {
slog.Warn("Entry has precertificate, use -include-precert to output")
} else if flags.includePrecert && entry.Precert != nil {
dnsNames = entry.Precert.TBSCertificate.DNSNames
}
for _, dnsName := range dnsNames {
fmt.Println(dnsName)
}
}
os.Exit(0)
}
}
}
slog.Error("Failed to find log", "log", flags.logToList, "operator", flags.operatorToList)
os.Exit(1)
}
if flags.logToList != "" {
fmt.Println("--log does not make sense witout --entry")
os.Exit(1)
}
if flags.operatorToList != "" {
for _, operator := range logList.Operators {
if strings.EqualFold(flags.operatorToList, operator.Name) {
for _, log := range operator.Logs {
fmt.Println(log.URL)
}
}
}
os.Exit(0)
}
for _, operator := range logList.Operators {
fmt.Println(operator.Name)
}
os.Exit(0)
}