* Update trivy 0.35.0->0.48.0
- Specify oras-go 1.2.4 in indirect dependencies
docker/docker changes a part of its API at 24.0
- registry: return concrete service type · moby/moby@7b3acdf
- 7b3acdff5d (diff-8325eae896b1149bf92c826d07fc29005b1b102000b766ffa5a238d791e0849bR18-R21)
oras-go 1.2.3 uses 23.0.1 and trivy transitively depends on docker/docker 24.y.z.
There is a build error between oras-go and docker/dockr.
- Update disabled analyzers
- Update language scanners, enable all of them
* move javadb init to scan.go
* Add options for java db init()
* Update scanner/base.go
* Remove unused codes
* Add some lock file names
* Typo fix
* Remove space character (0x20)
* Add java-db options for integration scan
* Minor fomartting fix
* minor fix
* conda is NOT supported by Trivy for library scan
* Configure trivy log in report command too
* Init trivy in scanner
* Use trivy's jar.go and replace client which does almost nothing
* mv jar.go
* Add sha1 hash to result and add filepath for report phase
* Undo added 'vuls scan' options
* Update oras-go to 1.2.4
* Move Java DB related config items to report side
* Add java db search in detect phase
* filter top level jar only
* Update trivy to 0.49.1
* go mod tidy
* Update to newer interface
* Refine lock file list, h/t MaineK00n
* Avoid else clauses if possible, h/t MaineK00n
* Avoid missing word for find and lang types, h/t MaineK00n
* Add missing ecosystems, h/t MaineK00n
* Add comments why to use custom jar analyzer, h/t MaineK00n
* Misc
* Misc
* Misc
* Include go-dep-parser's pares.go for modification
* Move digest field from LibraryScanner to Library
* Use inner jars sha1 for each
* Add Seek to file head before handling zip file entry
* Leave Digest feild empty for entries from pom.xml
* Don't import python/pkg (don't look into package.json)
* Make privete where private is sufficient
* Remove duplicate after Java DB lookup
* misc
* go mod tidy
* Comment out ruby/gemspec
* misc
* Comment out python/packaging
* misc
* Use custom jar
* Update scanner/trivy/jar/parse.go
Co-authored-by: MaineK00n <mainek00n.1229@gmail.com>
* Update scanner/trivy/jar/parse.go
Co-authored-by: MaineK00n <mainek00n.1229@gmail.com>
* Update scanner/trivy/jar/parse.go
Co-authored-by: MaineK00n <mainek00n.1229@gmail.com>
* Update scanner/trivy/jar/parse.go
Co-authored-by: MaineK00n <mainek00n.1229@gmail.com>
* Update scanner/trivy/jar/parse.go
Co-authored-by: MaineK00n <mainek00n.1229@gmail.com>
* Update scanner/trivy/jar/jar.go
Co-authored-by: MaineK00n <mainek00n.1229@gmail.com>
* Update detector/library.go
Co-authored-by: MaineK00n <mainek00n.1229@gmail.com>
* Update models/library.go
Co-authored-by: MaineK00n <mainek00n.1229@gmail.com>
* Update scanner/base.go
Co-authored-by: MaineK00n <mainek00n.1229@gmail.com>
* Update scanner/trivy/jar/parse.go
Co-authored-by: MaineK00n <mainek00n.1229@gmail.com>
* Update scanner/trivy/jar/parse.go
Co-authored-by: MaineK00n <mainek00n.1229@gmail.com>
* Missing changes in name change
* Update models/github.go
Co-authored-by: MaineK00n <mainek00n.1229@gmail.com>
* Update models/library.go
Co-authored-by: MaineK00n <mainek00n.1229@gmail.com>
* Update models/library.go
Co-authored-by: MaineK00n <mainek00n.1229@gmail.com>
* Update models/library.go
Co-authored-by: MaineK00n <mainek00n.1229@gmail.com>
* Update scanner/base.go
Co-authored-by: MaineK00n <mainek00n.1229@gmail.com>
* Update scanner/base.go
Co-authored-by: MaineK00n <mainek00n.1229@gmail.com>
* Update scanner/trivy/jar/jar.go
Co-authored-by: MaineK00n <mainek00n.1229@gmail.com>
* Don't import fanal/types at github.go
* Rewrite code around java db initialization
* Add comment
* refactor
* Close java db client
* rename
* Let LibraryScanner have java db client
* Update detector/library.go
Co-authored-by: MaineK00n <mainek00n.1229@gmail.com>
* Update detector/library.go
Co-authored-by: MaineK00n <mainek00n.1229@gmail.com>
* Update detector/library.go
Co-authored-by: MaineK00n <mainek00n.1229@gmail.com>
* Update detector/library.go
Co-authored-by: MaineK00n <mainek00n.1229@gmail.com>
* inline variable
* misc
* Fix typo
---------
Co-authored-by: MaineK00n <mainek00n.1229@gmail.com>
114 lines
3.4 KiB
Go
114 lines
3.4 KiB
Go
//go:build !scanner
|
|
// +build !scanner
|
|
|
|
package detector
|
|
|
|
import (
|
|
"context"
|
|
|
|
trivydb "github.com/aquasecurity/trivy-db/pkg/db"
|
|
"github.com/aquasecurity/trivy-db/pkg/metadata"
|
|
"github.com/aquasecurity/trivy/pkg/db"
|
|
ftypes "github.com/aquasecurity/trivy/pkg/fanal/types"
|
|
"github.com/aquasecurity/trivy/pkg/javadb"
|
|
"github.com/aquasecurity/trivy/pkg/log"
|
|
"golang.org/x/xerrors"
|
|
|
|
"github.com/future-architect/vuls/config"
|
|
"github.com/future-architect/vuls/logging"
|
|
"github.com/future-architect/vuls/models"
|
|
)
|
|
|
|
// DetectLibsCves fills LibraryScanner information
|
|
func DetectLibsCves(r *models.ScanResult, trivyOpts config.TrivyOpts, logOpts logging.LogOpts, noProgress bool) (err error) {
|
|
totalCnt := 0
|
|
if len(r.LibraryScanners) == 0 {
|
|
return
|
|
}
|
|
|
|
// initialize trivy's logger and db
|
|
err = log.InitLogger(logOpts.Debug, logOpts.Quiet)
|
|
if err != nil {
|
|
return xerrors.Errorf("Failed to init trivy logger. err: %w", err)
|
|
}
|
|
|
|
logging.Log.Info("Updating library db...")
|
|
if err := downloadDB("", trivyOpts, noProgress, false); err != nil {
|
|
return xerrors.Errorf("Failed to download trivy DB. err: %w", err)
|
|
}
|
|
if err := trivydb.Init(trivyOpts.TrivyCacheDBDir); err != nil {
|
|
return xerrors.Errorf("Failed to init trivy DB. err: %w", err)
|
|
}
|
|
defer trivydb.Close()
|
|
|
|
var javaDBClient *javadb.DB
|
|
defer javaDBClient.Close()
|
|
for _, lib := range r.LibraryScanners {
|
|
if lib.Type == ftypes.Jar {
|
|
if javaDBClient == nil {
|
|
javadb.Init(trivyOpts.TrivyCacheDBDir, trivyOpts.TrivyJavaDBRepository, trivyOpts.TrivySkipJavaDBUpdate, noProgress, ftypes.RegistryOptions{})
|
|
|
|
javaDBClient, err = javadb.NewClient()
|
|
if err != nil {
|
|
return xerrors.Errorf("Failed to download or open trivy Java DB. err: %w", err)
|
|
}
|
|
}
|
|
lib.JavaDBClient = javaDBClient
|
|
}
|
|
|
|
vinfos, err := lib.Scan()
|
|
if err != nil {
|
|
return xerrors.Errorf("Failed to scan library. err: %w", err)
|
|
}
|
|
for _, vinfo := range vinfos {
|
|
vinfo.Confidences.AppendIfMissing(models.TrivyMatch)
|
|
if v, ok := r.ScannedCves[vinfo.CveID]; !ok {
|
|
r.ScannedCves[vinfo.CveID] = vinfo
|
|
} else {
|
|
v.LibraryFixedIns = append(v.LibraryFixedIns, vinfo.LibraryFixedIns...)
|
|
r.ScannedCves[vinfo.CveID] = v
|
|
}
|
|
}
|
|
totalCnt += len(vinfos)
|
|
}
|
|
|
|
logging.Log.Infof("%s: %d CVEs are detected with Library",
|
|
r.FormatServerName(), totalCnt)
|
|
|
|
return nil
|
|
}
|
|
|
|
func downloadDB(appVersion string, trivyOpts config.TrivyOpts, noProgress, skipUpdate bool) error {
|
|
client := db.NewClient(trivyOpts.TrivyCacheDBDir, noProgress)
|
|
ctx := context.Background()
|
|
needsUpdate, err := client.NeedsUpdate(appVersion, skipUpdate)
|
|
if err != nil {
|
|
return xerrors.Errorf("database error: %w", err)
|
|
}
|
|
|
|
if needsUpdate {
|
|
logging.Log.Info("Need to update DB")
|
|
logging.Log.Info("Downloading DB...")
|
|
if err := client.Download(ctx, trivyOpts.TrivyCacheDBDir, ftypes.RegistryOptions{}); err != nil {
|
|
return xerrors.Errorf("Failed to download vulnerability DB. err: %w", err)
|
|
}
|
|
}
|
|
|
|
// for debug
|
|
if err := showDBInfo(trivyOpts.TrivyCacheDBDir); err != nil {
|
|
return xerrors.Errorf("Failed to show database info. err: %w", err)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func showDBInfo(cacheDir string) error {
|
|
m := metadata.NewClient(cacheDir)
|
|
meta, err := m.Get()
|
|
if err != nil {
|
|
return xerrors.Errorf("Failed to get DB metadata. err: %w", err)
|
|
}
|
|
log.Logger.Debugf("DB Schema: %d, UpdatedAt: %s, NextUpdate: %s, DownloadedAt: %s",
|
|
meta.Version, meta.UpdatedAt, meta.NextUpdate, meta.DownloadedAt)
|
|
return nil
|
|
}
|