Exemplo n.º 1
0
func (api cvedictClient) FetchCveDetailsFromCveDB(cveIDs []string) (cveDetails cve.CveDetails, err error) {
	log.Debugf("open cve-dictionary db (%s)", config.Conf.CveDBType)
	cveconfig.Conf.DBType = config.Conf.CveDBType
	if config.Conf.CveDBType == "sqlite3" {
		cveconfig.Conf.DBPath = config.Conf.CveDBPath
	} else {
		cveconfig.Conf.DBPath = config.Conf.CveDictionaryURL
	}
	cveconfig.Conf.DebugSQL = config.Conf.DebugSQL
	if err := cvedb.OpenDB(); err != nil {
		return []cve.CveDetail{},
			fmt.Errorf("Failed to open DB. err: %s", err)
	}
	for _, cveID := range cveIDs {
		cveDetail := cvedb.Get(cveID)
		if len(cveDetail.CveID) == 0 {
			cveDetails = append(cveDetails, cve.CveDetail{
				CveID: cveID,
			})
		} else {
			cveDetails = append(cveDetails, cveDetail)
		}
	}

	// order by CVE ID desc
	sort.Sort(cveDetails)
	return
}
Exemplo n.º 2
0
Arquivo: db.go Projeto: Rompei/vuls
func selectCveInfos(result *m.ScanResult, fieldName string) []m.CveInfo {
	cveInfos := []m.CveInfo{}
	db.Model(&result).Related(&cveInfos, fieldName)

	for i, cveInfo := range cveInfos {
		cveDetail := cve.CveDetail{}
		db.Model(&cveInfo).Related(&cveDetail, "CveDetail")
		id := cveDetail.CveID
		filledCveDetail := cvedb.Get(id, db)
		cveInfos[i].CveDetail = filledCveDetail

		packs := []m.PackageInfo{}
		db.Model(&cveInfo).Related(&packs, "Packages")
		cveInfos[i].Packages = packs

		advisories := []m.DistroAdvisory{}
		db.Model(&cveInfo).Related(&advisories, "DistroAdvisories")
		cveInfos[i].DistroAdvisories = advisories

		names := []m.CpeName{}
		db.Model(&cveInfo).Related(&names, "CpeNames")
		cveInfos[i].CpeNames = names
	}
	return cveInfos
}