Пример #1
0
def top_taxii(request):
    debug_print('>>>top_taxii enter')
    #method check
    debug_print('>>>HTTP method:' + str(request.method))
    if request.method != 'GET':
        data = get_no_accept_json_data('Invalid HTTP method')
        r = JsonResponse(data,
                         safe=False,
                         content_type=RESPONSE_COMMON_CONTENT_TYPE_TAXII_JSON)
        r.status_code = 406
        return r

    #Accept check
    debug_print('>>>request.META.has_key(HTTP_ACCEPT):' +
                str(request.META.has_key('HTTP_ACCEPT')))
    if request.META.has_key('HTTP_ACCEPT') == False:
        print '>>>no HTTP_ACCEPT'
        data = get_no_accept_json_data('No Accept')
        r = JsonResponse(data,
                         safe=False,
                         content_type=RESPONSE_COMMON_CONTENT_TYPE_TAXII_JSON)
        r.status_code = 406
        return r

    if check_http_accept(request) == True:
        debug_print('>>>Invalid Accept')
        data = get_no_accept_json_data('Invalid Accept')
        r = JsonResponse(data,
                         safe=False,
                         content_type=RESPONSE_COMMON_CONTENT_TYPE_TAXII_JSON)
        r.status_code = 406
        return r

    #Authenticate check
    r = check_common_authorization(request)
    if r is not None:
        return r

    data = {
        'title': 'TAXII Server Under Test',
        'description': 'This is a TAXII Server under test',
        'contact': 'Please contact x-xxx-xxx-xxxx',
        'default': '%s/%s/' % (TXS_HOST_PORT, API_ROOT_1),
        'api_roots': ['%s/%s/' % (TXS_HOST_PORT, API_ROOT_1)]
    }
    return JsonResponse(data,
                        safe=False,
                        content_type=RESPONSE_COMMON_CONTENT_TYPE_TAXII_JSON)
Пример #2
0
def top(request):
    debug_print('>>>top enter')
    #method check
    debug_print('>>>HTTP method:' + str(request.method))
    if request.method != 'GET':
        data = get_no_accept_json_data('Invalid HTTP method')
        r = JsonResponse(data,
                         safe=False,
                         content_type=RESPONSE_COMMON_CONTENT_TYPE_TAXII_JSON)
        r.status_code = 406
        return r

    #Accept check
    debug_print('>>>request.META.has_key(HTTP_ACCEPT):' +
                str(request.META.has_key('HTTP_ACCEPT')))
    if request.META.has_key('HTTP_ACCEPT') == False:
        print '>>>no HTTP_ACCEPT'
        data = get_no_accept_json_data('No Accept')
        r = JsonResponse(data,
                         safe=False,
                         content_type=RESPONSE_COMMON_CONTENT_TYPE_TAXII_JSON)
        r.status_code = 406
        return r

    if check_http_accept(request) == True:
        debug_print('>>>Invalid Accept')
        data = get_no_accept_json_data('Invalid Accept')
        r = JsonResponse(data,
                         safe=False,
                         content_type=RESPONSE_COMMON_CONTENT_TYPE_TAXII_JSON)
        r.status_code = 406
        return r

    #Authenticate check
    r = check_common_authorization(request)
    if r is not None:
        return r

    data = {
        'title': 'Sharing Group 1',
        'description': 'This sharing group shares intelligence.',
        'versions': ['taxii-2.0'],
        'max_content_length': MAX_CONTENT_LENGTH
    }
    return JsonResponse(data,
                        safe=False,
                        content_type=RESPONSE_COMMON_CONTENT_TYPE_TAXII_JSON)
