Skip to content

Commit d2cb099

Browse files
committed
refactor(static-ct): remove leftover code
1 parent 5173fb7 commit d2cb099

2 files changed

Lines changed: 9 additions & 44 deletions

File tree

internal/certificatetransparency/ct-tiled.go

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -118,43 +118,6 @@ func FetchCheckpoint(ctx context.Context, client *http.Client, baseURL string) (
118118
}, nil
119119
}
120120

121-
// FetchTile fetches a tile from the tiled CT log using the provided client.
122-
// If partialWidth > 0, fetches a partial tile with that width (1-255).
123-
func FetchTile(ctx context.Context, client *http.Client, baseURL string, tileIndex, partialWidth uint64) ([]TileLeaf, error) {
124-
baseURL = strings.TrimRight(baseURL, "/")
125-
tilePath := encodeTilePath(tileIndex)
126-
127-
if partialWidth > 0 {
128-
tilePath = fmt.Sprintf("%s.p/%d", tilePath, partialWidth)
129-
}
130-
131-
url := fmt.Sprintf("%s/tile/data/%s", baseURL, tilePath)
132-
133-
req, newReqErr := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
134-
if newReqErr != nil {
135-
return nil, fmt.Errorf("failed to create tile request: %w", newReqErr)
136-
}
137-
138-
req.Header.Set("User-Agent", UserAgent)
139-
140-
resp, reqErr := client.Do(req)
141-
if reqErr != nil {
142-
return nil, fmt.Errorf("fetching tile %d: %w", tileIndex, reqErr)
143-
}
144-
defer resp.Body.Close()
145-
146-
if resp.StatusCode != http.StatusOK {
147-
return nil, fmt.Errorf("%w: unexpected status code %d", ErrRequestFailed, resp.StatusCode)
148-
}
149-
150-
data, err := io.ReadAll(resp.Body)
151-
if err != nil {
152-
return nil, fmt.Errorf("reading tile data: %w", err)
153-
}
154-
155-
return ParseTileData(data)
156-
}
157-
158121
// ParseTileData parses the binary tile data into TileLeaf entries using cryptobyte.
159122
func ParseTileData(data []byte) ([]TileLeaf, error) {
160123
var leaves []TileLeaf
@@ -316,7 +279,7 @@ func (s *StaticCTClient) Monitor(ctx context.Context, foundCert func(*ct.RawLogE
316279
// It returns true if at least one full tile was fetched.
317280
func (s *StaticCTClient) fetchAndProcessTiles(ctx context.Context, foundCert func(*ct.RawLogEntry), foundPrecert func(*ct.RawLogEntry)) (bool, error) {
318281
// Fetch current checkpoint
319-
checkpoint, fetchErr := s.fetchCheckpoint(ctx)
282+
checkpoint, fetchErr := s.FetchCheckpoint(ctx)
320283
if fetchErr != nil {
321284
return false, fmt.Errorf("fetching checkpoint: %w", fetchErr)
322285
}
@@ -425,8 +388,8 @@ func (s *StaticCTClient) fetchTile(ctx context.Context, tileIndex, partialWidth
425388
return ParseTileData(data)
426389
}
427390

428-
// fetchCheckpoint fetches the checkpoint from a tiled CT log using the provided client.
429-
func (s *StaticCTClient) fetchCheckpoint(ctx context.Context) (*TiledCheckpoint, error) {
391+
// FetchCheckpoint fetches the checkpoint from a tiled CT log using the provided client.
392+
func (s *StaticCTClient) FetchCheckpoint(ctx context.Context) (*TiledCheckpoint, error) {
430393
url := s.url + "/checkpoint"
431394

432395
req, newReqErr := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)

internal/certificatetransparency/ct-watcher.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,8 @@ func (w *Watcher) CreateIndexFile(filePath string) error {
309309
metrics.Metrics.Init(operator.Name, normalizedURL)
310310
log.Println("Fetching checkpoint for", normalizedURL)
311311

312-
checkpoint, fetchErr := FetchCheckpoint(w.context, httpClient, transparencyLog.MonitoringURL)
312+
staticCTClient := NewStaticCTClient(transparencyLog.MonitoringURL, httpClient, UserAgent, 0)
313+
checkpoint, fetchErr := staticCTClient.FetchCheckpoint(w.context)
313314
if fetchErr != nil {
314315
log.Printf("Could not get checkpoint for '%s': %s\n", transparencyLog.MonitoringURL, fetchErr)
315316
return ErrFetchingSTHFailed
@@ -469,19 +470,20 @@ func (w *worker) runStandardWorker(ctx context.Context) error {
469470
func (w *worker) runTiledWorker(ctx context.Context) error {
470471
httpClient := newHTTPClient()
471472

473+
staticCTClient := NewStaticCTClient(w.ctURL, httpClient, UserAgent, w.ctIndex)
474+
472475
// If recovery is enabled and the CT index is set, we start at the saved index. Otherwise, we start at the latest checkpoint.
473476
validSavedCTIndexExists := config.AppConfig.General.Recovery.Enabled
474477
if !validSavedCTIndexExists {
475-
checkpoint, err := FetchCheckpoint(ctx, httpClient, w.ctURL)
478+
checkpoint, err := staticCTClient.FetchCheckpoint(ctx)
476479
if err != nil {
477480
log.Printf("Could not get checkpoint for '%s': %s\n", w.ctURL, err)
478481
return ErrFetchingSTHFailed
479482
}
480483
// Start at the latest checkpoint to skip all the past certificates
481-
w.ctIndex = checkpoint.Size
484+
staticCTClient.ctIndex = checkpoint.Size
482485
}
483486

484-
staticCTClient := NewStaticCTClient(w.ctURL, httpClient, UserAgent, w.ctIndex)
485487
err := staticCTClient.Monitor(ctx, w.foundCertCallback, w.foundPrecertCallback)
486488
if err != nil {
487489
return fmt.Errorf("error scanning for certificates: %w", err)

0 commit comments

Comments
 (0)