@@ -25,8 +25,6 @@ const (
25
25
26
26
alpineEcosystem = "Alpine"
27
27
alpineSecurityTrackerURL = "https://security.alpinelinux.org/vuln"
28
- debianEcosystem = "Debian"
29
- debianSecurityTrackerURL = "https://security-tracker.debian.org/tracker"
30
28
)
31
29
32
30
func main () {
@@ -47,7 +45,7 @@ func main() {
47
45
logger .Fatal ("Can't create output path" , slog .Any ("err" , err ))
48
46
}
49
47
50
- allCves := loadAllCVEs (* cvePath )
48
+ allCves := vulns . LoadAllCVEs (* cvePath )
51
49
allParts , cveModifiedMap := loadParts (* partsInputPath )
52
50
combinedData := combineIntoOSV (allCves , allParts , * cveListPath , cveModifiedMap )
53
51
writeOSVFile (combinedData , * osvOutputPath )
@@ -166,14 +164,10 @@ func combineIntoOSV(loadedCves map[cves.CVEID]cves.Vulnerability, allParts map[c
166
164
}
167
165
}
168
166
169
- addedDebianURL := false
170
167
addedAlpineURL := false
171
168
for _ , pkgInfo := range allParts [cveID ] {
172
169
convertedCve .AddPkgInfo (pkgInfo )
173
- if strings .HasPrefix (pkgInfo .Ecosystem , debianEcosystem ) && ! addedDebianURL {
174
- addReference (string (cveID ), debianEcosystem , convertedCve )
175
- addedDebianURL = true
176
- } else if strings .HasPrefix (pkgInfo .Ecosystem , alpineEcosystem ) && ! addedAlpineURL {
170
+ if strings .HasPrefix (pkgInfo .Ecosystem , alpineEcosystem ) && ! addedAlpineURL {
177
171
addReference (string (cveID ), alpineEcosystem , convertedCve )
178
172
addedAlpineURL = true
179
173
}
@@ -209,47 +203,11 @@ func writeOSVFile(osvData map[cves.CVEID]*vulns.Vulnerability, osvOutputPath str
209
203
logger .Info ("Successfully written OSV files" , slog .Int ("count" , len (osvData )))
210
204
}
211
205
212
- // loadAllCVEs loads the downloaded CVE's from the NVD database into memory.
213
- func loadAllCVEs (cvePath string ) map [cves.CVEID ]cves.Vulnerability {
214
- dir , err := os .ReadDir (cvePath )
215
- if err != nil {
216
- logger .Fatal ("Failed to read dir" , slog .String ("path" , cvePath ), slog .Any ("err" , err ))
217
- }
218
-
219
- result := make (map [cves.CVEID ]cves.Vulnerability )
220
-
221
- for _ , entry := range dir {
222
- if ! strings .HasSuffix (entry .Name (), ".json" ) {
223
- continue
224
- }
225
- file , err := os .Open (path .Join (cvePath , entry .Name ()))
226
- if err != nil {
227
- logger .Fatal ("Failed to open CVE JSON" , slog .String ("path" , path .Join (cvePath , entry .Name ())), slog .Any ("err" , err ))
228
- }
229
- var nvdcve cves.CVEAPIJSON20Schema
230
- err = json .NewDecoder (file ).Decode (& nvdcve )
231
- if err != nil {
232
- logger .Fatal ("Failed to decode JSON" , slog .String ("file" , file .Name ()), slog .Any ("err" , err ))
233
- }
234
-
235
- for _ , item := range nvdcve .Vulnerabilities {
236
- result [item .CVE .ID ] = item
237
- }
238
- logger .Info ("Loaded CVE " + entry .Name (), slog .String ("cve" , entry .Name ()))
239
- file .Close ()
240
- }
241
-
242
- return result
243
- }
244
-
245
206
// addReference adds the related security tracker URL to a given vulnerability's references
246
207
func addReference (cveID string , ecosystem string , convertedCve * vulns.Vulnerability ) {
247
208
securityReference := osvschema.Reference {Type : osvschema .ReferenceAdvisory }
248
- switch ecosystem {
249
- case alpineEcosystem :
209
+ if ecosystem == alpineEcosystem {
250
210
securityReference .URL , _ = url .JoinPath (alpineSecurityTrackerURL , cveID )
251
- case debianEcosystem :
252
- securityReference .URL , _ = url .JoinPath (debianSecurityTrackerURL , cveID )
253
211
}
254
212
255
213
if securityReference .URL == "" {
0 commit comments