-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Benji Visser <benji@093b.org>
- Loading branch information
Showing
24 changed files
with
521 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package cpe | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/noqcks/xeol/internal/log" | ||
) | ||
|
||
func Destructure(cpe string) (shortCPE, version string) { | ||
parts := strings.Split(cpe, ":") | ||
|
||
if len(parts) < 5 { | ||
log.Debugf("CPE string '%s' is too short", cpe) | ||
return "", "" | ||
} | ||
|
||
var splitIndex int | ||
if parts[1] == "2.3" { | ||
splitIndex = 5 | ||
} else { | ||
splitIndex = 4 | ||
} | ||
|
||
return strings.Join(parts[:splitIndex], ":"), parts[splitIndex] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package cpe | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestCpeDestructure(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
input string | ||
expectedShortCpe string | ||
expectedVersion string | ||
}{ | ||
{ | ||
name: "Exact CPE 2.2", | ||
input: "cpe:/a:apache:struts:2.5.10", | ||
expectedShortCpe: "cpe:/a:apache:struts", | ||
expectedVersion: "2.5.10", | ||
}, | ||
{ | ||
name: "Exact CPE 2.3", | ||
input: "cpe:2.3:a:apache:struts:2.5.10", | ||
expectedShortCpe: "cpe:2.3:a:apache:struts", | ||
expectedVersion: "2.5.10", | ||
}, | ||
{ | ||
name: "CPE 2.2", | ||
input: "cpe:/a:apache:struts:2.5:*:*:*:*:*:*:*", | ||
expectedShortCpe: "cpe:/a:apache:struts", | ||
expectedVersion: "2.5", | ||
}, | ||
{ | ||
name: "CPE 2.3", | ||
input: "cpe:2.3:a:apache:struts:2.5:*:*:*:*:*:*:*", | ||
expectedShortCpe: "cpe:2.3:a:apache:struts", | ||
expectedVersion: "2.5", | ||
}, | ||
{ | ||
name: "Empty CPE", | ||
input: "", | ||
expectedShortCpe: "", | ||
expectedVersion: "", | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
gotCpe, gotVersion := Destructure(tc.input) | ||
|
||
if gotVersion != tc.expectedVersion { | ||
t.Errorf("Expected version '%v', got '%v'", tc.expectedVersion, gotVersion) | ||
} | ||
if gotCpe != tc.expectedShortCpe { | ||
t.Errorf("Expected short CPE '%v', got '%v'", tc.expectedShortCpe, gotCpe) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
FROM docker.io/fedora:29@sha256:2c20e5bb324735427f8a659e36f4fe14d6955c74c7baa25067418dddbb71d67a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,20 @@ | ||
package eol | ||
|
||
import "github.com/noqcks/xeol/xeol/pkg" | ||
import ( | ||
"github.com/anchore/syft/syft/linux" | ||
|
||
"github.com/noqcks/xeol/xeol/pkg" | ||
) | ||
|
||
type Provider interface { | ||
ProviderByPurl | ||
ProviderByPackagePurl | ||
ProviderByDistroCpe | ||
} | ||
|
||
type ProviderByPackagePurl interface { | ||
GetByPackagePurl(p pkg.Package) ([]Cycle, error) | ||
} | ||
|
||
type ProviderByPurl interface { | ||
GetByPurl(p pkg.Package) ([]Cycle, error) | ||
type ProviderByDistroCpe interface { | ||
GetByDistroCpe(distro *linux.Release) (string, []Cycle, error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package distro | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/anchore/syft/syft/linux" | ||
|
||
"github.com/noqcks/xeol/xeol/eol" | ||
"github.com/noqcks/xeol/xeol/match" | ||
"github.com/noqcks/xeol/xeol/search" | ||
) | ||
|
||
type Matcher struct { | ||
UseCpes bool | ||
} | ||
|
||
type MatcherConfig struct { | ||
UseCpes bool | ||
} | ||
|
||
func NewPackageMatcher(cfg MatcherConfig) *Matcher { | ||
return &Matcher{ | ||
UseCpes: cfg.UseCpes, | ||
} | ||
} | ||
|
||
func (m *Matcher) Type() match.MatcherType { | ||
return match.PackageMatcher | ||
} | ||
|
||
func (m *Matcher) Match(store eol.Provider, d *linux.Release, eolMatchDate time.Time) (match.Match, error) { | ||
return search.ByDistroCpe(store, d, eolMatchDate) | ||
} |
Oops, something went wrong.