def in_protocol_filter(self, consumer, queue, message): try: # Decrypt message cnf = bus.cnf self._logger.debug('Decrypting message') crypto_key = binascii.a2b_base64(cnf.read_key(self.crypto_key_path)) xml = cryptotool.decrypt(message, crypto_key) # Remove special chars return xml.strip(''.join(chr(i) for i in range(0, 31))) except (BaseException, Exception), e: raise MessagingError('Cannot decrypt message. error: %s; raw message: %s' % (e, message))
def start(self): if self.running: raise MessagingError('Message consumer is already running') r = urlparse(self.endpoint) try: if self._server is None: self._logger.info('Building message consumer server on %s:%s', r.hostname, r.port) #server_class = HTTPServer if sys.version_info >= (2,6) else _HTTPServer25 self._server = HTTPServer((r.hostname, r.port), self._get_request_handler_class()) except (BaseException, Exception), e: self._logger.error("Cannot build server on port %s. %s", r.port, e) return
def load(self, message_id, is_ingoing): cur = self._conn().cursor() try: cur.execute('SELECT * FROM p2p_message ' \ 'WHERE message_id = ? AND is_ingoing = ?', [message_id, int(bool(is_ingoing))]) row = cur.fetchone() if not row is None: message = P2pMessage() self._unmarshall(message, row) return message else: raise MessagingError("Cannot find message (message_id: %s)" % message_id) finally: cur.close()
def in_protocol_filter(self, consumer, queue, message): try: # Decrypt message cnf = bus.cnf self._logger.debug('Decrypting message') crypto_key = binascii.a2b_base64(cnf.read_key( self.crypto_key_path)) xml = cryptotool.decrypt(message, crypto_key) # Remove special chars return xml.strip(''.join(chr(i) for i in range(0, 31))) except: self._logger.debug('Decryption error', exc_info=sys.exc_info()) self._logger.debug('Crypto key: %s', crypto_key) self._logger.debug('Raw message: %s', message) raise MessagingError('Cannot decrypt message')
def out_protocol_filter(self, producer, queue, message, headers): try: # Encrypt message cnf = bus.cnf self._logger.debug('Encrypting message') crypto_key = binascii.a2b_base64(cnf.read_key(self.crypto_key_path)) data = cryptotool.encrypt(message, crypto_key) # Generate signature signature, timestamp = cryptotool.sign_http_request(data, crypto_key) # Add extra headers headers['Date'] = timestamp headers['X-Signature'] = signature headers['X-Server-Id'] = self.server_id return data except (BaseException, Exception), e: raise MessagingError('Cannot encrypt message. error: %s' % (e))