mirror of
https://github.com/anchore/syft.git
synced 2026-11-05 00:46:38 +01:00
fix: disable cert validation in dotnet-portable-executable-cataloger by default (#3677)
Signed-off-by: rogueai <rogueai@users.noreply.github.com> Signed-off-by: Keith Zantow <kzantow@gmail.com> Co-authored-by: Keith Zantow <kzantow@gmail.com>
This commit is contained in:
@@ -2,6 +2,7 @@ package pkgcataloging
|
||||
|
||||
import (
|
||||
"github.com/anchore/syft/syft/pkg/cataloger/binary"
|
||||
"github.com/anchore/syft/syft/pkg/cataloger/dotnet"
|
||||
"github.com/anchore/syft/syft/pkg/cataloger/golang"
|
||||
"github.com/anchore/syft/syft/pkg/cataloger/java"
|
||||
"github.com/anchore/syft/syft/pkg/cataloger/javascript"
|
||||
@@ -11,6 +12,7 @@ import (
|
||||
|
||||
type Config struct {
|
||||
Binary binary.ClassifierCatalogerConfig `yaml:"binary" json:"binary" mapstructure:"binary"`
|
||||
Dotnet dotnet.CatalogerConfig `yaml:"dotnet" json:"dotnet" mapstructure:"dotnet"`
|
||||
Golang golang.CatalogerConfig `yaml:"golang" json:"golang" mapstructure:"golang"`
|
||||
JavaArchive java.ArchiveCatalogerConfig `yaml:"java-archive" json:"java-archive" mapstructure:"java-archive"`
|
||||
JavaScript javascript.CatalogerConfig `yaml:"javascript" json:"javascript" mapstructure:"javascript"`
|
||||
@@ -21,6 +23,7 @@ type Config struct {
|
||||
func DefaultConfig() Config {
|
||||
return Config{
|
||||
Binary: binary.DefaultClassifierCatalogerConfig(),
|
||||
Dotnet: dotnet.DefaultCatalogerConfig(),
|
||||
Golang: golang.DefaultCatalogerConfig(),
|
||||
LinuxKernel: kernel.DefaultLinuxKernelCatalogerConfig(),
|
||||
Python: python.DefaultCatalogerConfig(),
|
||||
@@ -33,6 +36,11 @@ func (c Config) WithBinaryConfig(cfg binary.ClassifierCatalogerConfig) Config {
|
||||
return c
|
||||
}
|
||||
|
||||
func (c Config) WithDotnetConfig(cfg dotnet.CatalogerConfig) Config {
|
||||
c.Dotnet = cfg
|
||||
return c
|
||||
}
|
||||
|
||||
func (c Config) WithGolangConfig(cfg golang.CatalogerConfig) Config {
|
||||
c.Golang = cfg
|
||||
return c
|
||||
|
||||
@@ -15,9 +15,10 @@ func NewDotnetDepsCataloger() pkg.Cataloger {
|
||||
}
|
||||
|
||||
// NewDotnetPortableExecutableCataloger returns a new Dotnet cataloger object base on portable executable files.
|
||||
func NewDotnetPortableExecutableCataloger() pkg.Cataloger {
|
||||
func NewDotnetPortableExecutableCataloger(cfg CatalogerConfig) pkg.Cataloger {
|
||||
p := dotnetPortableExecutableParser{cfg: cfg}
|
||||
return generic.NewCataloger("dotnet-portable-executable-cataloger").
|
||||
WithParserByGlobs(parseDotnetPortableExecutable, "**/*.dll", "**/*.exe")
|
||||
WithParserByGlobs(p.parseDotnetPortableExecutable, "**/*.dll", "**/*.exe")
|
||||
}
|
||||
|
||||
func NewDotnetPackagesLockCataloger() pkg.Cataloger {
|
||||
|
||||
@@ -25,7 +25,7 @@ func TestCataloger_Globs(t *testing.T) {
|
||||
{
|
||||
name: "obtain portable executable files",
|
||||
fixture: "test-fixtures/glob-paths",
|
||||
cataloger: NewDotnetPortableExecutableCataloger(),
|
||||
cataloger: NewDotnetPortableExecutableCataloger(DefaultCatalogerConfig()),
|
||||
expected: []string{
|
||||
"src/something.dll",
|
||||
"src/something.exe",
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package dotnet
|
||||
|
||||
type CatalogerConfig struct {
|
||||
EnableCertificateValidation bool `json:"enable-certificate-validation" yaml:"enable-certificate-validation" mapstructure:"enable-certificate-validation"`
|
||||
}
|
||||
|
||||
func (c CatalogerConfig) WithCertificateValidation(enable bool) CatalogerConfig {
|
||||
c.EnableCertificateValidation = enable
|
||||
return c
|
||||
}
|
||||
|
||||
func DefaultCatalogerConfig() CatalogerConfig {
|
||||
return CatalogerConfig{}
|
||||
}
|
||||
@@ -18,15 +18,17 @@ import (
|
||||
"github.com/anchore/syft/syft/pkg/cataloger/generic"
|
||||
)
|
||||
|
||||
var _ generic.Parser = parseDotnetPortableExecutable
|
||||
type dotnetPortableExecutableParser struct {
|
||||
cfg CatalogerConfig
|
||||
}
|
||||
|
||||
func parseDotnetPortableExecutable(_ context.Context, _ file.Resolver, _ *generic.Environment, f file.LocationReadCloser) ([]pkg.Package, []artifact.Relationship, error) {
|
||||
func (p dotnetPortableExecutableParser) parseDotnetPortableExecutable(_ context.Context, _ file.Resolver, _ *generic.Environment, f file.LocationReadCloser) ([]pkg.Package, []artifact.Relationship, error) {
|
||||
by, err := io.ReadAll(f)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("unable to read file: %w", err)
|
||||
}
|
||||
|
||||
peFile, err := pe.NewBytes(by, &pe.Options{})
|
||||
peFile, err := pe.NewBytes(by, &pe.Options{DisableCertValidation: !p.cfg.EnableCertificateValidation})
|
||||
if err != nil {
|
||||
log.Tracef("unable to create PE instance for file '%s': %v", f.RealPath, err)
|
||||
return nil, nil, err
|
||||
|
||||
@@ -298,10 +298,13 @@ func TestParseDotnetPortableExecutable(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_corruptDotnetPE(t *testing.T) {
|
||||
p := dotnetPortableExecutableParser{
|
||||
cfg: DefaultCatalogerConfig(),
|
||||
}
|
||||
pkgtest.NewCatalogTester().
|
||||
FromFile(t, "test-fixtures/glob-paths/src/something.exe").
|
||||
WithError().
|
||||
TestParser(t, parseDotnetPortableExecutable)
|
||||
TestParser(t, p.parseDotnetPortableExecutable)
|
||||
}
|
||||
|
||||
func Test_extractVersion(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user