-
Notifications
You must be signed in to change notification settings - Fork 238
Analysis tag scheduler #87
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9880f21
First working solution.\n Missing tests.\n Shutdown of Daemon hangs.
dorpvom e719b9e
added first series of tests along. added tag for crypto material
dorpvom d508754
Merge branch 'master' of https://github.com/fkie-cad/FACT_core into a…
dorpvom 9c6d723
fixed tests
dorpvom f6850ae
Changed logic of test. Now more usable check.
dorpvom 70036ad
Added test for filter
dorpvom 7bca3c9
initial tests for helper
dorpvom 9ccdf8e
fixed manipulation of shared object
dorpvom 5e375f1
Added tests for helper functions. Added exception handling.
dorpvom 7d38be3
Added integration tests for storage
dorpvom 6b9b1ef
Merge branch 'master' of github.com:fkie-cad/FACT_core into analysis-…
dorpvom 3ef8a42
review comment applied
dorpvom 6485889
Merge branch 'master' of github.com:fkie-cad/FACT_core into analysis-…
dorpvom 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 was deleted.
Oops, something went wrong.
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 |
|---|---|---|
| @@ -1,8 +1,55 @@ | ||
| class TagColor: | ||
|
|
||
| GRAY = 'default' | ||
| BLUE = 'primary' | ||
| GREEN = 'success' | ||
| LIGHT_BLUE = 'info' | ||
| ORANGE = 'warning' | ||
| RED = 'danger' | ||
|
|
||
|
|
||
| def check_tags(file_object, analysis_name): | ||
| tags, root_uid = None, None | ||
| if analysis_name in file_object.processed_analysis and 'tags' in file_object.processed_analysis[analysis_name]: | ||
| try: | ||
| root_uid = file_object.processed_analysis[analysis_name]['tags'].pop('root_uid') | ||
| except (KeyError, AttributeError): | ||
| return dict(notags=True) | ||
| tags = file_object.processed_analysis[analysis_name]['tags'] | ||
| return dict(notags=False, tags=tags, plugin=analysis_name, uid=root_uid) if root_uid else dict(notags=True) | ||
|
|
||
|
|
||
| def add_tags_to_object(file_object, analysis_name): | ||
| if analysis_name in file_object.processed_analysis and 'tags' in file_object.processed_analysis[analysis_name]: | ||
| tags = file_object.processed_analysis[analysis_name]['tags'] | ||
| file_object.analysis_tags[analysis_name] = tags | ||
| return file_object | ||
|
|
||
|
|
||
| def update_tags(old_tags, plugin_name, tag_name, tag): | ||
| tag_is_stable, message = check_tag_integrity(tag) | ||
|
|
||
| if not tag_is_stable: | ||
| raise ValueError(message) | ||
|
|
||
| if plugin_name not in old_tags: | ||
| old_tags[plugin_name] = {tag_name: tag} | ||
|
|
||
| old_tags[plugin_name][tag_name] = tag | ||
|
|
||
| return old_tags | ||
|
|
||
|
|
||
| def check_tag_integrity(tag): | ||
| if any(key not in tag for key in ['value', 'color', 'propagate']): | ||
| return False, 'missing key' | ||
|
|
||
| if tag['color'] not in [TagColor.GREEN, TagColor.GRAY, TagColor.BLUE, TagColor.LIGHT_BLUE, TagColor.ORANGE, TagColor.RED]: | ||
| return False, 'bad tag color' | ||
|
|
||
| if not isinstance(tag['value'], str): | ||
| return False, 'tag value has to be a string' | ||
|
|
||
| if tag['propagate'] not in [True, False]: | ||
| return False, 'tag propagate key has to be a boolean' | ||
|
|
||
| return True, 'empty' |
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
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
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 |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import logging | ||
| from queue import Empty | ||
| from multiprocessing import Value | ||
| from helperFunctions.process import ExceptionSafeProcess | ||
|
|
||
|
|
||
| class TaggingDaemon: | ||
| def __init__(self, analysis_scheduler=None, db_interface=None): | ||
| self.parent = analysis_scheduler | ||
| self.config = self.parent.config | ||
| self.db_interface = db_interface if db_interface else self.parent.db_backend_service | ||
| self.stop_condition = Value('i', 0) | ||
|
|
||
| self.start_tagging_process() | ||
| logging.info('Tagging daemon online') | ||
|
|
||
| def shutdown(self): | ||
| self.stop_condition.value = 1 | ||
| self.tagging_process.join() | ||
| logging.info('Tagging daemon offline') | ||
|
|
||
| def start_tagging_process(self): | ||
| self.tagging_process = ExceptionSafeProcess(target=self._analysis_tag_scheduler_main) | ||
| self.tagging_process.start() | ||
|
|
||
| def _analysis_tag_scheduler_main(self): | ||
| while self.stop_condition.value == 0: | ||
| self._fetch_next_tag() | ||
|
|
||
| def _fetch_next_tag(self): | ||
| try: | ||
| tags = self.parent.tag_queue.get(timeout=int(self.config['ExpertSettings']['block_delay'])) | ||
| except Empty: | ||
| return | ||
|
|
||
| if not tags['notags']: | ||
| if self.db_interface.existence_quick_check(tags['uid']): | ||
| self._process_tags(tags) | ||
| else: | ||
| self.parent.tag_queue.put(tags) | ||
|
|
||
| def _process_tags(self, tags): | ||
| uid = tags['uid'] | ||
| plugin_name = tags['plugin'] | ||
| for tag_name, tag in tags['tags'].items(): | ||
| if tag['propagate']: | ||
| # Tags should be deleted as well, how ? | ||
| self.db_interface.update_analysis_tags(uid=uid, plugin_name=plugin_name, tag_name=tag_name, tag=tag) | ||
| logging.debug('Tag {} set for plugin {} and uid {}'.format(tag_name, plugin_name, uid)) |
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
Oops, something went wrong.
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.
Change should be applied to src/web_interface/templates/analysis_plugins/generic.html as well