From 7bb5602d09e18b21c4ad6b232d921729b0ddba33 Mon Sep 17 00:00:00 2001 From: Andrew Ayer Date: Thu, 4 Apr 2024 07:55:44 -0400 Subject: [PATCH] Refine interface for malformed log entries --- monitor/fsstate.go | 6 +++--- monitor/process.go | 2 +- monitor/state.go | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/monitor/fsstate.go b/monitor/fsstate.go index 6b84f87..550ba5b 100644 --- a/monitor/fsstate.go +++ b/monitor/fsstate.go @@ -146,7 +146,7 @@ func (s *FilesystemState) NotifyCert(ctx context.Context, cert *DiscoveredCert) return nil } -func (s *FilesystemState) NotifyMalformedEntry(ctx context.Context, entry *LogEntry, parseError string) error { +func (s *FilesystemState) NotifyMalformedEntry(ctx context.Context, entry *LogEntry, parseError error) error { var ( dirPath = filepath.Join(s.logStateDir(entry.Log.LogID), "malformed_entries") entryPath = filepath.Join(dirPath, fmt.Sprintf("%d.json", entry.Index)) @@ -168,7 +168,7 @@ func (s *FilesystemState) NotifyMalformedEntry(ctx context.Context, entry *LogEn fmt.Fprintf(text, "Unable to determine if log entry matches your watchlist. Please file a bug report at https://github.com/SSLMate/certspotter/issues/new with the following details:\n") writeField("Log Entry", fmt.Sprintf("%d @ %s", entry.Index, entry.Log.URL)) writeField("Leaf Hash", entry.LeafHash.Base64String()) - writeField("Error", parseError) + writeField("Error", parseError.Error()) if err := writeJSONFile(entryPath, entryJSON, 0666); err != nil { return fmt.Errorf("error saving JSON file: %w", err) @@ -183,7 +183,7 @@ func (s *FilesystemState) NotifyMalformedEntry(ctx context.Context, entry *LogEn "LOG_URI=" + entry.Log.URL, "ENTRY_INDEX=" + fmt.Sprint(entry.Index), "LEAF_HASH=" + entry.LeafHash.Base64String(), - "PARSE_ERROR=" + parseError, + "PARSE_ERROR=" + parseError.Error(), "ENTRY_FILENAME=" + entryPath, "TEXT_FILENAME=" + textPath, "CERT_PARSEABLE=no", // backwards compat with pre-0.15.0; not documented diff --git a/monitor/process.go b/monitor/process.go index faa2531..c416d55 100644 --- a/monitor/process.go +++ b/monitor/process.go @@ -111,7 +111,7 @@ func processCertificate(ctx context.Context, config *Config, entry *LogEntry, ce } func processMalformedLogEntry(ctx context.Context, config *Config, entry *LogEntry, parseError error) error { - if err := config.State.NotifyMalformedEntry(ctx, entry, parseError.Error()); err != nil { + if err := config.State.NotifyMalformedEntry(ctx, entry, parseError); err != nil { return fmt.Errorf("error notifying about malformed log entry %d in %s (%q): %w", entry.Index, entry.Log.URL, parseError, err) } return nil diff --git a/monitor/state.go b/monitor/state.go index 7d85402..a5921ee 100644 --- a/monitor/state.go +++ b/monitor/state.go @@ -55,7 +55,7 @@ type StateProvider interface { NotifyCert(context.Context, *DiscoveredCert) error // Called when certspotter fails to parse a log entry. - NotifyMalformedEntry(ctx context.Context, entry *LogEntry, parseError string) error + NotifyMalformedEntry(context.Context, *LogEntry, error) error // Called when a health check fails. The log is nil if the // feailure is not associated with a log.