Esempio n. 1
0
def add_new_actor_identifier(identifier_type,
                             identifier=None,
                             source=None,
                             source_method='',
                             source_reference='',
                             analyst=None):
    """
    Add an Actor Identifier to CRITs.

    :param identifier_type: The Actor Identifier Type.
    :type identifier_type: str
    :param identifier: The Actor Identifier.
    :type identifier: str
    :param source: Name of the source which provided this information.
    :type source: str
    :param source_method: Method of acquiring this data.
    :type source_method: str
    :param source_reference: A reference to this data.
    :type source_reference: str
    :param analyst: The user adding this actor.
    :type analyst: str
    :returns: dict with keys:
              "success" (boolean),
              "message" (str),
    """

    actor_identifier = ActorIdentifier.objects(identifier_type=identifier_type,
                                               name=identifier).first()

    if not actor_identifier:
        actor_identifier = ActorIdentifier()
        actor_identifier.set_identifier_type(identifier_type)
        if not actor_identifier.identifier_type:
            return {'success': False, 'message': "Unknown Identifier Type"}
        if not identifier:
            return {'success': False, 'message': "Missing Identifier"}
        actor_identifier.name = identifier.strip()

    if isinstance(source, basestring):
        source = [
            create_embedded_source(source,
                                   reference=source_reference,
                                   method=source_method,
                                   analyst=analyst)
        ]

    if source:
        for s in source:
            actor_identifier.add_source(s)
    else:
        return {"success": False, "message": "Missing source information."}

    actor_identifier.save(username=analyst)
    actor_identifier.reload()

    return {
        'success': True,
        'id': str(actor_identifier.id),
        'message': "Actor Identifier added successfully!"
    }
Esempio n. 2
0
def add_new_actor_identifier(identifier_type, identifier=None, source=None,
                             source_method='', source_reference='',
                             source_tlp=None, user=None):
    """
    Add an Actor Identifier to CRITs.

    :param identifier_type: The Actor Identifier Type.
    :type identifier_type: str
    :param identifier: The Actor Identifier.
    :type identifier: str
    :param source: Name of the source which provided this information.
    :type source: str
    :param source_method: Method of acquiring this data.
    :type source_method: str
    :param source_reference: A reference to this data.
    :type source_reference: str
    :param source_tlp: The TLP for this identifier.
    :type source_tlp: str
    :param user: The user adding this actor.
    :type user: :class:`crits.core.user.CRITsUser`
    :returns: dict with keys:
              "success" (boolean),
              "message" (str),
    """

    actor_identifier = ActorIdentifier.objects(identifier_type=identifier_type,
                                               name=identifier).first()

    if not actor_identifier:
        actor_identifier = ActorIdentifier()
        actor_identifier.set_identifier_type(identifier_type)
        if not actor_identifier.identifier_type:
            return {'success': False,
                    'message': "Unknown Identifier Type"}
        if not identifier:
            return {'success': False,
                    'message': "Missing Identifier"}
        actor_identifier.name = identifier.strip()

    if isinstance(source, basestring):
        source = [create_embedded_source(source,
                                         reference=source_reference,
                                         method=source_method,
                                         tlp=source_tlp,
                                         analyst=user.username)]

    if source:
        for s in source:
            actor_identifier.add_source(s)
    else:
        return {"success" : False, "message" : "Missing source information."}

    actor_identifier.save(username=user.username)
    actor_identifier.reload()

    return {'success': True,
            'id': str(actor_identifier.id),
            'message': "Actor Identifier added successfully!"}
Esempio n. 3
0
def actor_identifier_type_values(type_=None, username=None):
    """
    Get the available Actor Identifier Type values.

    :param active: Only get active ones.
    :type active: boolean
    :returns: list
    """

    result = {}

    if username and type_:
        sources = user_sources(username)
        ids = ActorIdentifier.objects(active="on",
                                      identifier_type=type_,
                                      source__name__in=sources).order_by('+name')
        result['items'] = [(i.name, i.name) for i in ids]
    else:
        result['items'] = []
    return result
Esempio n. 4
0
def actor_identifier_type_values(type_=None, username=None):
    """
    Get the available Actor Identifier Type values.

    :param active: Only get active ones.
    :type active: boolean
    :returns: list
    """

    result = {}

    if username and type_:
        sources = user_sources(username)
        ids = ActorIdentifier.objects(
            active="on", identifier_type=type_,
            source__name__in=sources).order_by('+name')
        result['items'] = [(i.name, i.name) for i in ids]
    else:
        result['items'] = []
    return result