Skip to content

Commit

Permalink
Merge pull request #78 from SenseUnit/report_bad_bl_lines
Browse files Browse the repository at this point in the history
Report bad blacklist lines
  • Loading branch information
Snawoot authored Oct 28, 2024
2 parents 7d92a9d + aa5c4d1 commit 8641503
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions auth/cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ func (auth *CertAuth) reload() error {
}

auth.logger.Info("reloading certificate blacklist from %q...", auth.blacklistFilename)
newBlacklistSet, err := newSerialNumberSetFromReader(f)
newBlacklistSet, err := newSerialNumberSetFromReader(f, func(parseErr error) {
auth.logger.Error("failed to parse line in %q: %v", auth.blacklistFilename, parseErr)
})
if err != nil {
return err
}
Expand Down Expand Up @@ -171,7 +173,7 @@ func (s *serialNumberSet) Has(serial *big.Int) bool {
return found
}

func newSerialNumberSetFromReader(r io.Reader) (*serialNumberSet, error) {
func newSerialNumberSetFromReader(r io.Reader, bad func(error)) (*serialNumberSet, error) {
set := make(map[serialNumberKey]struct{})
scanner := bufio.NewScanner(r)
for scanner.Scan() {
Expand All @@ -182,6 +184,9 @@ func newSerialNumberSetFromReader(r io.Reader) (*serialNumberSet, error) {
}
serial, err := parseSerialBytes(line)
if err != nil {
if bad != nil {
bad(fmt.Errorf("bad serial number line %q: %w", line, err))
}
continue
}
set[normalizeSNBytes(serial)] = struct{}{}
Expand Down
4 changes: 2 additions & 2 deletions auth/cert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func TestSerialNumberSetSmoke(t *testing.T) {
output: true,
},
}
s, err := newSerialNumberSetFromReader(strings.NewReader(testFile))
s, err := newSerialNumberSetFromReader(strings.NewReader(testFile), nil)
if err != nil {
t.Fatalf("unable to load test set: %v", err)
}
Expand Down Expand Up @@ -158,7 +158,7 @@ func TestSerialNumberSetEmpty(t *testing.T) {
output: false,
},
}
s, err := newSerialNumberSetFromReader(strings.NewReader(testFile))
s, err := newSerialNumberSetFromReader(strings.NewReader(testFile), nil)
if err != nil {
t.Fatalf("unable to load test set: %v", err)
}
Expand Down

0 comments on commit 8641503

Please sign in to comment.