feat: nginx binary classifier (#1988)

Signed-off-by: SemProvoost <27961543+SemProvoost@users.noreply.github.com>
This commit is contained in:
Sem Provoost 2023-08-03 19:09:31 +02:00 committed by GitHub
parent e55277f26d
commit 433a7b8a42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 0 deletions

View File

@ -643,6 +643,30 @@ func Test_Cataloger_DefaultClassifiers_PositiveCases(t *testing.T) {
Metadata: metadata("consul-binary"),
},
},
{
name: "positive-nginx-1.25.1",
fixtureDir: "test-fixtures/classifiers/positive/nginx-1.25.1",
expected: pkg.Package{
Name: "nginx",
Version: "1.25.1",
Type: "binary",
PURL: "pkg:generic/nginx@1.25.1",
Locations: locations("nginx"),
Metadata: metadata("nginx-binary"),
},
},
{
name: "positive-nginx-openresty-1.21.4.2",
fixtureDir: "test-fixtures/classifiers/positive/nginx-openresty-1.21.4.2",
expected: pkg.Package{
Name: "nginx",
Version: "1.21.4",
Type: "binary",
PURL: "pkg:generic/nginx@1.21.4",
Locations: locations("nginx"),
Metadata: metadata("nginx-binary"),
},
},
}
for _, test := range tests {

View File

@ -254,6 +254,21 @@ var defaultClassifiers = []classifier{
PURL: mustPURL("pkg:golang/github.com/hashicorp/consul@version"),
CPEs: singleCPE("cpe:2.3:a:hashicorp:consul:*:*:*:*:*:*:*:*"),
},
{
Class: "nginx-binary",
FileGlob: "**/nginx",
EvidenceMatcher: fileContentsVersionMatcher(
// [NUL]nginx version: nginx/1.25.1 - fetches '1.25.1'
// [NUL]nginx version: openresty/1.21.4.1 - fetches '1.21.4' as this is the nginx version part
`(?m)(\x00|\?)nginx version: [^\/]+\/(?P<version>[0-9]+\.[0-9]+\.[0-9]+(?:\+\d+)?(?:-\d+)?)`,
),
Package: "nginx",
PURL: mustPURL("pkg:generic/nginx@version"),
CPEs: []cpe.CPE{
cpe.Must("cpe:2.3:a:f5:nginx:*:*:*:*:*:*:*:*"),
cpe.Must("cpe:2.3:a:nginx:nginx:*:*:*:*:*:*:*:*"),
},
},
}
// in both binaries and shared libraries, the version pattern is [NUL]3.11.2[NUL]