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
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import sys
|
||||
import json
|
||||
import os
|
||||
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:
|
||||
from settings import with_distribution
|
||||
except ImportError:
|
||||
|
@ -62,19 +61,21 @@ def saveEvent(event, misp):
|
|||
print(e)
|
||||
sys.exit('Could not create the event dump.')
|
||||
|
||||
|
||||
def getSignature(stringified_event, misp):
|
||||
try:
|
||||
signature = misp.direct_call('/cryptographicKeys/serverSign', stringified_event)
|
||||
signature = misp.sign_blob(stringified_event)
|
||||
return signature
|
||||
except Exception as 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.')
|
||||
|
||||
|
||||
def saveHashes(hashes):
|
||||
try:
|
||||
with open(os.path.join(outputdir, 'hashes.csv'), 'w') as hashFile:
|
||||
for element in hashes:
|
||||
hashFile.write('{},{}\n'.format(element[0], element[1]))
|
||||
hashFile.write(f'{element[0]},{element[1]}\n')
|
||||
except Exception as e:
|
||||
print(e)
|
||||
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)
|
||||
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 ###
|
||||
|
||||
# ## BEGIN Statistics ###
|
||||
|
|
|
@ -1602,6 +1602,8 @@ class MISPEvent(AnalystDataBehaviorMixin):
|
|||
|
||||
def _set_default(self) -> None:
|
||||
"""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'):
|
||||
self.published = True
|
||||
if not hasattr(self, 'uuid'):
|
||||
|
@ -1722,7 +1724,7 @@ class MISPEvent(AnalystDataBehaviorMixin):
|
|||
event_report.pop('SharingGroup', None)
|
||||
event_report.pop('sharing_group_id', None)
|
||||
to_return['EventReport'].append(event_report.to_dict())
|
||||
|
||||
|
||||
if with_cryptographic_keys and self.cryptographic_keys:
|
||||
to_return['CryptographicKey'] = []
|
||||
for cryptographic_key in self.cryptographic_keys:
|
||||
|
@ -1765,7 +1767,7 @@ class MISPEvent(AnalystDataBehaviorMixin):
|
|||
@property
|
||||
def event_reports(self) -> list[MISPEventReport]:
|
||||
return self.EventReport
|
||||
|
||||
|
||||
@property
|
||||
def cryptographic_keys(self) -> list[MISPCryptographicKey]:
|
||||
return self.CryptographicKey
|
||||
|
@ -2250,12 +2252,14 @@ class MISPWarninglist(AbstractMISP):
|
|||
kwargs = kwargs['Warninglist']
|
||||
super().from_dict(**kwargs)
|
||||
|
||||
|
||||
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:
|
||||
kwargs = kwargs['CryptographicKey']
|
||||
super().from_dict(**kwargs)
|
||||
|
||||
|
||||
class MISPTaxonomy(AbstractMISP):
|
||||
|
||||
enabled: bool
|
||||
|
|
Loading…
Reference in New Issue