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...")
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...")
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
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
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))
#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')