Skip to content

Commit e848338

Browse files
committed
feat: add new config option to drop old CT logs
This fixes #51 but adds the ability to keep the current behavior.
1 parent 7564383 commit e848338

4 files changed

Lines changed: 36 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99
### Added
10+
- Remove old CT logs as soon as they are removed from the Google CT Loglist (#60)
1011
### Changed
1112
### Fixed
1213
### Docs

config.sample.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,6 @@ general:
2828
- url: https://dodo.ct.comodo.com/
2929
operator: "Comodo"
3030
description: "Comodo Dodo"
31+
# Google regularly updates the log list. If this option is set to true, the server will remove all old logs.
32+
# This option defaults to true. See https://github.com/d-Rickyy-b/certstream-server-go/issues/51
33+
drop_old_logs: true

internal/certificatetransparency/ct-watcher.go

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (w *Watcher) Start() {
5555
}
5656

5757
// initialize the watcher with currently available logs
58-
w.addNewlyAvailableLogs()
58+
w.updateLogs()
5959

6060
log.Println("Started CT watcher")
6161
go certHandler(w.certChan)
@@ -69,33 +69,39 @@ func (w *Watcher) Start() {
6969
// This method is blocking. It can be stopped by cancelling the context.
7070
func (w *Watcher) watchNewLogs() {
7171
// Add all available logs to the watcher
72-
w.addNewlyAvailableLogs()
72+
w.updateLogs()
7373

7474
// Check for new logs once every hour
7575
ticker := time.NewTicker(1 * time.Hour)
7676
for {
7777
select {
7878
case <-ticker.C:
79-
w.addNewlyAvailableLogs()
79+
w.updateLogs()
8080
case <-w.context.Done():
8181
ticker.Stop()
8282
return
8383
}
8484
}
8585
}
8686

87-
// The transparency log list is constantly updated with new Log servers.
88-
// This function checks for new ct logs and adds them to the watcher.
89-
func (w *Watcher) addNewlyAvailableLogs() {
90-
log.Println("Checking for new ct logs...")
91-
87+
func (w *Watcher) updateLogs() {
9288
// Get a list of urls of all CT logs
9389
logList, err := getAllLogs()
9490
if err != nil {
9591
log.Println(err)
9692
return
9793
}
9894

95+
w.addNewlyAvailableLogs(logList)
96+
if *config.AppConfig.General.DropOldLogs {
97+
w.dropRemovedLogs(logList)
98+
}
99+
}
100+
101+
// addNewlyAvailableLogs checks the transparency log list for new Log servers and adds workers for those to the watcher.
102+
func (w *Watcher) addNewlyAvailableLogs(logList loglist3.LogList) {
103+
log.Println("Checking for new ct logs...")
104+
99105
newCTs := 0
100106

101107
// Check the ct log list for new, unwatched logs
@@ -139,6 +145,12 @@ func (w *Watcher) addNewlyAvailableLogs() {
139145

140146
log.Printf("New ct logs found: %d\n", newCTs)
141147
log.Printf("Currently monitored ct logs: %d\n", len(w.workers))
148+
}
149+
150+
// dropRemovedLogs checks if any of the currently monitored logs are no longer in the log list.
151+
// If they are not, the CT Logs are probably no longer relevant and the corresponding workers will be stopped.
152+
func (w *Watcher) dropRemovedLogs(logList loglist3.LogList) {
153+
removedCTs := 0
142154

143155
// Iterate over all workers and check if they are still in the logList
144156
// If they are not, the CT Logs are probably no longer relevant.
@@ -163,9 +175,13 @@ func (w *Watcher) addNewlyAvailableLogs() {
163175
// If the log is not in the loglist, stop the worker
164176
if !onLogList {
165177
log.Printf("Stopping worker. CT URL not found in LogList: '%s'\n", ctWorker.ctURL)
178+
removedCTs++
166179
ctWorker.stop()
167180
}
168181
}
182+
183+
log.Printf("Removed ct logs: %d\n", removedCTs)
184+
log.Printf("Currently monitored ct logs: %d\n", len(w.workers))
169185
}
170186

171187
// Stop stops the watcher.

internal/config/config.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type Config struct {
4747
}
4848
General struct {
4949
AdditionalLogs []LogConfig `yaml:"additional_logs"`
50+
DropOldLogs *bool `yaml:"drop_old_logs"`
5051
}
5152
}
5253

@@ -211,5 +212,12 @@ func validateConfig(config *Config) bool {
211212

212213
config.General.AdditionalLogs = validLogs
213214

215+
// If the cleanup flag is not set, default to true
216+
if config.General.DropOldLogs == nil {
217+
log.Println("drop_old_logs is not set, defaulting to true")
218+
defaultCleanup := true
219+
config.General.DropOldLogs = &defaultCleanup
220+
}
221+
214222
return true
215223
}

0 commit comments

Comments
 (0)