コード例 #1
0
    def connect(self, params):
        broker_ca, client_crt, client_key, address = (
            params.get("broker_ca").get("privateKey"),
            params.get("client_crt").get("privateKey"),
            params.get("client_key").get("privateKey"),
            params.get("host"),
        )

        # Fix escaping issues in keys
        broker_ca = self.fix_escaping_issues(broker_ca)
        client_crt = self.fix_escaping_issues(client_crt)
        client_key = self.fix_escaping_issues(client_key)

        # Create temp files for certificates
        with open("broker_ca", "w") as broker_ca_file:
            broker_ca_file.write(broker_ca)
        with open("client_crt", "w") as client_crt_file:
            client_crt_file.write(client_crt)
        with open("client_key", "w") as client_key_file:
            client_key_file.write(client_key)

        self.config = DxlClientConfig(
            broker_ca_bundle=broker_ca_file.name,
            cert_file=client_crt_file.name,
            private_key=client_key_file.name,
            brokers=[Broker.parse("ssl://{}".format(address))],
        )

        self.logger.info("Connect: Connecting...")
コード例 #2
0
    def connect(self, params):
        broker_ca, client_crt, client_key, address = params.get('broker_ca').get('privateKey'), \
                                                     params.get('client_crt').get('privateKey'), \
                                                     params.get('client_key').get('privateKey'), \
                                                     params.get('host')

        # Fix escaping issues in keys
        broker_ca = self.fix_escaping_issues(broker_ca)
        client_crt = self.fix_escaping_issues(client_crt)
        client_key = self.fix_escaping_issues(client_key)

        # Create temp files for certificates
        with open('broker_ca', 'w') as broker_ca_file:
            broker_ca_file.write(broker_ca)
        with open('client_crt', 'w') as client_crt_file:
            client_crt_file.write(client_crt)
        with open('client_key', 'w') as client_key_file:
            client_key_file.write(client_key)

        self.config = DxlClientConfig(
            broker_ca_bundle=broker_ca_file.name,
            cert_file=client_crt_file.name,
            private_key=client_key_file.name,
            brokers=[Broker.parse('ssl://{}'.format(address))])

        self.logger.info("Connect: Connecting...")
コード例 #3
0
 def get_client_config(self):
     config = DxlClientConfig(
         broker_ca_bundle=self.broker_ca_bundle,
         cert_file=self.cert_file,
         private_key=self.private_key,
         brokers=[Broker.parse(url) for url in self.broker_urls])
     config.connect_retries = CONNECT_RETRIES
     config.reconnect_delay = RECONNECT_DELAY
     config.reconnect_delay_max = RECONNECT_DELAY_MAX
     return config
コード例 #4
0
def _get_brokers_from_list(broker_list):
    """
    Helper function that generates a broker list from a dictionary containing brokers in this format
    {
        "{guid}": "{guid};port;broker-name;broker_ip",
        "{guid-2}": "{guid-2};port;broker-2-name;broker-2-ip",
        ...
    }
    :param broker_list: Dictionary with brokers info
    :return: list of broker objects
    """
    brokers = None
    if broker_list is not None:
        brokers = []
        for _, value in broker_list.items():
            # Set hostname to avoid validation error, will be overridden by parse
            broker = Broker(host_name='none')
            broker._parse(value)
            brokers.append(broker)
    return brokers
コード例 #5
0
ファイル: McAfee-MAR.py プロジェクト: spearmin10/content
def get_client_config():
    config = DxlClientConfig(
        broker_ca_bundle=broker_ca_bundle,
        cert_file=cert_file,
        private_key=private_key,
        brokers=[Broker.parse(url) for url in broker_urls])

    config.connect_retries = 1
    config.reconnect_delay = 1
    config.reconnect_delay_max = 10

    return config
コード例 #6
0
ファイル: dxl_broker.py プロジェクト: FlyingDiver/Indigo-MQTT
    def __init__(self, device):
        self.logger = logging.getLogger("Plugin.DXLBroker")
        self.deviceID = device.id

        address = device.pluginProps.get(u'address', "")
        port = device.pluginProps.get(u'port', "")
        ca_bundle = indigo.server.getInstallFolderPath(
        ) + '/' + device.pluginProps.get(u'ca_bundle', "")
        cert_file = indigo.server.getInstallFolderPath(
        ) + '/' + device.pluginProps.get(u'cert_file', "")
        private_key = indigo.server.getInstallFolderPath(
        ) + '/' + device.pluginProps.get(u'private_key', "")

        self.logger.debug(
            f"{device.name}: Broker __init__ address = {address}, ca_bundle = {ca_bundle}, cert_file = {cert_file}, private_key = {private_key}"
        )

        device.updateStateOnServer(key="status", value="Not Connected")
        device.updateStateImageOnServer(indigo.kStateImageSel.SensorOff)

        # Create the client configuration
        broker = Broker.parse(f"ssl://{address}:{port}")
        config = DxlClientConfig(broker_ca_bundle=ca_bundle,
                                 cert_file=cert_file,
                                 private_key=private_key,
                                 brokers=[broker])

        # Create the DXL client
        self.dxl_client = DxlClient(config)

        # Connect to the fabric
        self.dxl_client.connect()
        device.updateStateOnServer(key="status", value="Connected")
        device.updateStateImageOnServer(indigo.kStateImageSel.SensorOn)

        subs = device.pluginProps.get(u'subscriptions', None)
        if subs:
            for topic in subs:
                self.dxl_client.add_event_callback(topic,
                                                   self.MyEventCallback(self))
                self.logger.info(u"{}: Subscribing to: {}".format(
                    device.name, topic))
コード例 #7
0
ファイル: verify.py プロジェクト: wstinkens/dockerfiles
from dxlclient.broker import Broker
test = Broker("test.com")
コード例 #8
0
#print "FILE EXISTS = {}".format(aws_machine.check_file_exists('/var/McAfee/dxlbroker/keystore/broker.crt'))
#print "FOLDER EXISTS = {}".format(aws_machine.check_folder_exists('/var/McAfee/dxlbroker/keystore2/'))
#print "FILE EXISTS = {}".format(aws_machine.check_file_exists('/var/McAfee/dxlbroker/keystore/broker2.crt'))

# STEP-4: connect python client (need SG with rule for port 8883: "Custom TCP Rule | TCP | 8883 | 0.0.0.0/0")
print "TEST: PYTHON CLIENT"
brokerCaBundle = "C:\\test\\dxlbroker_install_files\\keystore\\ca-broker.crt"
certFile = "C:\\test\\dxlbroker_install_files\\keystore\\broker.crt"
privateKey = "C:\\test\\dxlbroker_install_files\\keystore\\broker.key"
brokerString = "ssl://{}".format(aws_machine.ip)
action = "publish_event"
topic = "/mcafee/client/controlevent"
config = DxlClientConfig(broker_ca_bundle=brokerCaBundle,
                         cert_file=certFile,
                         private_key=privateKey,
                         brokers=[Broker.parse(brokerString)])

with DxlClient(config) as dxl_client:
    # Connect to the fabric
    dxl_client.connect()
    if dxl_client.connected:
        print "Connected ... \n"
    else:
        print "Not Connected ... \n"

    sleepTime = 1
    rb = os.urandom(100)
    event = Event(str(topic))
    event.payload = rb
    print "payload={}".format(rb)
    topic.encode('ascii', 'ignore')