Skip to content

Commit 8359b42

Browse files
committed
feat: ability to add custom tiled logs via config
1 parent bcb2de6 commit 8359b42

2 files changed

Lines changed: 70 additions & 14 deletions

File tree

internal/certificatetransparency/ct-watcher.go

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ import (
1313
"sync/atomic"
1414
"time"
1515

16+
"github.com/google/trillian/client/backoff"
17+
1618
"github.com/d-Rickyy-b/certstream-server-go/internal/config"
1719
"github.com/d-Rickyy-b/certstream-server-go/internal/models"
1820
"github.com/d-Rickyy-b/certstream-server-go/internal/web"
19-
"github.com/google/trillian/client/backoff"
2021

2122
ct "github.com/google/certificate-transparency-go"
2223
"github.com/google/certificate-transparency-go/client"
@@ -569,7 +570,7 @@ func (w *worker) foundPrecertCallback(rawEntry *ct.RawLogEntry) {
569570
// certHandler takes the entries out of the entryChan channel and broadcasts them to all clients.
570571
// Only a single instance of the certHandler runs per certstream server.
571572
func certHandler(entryChan chan models.Entry) {
572-
var processed int64
573+
var processed uint64
573574

574575
for {
575576
entry := <-entryChan
@@ -634,10 +635,11 @@ func getAllLogs() (loglist3.LogList, error) {
634635
}
635636

636637
// Add manually added logs from config to the allLogs list
637-
if config.AppConfig.General.AdditionalLogs == nil {
638-
return allLogs, nil
639-
}
638+
// if config.AppConfig.General.AdditionalLogs == nil {
639+
// return allLogs, nil
640+
// }
640641

642+
logFound:
641643
for _, additionalLog := range config.AppConfig.General.AdditionalLogs {
642644
customLog := loglist3.Log{
643645
URL: additionalLog.URL,
@@ -647,10 +649,16 @@ func getAllLogs() (loglist3.LogList, error) {
647649
operatorFound := false
648650
for _, operator := range allLogs.Operators {
649651
if operator.Name == additionalLog.Operator {
650-
// TODO Check if the log is already in the list
651-
operator.Logs = append(operator.Logs, &customLog)
652652
operatorFound = true
653653

654+
for _, ctlog := range operator.Logs {
655+
if ctlog.URL == additionalLog.URL {
656+
// Log already exists, skip it.
657+
break logFound
658+
}
659+
}
660+
// This works, since allLogs.Operators is a slice of pointers.
661+
operator.Logs = append(operator.Logs, &customLog)
654662
break
655663
}
656664
}
@@ -664,6 +672,39 @@ func getAllLogs() (loglist3.LogList, error) {
664672
}
665673
}
666674

675+
for _, additionalLog := range config.AppConfig.General.AdditionalTiledLogs {
676+
customLog := loglist3.TiledLog{
677+
MonitoringURL: additionalLog.URL,
678+
Description: additionalLog.Description,
679+
}
680+
681+
operatorFound := false
682+
683+
tiledLogFound:
684+
for _, operator := range allLogs.Operators {
685+
if operator.Name == additionalLog.Operator {
686+
operatorFound = true
687+
for _, tl := range operator.TiledLogs {
688+
if tl.MonitoringURL == additionalLog.URL {
689+
// Log already exists, skip it.
690+
break tiledLogFound
691+
}
692+
}
693+
// This works, since allLogs.Operators is a slice of pointers.
694+
operator.TiledLogs = append(operator.TiledLogs, &customLog)
695+
break
696+
}
697+
}
698+
699+
if !operatorFound {
700+
newOperator := loglist3.Operator{
701+
Name: additionalLog.Operator,
702+
TiledLogs: []*loglist3.TiledLog{&customLog},
703+
}
704+
allLogs.Operators = append(allLogs.Operators, &newOperator)
705+
}
706+
}
707+
667708
return allLogs, nil
668709
}
669710

internal/config/config.go

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,11 @@ type Config struct {
5555
// DisableDefaultLogs indicates whether the default logs used in Google Chrome and provided by Google should be disabled.
5656
DisableDefaultLogs bool `yaml:"disable_default_logs"`
5757
// AdditionalLogs contains additional logs provided by the user that can be used in addition to the default logs.
58-
AdditionalLogs []LogConfig `yaml:"additional_logs"`
59-
BufferSizes BufferSizes `yaml:"buffer_sizes"`
60-
DropOldLogs *bool `yaml:"drop_old_logs"`
61-
Recovery struct {
58+
AdditionalLogs []LogConfig `yaml:"additional_logs"`
59+
AdditionalTiledLogs []LogConfig `yaml:"additional_tiled_logs"`
60+
BufferSizes BufferSizes `yaml:"buffer_sizes"`
61+
DropOldLogs *bool `yaml:"drop_old_logs"`
62+
Recovery struct {
6263
Enabled bool `yaml:"enabled"`
6364
CTIndexFile string `yaml:"ct_index_file"`
6465
} `yaml:"recovery"`
@@ -211,7 +212,7 @@ func validateConfig(config *Config) bool {
211212
}
212213
}
213214

214-
var validLogs []LogConfig
215+
var validLogs, validTiledLogs []LogConfig
215216
if len(config.General.AdditionalLogs) > 0 {
216217
for _, ctLog := range config.General.AdditionalLogs {
217218
if !URLRegex.MatchString(ctLog.URL) {
@@ -221,11 +222,25 @@ func validateConfig(config *Config) bool {
221222

222223
validLogs = append(validLogs, ctLog)
223224
}
224-
} else if len(config.General.AdditionalLogs) == 0 && config.General.DisableDefaultLogs {
225-
log.Fatalln("Default logs are disabled, but no additional logs are configured. Please add at least one log to the config or enable default logs.")
225+
}
226+
227+
if len(config.General.AdditionalTiledLogs) > 0 {
228+
for _, ctLog := range config.General.AdditionalTiledLogs {
229+
if !URLRegex.MatchString(ctLog.URL) {
230+
log.Println("Ignoring invalid additional log URL: ", ctLog.URL)
231+
continue
232+
}
233+
234+
validTiledLogs = append(validTiledLogs, ctLog)
235+
}
226236
}
227237

228238
config.General.AdditionalLogs = validLogs
239+
config.General.AdditionalTiledLogs = validTiledLogs
240+
241+
if len(config.General.AdditionalLogs) == 0 && len(config.General.AdditionalTiledLogs) == 0 && config.General.DisableDefaultLogs {
242+
log.Fatalln("Default logs are disabled, but no additional logs are configured. Please add at least one log to the config or enable default logs.")
243+
}
229244

230245
if config.General.BufferSizes.Websocket <= 0 {
231246
config.General.BufferSizes.Websocket = 300

0 commit comments

Comments
 (0)