Пример #1
0
def persist_content(manager,
                    collection_name,
                    service_id,
                    timestamp=None,
                    binding=CB_STIX_XML_111,
                    subtypes=[]):

    timestamp = timestamp or get_utc_now()

    content_binding = entities.ContentBindingEntity(binding=binding,
                                                    subtypes=subtypes)

    content = entities.ContentBlockEntity(content=CONTENT,
                                          timestamp_label=timestamp,
                                          message=MESSAGE,
                                          content_binding=content_binding)

    collection = manager.get_collection(collection_name, service_id)

    if not collection:
        raise ValueError('No collection with name {}'.format(collection_name))

    content = manager.create_content(content, collections=[collection])

    return content
Пример #2
0
    def get_content_blocks(self,
                           collection_id=None,
                           start_time=None,
                           end_time=None,
                           bindings=None,
                           offset=0,
                           limit=None):
        log.info("TRACE: get_content_blocks")
        collection_name = sorted(
            context.account.permissions.keys())[collection_id]
        tags = self.tag % collection_name if collection_name != "default" else None
        misp_evts = context.account.details["misp"].search(
            return_format="stix",
            date_from=start_time if start_time else None,
            date_to=end_time if end_time else None,
            tags=tags,
            to_ids=self.to_ids,
            limit=limit,
            page=(int(offset / limit + 1) if limit else None)).encode("utf-8")

        blocks = []
        for stix, timestamp in conv.stix_indicators(six.BytesIO(misp_evts)):
            log.info("TRACE: get_content_blocks event %s" % bindings)
            blocks.append(
                entities.ContentBlockEntity(
                    stix,
                    timestamp,
                    content_binding=entities.ContentBindingEntity(
                        "urn:stix.mitre.org:xml:1.1.1")))
        return blocks
Пример #3
0
def deserialize_content_bindings(content_bindings):
    raw_bindings = json.loads(content_bindings)

    bindings = []
    for (binding, subtypes) in raw_bindings:
        entity = entities.ContentBindingEntity(binding, subtypes=subtypes)
        bindings.append(entity)

    return bindings
Пример #4
0
def to_block_entity(model):
    if not model:
        return

    subtypes = [model.binding_subtype] if model.binding_subtype else None

    return entities.ContentBlockEntity(
        id=model.id,
        content=model.content,
        timestamp_label=enforce_timezone(model.timestamp_label),
        content_binding=entities.ContentBindingEntity(model.binding_id,
                                                      subtypes=subtypes),
        message=model.message,
        inbox_message_id=model.inbox_message_id,
    )