Exemple #1
0
 def init_server(self, version=TAXII_VER_2_0):
     """
     Initializes a server in the requested version
     :param version: taxii version key (either 2.0 or 2.1)
     """
     server_url = urljoin(self.base_url)
     self._conn = _HTTPConnection(verify=self.verify,
                                  proxies=self.proxies,
                                  version=version,
                                  auth=self.auth,
                                  cert=self.crt)
     if self.auth_header:
         # add auth_header to the session object
         self._conn.session.headers = (  # type: ignore[attr-defined]
             merge_setting(
                 self._conn.session.headers,  # type: ignore[attr-defined]
                 {self.auth_header: self.auth_key},
                 dict_class=CaseInsensitiveDict,
             ), )
     if version is TAXII_VER_2_0:
         self.server = v20.Server(
             server_url,
             verify=self.verify,
             proxies=self.proxies,
             conn=self._conn,
         )
     else:
         self.server = v21.Server(
             server_url,
             verify=self.verify,
             proxies=self.proxies,
             conn=self._conn,
         )
Exemple #2
0
    def __init__(self):
        """Read in config variables"""

        config_file_path = os.path.dirname(os.path.abspath(__file__))
        config_file_path += "/config.yml"
        config = (
            yaml.load(open(config_file_path), Loader=yaml.FullLoader)
            if os.path.isfile(config_file_path)
            else {}
        )
        self.helper = OpenCTIConnectorHelper(config)

        username = get_config_variable(
            "TAXII2_USERNAME", ["taxii2", "username"], config
        )
        password = get_config_variable(
            "TAXII2_PASSWORD", ["taxii2", "password"], config
        )
        server_url = get_config_variable(
            "TAXII2_DISCOVERY_URL", ["taxii2", "discovery_url"], config
        )
        self.verify_ssl = get_config_variable(
            "VERIFY_SSL", ["taxii2", "verify_ssl"], config, default=True
        )

        # if V21 flag set to true
        if get_config_variable("TAXII2_V21", ["taxii2", "v2.1"], config, default=True):
            self.server = tx21.Server(
                server_url, user=username, password=password, verify=self.verify_ssl
            )
        else:
            self.server = tx20.Server(
                server_url, user=username, password=password, verify=self.verify_ssl
            )

        self.collections = get_config_variable(
            "TAXII2_COLLECTIONS", ["taxii2", "collections"], config
        ).split(",")

        self.initial_history = get_config_variable(
            "TAXII2_INITIAL_HISTORY", ["taxii2", "initial_history"], config, True
        )

        self.per_request = get_config_variable(
            "TAXII2_PER_REQUEST", ["taxii2", "per_request"], config, True
        )

        self.interval = get_config_variable(
            "TAXII2_INTERVAL", ["taxii2", "interval"], config, True, 1
        )

        self.update_existing_data = get_config_variable(
            "CONNECTOR_UPDATE_EXISTING_DATA",
            ["connector", "update_existing_data"],
            config,
        )