mirror of https://github.com/MISP/PyMISP
new: create a sign_blob method to sign events
parent
671c9fabf5
commit
6c3e91cbc0
|
@ -1,11 +1,10 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
from pymisp import ExpandedPyMISP
|
from pymisp import ExpandedPyMISP
|
||||||
from settings import url, key, ssl, outputdir, filters, valid_attribute_distribution_levels, with_signatures
|
from settings import url, key, ssl, outputdir, filters, valid_attribute_distribution_levels
|
||||||
try:
|
try:
|
||||||
from settings import with_distribution
|
from settings import with_distribution
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -62,19 +61,21 @@ def saveEvent(event, misp):
|
||||||
print(e)
|
print(e)
|
||||||
sys.exit('Could not create the event dump.')
|
sys.exit('Could not create the event dump.')
|
||||||
|
|
||||||
|
|
||||||
def getSignature(stringified_event, misp):
|
def getSignature(stringified_event, misp):
|
||||||
try:
|
try:
|
||||||
signature = misp.direct_call('/cryptographicKeys/serverSign', stringified_event)
|
signature = misp.sign_blob(stringified_event)
|
||||||
return signature
|
return signature
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
sys.exit('Could not get the signature for the event from the MISP instance. Perhaps the user does not have the necessary permissions.')
|
sys.exit('Could not get the signature for the event from the MISP instance. Perhaps the user does not have the necessary permissions.')
|
||||||
|
|
||||||
|
|
||||||
def saveHashes(hashes):
|
def saveHashes(hashes):
|
||||||
try:
|
try:
|
||||||
with open(os.path.join(outputdir, 'hashes.csv'), 'w') as hashFile:
|
with open(os.path.join(outputdir, 'hashes.csv'), 'w') as hashFile:
|
||||||
for element in hashes:
|
for element in hashes:
|
||||||
hashFile.write('{},{}\n'.format(element[0], element[1]))
|
hashFile.write(f'{element[0]},{element[1]}\n')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
sys.exit('Could not create the quick hash lookup file.')
|
sys.exit('Could not create the quick hash lookup file.')
|
||||||
|
|
|
@ -3541,6 +3541,14 @@ class PyMISP:
|
||||||
response = self._prepare_request('POST', url, data=to_post)
|
response = self._prepare_request('POST', url, data=to_post)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
def sign_blob(self, blob: str) -> str:
|
||||||
|
"""Sign a blob
|
||||||
|
|
||||||
|
:param blob: blob to sign
|
||||||
|
"""
|
||||||
|
response = self._prepare_request('POST', '/cryptographicKeys/serverSign', data=blob)
|
||||||
|
return self._check_response(response, lenient_response_type=True)
|
||||||
|
|
||||||
# ## END Others ###
|
# ## END Others ###
|
||||||
|
|
||||||
# ## BEGIN Statistics ###
|
# ## BEGIN Statistics ###
|
||||||
|
|
|
@ -1602,6 +1602,8 @@ class MISPEvent(AnalystDataBehaviorMixin):
|
||||||
|
|
||||||
def _set_default(self) -> None:
|
def _set_default(self) -> None:
|
||||||
"""There are a few keys that could, or need to be set by default for the feed generator"""
|
"""There are a few keys that could, or need to be set by default for the feed generator"""
|
||||||
|
if not hasattr(self, 'protected'):
|
||||||
|
self.protected = False
|
||||||
if not hasattr(self, 'published'):
|
if not hasattr(self, 'published'):
|
||||||
self.published = True
|
self.published = True
|
||||||
if not hasattr(self, 'uuid'):
|
if not hasattr(self, 'uuid'):
|
||||||
|
@ -1722,7 +1724,7 @@ class MISPEvent(AnalystDataBehaviorMixin):
|
||||||
event_report.pop('SharingGroup', None)
|
event_report.pop('SharingGroup', None)
|
||||||
event_report.pop('sharing_group_id', None)
|
event_report.pop('sharing_group_id', None)
|
||||||
to_return['EventReport'].append(event_report.to_dict())
|
to_return['EventReport'].append(event_report.to_dict())
|
||||||
|
|
||||||
if with_cryptographic_keys and self.cryptographic_keys:
|
if with_cryptographic_keys and self.cryptographic_keys:
|
||||||
to_return['CryptographicKey'] = []
|
to_return['CryptographicKey'] = []
|
||||||
for cryptographic_key in self.cryptographic_keys:
|
for cryptographic_key in self.cryptographic_keys:
|
||||||
|
@ -1765,7 +1767,7 @@ class MISPEvent(AnalystDataBehaviorMixin):
|
||||||
@property
|
@property
|
||||||
def event_reports(self) -> list[MISPEventReport]:
|
def event_reports(self) -> list[MISPEventReport]:
|
||||||
return self.EventReport
|
return self.EventReport
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def cryptographic_keys(self) -> list[MISPCryptographicKey]:
|
def cryptographic_keys(self) -> list[MISPCryptographicKey]:
|
||||||
return self.CryptographicKey
|
return self.CryptographicKey
|
||||||
|
@ -2250,12 +2252,14 @@ class MISPWarninglist(AbstractMISP):
|
||||||
kwargs = kwargs['Warninglist']
|
kwargs = kwargs['Warninglist']
|
||||||
super().from_dict(**kwargs)
|
super().from_dict(**kwargs)
|
||||||
|
|
||||||
|
|
||||||
class MISPCryptographicKey(AbstractMISP):
|
class MISPCryptographicKey(AbstractMISP):
|
||||||
def from_dict(self, **kwargs) -> None: # type: ignore[no-untyped-def]
|
def from_dict(self, **kwargs) -> None: # type: ignore[no-untyped-def]
|
||||||
if 'CryptographicKey' in kwargs:
|
if 'CryptographicKey' in kwargs:
|
||||||
kwargs = kwargs['CryptographicKey']
|
kwargs = kwargs['CryptographicKey']
|
||||||
super().from_dict(**kwargs)
|
super().from_dict(**kwargs)
|
||||||
|
|
||||||
|
|
||||||
class MISPTaxonomy(AbstractMISP):
|
class MISPTaxonomy(AbstractMISP):
|
||||||
|
|
||||||
enabled: bool
|
enabled: bool
|
||||||
|
|
Loading…
Reference in New Issue