示例#1
0
文件: views.py 项目: tkhsknsk/stip-rs
#oasis:stip_kago
HTTP_AUTHORIZATION_VALUE = 'Basic b2FzaXM6c3RpcF9rYWdv'
MAX_CONTENT_LENGTH = 10000000

API_ROOT_1 = 'api1'

#TXSが登録するコミュニティの名前
_taxii2_community_name = 'taxii2'
#TXSが登録するユーザー名
_taxii_publisher = 'admin'

try:
    _community = Communities.objects.get(name=_taxii2_community_name)
except:
    _community = None
_via = Vias.get_via_taxii_publish(_taxii_publisher)


def get_no_accept_json_data(message,
                            error_id='To be determined',
                            error_code='To be determined'):
    return {
        'title': 'Incorrect Taxii Version',
        'description': 'An incorrent Taxii version was used in the post',
        'error_id': error_id,
        'error_code': error_code,
        'http_status': '406',
        'external_details': message,
        'details': {
            'version': '1.0',
        }
示例#2
0
    def __init__(self,
                 service_yaml_path,
                 community_name,
                 taxii_publisher,
                 black_account_list,
                 version_path):
        with open(service_yaml_path, 'r', encoding='utf-8') as fp:
            services = yaml.load(fp)

        try:
            with open(version_path, 'r', encoding='utf-8') as fp:
                version = fp.readline().strip()
        except IOError:
            version = 'No version information.'

        print('>>>>>: S-TIP TAXII Server Start: ' + str(version))

        self.community = Communities.objects.get(name=community_name)
        self.via = Vias.get_via_taxii_publish(taxii_publisher)

        # opentaxii.taxii.entities.ServiceEntityのリスト作成
        self.services = []

        for service in services:
            id = service['id']
            type_ = service['type']
            del service['id']
            del service['type']
            self.services.append(ServiceEntity(
                type_,
                service,
                id=id))

        # opentaxii.taxii.entities.CollectionEntityのリスト作成
        self.collections = []
        # collectionとserviceの連携を記録
        self.service_to_collection = []

        # account の blacklist を作成
        if len(black_account_list) != 0:
            self.black_account_list = black_account_list.split(',')
        else:
            self.black_account_list = []
        # print '>>>black_account_list :' +str(self.black_account_list)

        id = 0
        for taxii_server in TaxiiServers.objects.all():
            name = taxii_server.collection_name
            description = None
            type_ = 'DATA_FEED'
            volume = None
            accept_all_content = True
            supported_content = None
            available = True
            ce = CollectionEntity(
                name,
                str(id),
                description=description,
                type=type_,
                volume=volume,
                accept_all_content=accept_all_content,
                supported_content=supported_content,
                available=available)
            self.collections.append(ce)

            # service_idとcollection_idの関連を検索
            service_ids = ['collection_management', 'poll', 'inbox']
            for service_id in service_ids:
                for service in self.services:
                    if service.id == service_id:
                        d = {}
                        d[service_id] = str(id)
                        self.service_to_collection.append(d)
            id += 1