Exemple #1
0
def _cmd_enc(arg1=None, arg2=None, arg3=None, arg4=None, arg5=None):
    global chat_msg_hook
    global room_msg_hook

    if arg1 == "end":
        prof.encryption_reset(arg2)

    elif arg1 == "chat_title" and arg2 == "set":
        prof.chat_set_titlebar_enctext(arg3, arg4)

    elif arg1 == "chat_title" and arg2 == "reset":
        prof.chat_unset_titlebar_enctext(arg3)

    elif arg1 == "chat_ch" and arg2 == "set" and arg3 == "in":
        prof.chat_set_incoming_char(arg4, arg5)

    elif arg1 == "chat_ch" and arg2 == "reset" and arg3 == "in":
        prof.chat_unset_incoming_char(arg4)

    elif arg1 == "chat_ch" and arg2 == "set" and arg3 == "out":
        prof.chat_set_outgoing_char(arg4, arg5)

    elif arg1 == "chat_ch" and arg2 == "reset" and arg3 == "out":
        prof.chat_unset_outgoing_char(arg4)

    elif arg1 == "room_title" and arg2 == "set":
        prof.room_set_titlebar_enctext(arg3, arg4)

    elif arg1 == "room_title" and arg2 == "reset":
        prof.room_unset_titlebar_enctext(arg3)

    elif arg1 == "room_ch" and arg2 == "set":
        prof.room_set_message_char(arg3, arg4)

    elif arg1 == "room_ch" and arg2 == "reset":
        prof.room_unset_message_char(arg3)

    elif arg1 == "chat_show":
        prof.chat_show(arg2, arg3)

    elif arg1 == "chat_show_themed":
        prof.chat_show_themed(arg2, "enc_py", "chat_msg", None, "p", arg3)

    elif arg1 == "room_show":
        prof.room_show(arg2, arg3)

    elif arg1 == "room_show_themed":
        prof.room_show_themed(arg2, "enc_py", "room_msg", None, "P", arg3)

    elif arg1 == "chat_msg":
        chat_msg_hook = arg2

    elif arg1 == "room_msg":
        room_msg_hook = arg2

    else:
        prof.cons_bad_cmd_usage("/enc_py")
Exemple #2
0
def _end_omemo_session(jid):
    ProfActiveOmemoChats.deactivate(jid)

    # Release OMEMO from titlebar
    prof.chat_unset_titlebar_enctext(jid)

    prof.chat_unset_incoming_char(jid)
    prof.chat_unset_outgoing_char(jid)

    prof.settings_string_list_remove(SETTINGS_GROUP, 'omemo_sessions', jid)

    show_chat_info(jid, 'OMEMO Session ended.')
def _end_omemo_session(jid):
    ProfActiveOmemoChats.deactivate(jid)

    # Release OMEMO from titlebar
    prof.chat_unset_titlebar_enctext(jid)

    prof.chat_unset_incoming_char(jid)
    prof.chat_unset_outgoing_char(jid)

    prof.settings_string_list_remove(SETTINGS_GROUP, 'omemo_sessions', jid)

    show_chat_info(jid, 'OMEMO Session ended.')
Exemple #4
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