fix: [stix1 import] Making sure the attribute or object uuid does not raise any issue depending on its type

- Unfortunately the type of the `uuid` field is
  not consistant depending how it has been
  generated: either with the PyMISP class
  `MISPAttribute` / `MISPObject`, or with a
  `MISPEvent.add_attribute` / `MISPEvent.add_object`
pull/8409/head
chrisr3d 2022-05-23 17:50:56 +02:00
parent 08acd50e8b
commit 07aa0e2c9e
No known key found for this signature in database
GPG Key ID: 6BBED1B63A6D639F
1 changed files with 4 additions and 2 deletions

View File

@ -97,10 +97,12 @@ class StixParser():
# and write it in the output file
def saveFile(self):
for attribute in self.misp_event.attributes:
if attribute.uuid.version not in _RFC_UUID_VERSIONS:
attribute_uuid = uuid.UUID(attribute.uuid) if isinstance(attribute.uuid, str) else attribute.uuid
if attribute_uuid.version not in _RFC_UUID_VERSIONS:
attribute.uuid = self._sanitize_uuid(attribute)
for misp_object in self.misp_event.objects:
if misp_object.uuid.version not in _RFC_UUID_VERSIONS:
object_uuid = uuid.UUID(misp_object.uuid) if isinstance(misp_object.uuid, str) else misp_object.uuid
if object_uuid.version not in _RFC_UUID_VERSIONS:
misp_object.uuid = self._sanitize_uuid(misp_object)
for reference in misp_object.references:
reference.object_uuid = misp_object.uuid