Example #1
0
def prof_on_iq_stanza_receive(stanza):
    stanza = ensure_unicode_stanza(stanza)
    log.info('Received IQ: {0}'.format(stanza))

    if xmpp.is_bundle_update(stanza):  # bundle information received
        log.info('Bundle update detected.')
        _handle_bundle_update(stanza)
        return False

    elif xmpp.is_devicelist_update(stanza):
        log.info('Device List update detected.')
        _handle_devicelist_update(stanza)
        return False

    return True
def prof_on_iq_stanza_receive(stanza):
    stanza = ensure_unicode_stanza(stanza)
    log.info('Received IQ: {0}'.format(stanza))

    if xmpp.is_bundle_update(stanza):  # bundle information received
        log.info('Bundle update detected.')
        _handle_bundle_update(stanza)
        return False

    elif xmpp.is_devicelist_update(stanza):
        log.info('Device List update detected.')
        _handle_devicelist_update(stanza)
        return False

    return True
Example #3
0
def prof_on_message_stanza_receive(stanza):
    stanza = ensure_unicode_stanza(stanza)

    log.info('Received Message: {0}'.format(stanza))
    if xmpp.is_devicelist_update(stanza):
        log.info('Device List update detected.')
        try:
            _handle_devicelist_update(stanza)
        except:
            log.exception('Failed to handle devicelist update.')

        return False

    if xmpp.is_encrypted_message(stanza):
        log.info('Received OMEMO encrypted message.')
        omemo_state = ProfOmemoState()

        try:
            msg_dict = xmpp.unpack_encrypted_stanza(stanza)
            sender = msg_dict['sender_jid']
            resource = msg_dict['sender_resource']
            sender_fulljid = sender + '/' + resource

            if sender_fulljid == ProfOmemoUser().fulljid:
                log.debug('Skipping own Message.')
                return False

            try:
                plain_msg = omemo_state.decrypt_msg(msg_dict)
            except Exception:
                log.exception('Could not decrypt Message.')
                return False

            if plain_msg is None:
                log.error('Could not decrypt Message')
                return True

            if plain_msg:
                # only mark the message if it was an OMEMO encrypted message
                try:
                    message_char = _get_omemo_message_char()
                    log.debug('Set incoming Message Character: {0}'.format(
                        message_char))
                    prof.chat_set_incoming_char(sender, message_char)
                    prof.incoming_message(sender, resource, plain_msg)
                finally:
                    prof.chat_unset_incoming_char(sender)

                # if this was the first OMEMO encrypted message received by
                # the sender (a.k.a. whenever profanity opens a new chat window
                # for a recipient), we automatically respond with OMEMO encrypted
                # messages. If encryption is turned off later by the user,
                # we respect that.
                if not ProfActiveOmemoChats.account_is_active(sender):
                    if not ProfActiveOmemoChats.account_is_deactivated(sender):
                        _start_omemo_session(sender)

            return False

        except Exception:
            # maybe not OMEMO encrypted, profanity will take care then
            log.exception('Could not handle encrypted message.')

    return True
def prof_on_message_stanza_receive(stanza):
    stanza = ensure_unicode_stanza(stanza)

    log.info('Received Message: {0}'.format(stanza))
    if xmpp.is_devicelist_update(stanza):
        log.info('Device List update detected.')
        try:
            _handle_devicelist_update(stanza)
        except:
            log.exception('Failed to handle devicelist update.')

        return False

    if xmpp.is_encrypted_message(stanza):
        log.info('Received OMEMO encrypted message.')
        omemo_state = ProfOmemoState()

        try:
            msg_dict = xmpp.unpack_encrypted_stanza(stanza)
            sender = msg_dict['sender_jid']
            resource = msg_dict['sender_resource']
            sender_fulljid = sender + '/' + resource

            if sender_fulljid == ProfOmemoUser().fulljid:
                log.debug('Skipping own Message.')
                return False

            try:
                plain_msg = omemo_state.decrypt_msg(msg_dict)
            except Exception:
                log.exception('Could not decrypt Message.')
                return False

            if plain_msg is None:
                log.error('Could not decrypt Message')
                return True

            if plain_msg:
                # only mark the message if it was an OMEMO encrypted message
                try:
                    message_char = _get_omemo_message_char()
                    log.debug('Set incoming Message Character: {0}'.format(message_char))
                    prof.chat_set_incoming_char(sender, message_char)
                    prof.incoming_message(sender, resource, plain_msg)
                finally:
                    prof.chat_unset_incoming_char(sender)

                # if this was the first OMEMO encrypted message received by
                # the sender (a.k.a. whenever profanity opens a new chat window
                # for a recipient), we automatically respond with OMEMO encrypted
                # messages. If encryption is turned off later by the user,
                # we respect that.
                if not ProfActiveOmemoChats.account_is_active(sender):
                    if not ProfActiveOmemoChats.account_is_deactivated(sender):
                        _start_omemo_session(sender)

            return False

        except Exception:
            # maybe not OMEMO encrypted, profanity will take care then
            log.exception('Could not handle encrypted message.')

    return True