コード例 #1
0
void
handle_incoming_message(char *from, char *message, gboolean priv)
{
#ifdef HAVE_LIBOTR
    gboolean was_decrypted = FALSE;
    char *newmessage;
    if (!priv) {
        newmessage = otr_decrypt_message(from, message, &was_decrypted);

        // internal OTR message
        if (newmessage == NULL) {
            return;
        }
    } else {
        newmessage = message;
    }

    ui_incoming_msg(from, newmessage, NULL, priv);
    ui_current_page_off();

    if (prefs_get_boolean(PREF_CHLOG) && !priv) {
        Jid *from_jid = jid_create(from);
        const char *jid = jabber_get_fulljid();
        Jid *jidp = jid_create(jid);

        if (!was_decrypted || (strcmp(prefs_get_string(PREF_OTR_LOG), "on") == 0)) {
            chat_log_chat(jidp->barejid, from_jid->barejid, newmessage, PROF_IN_LOG, NULL);
        } else if (strcmp(prefs_get_string(PREF_OTR_LOG), "redact") == 0) {
            chat_log_chat(jidp->barejid, from_jid->barejid, "[redacted]", PROF_IN_LOG, NULL);
        }

        jid_destroy(jidp);
        jid_destroy(from_jid);
    }

    if (!priv)
        otr_free_message(newmessage);
#else
    ui_incoming_msg(from, message, NULL, priv);
    ui_current_page_off();

    if (prefs_get_boolean(PREF_CHLOG) && !priv) {
        Jid *from_jid = jid_create(from);
        const char *jid = jabber_get_fulljid();
        Jid *jidp = jid_create(jid);
        chat_log_chat(jidp->barejid, from_jid->barejid, message, PROF_IN_LOG, NULL);
        jid_destroy(jidp);
        jid_destroy(from_jid);
    }
#endif
}
コード例 #2
0
ファイル: server_events.c プロジェクト: fisle/profanity
static void
_sv_ev_incoming_otr(ProfChatWin *chatwin, gboolean new_win, char *barejid, char *resource, char *message, GDateTime *timestamp)
{
    gboolean decrypted = FALSE;
    char *otr_res = otr_on_message_recv(barejid, resource, message, &decrypted);
    if (otr_res) {
        if (decrypted) {
            chatwin_incoming_msg(chatwin, resource, otr_res, timestamp, new_win, PROF_MSG_OTR);
            chatwin->pgp_send = FALSE;
        } else {
            chatwin_incoming_msg(chatwin, resource, otr_res, timestamp, new_win, PROF_MSG_PLAIN);
        }
        chat_log_otr_msg_in(barejid, otr_res, decrypted, timestamp);
        otr_free_message(otr_res);
        chatwin->pgp_recv = FALSE;
    }
}
コード例 #3
0
ファイル: otr.c プロジェクト: BlueMonday/profanity
gboolean
otr_on_message_send(ProfChatWin *chatwin, const char *const message)
{
    char *id = NULL;
    prof_otrpolicy_t policy = otr_get_policy(chatwin->barejid);

    // Send encrypted message
    if (otr_is_secure(chatwin->barejid)) {
        char *encrypted = otr_encrypt_message(chatwin->barejid, message);
        if (encrypted) {
            id = message_send_chat_otr(chatwin->barejid, encrypted);
            chat_log_otr_msg_out(chatwin->barejid, message);
            chatwin_outgoing_msg(chatwin, message, id, PROF_MSG_OTR);
            otr_free_message(encrypted);
            free(id);
            return TRUE;
        } else {
            ui_win_error_line((ProfWin*)chatwin, "Failed to encrypt and send message.");
            return TRUE;
        }
    }

    // show error if not secure and policy always
    if (policy == PROF_OTRPOLICY_ALWAYS) {
        ui_win_error_line((ProfWin*)chatwin, "Failed to send message. OTR policy set to: always");
        return TRUE;
    }

    // tag and send for policy opportunistic
    if (policy == PROF_OTRPOLICY_OPPORTUNISTIC) {
        char *otr_tagged_msg = otr_tag_message(message);
        id = message_send_chat_otr(chatwin->barejid, otr_tagged_msg);
        chatwin_outgoing_msg(chatwin, message, id, PROF_MSG_PLAIN);
        chat_log_msg_out(chatwin->barejid, message);
        free(otr_tagged_msg);
        free(id);
        return TRUE;
    }

    return FALSE;
}
コード例 #4
0
ファイル: server_events.c プロジェクト: diagprov/profanity
void
sv_ev_incoming_message(char *barejid, char *resource, char *message, char *enc_message)
{
    gboolean new_win = FALSE;
    ProfChatWin *chatwin = wins_get_chat(barejid);
    if (!chatwin) {
        ProfWin *window = wins_new_chat(barejid);
        chatwin = (ProfChatWin*)window;
        new_win = TRUE;
    }

// OTR suported, PGP supported
#ifdef HAVE_LIBOTR
#ifdef HAVE_LIBGPGME
    prof_enc_t enc_mode = chatwin->enc_mode;
    if (enc_message) {
        if (enc_mode == PROF_ENC_OTR) {
            win_println((ProfWin*)chatwin, "PGP encrypted message received whilst in OTR session.");
        } else { // PROF_ENC_NONE, PROF_ENC_PGP
            char *decrypted = p_gpg_decrypt(barejid, enc_message);
            if (decrypted) {
                if (enc_mode == PROF_ENC_NONE) {
                    win_println((ProfWin*)chatwin, "PGP encryption enabled.");
                }
                ui_incoming_msg(chatwin, resource, decrypted, NULL, new_win);
                chat_log_pgp_msg_in(barejid, decrypted);
                chatwin->enc_mode = PROF_ENC_PGP;
            } else {
                ui_incoming_msg(chatwin, resource, message, NULL, new_win);
                chat_log_msg_in(barejid, message);
                chatwin->enc_mode = PROF_ENC_NONE;
            }
        }
    } else {
        if (enc_mode == PROF_ENC_PGP) {
            win_println((ProfWin*)chatwin, "PGP encryption disabled.");
            ui_incoming_msg(chatwin, resource, message, NULL, new_win);
            chat_log_msg_in(barejid, message);
            chatwin->enc_mode = PROF_ENC_NONE;
        } else {
            gboolean decrypted = FALSE;
            char *otr_res = otr_on_message_recv(barejid, resource, message, &decrypted);
            if (otr_res) {
                ui_incoming_msg(chatwin, resource, otr_res, NULL, new_win);
                chat_log_otr_msg_in(barejid, otr_res, decrypted);
                otr_free_message(otr_res);
            }
        }
    }
    return;
#endif
#endif

// OTR supported, PGP unsupported
#ifdef HAVE_LIBOTR
#ifndef HAVE_LIBGPGME
    gboolean decrypted = FALSE;
    char *otr_res = otr_on_message_recv(barejid, resource, message, &decrypted);
    if (otr_res) {
        ui_incoming_msg(chatwin, resource, otr_res, NULL, new_win);
        chat_log_otr_msg_in(barejid, otr_res, decrypted);
        otr_free_message(otr_res);
    }
    return;
#endif
#endif

// OTR unsupported, PGP supported
#ifndef HAVE_LIBOTR
#ifdef HAVE_LIBGPGME
    if (enc_message) {
        char *decrypted = p_gpg_decrypt(barejid, enc_message);
        if (decrypted) {
            ui_incoming_msg(chatwin, resource, decrypted, NULL, new_win);
            chat_log_pgp_msg_in(barejid, decrypted);
            chatwin->enc_mode = PROF_ENC_PGP;
        } else {
            ui_incoming_msg(chatwin, resource, message, NULL, new_win);
            chat_log_msg_in(barejid, message);
            chatwin->enc_mode = PROF_ENC_NONE;
        }
    } else {
        ui_incoming_msg(chatwin, resource, message, NULL, new_win);
        chat_log_msg_in(barejid, message);
        chatwin->enc_mode = PROF_ENC_NONE;
    }
    return;
#endif
#endif

// OTR unsupported, PGP unsupported
#ifndef HAVE_LIBOTR
#ifndef HAVE_LIBGPGME
    ui_incoming_msg(chatwin, resource, message, NULL, new_win);
    chat_log_msg_in(barejid, message);
    chatwin->enc_mode = PROF_ENC_NONE;
    return;
#endif
#endif
}
コード例 #5
0
ファイル: server_events.c プロジェクト: dotoole/profanity
void
handle_incoming_message(char *from, char *message, gboolean priv)
{
#ifdef HAVE_LIBOTR
    gboolean was_decrypted = FALSE;
    char *newmessage;

    prof_otrpolicy_t policy = otr_get_policy(from);
    char *whitespace_base = strstr(message,OTRL_MESSAGE_TAG_BASE);

    if (!priv) {
        //check for OTR whitespace (opportunistic or always)
        if (policy == PROF_OTRPOLICY_OPPORTUNISTIC || policy == PROF_OTRPOLICY_ALWAYS) {
            if (whitespace_base) {
                if (strstr(message, OTRL_MESSAGE_TAG_V2) || strstr(message, OTRL_MESSAGE_TAG_V1)) {
                    // Remove whitespace pattern for proper display in UI
                    // Handle both BASE+TAGV1/2(16+8) and BASE+TAGV1+TAGV2(16+8+8)
                    int tag_length	=	24;
                    if (strstr(message, OTRL_MESSAGE_TAG_V2) && strstr(message, OTRL_MESSAGE_TAG_V1)) {
                        tag_length = 32;
                    }
                    memmove(whitespace_base, whitespace_base+tag_length, tag_length);
                    char *otr_query_message = otr_start_query();
                    cons_show("OTR Whitespace pattern detected. Attempting to start OTR session...");
                    message_send(otr_query_message, from);
                }
            }
        }
        newmessage = otr_decrypt_message(from, message, &was_decrypted);

        // internal OTR message
        if (newmessage == NULL) {
            return;
        }
    } else {
        newmessage = message;
    }
    if (policy == PROF_OTRPOLICY_ALWAYS && !was_decrypted && !whitespace_base) {
        char *otr_query_message = otr_start_query();
        cons_show("Attempting to start OTR session...");
        message_send(otr_query_message, from);
    }

    ui_incoming_msg(from, newmessage, NULL, priv);

    if (prefs_get_boolean(PREF_CHLOG) && !priv) {
        Jid *from_jid = jid_create(from);
        const char *jid = jabber_get_fulljid();
        Jid *jidp = jid_create(jid);

        char *pref_otr_log = prefs_get_string(PREF_OTR_LOG);
        if (!was_decrypted || (strcmp(pref_otr_log, "on") == 0)) {
            chat_log_chat(jidp->barejid, from_jid->barejid, newmessage, PROF_IN_LOG, NULL);
        } else if (strcmp(pref_otr_log, "redact") == 0) {
            chat_log_chat(jidp->barejid, from_jid->barejid, "[redacted]", PROF_IN_LOG, NULL);
        }
        prefs_free_string(pref_otr_log);

        jid_destroy(jidp);
        jid_destroy(from_jid);
    }

    if (!priv)
        otr_free_message(newmessage);
#else
    ui_incoming_msg(from, message, NULL, priv);

    if (prefs_get_boolean(PREF_CHLOG) && !priv) {
        Jid *from_jid = jid_create(from);
        const char *jid = jabber_get_fulljid();
        Jid *jidp = jid_create(jid);
        chat_log_chat(jidp->barejid, from_jid->barejid, message, PROF_IN_LOG, NULL);
        jid_destroy(jidp);
        jid_destroy(from_jid);
    }
#endif
}