Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions internal/scan/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,14 +457,16 @@ func walkDirScan(ctx context.Context, cfg *types.Config, tag *v1.TagReference, c
klog.V(1).InfoS("scanning success", "image", getImage(res), "path", innerPath, "status", "success")
} else {
status := res.Status()
klog.InfoS("scanning "+status,
"image", getImage(res),
"path", innerPath,
"error", res.Error.Error,
"component", getComponent(res),
"tag", getTag(res),
"rpm", res.RPM,
"status", status)
for _, err := range res.Errors {
klog.InfoS("scanning "+status,
"image", getImage(res),
"path", innerPath,
"error", err.Error,
"component", getComponent(res),
"tag", getTag(res),
"rpm", res.RPM,
"status", status)
}
}
results.Append(res)
return nil
Expand Down
1 change: 1 addition & 0 deletions internal/types/error_map.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions internal/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ var (
ErrOSNotCertified = errors.New("operating system is not FIPS certified")
ErrDistributionFileMissing = errors.New("could not find distribution file")
ErrCertifiedDistributionsEmpty = errors.New("certified_distributions is empty, consider using -V [VERSION] for check-payload")
ErrDetectedExcludedModule = errors.New("detected a library that is incompatible with FIPS, check to make sure it is not performing any cryptographic operations")
)
1 change: 1 addition & 0 deletions internal/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ type ScanResult struct {
Path string
Skip bool
Error *ValidationError
Errors []*ValidationError
}

type ScanResults struct {
Expand Down
7 changes: 6 additions & 1 deletion internal/types/types_scan_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ func (r *ScanResult) SetOS(info OSInfo) *ScanResult {
}

func (r *ScanResult) SetValidationError(err *ValidationError) *ScanResult {
r.Error = err
if r.Error != nil {
r.Errors = append(r.Errors, err)
} else {
r.Error = err
r.Errors = append(r.Errors, err)
}
return r
}

Expand Down
38 changes: 36 additions & 2 deletions internal/validations/validations.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"fmt"
"io"
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"
Expand Down Expand Up @@ -67,6 +68,7 @@ var validationFns = map[string][]ValidationFn{
validateGoStatic,
validateGoOpenssl,
validateGoTagsAndExperiment,
validateExcludedCryptoModules,
},
"exe": {
validateNotStatic,
Expand Down Expand Up @@ -288,6 +290,35 @@ func validateNotStatic(_ context.Context, _ string, baton *Baton) *types.Validat
return types.NewValidationError(types.ErrNotDynLinked)
}

func validateExcludedCryptoModules(ctx context.Context, path string, baton *Baton) *types.ValidationError {
var symbols bytes.Buffer
cmd := exec.CommandContext(ctx, "nm", "-j", path)
cmd.Stdout = &symbols
if err := cmd.Run(); err != nil {
return types.NewValidationError(err)
}

// Make this more flexible by deriving the excluded modules from
// configuration.
excluded := []byte("golang.org/x/crypto")
errs := []*types.ValidationError{}
symtable, err := golang.ReadTable(path, baton.GoBuildInfo)
if err != nil {
return types.NewValidationError(fmt.Errorf("go: could not read table for %v: %w", filepath.Base(path), err))
}
for _, f := range symtable.Funcs {
if strings.Contains(f.Name, string(excluded)) {
fmt.Fprintf(os.Stderr, "%s\n", f.Name)
errs = append(errs, types.NewValidationError(types.ErrDetectedExcludedModule).SetWarning())
}
}
if len(errs) > 0 {
return errs[0]
} else {
return nil
}
}

func isGoExecutable(path string, baton *Baton) (bool, error) {
bi, err := buildinfo.ReadFile(path)
if err != nil {
Expand Down Expand Up @@ -386,6 +417,7 @@ checks:
// See if the error is to be ignored.
for _, list := range errIgnores {
if list.Ignore(innerPath, err.Error) {
klog.Info("ignoring %s for ", err.Error, innerPath)
continue checks
}
}
Expand All @@ -407,10 +439,12 @@ checks:
}
}
}
return res.SetValidationError(err)
res.SetValidationError(err)
}
}

if res.Error != nil {
return res
}
return res.Success()
}

Expand Down