Пример #3
0
def collections_objects(request, id_):
    debug_print('>>>collections_objects enter')
    debug_print('>>>id_ :' + str(id_))
    #Authenticate check
    r = check_common_authorization(request)
    if r is not None:
        debug_print('>>>Invalid Authentication.')
        return r

    if id_ == READ_COLLECTION:
        #Read Collection
        debug_print('>>>Read Collection.')
        if request.method != 'GET':
            #ReadCollcetion 指定時に GET 以外はNG
            debug_print('>>>Invalid HTTP Method:' + str(request.method))
            data = get_no_accept_json_data('Invalid HTTP method')
            r = JsonResponse(data,
                             safe=False,
                             content_type=RESPONSE_CONTENT_TYPE_STIX_JSON)
            r.status_code = 406
            return r
        #Accept check
        if request.META.has_key('HTTP_ACCEPT') == False:
            debug_print('>>>No HTTP_ACCEPT.')
            data = get_no_accept_json_data('No Accept')
            r = JsonResponse(data,
                             safe=False,
                             content_type=RESPONSE_CONTENT_TYPE_STIX_JSON)
            r.status_code = 406
            return r

        if check_http_accept(request) == True:
            debug_print('>>>HTTP_ACCEPT Invalid:' +
                        str(request.META['HTTP_ACCEPT']))
            data = get_no_accept_json_data('Invalid Accept')
            r = JsonResponse(data,
                             safe=False,
                             content_type=RESPONSE_CONTENT_TYPE_STIX_JSON)
            r.status_code = 406
            return r
        return get_read_collection_content()
    elif id_ == WRITE_COLLECTION:
        #Write Collection
        debug_print('>>>Write Collection.')
        if request.method != 'POST':
            #WirteCollcetion 指定時に POST 以外はNG
            debug_print('>>>Invalid HTTP Method:' + str(request.method))
            data = get_no_accept_json_data('Invalid HTTP method')
            r = JsonResponse(data,
                             safe=False,
                             content_type=RESPONSE_CONTENT_TYPE_STIX_JSON)
            r.status_code = 406
            return r

        #max-content-length check
        if int(request.META['CONTENT_LENGTH']) > MAX_CONTENT_LENGTH:
            debug_print('>>>Too much content size:' +
                        str(request.META['CONTENT_LENGTH']))
            data = get_no_accept_json_data('Too much content size')
            r = JsonResponse(data,
                             safe=False,
                             content_type=RESPONSE_CONTENT_TYPE_STIX_JSON)
            r.status_code = 406
            return r

        #Accept check
        if request.META.has_key('HTTP_ACCEPT') == False:
            debug_print('>>>No HTTP_ACCEPT.')
            data = get_no_accept_json_data('No Accept')
            r = JsonResponse(data,
                             safe=False,
                             content_type=RESPONSE_CONTENT_TYPE_STIX_JSON)
            r.status_code = 406
            return r

        if check_http_accept(request) == True:
            debug_print('>>>HTTP_ACCEPT Invalid:' +
                        str(request.META['HTTP_ACCEPT']))
            data = get_no_accept_json_data('Invalid Accept')
            r = JsonResponse(data,
                             safe=False,
                             content_type=RESPONSE_CONTENT_TYPE_STIX_JSON)
            r.status_code = 406
            return r
        data = post_write_collection(request.body)
        r = JsonResponse(data,
                         safe=False,
                         content_type=RESPONSE_CONTENT_TYPE_TAXII_JSON)
        r.status_code = 202
        return r
    elif id_ == READ_WRITE_COLLECTION:
        #ReadWrite Collection
        debug_print('>>>ReadWrite Collection.')
        if request.method == 'GET':
            return get_read_collection_content()
        elif request.method == 'POST':
            #max-content-length check
            if int(request.META['CONTENT_LENGTH']) > MAX_CONTENT_LENGTH:
                debug_print('>>>Too much content size:' +
                            str(request.META['CONTENT_LENGTH']))
                data = get_no_accept_json_data('Too much content size')
                r = JsonResponse(data,
                                 safe=False,
                                 content_type=RESPONSE_CONTENT_TYPE_STIX_JSON)
                r.status_code = 406
                return r
            data = post_write_collection(request.body)
            r = JsonResponse(data,
                             safe=False,
                             content_type=RESPONSE_CONTENT_TYPE_TAXII_JSON)
            r.status_code = 202
            return r
        else:
            debug_print('>>>Invalid HTTP Method:' + str(request.method))
            data = get_no_accept_json_data('Invalid HTTP method')
            r = JsonResponse(data,
                             safe=False,
                             content_type=RESPONSE_CONTENT_TYPE_STIX_JSON)
            r.status_code = 406
            return r
    else:
        #unmatched collection id
        debug_print('>>>Unmatched Collection:' + str(id_))
        data = {
            'title': 'Incorrect Collection Get',
            'description': 'An incorrect URL for a collection was accessed',
            'error_id': 'To be determined',
            'error_code': 'To be determined',
            'http_status': '404',
            'external_details': 'To be determined',
            "details": {
                "collection": id_,
            }
        }
        j = JsonResponse(data,
                         safe=False,
                         content_type=RESPONSE_CONTENT_TYPE_STIX_JSON)
        j.status_code = 404
        return j

    return JsonResponse(data,
                        safe=False,
                        content_type=RESPONSE_CONTENT_TYPE_STIX_JSON)
