Clean up stderr logging

This commit is contained in:
2026-04-05 22:54:29 +02:00
parent 76e3ce28e1
commit 8efc43b0e4
2 changed files with 6 additions and 30 deletions

View File

@@ -102,37 +102,18 @@ func runLeafIndex(logURL, indexStr string, opts utils.Options) {
tile.L = -1 tile.L = -1
partialPath := sunlight.TilePath(tile) partialPath := sunlight.TilePath(tile)
fullTile := tile
fullTile.W = sunlight.TileWidth
fullPath := sunlight.TilePath(fullTile)
positionInTile := leafIndex % sunlight.TileWidth positionInTile := leafIndex % sunlight.TileWidth
fmt.Fprintf(os.Stderr, "Leaf Index: %d\n", leafIndex) tileData, err := utils.FetchTile(logURL + "/" + partialPath)
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)
if err != nil { if err != nil {
fullURL := logURL + "/" + fullPath fatal("failed to fetch tile: %v", err)
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")
} }
tileData, err = utils.Decompress(tileData) tileData, err = utils.Decompress(tileData)
if err != nil { if err != nil {
fatal("failed to decompress tile: %v", err) 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) entry, err := utils.DumpEntryAtPosition(tileData, int(positionInTile), leafIndex, opts)
if err != nil { 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) 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) tileData, err = utils.FetchTile(arg)
if err != nil { if err != nil {
fatal("failed to fetch tile: %v", err) fatal("failed to fetch tile: %v", err)
} }
fmt.Fprintf(os.Stderr, "Fetched %d bytes\n", len(tileData))
} else { } else {
// File input. // File input.
if opts.ShowIssuer { if opts.ShowIssuer {
@@ -175,14 +154,12 @@ func runTileDump(arg, monitoringURL string, opts utils.Options) {
if err != nil { if err != nil {
fatal("failed to read file: %v", err) 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) tileData, err = utils.Decompress(tileData)
if err != nil { if err != nil {
fatal("failed to decompress tile: %v", err) 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) result, err := utils.DumpAllEntries(tileData, opts)
if err != nil { if err != nil {

View File

@@ -32,8 +32,8 @@ var (
) )
var ( var (
oidSCTList = asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 11129, 2, 4, 2} 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} oidCTPoison = asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 11129, 2, 4, 3}
) )
// CTLogInfo holds details about a CT log from the log list. // CTLogInfo holds details about a CT log from the log list.
@@ -162,6 +162,7 @@ type DumpResult struct {
// FetchURL fetches data from a URL. // FetchURL fetches data from a URL.
func FetchURL(url string) ([]byte, error) { func FetchURL(url string) ([]byte, error) {
fmt.Fprintf(os.Stderr, "Fetching: %s\n", url)
resp, err := http.Get(url) resp, err := http.Get(url)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -184,9 +185,7 @@ func FetchTile(url string) ([]byte, error) {
// On 404, try stripping the partial-tile suffix (.p/NNN) // On 404, try stripping the partial-tile suffix (.p/NNN)
if err.Error() == "HTTP 404" { if err.Error() == "HTTP 404" {
if idx := strings.Index(url, ".p/"); idx != -1 { if idx := strings.Index(url, ".p/"); idx != -1 {
fullURL := url[:idx] return FetchURL(url[:idx])
fmt.Fprintf(os.Stderr, "Partial tile not found, trying full tile: %s\n", fullURL)
return FetchURL(fullURL)
} }
} }
return nil, err return nil, err