-
Notifications
You must be signed in to change notification settings - Fork 5
Copy OSS info if checksum matches #148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,6 +57,34 @@ def get_oss_lic_in_jar(data): | |
| return license | ||
|
|
||
|
|
||
| def copy_oss_info_by_checksum(bin_list): | ||
| checksum_groups = {} | ||
|
|
||
| for bin in bin_list: | ||
| if bin.checksum and bin.checksum != "": | ||
bjk7119 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if bin.checksum not in checksum_groups: | ||
| checksum_groups[bin.checksum] = [] | ||
| checksum_groups[bin.checksum].append(bin) | ||
|
|
||
| for checksum, bins in checksum_groups.items(): | ||
| if len(bins) > 1: | ||
| dup_bin = None | ||
| for bin in bins: | ||
| if bin.oss_items and len(bin.oss_items) > 0: | ||
| dup_bin = bin | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이렇게 세팅하면 Binary DB을 load한 binary인지, OWASP에서 값을 읽어온 binary인지 구분이 되나요? |
||
| break | ||
|
|
||
| if dup_bin: | ||
| for bin in bins: | ||
| if bin != dup_bin and (not bin.oss_items or len(bin.oss_items) == 0): | ||
| bin.set_oss_items(dup_bin.oss_items) | ||
| bin.found_in_owasp = dup_bin.found_in_owasp | ||
| if dup_bin.vulnerability_items: | ||
| bin.vulnerability_items.extend(dup_bin.vulnerability_items) | ||
| logger.debug(f"Copied OSS info from {dup_bin.source_name_or_path} to {bin.source_name_or_path} (checksum: {checksum})") | ||
| return bin_list | ||
|
|
||
|
|
||
| def merge_binary_list(owasp_items, vulnerability_items, bin_list): | ||
| not_found_bin = [] | ||
|
|
||
|
|
@@ -83,6 +111,7 @@ def merge_binary_list(owasp_items, vulnerability_items, bin_list): | |
| not_found_bin.append(bin_item) | ||
|
|
||
| bin_list += not_found_bin | ||
| bin_list = copy_oss_info_by_checksum(bin_list) | ||
| return bin_list | ||
|
|
||
|
|
||
|
|
@@ -166,6 +195,7 @@ def get_oss_info_from_pkg_info(pkg_info): | |
|
|
||
|
|
||
| def analyze_jar_file(path_to_find_bin, path_to_exclude): | ||
| remove_owasp_item = [] | ||
| owasp_items = {} | ||
| remove_vulnerability_items = [] | ||
| vulnerability_items = {} | ||
|
|
@@ -192,7 +222,8 @@ def analyze_jar_file(path_to_find_bin, path_to_exclude): | |
| success = False | ||
| return owasp_items, vulnerability_items, success | ||
|
|
||
| dependencies = jar_contents.get("dependencies") | ||
| dependencies = jar_contents.get("dependencies", []) | ||
|
|
||
| try: | ||
| for val in dependencies: | ||
| bin_with_path = "" | ||
|
|
@@ -260,30 +291,20 @@ def analyze_jar_file(path_to_find_bin, path_to_exclude): | |
| vulnerability_items = get_vulnerability_info(file_with_path, vulnerability, vulnerability_items, remove_vulnerability_items) | ||
|
|
||
| if oss_name != "" or oss_ver != "" or oss_license != "" or oss_dl_url != "": | ||
| oss_list_for_file = owasp_items.get(file_with_path, []) | ||
|
|
||
| existing_oss = None | ||
| for item in oss_list_for_file: | ||
| if item.name == oss_name and item.version == oss_ver: | ||
| existing_oss = item | ||
| break | ||
|
|
||
| if not existing_oss: | ||
| oss = OssItem(oss_name, oss_ver, oss_license, oss_dl_url) | ||
| oss.comment = "OWASP result" | ||
| oss = OssItem(oss_name, oss_ver, oss_license, oss_dl_url) | ||
| oss.comment = "OWASP result" | ||
|
|
||
| if file_with_path in owasp_items: | ||
| owasp_items[file_with_path].append(oss) | ||
| else: | ||
| owasp_items[file_with_path] = [oss] | ||
| remove_owasp_item = owasp_items.get(file_with_path) | ||
| if remove_owasp_item: | ||
| remove_owasp_item.append(oss) | ||
| else: | ||
| owasp_items[file_with_path] = [oss] | ||
| except Exception as ex: | ||
| logger.debug(f"Error to get depency Info in jar_contets: {ex}") | ||
| success = False | ||
| logger.debug(f"Error to get dependency Info in jar_contents: {ex}") | ||
|
|
||
| try: | ||
| if os.path.isfile(json_file): | ||
| os.remove(json_file) | ||
| except Exception as ex: | ||
| logger.debug(f"Error - There is no .json file : {ex}") | ||
|
|
||
| return owasp_items, vulnerability_items, success | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bjk7119 , 이 방법보다 중복으로 찍히는 로직을 확인하는 것을 제안드립니다.
재현이 불가하셔서 로직 내 중복 원인이 확인되지 않는 상태인가요?