@@ -35,9 +35,66 @@ def __init__(self, filename: str, vextype: str, logger=None):
35
35
self .parsed_data = defaultdict (dict )
36
36
self .serialNumbers = set ()
37
37
self .vex_handler = VexHandler (self .logger )
38
+ self .vex_product_info = {}
38
39
39
40
def parse_vex (self ) -> DefaultDict [ProductInfo , TriageData ]:
40
41
"""Parses the VEX file and extracts the necessary fields from the vulnerabilities."""
41
42
# Use VexHandler to parse the VEX file
42
43
self .parsed_data = self .vex_handler .parse (self .filename , self .vextype )
44
+ self ._extract_product_info ()
43
45
return self .parsed_data
46
+
47
+ def _extract_product_info (self ):
48
+ """Extracts the product information from the parsed VEX file"""
49
+ product_info = {}
50
+
51
+ # Try to get metadata from the VEX handler
52
+ try :
53
+ # Get the actual VEX type that was detected
54
+ detected_type = self .vex_handler ._detect_vex_type (self .filename )
55
+ if detected_type :
56
+ self .vextype = detected_type
57
+
58
+ # For CycloneDX, try to extract metadata from the parsed file
59
+ if self .vextype == "cyclonedx" :
60
+ import json
61
+
62
+ try :
63
+ with open (self .filename , encoding = "utf-8" ) as f :
64
+ vex_data = json .load (f )
65
+
66
+ metadata = vex_data .get ("metadata" , {})
67
+ component = metadata .get ("component" , {})
68
+
69
+ product_info ["product" ] = component .get ("name" , "" )
70
+ product_info ["release" ] = component .get ("version" , "" )
71
+ product_info ["vendor" ] = component .get ("supplier" , {}).get (
72
+ "name" , ""
73
+ )
74
+
75
+ except (json .JSONDecodeError , FileNotFoundError , KeyError ) as e :
76
+ self .logger .warning (
77
+ f"Could not extract product info from CycloneDX VEX: { e } "
78
+ )
79
+
80
+ elif self .vextype == "csaf" :
81
+ # For CSAF, product info would be in the document
82
+ product_info ["product" ] = ""
83
+ product_info ["release" ] = ""
84
+ product_info ["vendor" ] = ""
85
+
86
+ elif self .vextype == "openvex" :
87
+ # For OpenVEX, limited product info available
88
+ product_info ["product" ] = ""
89
+ product_info ["release" ] = ""
90
+ product_info ["vendor" ] = ""
91
+
92
+ except Exception as e :
93
+ self .logger .debug (f"Error extracting product info: { e } " )
94
+
95
+ # Set default values if not found
96
+ for key in ["product" , "release" , "vendor" ]:
97
+ if key not in product_info :
98
+ product_info [key ] = ""
99
+
100
+ self .vex_product_info = product_info
0 commit comments