forked from zmap/zcrypto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
52 lines (48 loc) · 1.29 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
package main
import (
"flag"
"fmt"
"log"
"encoding/json"
ct "github.com/corny/zcrypto/ct"
"github.com/corny/zcrypto/ct/client"
"github.com/corny/zcrypto/x509"
)
// Processes the given entry in the specified log.
func processEntry(entry ct.LogEntry) (*x509.Certificate, error) {
cert := &x509.Certificate{}
switch entry.Leaf.TimestampedEntry.EntryType {
case ct.X509LogEntryType:
innerCert, err := x509.ParseCertificate(entry.Leaf.TimestampedEntry.X509Entry)
if err != nil {
return nil, err
}
cert = innerCert
case ct.PrecertLogEntryType:
innerCert, err := x509.ParseCertificate(entry.Leaf.TimestampedEntry.PrecertEntry.TBSCertificate)
if err != nil {
return nil, err
}
cert = innerCert
}
return cert, nil
}
func main() {
var logURI = flag.String("log_uri", "http://ct.googleapis.com/aviator", "CT log base URI")
var indexToParse = flag.Int64("index", 1, "Index to parse")
flag.Parse()
logClient := client.New(*logURI)
entries, err := logClient.GetEntries(*indexToParse, *indexToParse)
if err != nil {
log.Fatal(err)
}
for _, entry := range entries {
cert, err := processEntry(entry)
if err != nil {
fmt.Printf("%d %s\n", entry.Index, err.Error())
continue
}
finalJSON, _ := json.Marshal(cert)
fmt.Printf("%d %s\n", entry.Index, string(finalJSON))
}
}