diff --git a/syft/pkg/cataloger/binary/cataloger_test.go b/syft/pkg/cataloger/binary/cataloger_test.go index 41f3348faf4..faa8b2dcd66 100644 --- a/syft/pkg/cataloger/binary/cataloger_test.go +++ b/syft/pkg/cataloger/binary/cataloger_test.go @@ -207,6 +207,42 @@ func Test_Cataloger_DefaultClassifiers_PositiveCases(t *testing.T) { Metadata: metadata("perl-binary"), }, }, + { + name: "positive-haproxy-1.5.14", + fixtureDir: "test-fixtures/classifiers/positive/haproxy-1.5.14", + expected: pkg.Package{ + Name: "haproxy", + Version: "1.5.14", + Type: "binary", + PURL: "pkg:generic/haproxy@1.5.14", + Locations: locations("haproxy"), + Metadata: metadata("haproxy-binary"), + }, + }, + { + name: "positive-haproxy-1.8.22", + fixtureDir: "test-fixtures/classifiers/positive/haproxy-1.8.22", + expected: pkg.Package{ + Name: "haproxy", + Version: "1.8.22", + Type: "binary", + PURL: "pkg:generic/haproxy@1.8.22", + Locations: locations("haproxy"), + Metadata: metadata("haproxy-binary"), + }, + }, + { + name: "positive-haproxy-2.7.3", + fixtureDir: "test-fixtures/classifiers/positive/haproxy-2.7.3", + expected: pkg.Package{ + Name: "haproxy", + Version: "2.7.3", + Type: "binary", + PURL: "pkg:generic/haproxy@2.7.3", + Locations: locations("haproxy"), + Metadata: metadata("haproxy-binary"), + }, + }, { name: "positive-redis-2.8.23", fixtureDir: "test-fixtures/classifiers/positive/redis-server-2.8.23", diff --git a/syft/pkg/cataloger/binary/classifier.go b/syft/pkg/cataloger/binary/classifier.go index d625166b03f..15272e92dce 100644 --- a/syft/pkg/cataloger/binary/classifier.go +++ b/syft/pkg/cataloger/binary/classifier.go @@ -51,6 +51,21 @@ type classifier struct { // evidenceMatcher is a function called to catalog Packages that match some sort of evidence type evidenceMatcher func(classifier classifier, reader source.LocationReadCloser) ([]pkg.Package, error) +func evidenceMatchers(matchers ...evidenceMatcher) evidenceMatcher { + return func(classifier classifier, reader source.LocationReadCloser) ([]pkg.Package, error) { + for _, matcher := range matchers { + match, err := matcher(classifier, reader) + if err != nil { + return nil, err + } + if match != nil { + return match, nil + } + } + return nil, nil + } +} + func fileNameTemplateVersionMatcher(fileNamePattern string, contentTemplate string) evidenceMatcher { pat := regexp.MustCompile(fileNamePattern) return func(classifier classifier, reader source.LocationReadCloser) ([]pkg.Package, error) { diff --git a/syft/pkg/cataloger/binary/default_classifiers.go b/syft/pkg/cataloger/binary/default_classifiers.go index 46bf31ca780..75e7befc3d5 100644 --- a/syft/pkg/cataloger/binary/default_classifiers.go +++ b/syft/pkg/cataloger/binary/default_classifiers.go @@ -120,6 +120,17 @@ var defaultClassifiers = []classifier{ Package: "busybox", CPEs: singleCPE("cpe:2.3:a:busybox:busybox:*:*:*:*:*:*:*:*"), }, + { + Class: "haproxy-binary", + FileGlob: "**/haproxy", + EvidenceMatcher: evidenceMatchers( + fileContentsVersionMatcher(`(?m)HA-Proxy version (?P[0-9]+\.[0-9]+\.[0-9]+)`), + fileContentsVersionMatcher(`(?m)(?P[0-9]+\.[0-9]+\.[0-9]+)-[0-9a-zA-Z]{7}.+HAProxy version`), + ), + Package: "haproxy", + PURL: mustPURL("pkg:generic/haproxy@version"), + CPEs: singleCPE("cpe:2.3:a:haproxy:haproxy:*:*:*:*:*:*:*:*"), + }, { Class: "perl-binary", FileGlob: "**/perl", diff --git a/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/haproxy-1.5.14/haproxy b/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/haproxy-1.5.14/haproxy new file mode 100644 index 00000000000..7fc2c2a35b4 --- /dev/null +++ b/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/haproxy-1.5.14/haproxy @@ -0,0 +1 @@ +HA-Proxy version 1.5.14 2015/07/02Copyright 2000-2015 Willy Tarreau diff --git a/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/haproxy-1.8.22/haproxy b/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/haproxy-1.8.22/haproxy new file mode 100644 index 00000000000..a424ab0ac66 Binary files /dev/null and b/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/haproxy-1.8.22/haproxy differ diff --git a/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/haproxy-2.7.3/haproxy b/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/haproxy-2.7.3/haproxy new file mode 100644 index 00000000000..da21a03ddc8 Binary files /dev/null and b/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/haproxy-2.7.3/haproxy differ