88import os
99import subprocess
1010import fosslight_util .constant as constant
11- from ._binary import BinaryItem , OssItem
11+ from ._binary import BinaryItem , OssItem , VulnerabilityItem
1212
1313
1414logger = logging .getLogger (constant .LOGGER_NAME )
@@ -41,7 +41,7 @@ def get_oss_lic_in_jar(data):
4141 return license
4242
4343
44- def merge_binary_list (owasp_items , bin_list ):
44+ def merge_binary_list (owasp_items , vulnerability_items , bin_list ):
4545 not_found_bin = []
4646
4747 # key : file_path / value : oss_list for one binary
@@ -50,6 +50,8 @@ def merge_binary_list(owasp_items, bin_list):
5050 for bin in bin_list :
5151 if bin .binary_strip_root == key :
5252 bin .set_oss_items (value , False )
53+ if vulnerability_items is not None :
54+ bin .set_vulnerability_items (vulnerability_items .get (key ))
5355 found = True
5456 break
5557
@@ -64,9 +66,36 @@ def merge_binary_list(owasp_items, bin_list):
6466 return bin_list
6567
6668
69+ def get_vulnerability_info (file_with_path , vulnerability , vulnerability_items , remove_vulnerability_items ):
70+ if vulnerability is not None :
71+ try :
72+ for vul_info in vulnerability :
73+ vul_id = ""
74+ nvd_url = ""
75+ for key , val in vul_info .items ():
76+ if key == 'id' :
77+ vul_id = val
78+ elif key == 'url' :
79+ nvd_url = val
80+
81+ vul_item = VulnerabilityItem (file_with_path , vul_id , nvd_url )
82+
83+ remove_vulnerability_items = vulnerability_items .get (file_with_path )
84+ if remove_vulnerability_items :
85+ remove_vulnerability_items .append (vul_item )
86+ else :
87+ vulnerability_items [file_with_path ] = [vul_item ]
88+ except Exception as ex :
89+ logger .info (f"Error to get vul_id and nvd_url: { ex } " )
90+
91+ return vulnerability_items
92+
93+
6794def ananlyze_jar_file (path_to_find_bin ):
6895 remove_owasp_item = []
6996 owasp_items = {}
97+ remove_vulnerability_items = []
98+ vulnerability_items = {}
7099
71100 try :
72101 command = f"dependency-check --scan { path_to_find_bin } --out { path_to_find_bin } --disableArchive --disableAssembly --disableRetireJS --disableNodeJS \
@@ -91,6 +120,7 @@ def ananlyze_jar_file(path_to_find_bin):
91120 get_oss_info = False
92121
93122 all_evidence = val .get ("evidenceCollected" )
123+ vulnerability = val .get ("vulnerabilityIds" )
94124 vendor_evidences = all_evidence .get ('vendorEvidence' )
95125 product_evidences = all_evidence .get ('productEvidence' )
96126 version_evidences = all_evidence .get ('versionEvidence' )
@@ -133,6 +163,12 @@ def ananlyze_jar_file(path_to_find_bin):
133163 if oss_ver == "" and (product_info ['name' ] == 'Implementation-Version' or product_info ['name' ] == 'Bundle-Version' ):
134164 oss_ver = product_info ['value' ]
135165
166+ # Get Vulnerability Info.
167+ try :
168+ vulnerability_items = get_vulnerability_info (file_with_path , vulnerability , vulnerability_items , remove_vulnerability_items )
169+ except Exception as ex :
170+ logger .info (f"Error to get vulnerability Info. : { ex } " )
171+
136172 if oss_name != "" or oss_ver != "" or oss_license != "" or oss_dl_url != "" :
137173 oss = OssItem (oss_name , oss_ver , oss_license , oss_dl_url )
138174 oss .set_comment ("OWASP Result. " )
@@ -148,4 +184,4 @@ def ananlyze_jar_file(path_to_find_bin):
148184 except Exception as ex :
149185 logger .warning (f"Error to use dependency-check : { ex } " )
150186
151- return owasp_items
187+ return owasp_items , vulnerability_items
0 commit comments