def recv(host, route): # Pem Files needed, be sure to replace the \n returned from the APIs with CR/LF # caroot.pem - the CA Root certificate - GET /rest/certificates/ca # client.pem, first POST /rest/certificates/client/rabbitmq Request body: # {"type":"RabbitMqClientCertV2","commonName":"default"} # GET /rest/certificates/client/rabbitmq/keypair/default # client.pem is the key with -----BEGIN CERTIFICATE----- # key.pem is the key with -----BEGIN RSA PRIVATE KEY----- # Setup our ssl options ssl_options = ({ "ca_certs": "caroot.pem", "certfile": "client.pem", "keyfile": "key.pem", "cert_reqs": ssl.CERT_REQUIRED, "ssl_version": ssl.PROTOCOL_TLSv1_1, "server_side": False }) # Connect to RabbitMQ print("Connecting to %s:5671, to change use --host hostName " % (host)) connection = None try: connection = pika.BlockingConnection( pika.ConnectionParameters(host, 5671, credentials=ExternalCredentials(), ssl=True, ssl_options=ssl_options)) except: connection = pika.BlockingConnection( pika.ConnectionParameters(host, 5671, credentials=ExternalCredentials(), ssl=True, ssl_options=ssl_options)) # Create and bind to queue EXCHANGE_NAME = "scmb" ROUTING_KEY = "scmb.#" if ('scmb' in route): ROUTING_KEY = route channel = connection.channel() result = channel.queue_declare() queue_name = result.method.queue print("ROUTING KEY: %s" % (ROUTING_KEY)) channel.queue_bind(exchange=EXCHANGE_NAME, queue=queue_name, routing_key=ROUTING_KEY) channel.basic_consume(callback, queue=queue_name, no_ack=True) # Start listening for messages channel.start_consuming()
def __init__(self, host: str = 'localhost', port: int = 5672, login: str = 'guest', password: str = 'guest', virtual_host: str = '/', ssl: bool = False, *, loop=None, **kwargs): self.loop = loop if loop else asyncio.get_event_loop() self.future_store = FutureStore(loop=self.loop) self.__credentials = PlainCredentials( login, password) if login else ExternalCredentials() self.__connection_parameters = ConnectionParameters( host=host, port=port, credentials=self.__credentials, virtual_host=virtual_host, ssl=ssl, **kwargs) self._channels = dict() self._connection = None self.__closing = None self.__write_lock = asyncio.Lock(loop=self.loop)
def __init__(self, host='localhost', port=5672, login='******', password='******', virtual_host='/', loop=None, **kwargs): self.loop = loop if loop else ioloop.IOLoop.current() self.future_store = common.FutureStore(loop=self.loop) self.__credentials = PlainCredentials( login, password) if login else ExternalCredentials() self.__connection_parameters = ConnectionParameters( host=host, port=port, credentials=self.__credentials, virtual_host=virtual_host, **kwargs) self._channels = dict() self._connection = None self.__closing = None self.__close_started = False self.__write_lock = locks.Lock()
def build_channel(self): connection = pika.BlockingConnection( pika.ConnectionParameters(self.proxy, self.proxy_port, self.proxy_vhost, credentials=ExternalCredentials(), ssl=True, ssl_options=self.ssl_options)) channel = connection.channel() channel.queue_declare(queue=self.skey, durable=True) channel.basic_qos(prefetch_count=1) channel.basic_consume(self.call_back, queue=self.skey) channel.start_consuming()
def scmb_connect(): scmb_server = util.config['oneview_config']['ip'] # Setup our ssl options ssl_options = ({ 'ca_certs': ONEVIEW_CA, 'certfile': SCMB_CERT, 'keyfile': SCMB_KEY, 'cert_reqs': ssl.CERT_REQUIRED, 'server_side': False }) scmb_connection = pika.BlockingConnection( pika.ConnectionParameters(scmb_server, 5671, credentials=ExternalCredentials(), ssl=True, ssl_options=ssl_options)) return scmb_connection
def scmb_connect(self): scmb_server = self.ov_ip # Setup our ssl options ssl_options = ({ 'ca_certs': _oneview_ca_path(self.ov_ip), 'certfile': _scmb_cert_path(self.ov_ip), 'keyfile': _scmb_key_path(self.ov_ip), 'cert_reqs': ssl.CERT_REQUIRED, 'server_side': False }) scmb_connection = pika.BlockingConnection( pika.ConnectionParameters(scmb_server, SCMB_PORT, credentials=ExternalCredentials(), socket_timeout=SCMB_SOCKET_TIMEOUT, ssl=True, ssl_options=ssl_options)) return scmb_connection
def scmb_connect(): # TODO(victorhugorodrigues): Remove after implementation for handling # multiple OneViews for events service scmb_server = config.get_oneview_multiple_ips()[0] # Setup our ssl options ssl_options = ({'ca_certs': _oneview_ca_path(), 'certfile': _scmb_cert_path(), 'keyfile': _scmb_key_path(), 'cert_reqs': ssl.CERT_REQUIRED, 'server_side': False}) scmb_connection = pika.BlockingConnection( pika.ConnectionParameters( scmb_server, SCMB_PORT, credentials=ExternalCredentials(), socket_timeout=SCMB_SOCKET_TIMEOUT, ssl=True, ssl_options=ssl_options)) return scmb_connection
def main(): conf = SafeConfigParser() conf_file = 'producer.conf' if os.path.exists(conf_file): conf.read(conf_file) for session in conf.sections(): if session == 'main': time_number = conf.get(session, 'number') time_type = conf.get(session, 'timetype') elif session == 'rmqproxy': proxy = conf.get(session, 'proxy') proxy_port = int(conf.get(session, 'proxy_port')) proxy_vhost = conf.get(session, 'proxy_vhost') ca_cert = conf.get(session, 'ca_cert') cert = conf.get(session, 'cert') key = conf.get(session, 'key') skey = conf.get(session, 'sensor_key') else: db_host = conf.get(session, 'db_host') db_user = conf.get(session, 'db_user') db_pass = conf.get(session, 'db_pass') db_name = conf.get(session, 'db_name') else: print('Error: ' + conf_file + ' does not exist!') exit(1) ssl_options = ({"ca_certs": ca_cert, "certfile": cert, "keyfile": key}) connection = pika.BlockingConnection( pika.ConnectionParameters(proxy, proxy_port, proxy_vhost, credentials=ExternalCredentials(), ssl=True, ssl_options=ssl_options)) channel = connection.channel() channel.queue_declare(queue=skey, durable=True) db_query = query(time_number, time_type) db = mdb.connect(db_host, db_user, db_pass, db_name) with db: cursor = db.cursor(mdb.cursors.DictCursor) cursor.execute(db_query) rows = cursor.fetchall() for row in rows: # add sensor key row.update({'sensor_key': skey}) # change datetime to string for serialize row.update({'timestamp': str(row.get('timestamp'))}) channel.basic_publish(exchange='', routing_key=skey, body=json.dumps(row), properties=pika.BasicProperties( delivery_mode=2)) # make message persistent connection.close()
final_event = misp.add_event(json_data) #event = misp.get_event(1) #final_event = misp.get_stix_event(15, False, False, False, False) #print(final_event) HOST ='212.34.151.202' SSL_PORT = 5671 SSL_OPTIONS = dict( ssl_version=ssl.PROTOCOL_TLSv1_1, ca_certs="./cacert.pem", keyfile="./key.pem", certfile="./cert.pem", cert_reqs=ssl.CERT_REQUIRED) credentials = ExternalCredentials() connection = pika.BlockingConnection(pika.ConnectionParameters(host=HOST, port=SSL_PORT, ssl=True, ssl_options=SSL_OPTIONS, socket_timeout=0.25, credentials=credentials)) channel = connection.channel() channel.queue_declare(queue='eu.cipsec.dw_input', durable=True) consumer_tag = channel.basic_consume(callback, queue='eu.cipsec.dw_input', no_ack=False, exclusive=False) print(' [*] Waiting for messages. To exit press CTRL+C') channel.start_consuming() connection.close()
def __init__(self, conf): # RabbitMQ general options self.cacertfile = conf['cacertfile'] self.certfile = conf['certfile'] self.exchange = conf['exchange'] self.status_exchange = conf['status_exchange'] self.fail_if_no_peer_cert = conf['fail_if_no_peer_cert'] self.heartbeat = conf['heartbeat'] self.host = conf['host'] self.keyfile = conf['keyfile'] self.password = conf['password'] self.port = conf['port'] self.ssl_port = conf['ssl_port'] self.queue = conf['uuid'] self.retry_delay = conf['retry_delay'] self.ssl_auth = conf['ssl_auth'] self.use_ssl = conf['use_ssl'] self.username = conf['username'] self.vhost = conf['vhost'] self.redelivery_timeout = conf['redelivery_timeout'] self.connection_attempts = conf['connection_attempts'] self.poller_delay = conf['poller_delay'] # Connection and channel initialization self._connection = None self._consume_channel = None self._consume_channel_number = None self._publish_channel = None self._publish_channel_number = None self._message_number = 0 self._deliveries = {} self._responses = [] self._closing = False self._processing = False # Plain credentials credentials = PlainCredentials(self.username, self.password) pika_options = {'host': self.host, 'port': self.port, 'virtual_host': self.vhost, 'credentials': credentials, 'connection_attempts': self.connection_attempts, 'retry_delay': self.retry_delay} # SSL options if self.use_ssl: pika_options['ssl'] = True pika_options['port'] = self.ssl_port if self.ssl_auth: pika_options['credentials'] = ExternalCredentials() pika_options['ssl_options'] = { 'ca_certs': self.cacertfile, 'certfile': self.certfile, 'keyfile': self.keyfile, 'cert_reqs': CERT_REQUIRED } if self.heartbeat: pika_options['heartbeat_interval'] = self.heartbeat self.parameters = pika.ConnectionParameters(**pika_options) self.print_config()