예제 #1
0
    def _send_msg(self, message, msgid):
        '''
        Send one message using stomppy.  The message will be signed using
        the host cert and key.  If an encryption certificate
        has been supplied, the message will also be encrypted.
        '''
        log.info('Sending message: %s', msgid)
        headers = {
            'destination': self._dest,
            'receipt': msgid,
            'empa-id': msgid
        }

        if message is not None:
            to_send = crypto.sign(message, self._cert, self._key)
            if self._enc_cert is not None:
                to_send = crypto.encrypt(to_send, self._enc_cert)
        else:
            to_send = ''

        try:
            # Try using the v4 method signiture
            self._conn.send(self._dest, to_send, headers=headers)
        except TypeError:
            # If it fails, use the v3 metod signiture
            self._conn.send(to_send, headers=headers)
예제 #2
0
파일: test_crypto.py 프로젝트: tswinb/ssm
    def test_decrypt(self):
        '''
        Check that the encrypted message can be decrypted and returns the
        original message.
        '''
        encrypted = encrypt(MSG, TEST_CERT_FILE)
        decrypted = decrypt(encrypted, TEST_CERT_FILE, TEST_KEY_FILE)

        if decrypted.strip() != MSG:
            self.fail('Failed to decrypt message.')
예제 #3
0
파일: test_crypto.py 프로젝트: apel/ssm
 def test_decrypt(self):
     '''
     Check that the encrypted message can be decrypted and returns the
     original message.
     '''
     encrypted = encrypt(MSG, TEST_CERT_FILE)
     decrypted = decrypt(encrypted, TEST_CERT_FILE, TEST_KEY_FILE)
    
     if decrypted.strip() != MSG:
         self.fail('Failed to decrypt message.') 
예제 #4
0
파일: test_crypto.py 프로젝트: tswinb/ssm
    def test_encrypt(self):
        '''
        Not a correct test yet.
        '''
        encrypted = encrypt(MSG, TEST_CERT_FILE)

        if not 'MIME-Version' in encrypted:
            self.fail('Encrypted message is not MIME')

        # Indirect testing, using the decrypt_message function.
        decrypted = decrypt(encrypted, TEST_CERT_FILE, TEST_KEY_FILE)

        if decrypted != MSG:
            self.fail("Encrypted message wasn't decrypted successfully.")

        # invalid cipher
        try:
            encrypted = encrypt(MSG, TEST_CERT_FILE, 'aes1024')
        except CryptoException:
            pass
예제 #5
0
 def test_encrypt(self):
     '''
     Not a correct test yet.
     '''
     encrypted = encrypt(MSG, self.certpath)
     
     if not 'MIME-Version' in encrypted:
         self.fail('Encrypted message is not MIME')
     
     # Indirect testing, using the decrypt_message function.
     decrypted = decrypt(encrypted, self.certpath, self.keypath)
     
     if decrypted != MSG:
         self.fail("Encrypted message wasn't decrypted successfully.")
         
     # invalid cipher
     try:
         encrypted = encrypt(MSG, self.certpath, 'aes1024')
     except CryptoException:
         pass    
예제 #6
0
파일: ssm2.py 프로젝트: pkoro/ssm
    def _send_msg(self, message, msgid):
        """
        Send one message using stomppy.  The message will be signed using 
        the host cert and key.  If an encryption certificate
        has been supplied, the message will also be encrypted.
        """
        log.info("Sending message: " + msgid)
        headers = {"destination": self._dest, "receipt": msgid, "empa-id": msgid}

        if message is not None:
            to_send = crypto.sign(message, self._cert, self._key)
            if self._enc_cert is not None:
                to_send = crypto.encrypt(to_send, self._enc_cert)
        else:
            to_send = ""

        self._conn.send(to_send, headers=headers)