Пример #4
0
def collections(request, id_):
    debug_print('>>>collections enter')
    debug_print('>>>id_ :' + str(id_))
    #method check
    if request.method != 'GET':
        debug_print('>>>Invalid HTTP method:' + str(request.method))
        data = get_no_accept_json_data('Invalid HTTP method')
        r = JsonResponse(data,
                         safe=False,
                         content_type=RESPONSE_CONTENT_TYPE_STIX_JSON)
        r.status_code = 406
        return r

    #Authenticate check
    r = check_common_authorization(request)
    if r is not None:
        debug_print('>>>Invalid Authentication.')
        return r

    #Accept check
    if request.META.has_key('HTTP_ACCEPT') == False:
        debug_print('>>>No HTTP_ACCEPT.')
        data = get_no_accept_json_data('No Accept')
        r = JsonResponse(data,
                         safe=False,
                         content_type=RESPONSE_CONTENT_TYPE_STIX_JSON)
        r.status_code = 406
        return r

    if check_http_accept(request) == True:
        debug_print('>>>HTTP_ACCEPT Invalid:' +
                    str(request.META['HTTP_ACCEPT']))
        data = get_no_accept_json_data('Invalid Accept')
        r = JsonResponse(data,
                         safe=False,
                         content_type=RESPONSE_CONTENT_TYPE_STIX_JSON)
        r.status_code = 406
        return r

    if id_ == READ_COLLECTION:
        data = {
            'id': id_,
            'title': 'Test Read Collection',
            'description': 'This is Test Read Collection',
            'can_read': True,
            'can_write': False,
            'media_types': [COLLECTION_MEDIA_TYPE]
        }
    elif id_ == WRITE_COLLECTION:
        data = {
            'id': id_,
            'title': 'Test Write Collection',
            'description': 'This is Test Write Collection',
            'can_read': False,
            'can_write': True,
            'media_types': [COLLECTION_MEDIA_TYPE]
        }
    elif id_ == READ_WRITE_COLLECTION:
        data = {
            'id': id_,
            'title': 'Test Read Write Collection',
            'description': 'This is Test Read Write Collection',
            'can_read': True,
            'can_write': True,
            'media_types': [COLLECTION_MEDIA_TYPE]
        }
    else:
        #unmatched collection id
        debug_print('>>>unmatched collection id:' + str(id_))
        data = {
            'title': 'Incorrect Collection Get',
            'description': 'An incorrect URL for a collection was accessed',
            'error_id': 'To be determined',
            'error_code': 'To be determined',
            'http_status': '404',
            'external_details': 'To be determined',
            "details": {
                "collection": request.path,
            }
        }
        j = JsonResponse(data,
                         safe=False,
                         content_type=RESPONSE_COMMON_CONTENT_TYPE_TAXII_JSON)
        j.status_code = 404
        return j

    return JsonResponse(data,
                        safe=False,
                        content_type=RESPONSE_CONTENT_TYPE_TAXII_JSON)
Пример #5
0
def collections_root(request):
    debug_print('>>>collections enter')
    #method check
    if request.method != 'GET':
        debug_print('>>>Invalid HTTP method:' + str(request.method))
        data = get_no_accept_json_data('Invalid HTTP method')
        r = JsonResponse(data,
                         safe=False,
                         content_type=RESPONSE_CONTENT_TYPE_STIX_JSON)
        r.status_code = 406
        return r

    #Authenticate check
    r = check_common_authorization(request)
    if r is not None:
        debug_print('>>>Invalid Authentication.')
        return r

    #Accept check
    if request.META.has_key('HTTP_ACCEPT') == False:
        debug_print('>>>No HTTP_ACCEPT.')
        data = get_no_accept_json_data('No Accept')
        r = JsonResponse(data,
                         safe=False,
                         content_type=RESPONSE_CONTENT_TYPE_STIX_JSON)
        r.status_code = 406
        return r

    if check_http_accept(request) == True:
        debug_print('>>>HTTP_ACCEPT Invalid:' +
                    str(request.META['HTTP_ACCEPT']))
        data = get_no_accept_json_data('Invalid Accept')
        r = JsonResponse(data,
                         safe=False,
                         content_type=RESPONSE_CONTENT_TYPE_STIX_JSON)
        r.status_code = 406
        return r

    collections = []
    data = {
        'id': READ_COLLECTION,
        'title': 'Test Read Collection',
        'description': 'This is Test Read Collection',
        'can_read': True,
        'can_write': False,
        'media_types': [COLLECTION_MEDIA_TYPE]
    }
    collections.append(data)
    data = {
        'id': WRITE_COLLECTION,
        'title': 'Test Write Collection',
        'description': 'This is Test Write Collection',
        'can_read': False,
        'can_write': True,
        'media_types': [COLLECTION_MEDIA_TYPE]
    }
    collections.append(data)
    data = {
        'id': READ_WRITE_COLLECTION,
        'title': 'Test Read Write Collection',
        'description': 'This is Test Read Write Collection',
        'can_read': True,
        'can_write': True,
        'media_types': [COLLECTION_MEDIA_TYPE]
    }
    collections.append(data)
    r = {}
    r['collections'] = collections

    return JsonResponse(r,
                        safe=False,
                        content_type=RESPONSE_CONTENT_TYPE_TAXII_JSON)