@@ -57,6 +57,34 @@ def get_oss_lic_in_jar(data):
5757 return license
5858
5959
60+ def copy_oss_info_by_checksum (bin_list ):
61+ checksum_groups = {}
62+
63+ for bin in bin_list :
64+ if bin .checksum and bin .checksum != "" :
65+ if bin .checksum not in checksum_groups :
66+ checksum_groups [bin .checksum ] = []
67+ checksum_groups [bin .checksum ].append (bin )
68+
69+ for checksum , bins in checksum_groups .items ():
70+ if len (bins ) > 1 :
71+ dup_bin = None
72+ for bin in bins :
73+ if bin .oss_items and len (bin .oss_items ) > 0 :
74+ dup_bin = bin
75+ break
76+
77+ if dup_bin :
78+ for bin in bins :
79+ if bin != dup_bin and (not bin .oss_items or len (bin .oss_items ) == 0 ):
80+ bin .set_oss_items (dup_bin .oss_items )
81+ bin .found_in_owasp = dup_bin .found_in_owasp
82+ if dup_bin .vulnerability_items :
83+ bin .vulnerability_items .extend (dup_bin .vulnerability_items )
84+ logger .debug (f"Copied OSS info from { dup_bin .source_name_or_path } to { bin .source_name_or_path } (checksum: { checksum } )" )
85+ return bin_list
86+
87+
6088def merge_binary_list (owasp_items , vulnerability_items , bin_list ):
6189 not_found_bin = []
6290
@@ -83,6 +111,7 @@ def merge_binary_list(owasp_items, vulnerability_items, bin_list):
83111 not_found_bin .append (bin_item )
84112
85113 bin_list += not_found_bin
114+ bin_list = copy_oss_info_by_checksum (bin_list )
86115 return bin_list
87116
88117
@@ -166,6 +195,7 @@ def get_oss_info_from_pkg_info(pkg_info):
166195
167196
168197def analyze_jar_file (path_to_find_bin , path_to_exclude ):
198+ remove_owasp_item = []
169199 owasp_items = {}
170200 remove_vulnerability_items = []
171201 vulnerability_items = {}
@@ -192,7 +222,8 @@ def analyze_jar_file(path_to_find_bin, path_to_exclude):
192222 success = False
193223 return owasp_items , vulnerability_items , success
194224
195- dependencies = jar_contents .get ("dependencies" )
225+ dependencies = jar_contents .get ("dependencies" , [])
226+
196227 try :
197228 for val in dependencies :
198229 bin_with_path = ""
@@ -260,30 +291,20 @@ def analyze_jar_file(path_to_find_bin, path_to_exclude):
260291 vulnerability_items = get_vulnerability_info (file_with_path , vulnerability , vulnerability_items , remove_vulnerability_items )
261292
262293 if oss_name != "" or oss_ver != "" or oss_license != "" or oss_dl_url != "" :
263- oss_list_for_file = owasp_items .get (file_with_path , [])
264-
265- existing_oss = None
266- for item in oss_list_for_file :
267- if item .name == oss_name and item .version == oss_ver :
268- existing_oss = item
269- break
270-
271- if not existing_oss :
272- oss = OssItem (oss_name , oss_ver , oss_license , oss_dl_url )
273- oss .comment = "OWASP result"
294+ oss = OssItem (oss_name , oss_ver , oss_license , oss_dl_url )
295+ oss .comment = "OWASP result"
274296
275- if file_with_path in owasp_items :
276- owasp_items [file_with_path ].append (oss )
277- else :
278- owasp_items [file_with_path ] = [oss ]
297+ remove_owasp_item = owasp_items .get (file_with_path )
298+ if remove_owasp_item :
299+ remove_owasp_item .append (oss )
300+ else :
301+ owasp_items [file_with_path ] = [oss ]
279302 except Exception as ex :
280- logger .debug (f"Error to get depency Info in jar_contets: { ex } " )
281- success = False
303+ logger .debug (f"Error to get dependency Info in jar_contents: { ex } " )
282304
283305 try :
284306 if os .path .isfile (json_file ):
285307 os .remove (json_file )
286308 except Exception as ex :
287309 logger .debug (f"Error - There is no .json file : { ex } " )
288-
289310 return owasp_items , vulnerability_items , success
0 commit comments