예제 #7
0
파일: ssm2.py 프로젝트: gregcorbett/ssm
 def _send_msg(self, message, msgid):
     '''
     Send one message using stomppy.  The message will be signed using 
     the host cert and key.  If an encryption certificate
     has been supplied, the message will also be encrypted.
     '''
     log.info('Sending message: %s', msgid)
     headers = {'destination': self._dest, 'receipt': msgid,
                'empa-id': msgid}
     
     if message is not None:
         to_send = crypto.sign(message, self._cert, self._key)
         if self._enc_cert is not None:
             to_send = crypto.encrypt(to_send, self._enc_cert)
     else:
         to_send = ''
         
     self._conn.send(to_send, headers=headers)
예제 #8
0
    def _send_msg_ams(self, text, msgid):
        """Send one message using AMS, returning the AMS ID of the mesage.

        The message will be signed using the host cert and key. If an
        encryption certificate has been supplied, the message will also be
        encrypted.
        """
        log.info('Sending message: %s', msgid)
        if text is not None:
            # First we sign the message
            to_send = crypto.sign(text, self._cert, self._key)
            # Possibly encrypt the message.
            if self._enc_cert is not None:
                to_send = crypto.encrypt(to_send, self._enc_cert)
            # Then we need to wrap text up as an AMS Message.
            message = AmsMessage(data=to_send,
                                 attributes={'empaid': msgid}).dict()

            argo_response = self._ams.publish(self._dest, message, retry=3)
            return argo_response['messageIds'][0]
예제 #9
0
    def _send_msg(self, message, msgid):
        '''
        Send one message using stomppy.  The message will be signed using 
        the host cert and key.  If an encryption certificate
        has been supplied, the message will also be encrypted.
        '''
        log.info('Sending message: ' + msgid)
        headers = {
            'destination': self._dest,
            'receipt': msgid,
            'empa-id': msgid
        }

        if message is not None:
            to_send = crypto.sign(message, self._cert, self._key)
            if self._enc_cert is not None:
                to_send = crypto.encrypt(to_send, self._enc_cert)
        else:
            to_send = ''

        self._conn.send(to_send, headers=headers)
예제 #10
0
    def send_all(self):
        '''
        Send all the messages in the outgoing queue.

        Either via STOMP or HTTPS (to an Argo Message Broker).
        '''
        log.info('Found %s messages.', self._outq.count())
        for msgid in self._outq:
            if not self._outq.lock(msgid):
                log.warn('Message was locked. %s will not be sent.', msgid)
                continue

            text = self._outq.get(msgid)

            if self._protocol == Ssm2.STOMP_MESSAGING:
                # Then we are sending to a STOMP message broker.
                self._send_msg(text, msgid)

                log.info('Waiting for broker to accept message.')
                while self._last_msg is None:
                    if not self.connected:
                        raise Ssm2Exception('Lost connection.')

                log_string = "Sent %s" % msgid

            elif self._protocol == Ssm2.AMS_MESSAGING:
                # Then we are sending to an Argo Messaging Service instance.
                if text is not None:
                    # First we sign the message
                    to_send = crypto.sign(text, self._cert, self._key)
                    # Possibly encrypt the message.
                    if self._enc_cert is not None:
                        to_send = crypto.encrypt(to_send, self._enc_cert)

                    # Then we need to wrap text up as an AMS Message.
                    message = AmsMessage(data=to_send,
                                         attributes={
                                             'empaid': msgid
                                         }).dict()

                    argo_response = self._ams.publish(self._dest, message)

                    argo_id = argo_response['messageIds'][0]
                    log_string = "Sent %s, Argo ID: %s" % (msgid, argo_id)

            else:
                # The SSM has been improperly configured
                raise Ssm2Exception('Unknown messaging protocol: %s' %
                                    self._protocol)

            time.sleep(0.1)
            # log that the message was sent
            log.info(log_string)

            self._last_msg = None
            self._outq.remove(msgid)

        log.info('Tidying message directory.')
        try:
            # Remove empty dirs and unlock msgs older than 5 min (default)
            self._outq.purge()
        except OSError, e:
            log.warn('OSError raised while purging message queue: %s', e)