2022-03-07 14:12:01 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*-coding:UTF-8 -*
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import redis
|
|
|
|
|
|
|
|
# sys.path.append(os.path.join(os.environ['AIL_BIN'], 'packages/'))
|
|
|
|
|
|
|
|
sys.path.append(os.path.join(os.environ['AIL_BIN'], 'lib/'))
|
|
|
|
import ConfigLoader
|
|
|
|
|
2022-08-19 14:53:31 +00:00
|
|
|
from lib.objects.abstract_subtype_object import AbstractSubtypeObject, get_all_id
|
2022-03-08 09:44:41 +00:00
|
|
|
from flask import url_for
|
2022-03-07 14:12:01 +00:00
|
|
|
|
|
|
|
config_loader = ConfigLoader.ConfigLoader()
|
|
|
|
|
|
|
|
config_loader = None
|
|
|
|
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
################################################################################
|
|
|
|
################################################################################
|
|
|
|
|
2022-08-19 14:53:31 +00:00
|
|
|
class Pgp(AbstractSubtypeObject):
|
2022-03-07 14:12:01 +00:00
|
|
|
"""
|
|
|
|
AIL Pgp Object. (strings)
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, id, subtype):
|
|
|
|
super(Pgp, self).__init__('pgp', id, subtype=subtype)
|
|
|
|
|
|
|
|
# def get_ail_2_ail_payload(self):
|
|
|
|
# payload = {'raw': self.get_gzip_content(b64=True),
|
|
|
|
# 'compress': 'gzip'}
|
|
|
|
# return payload
|
|
|
|
|
|
|
|
# # WARNING: UNCLEAN DELETE /!\ TEST ONLY /!\
|
|
|
|
def delete(self):
|
|
|
|
# # TODO:
|
|
|
|
pass
|
|
|
|
|
2022-09-19 07:50:46 +00:00
|
|
|
# # TODO:
|
2022-10-25 14:25:19 +00:00
|
|
|
def get_meta(self, options=set()):
|
|
|
|
meta = self._get_meta()
|
|
|
|
meta['id'] = self.id
|
|
|
|
meta['subtype'] = self.subtype
|
2022-11-22 09:47:15 +00:00
|
|
|
meta['tags'] = self.get_tags(r_list=True)
|
2022-10-25 14:25:19 +00:00
|
|
|
return meta
|
2022-09-19 07:50:46 +00:00
|
|
|
|
2022-03-07 14:12:01 +00:00
|
|
|
def get_link(self, flask_context=False):
|
|
|
|
if flask_context:
|
2022-10-25 14:25:19 +00:00
|
|
|
url = url_for('correlation.show_correlation', type=self.type, subtype=self.subtype, id=self.id)
|
2022-03-07 14:12:01 +00:00
|
|
|
else:
|
2022-10-25 14:25:19 +00:00
|
|
|
url = f'{baseurl}/correlation/show?type={self.type}&subtype={self.subtype}&id={self.id}'
|
2022-03-07 14:12:01 +00:00
|
|
|
return url
|
|
|
|
|
|
|
|
def get_svg_icon(self):
|
|
|
|
if self.subtype == 'key':
|
|
|
|
icon = '\uf084'
|
|
|
|
elif self.subtype == 'name':
|
|
|
|
icon = '\uf507'
|
|
|
|
elif self.subtype == 'mail':
|
|
|
|
icon = '\uf1fa'
|
|
|
|
else:
|
|
|
|
icon = 'times'
|
|
|
|
return {'style': 'fas', 'icon': icon, 'color': '#44AA99', 'radius':5}
|
|
|
|
|
2022-07-08 07:47:47 +00:00
|
|
|
def get_misp_object(self):
|
|
|
|
obj_attrs = []
|
|
|
|
obj = MISPObject('pgp-meta')
|
|
|
|
obj.first_seen = self.get_first_seen()
|
|
|
|
obj.last_seen = self.get_last_seen()
|
|
|
|
|
|
|
|
if self.subtype=='key':
|
|
|
|
obj_attrs.append( obj.add_attribute('key-id', value=self.id) )
|
|
|
|
elif self.subtype=='name':
|
|
|
|
obj_attrs.append( obj.add_attribute('user-id-name', value=self.id) )
|
|
|
|
else: # mail
|
|
|
|
obj_attrs.append( obj.add_attribute('user-id-email', value=self.id) )
|
|
|
|
|
|
|
|
for obj_attr in obj_attrs:
|
|
|
|
for tag in self.get_tags():
|
|
|
|
obj_attr.add_tag(tag)
|
|
|
|
return obj
|
|
|
|
|
2022-03-07 14:12:01 +00:00
|
|
|
############################################################################
|
|
|
|
############################################################################
|
|
|
|
|
2022-08-19 14:53:31 +00:00
|
|
|
def get_all_subtypes():
|
2022-09-01 12:04:00 +00:00
|
|
|
#return get_object_all_subtypes(self.type)
|
2022-08-19 14:53:31 +00:00
|
|
|
return ['key', 'mail', 'name']
|
2022-03-07 14:12:01 +00:00
|
|
|
|
2022-08-19 14:53:31 +00:00
|
|
|
def get_all_pgps():
|
|
|
|
pgps = {}
|
|
|
|
for subtype in get_all_subtypes():
|
|
|
|
pgps[subtype] = get_all_pgps_by_subtype(subtype)
|
|
|
|
return pgps
|
|
|
|
|
|
|
|
def get_all_pgps_by_subtype(subtype):
|
|
|
|
return get_all_id('pgp', subtype)
|
2022-03-07 14:12:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if __name__ == '__main__':
|