Skip to content

Commit c602bfa

Browse files
committed
feat: remove certLink for tiled logs and add field to source object
This is a way to differentiate between the two log types.
1 parent 2600cb0 commit c602bfa

3 files changed

Lines changed: 27 additions & 7 deletions

File tree

internal/certificatetransparency/ct-parser.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@ import (
2323
)
2424

2525
// parseData converts a *ct.RawLogEntry struct into a certstream.Data struct by copying some values and calculating others.
26-
func parseData(entry *ct.RawLogEntry, operatorName, logName, ctURL string) (models.Data, error) {
27-
certLink := fmt.Sprintf("%s/ct/v1/get-entries?start=%d&end=%d", ctURL, entry.Index, entry.Index)
28-
// TODO implement tiled cert link
26+
func parseData(entry *ct.RawLogEntry, operatorName, logName, ctURL, logType string) (models.Data, error) {
27+
var certLink string
28+
// There is no direct link for tiled ct logs
29+
if logType == models.SourceIsRFC6962 {
30+
certLink = fmt.Sprintf("%s/ct/v1/get-entries?start=%d&end=%d", ctURL, entry.Index, entry.Index)
31+
}
2932

3033
// Create main data structure
3134
data := models.Data{
@@ -38,6 +41,7 @@ func parseData(entry *ct.RawLogEntry, operatorName, logName, ctURL string) (mode
3841
Timestamp: float64(entry.Leaf.TimestampedEntry.Timestamp) / 1_000,
3942
Operator: operatorName,
4043
NormalizedURL: normalizeCtlogURL(ctURL),
44+
Type: logType,
4145
},
4246
UpdateType: "X509LogEntry",
4347
}
@@ -414,12 +418,12 @@ func keyUsageToString(k x509.KeyUsage) string {
414418
}
415419

416420
// ParseCertstreamEntry creates an Entry from a ct.RawLogEntry.
417-
func ParseCertstreamEntry(rawEntry *ct.RawLogEntry, operatorName, logname, ctURL string) (models.Entry, error) {
421+
func ParseCertstreamEntry(rawEntry *ct.RawLogEntry, operatorName, logname, ctURL, logType string) (models.Entry, error) {
418422
if rawEntry == nil {
419423
return models.Entry{}, errors.New("certstream entry is nil")
420424
}
421425

422-
data, err := parseData(rawEntry, operatorName, logname, ctURL)
426+
data, err := parseData(rawEntry, operatorName, logname, ctURL, logType)
423427
if err != nil {
424428
return models.Entry{}, err
425429
}

internal/certificatetransparency/ct-watcher.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,12 @@ func (w *worker) processTile(ctx context.Context, hc *http.Client, tileIndex uin
562562

563563
// foundCertCallback is the callback that handles cases where new regular certs are found.
564564
func (w *worker) foundCertCallback(rawEntry *ct.RawLogEntry) {
565-
entry, parseErr := ParseCertstreamEntry(rawEntry, w.operatorName, w.name, w.ctURL)
565+
logType := models.SourceIsRFC6962
566+
if w.isTiled {
567+
logType = models.SourceIsTiled
568+
}
569+
570+
entry, parseErr := ParseCertstreamEntry(rawEntry, w.operatorName, w.name, w.ctURL, logType)
566571
if parseErr != nil {
567572
log.Println("Error parsing certstream entry: ", parseErr)
568573
return
@@ -576,7 +581,12 @@ func (w *worker) foundCertCallback(rawEntry *ct.RawLogEntry) {
576581

577582
// foundPrecertCallback is the callback that handles cases where new precerts are found.
578583
func (w *worker) foundPrecertCallback(rawEntry *ct.RawLogEntry) {
579-
entry, parseErr := ParseCertstreamEntry(rawEntry, w.operatorName, w.name, w.ctURL)
584+
logType := models.SourceIsRFC6962
585+
if w.isTiled {
586+
logType = models.SourceIsTiled
587+
}
588+
589+
entry, parseErr := ParseCertstreamEntry(rawEntry, w.operatorName, w.name, w.ctURL, logType)
580590
if parseErr != nil {
581591
log.Println("Error parsing certstream entry: ", parseErr)
582592
return

internal/models/certstream.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,18 @@ type Data struct {
9696
UpdateType string `json:"update_type"`
9797
}
9898

99+
const (
100+
SourceIsTiled = "tiled"
101+
SourceIsRFC6962 = "rfc6962"
102+
)
103+
99104
type Source struct {
100105
Name string `json:"name"`
101106
URL string `json:"url"`
102107
Timestamp float64 `json:"timestamp"`
103108
Operator string `json:"-"`
104109
NormalizedURL string `json:"-"`
110+
Type string `json:"type"`
105111
}
106112

107113
type LeafCert struct {

0 commit comments

Comments
 (0)