From 8efc43b0e44218a823cd4153ad7f32050ae63ae8 Mon Sep 17 00:00:00 2001 From: Pim van Pelt Date: Sun, 5 Apr 2026 22:54:29 +0200 Subject: [PATCH] Clean up stderr logging --- cmd/ctfetch/main.go | 27 ++------------------------- internal/utils/utils.go | 9 ++++----- 2 files changed, 6 insertions(+), 30 deletions(-) diff --git a/cmd/ctfetch/main.go b/cmd/ctfetch/main.go index f5f0aba..e811a10 100644 --- a/cmd/ctfetch/main.go +++ b/cmd/ctfetch/main.go @@ -102,37 +102,18 @@ func runLeafIndex(logURL, indexStr string, opts utils.Options) { tile.L = -1 partialPath := sunlight.TilePath(tile) - fullTile := tile - fullTile.W = sunlight.TileWidth - fullPath := sunlight.TilePath(fullTile) positionInTile := leafIndex % sunlight.TileWidth - fmt.Fprintf(os.Stderr, "Leaf Index: %d\n", leafIndex) - fmt.Fprintf(os.Stderr, "Position in tile: %d\n", positionInTile) - fmt.Fprintf(os.Stderr, "Partial tile path: %s\n", partialPath) - fmt.Fprintf(os.Stderr, "Full tile path: %s\n", fullPath) - - partialURL := logURL + "/" + partialPath - fmt.Fprintf(os.Stderr, "Trying: %s\n", partialURL) - tileData, err := utils.FetchTile(partialURL) + tileData, err := utils.FetchTile(logURL + "/" + partialPath) if err != nil { - fullURL := logURL + "/" + fullPath - fmt.Fprintf(os.Stderr, "Partial tile failed, trying: %s\n", fullURL) - tileData, err = utils.FetchURL(fullURL) - if err != nil { - fatal("failed to fetch tile: %v", err) - } - fmt.Fprintf(os.Stderr, "Successfully fetched full tile\n") - } else { - fmt.Fprintf(os.Stderr, "Successfully fetched partial tile\n") + fatal("failed to fetch tile: %v", err) } tileData, err = utils.Decompress(tileData) if err != nil { fatal("failed to decompress tile: %v", err) } - fmt.Fprintf(os.Stderr, "Tile size: %d bytes\n\n", len(tileData)) entry, err := utils.DumpEntryAtPosition(tileData, int(positionInTile), leafIndex, opts) if err != nil { @@ -156,12 +137,10 @@ func runTileDump(arg, monitoringURL string, opts utils.Options) { fatal("+issuer requires a log root URL; none could be derived from %q and --monitoring-url is not set", arg) } } - fmt.Fprintf(os.Stderr, "Fetching: %s\n", arg) tileData, err = utils.FetchTile(arg) if err != nil { fatal("failed to fetch tile: %v", err) } - fmt.Fprintf(os.Stderr, "Fetched %d bytes\n", len(tileData)) } else { // File input. if opts.ShowIssuer { @@ -175,14 +154,12 @@ func runTileDump(arg, monitoringURL string, opts utils.Options) { if err != nil { fatal("failed to read file: %v", err) } - fmt.Fprintf(os.Stderr, "Read %d bytes from %s\n", len(tileData), arg) } tileData, err = utils.Decompress(tileData) if err != nil { fatal("failed to decompress tile: %v", err) } - fmt.Fprintf(os.Stderr, "Tile size: %d bytes\n\n", len(tileData)) result, err := utils.DumpAllEntries(tileData, opts) if err != nil { diff --git a/internal/utils/utils.go b/internal/utils/utils.go index b56398f..6c8eab6 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -32,8 +32,8 @@ var ( ) var ( - oidSCTList = asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 11129, 2, 4, 2} - oidCTPoison = asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 11129, 2, 4, 3} + oidSCTList = asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 11129, 2, 4, 2} + oidCTPoison = asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 11129, 2, 4, 3} ) // CTLogInfo holds details about a CT log from the log list. @@ -162,6 +162,7 @@ type DumpResult struct { // FetchURL fetches data from a URL. func FetchURL(url string) ([]byte, error) { + fmt.Fprintf(os.Stderr, "Fetching: %s\n", url) resp, err := http.Get(url) if err != nil { return nil, err @@ -184,9 +185,7 @@ func FetchTile(url string) ([]byte, error) { // On 404, try stripping the partial-tile suffix (.p/NNN) if err.Error() == "HTTP 404" { if idx := strings.Index(url, ".p/"); idx != -1 { - fullURL := url[:idx] - fmt.Fprintf(os.Stderr, "Partial tile not found, trying full tile: %s\n", fullURL) - return FetchURL(fullURL) + return FetchURL(url[:idx]) } } return nil, err