1
1
mirror of https://github.com/profanity-im/profanity.git synced 2025-01-03 14:57:42 -05:00

Log and print outgoing encrypted message

This commit is contained in:
Paul Fariello 2019-03-18 20:30:28 +01:40
parent a9d55dec92
commit 4e1ffa6bdb
11 changed files with 227 additions and 74 deletions

View File

@ -218,7 +218,10 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg, const char *const oo
#ifndef HAVE_LIBGPGME
#ifdef HAVE_OMEMO
if (chatwin->is_omemo) {
omemo_on_message_send((ProfWin *)chatwin, plugin_msg, request_receipt, FALSE);
char *id = omemo_on_message_send((ProfWin *)chatwin, plugin_msg, request_receipt, FALSE);
chat_log_omemo_msg_out(chatwin->barejid, plugin_msg);
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_OMEMO, request_receipt);
free(id);
} else {
char *id = message_send_chat(chatwin->barejid, plugin_msg, oob_url, request_receipt);
chat_log_msg_out(chatwin->barejid, plugin_msg);
@ -238,7 +241,10 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg, const char *const oo
#ifndef HAVE_LIBGPGME
#ifdef HAVE_OMEMO
if (chatwin->is_omemo) {
omemo_on_message_send((ProfWin *)chatwin, plugin_msg, request_receipt, FALSE);
char *id = omemo_on_message_send((ProfWin *)chatwin, plugin_msg, request_receipt, FALSE);
chat_log_omemo_msg_out(chatwin->barejid, plugin_msg);
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_OMEMO, request_receipt);
free(id);
} else {
gboolean handled = otr_on_message_send(chatwin, plugin_msg, request_receipt);
if (!handled) {
@ -261,7 +267,10 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg, const char *const oo
#ifdef HAVE_LIBGPGME
#ifdef HAVE_OMEMO
if (chatwin->is_omemo) {
omemo_on_message_send((ProfWin *)chatwin, plugin_msg, request_receipt, FALSE);
char *id = omemo_on_message_send((ProfWin *)chatwin, plugin_msg, request_receipt, FALSE);
chat_log_omemo_msg_out(chatwin->barejid, plugin_msg);
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_OMEMO, request_receipt);
free(id);
} else if (chatwin->pgp_send) {
char *id = message_send_chat_pgp(chatwin->barejid, plugin_msg, request_receipt);
chat_log_pgp_msg_out(chatwin->barejid, plugin_msg);
@ -286,7 +295,10 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg, const char *const oo
#ifdef HAVE_LIBGPGME
#ifdef HAVE_OMEMO
if (chatwin->is_omemo) {
omemo_on_message_send((ProfWin *)chatwin, plugin_msg, request_receipt, FALSE);
char *id = omemo_on_message_send((ProfWin *)chatwin, plugin_msg, request_receipt, FALSE);
chat_log_omemo_msg_out(chatwin->barejid, plugin_msg);
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_OMEMO, request_receipt);
free(id);
} else if (chatwin->pgp_send) {
char *id = message_send_chat_pgp(chatwin->barejid, plugin_msg, request_receipt);
chat_log_pgp_msg_out(chatwin->barejid, plugin_msg);
@ -336,9 +348,14 @@ cl_ev_send_muc_msg(ProfMucWin *mucwin, const char *const msg, const char *const
#ifdef HAVE_OMEMO
if (mucwin->is_omemo) {
omemo_on_message_send((ProfWin *)mucwin, plugin_msg, FALSE, TRUE);
char *id = omemo_on_message_send((ProfWin *)mucwin, plugin_msg, FALSE, TRUE);
groupchat_log_omemo_msg_out(mucwin->roomjid, plugin_msg);
mucwin_outgoing_msg(mucwin, plugin_msg, PROF_MSG_OMEMO);
free(id);
} else {
message_send_groupchat(mucwin->roomjid, plugin_msg, oob_url);
groupchat_log_msg_out(mucwin->roomjid, plugin_msg);
mucwin_outgoing_msg(mucwin, plugin_msg, PROF_MSG_PLAIN);
}
plugins_post_room_message_send(mucwin->roomjid, plugin_msg);
@ -348,6 +365,8 @@ cl_ev_send_muc_msg(ProfMucWin *mucwin, const char *const msg, const char *const
#ifndef HAVE_OMEMO
message_send_groupchat(mucwin->roomjid, plugin_msg, oob_url);
groupchat_log_msg_out(mucwin->roomjid, plugin_msg);
mucwin_outgoing_msg(mucwin, plugin_msg, id, PROF_MSG_PLAIN, request_receipt);
plugins_post_room_message_send(mucwin->roomjid, plugin_msg);
free(plugin_msg);

View File

@ -260,21 +260,26 @@ sv_ev_room_history(const char *const room_jid, const char *const nick,
}
void
sv_ev_room_message(const char *const room_jid, const char *const nick, const char *const message)
sv_ev_room_message(const char *const room_jid, const char *const nick, const char *const message, gboolean omemo)
{
if (prefs_get_boolean(PREF_GRLOG)) {
Jid *jid = jid_create(connection_get_fulljid());
groupchat_log_chat(jid->barejid, room_jid, nick, message);
jid_destroy(jid);
}
ProfMucWin *mucwin = wins_get_muc(room_jid);
if (!mucwin) {
return;
}
char *new_message = plugins_pre_room_message_display(room_jid, nick, message);
char *mynick = muc_nick(mucwin->roomjid);
if (g_strcmp0(mynick, nick) == 0) {
/* Ignore message reflection */
return;
}
if (omemo) {
groupchat_log_omemo_msg_in(room_jid, nick, message);
} else {
groupchat_log_msg_in(room_jid, nick, message);
}
char *new_message = plugins_pre_room_message_display(room_jid, nick, message);
gboolean whole_word = prefs_get_boolean(PREF_NOTIFY_MENTION_WHOLE_WORD);
gboolean case_sensitive = prefs_get_boolean(PREF_NOTIFY_MENTION_CASE_SENSITIVE);
@ -289,7 +294,11 @@ sv_ev_room_message(const char *const room_jid, const char *const nick, const cha
GList *triggers = prefs_message_get_triggers(new_message);
mucwin_message(mucwin, nick, new_message, mentions, triggers);
if (omemo) {
mucwin_incoming_msg(mucwin, nick, new_message, mentions, triggers, PROF_MSG_OMEMO);
} else {
mucwin_incoming_msg(mucwin, nick, new_message, mentions, triggers, PROF_MSG_PLAIN);
}
g_slist_free(mentions);
@ -607,15 +616,50 @@ sv_ev_incoming_carbon(char *barejid, char *resource, char *message, char *pgp_me
}
#ifdef HAVE_LIBGPGME
#ifndef HAVE_OMEMO
if (pgp_message) {
_sv_ev_incoming_pgp(chatwin, new_win, barejid, resource, message, pgp_message, NULL);
} else {
_sv_ev_incoming_plain(chatwin, new_win, barejid, resource, message, NULL);
}
#else
_sv_ev_incoming_plain(chatwin, new_win, barejid, resource, message, NULL);
#endif
rosterwin_roster();
return;
#endif
#endif
#ifdef HAVE_LIBGPGME
#ifdef HAVE_OMEMO
if (pgp_message) {
_sv_ev_incoming_pgp(chatwin, new_win, barejid, resource, message, pgp_message, NULL);
} else if (omemo) {
_sv_ev_incoming_omemo(chatwin, new_win, barejid, resource, message, NULL);
} else {
_sv_ev_incoming_plain(chatwin, new_win, barejid, resource, message, NULL);
}
rosterwin_roster();
return;
#endif
#endif
#ifndef HAVE_LIBGPGME
#ifdef HAVE_OMEMO
if (omemo) {
_sv_ev_incoming_omemo(chatwin, new_win, barejid, resource, message, NULL);
} else {
_sv_ev_incoming_plain(chatwin, new_win, barejid, resource, message, NULL);
}
rosterwin_roster();
return;
#endif
#endif
#ifndef HAVE_LIBGPGME
#ifndef HAVE_OMEMO
_sv_ev_incoming_plain(chatwin, new_win, barejid, resource, message, NULL);
rosterwin_roster();
return;
#endif
#endif
}
void

View File

@ -46,9 +46,9 @@ void sv_ev_room_invite(jabber_invite_t invite_type,
void sv_ev_room_broadcast(const char *const room_jid, const char *const message);
void sv_ev_room_subject(const char *const room, const char *const nick, const char *const subject);
void sv_ev_room_history(const char *const room_jid, const char *const nick,
GDateTime *timestamp, const char *const message);
GDateTime *timestamp, const char *const message, gboolean omemo);
void sv_ev_room_message(const char *const room_jid, const char *const nick,
const char *const message);
const char *const message, gboolean omemo);
void sv_ev_incoming_message(char *barejid, char *resource, char *message, char *pgp_message, GDateTime *timestamp, gboolean omemo);
void sv_ev_incoming_private_message(const char *const fulljid, char *message);
void sv_ev_delayed_private_message(const char *const fulljid, char *message, GDateTime *timestamp);

View File

@ -48,6 +48,7 @@
#include "config/files.h"
#include "config/preferences.h"
#include "xmpp/xmpp.h"
#include "xmpp/muc.h"
#define PROF "prof"
@ -89,6 +90,8 @@ static void _rotate_log_file(void);
static char* _log_string_from_level(log_level_t level);
static void _chat_log_chat(const char *const login, const char *const other, const gchar *const msg,
chat_log_direction_t direction, GDateTime *timestamp);
static void _groupchat_log_chat(const gchar *const login, const gchar *const room, const gchar *const nick,
const gchar *const msg);
void
log_debug(const char *const msg, ...)
@ -440,7 +443,66 @@ _chat_log_chat(const char *const login, const char *const other, const char *con
}
void
groupchat_log_chat(const gchar *const login, const gchar *const room, const gchar *const nick, const gchar *const msg)
groupchat_log_msg_out(const gchar *const room, const gchar *const msg)
{
if (prefs_get_boolean(PREF_GRLOG)) {
const char *jid = connection_get_fulljid();
Jid *jidp = jid_create(jid);
char *mynick = muc_nick(room);
_groupchat_log_chat(jidp->barejid, room, mynick, msg);
jid_destroy(jidp);
}
}
void
groupchat_log_msg_in(const gchar *const room, const gchar *const nick, const gchar *const msg)
{
if (prefs_get_boolean(PREF_GRLOG)) {
const char *jid = connection_get_fulljid();
Jid *jidp = jid_create(jid);
_groupchat_log_chat(jidp->barejid, room, nick, msg);
jid_destroy(jidp);
}
}
void
groupchat_log_omemo_msg_out(const gchar *const room, const gchar *const msg)
{
if (prefs_get_boolean(PREF_CHLOG)) {
const char *jid = connection_get_fulljid();
Jid *jidp = jid_create(jid);
char *pref_omemo_log = prefs_get_string(PREF_OMEMO_LOG);
char *mynick = muc_nick(room);
if (strcmp(pref_omemo_log, "on") == 0) {
_groupchat_log_chat(jidp->barejid, room, mynick, msg);
} else if (strcmp(pref_omemo_log, "redact") == 0) {
_groupchat_log_chat(jidp->barejid, room, mynick, "[redacted]");
}
prefs_free_string(pref_omemo_log);
jid_destroy(jidp);
}
}
void
groupchat_log_omemo_msg_in(const gchar *const room, const gchar *const nick, const gchar *const msg)
{
if (prefs_get_boolean(PREF_CHLOG)) {
const char *jid = connection_get_fulljid();
Jid *jidp = jid_create(jid);
char *pref_omemo_log = prefs_get_string(PREF_OMEMO_LOG);
if (strcmp(pref_omemo_log, "on") == 0) {
_groupchat_log_chat(jidp->barejid, room, nick, msg);
} else if (strcmp(pref_omemo_log, "redact") == 0) {
_groupchat_log_chat(jidp->barejid, room, nick, "[redacted]");
}
prefs_free_string(pref_omemo_log);
jid_destroy(jidp);
}
}
void
_groupchat_log_chat(const gchar *const login, const gchar *const room, const gchar *const nick,
const gchar *const msg)
{
struct dated_chat_log *dated_log = g_hash_table_lookup(groupchat_logs, room);

View File

@ -82,7 +82,10 @@ void chat_log_close(void);
GSList* chat_log_get_previous(const gchar *const login, const gchar *const recipient);
void groupchat_log_init(void);
void groupchat_log_chat(const gchar *const login, const gchar *const room, const gchar *const nick,
const gchar *const msg);
void groupchat_log_msg_out(const gchar *const room, const gchar *const msg);
void groupchat_log_msg_in(const gchar *const room, const gchar *const nick, const gchar *const msg);
void groupchat_log_omemo_msg_out(const gchar *const room, const gchar *const msg);
void groupchat_log_omemo_msg_in(const gchar *const room, const gchar *const nick, const gchar *const msg);
#endif

View File

@ -542,16 +542,14 @@ out:
jid_destroy(ownjid);
}
gboolean
char *
omemo_on_message_send(ProfWin *win, const char *const message, gboolean request_receipt, gboolean muc)
{
char *id = NULL;
int res;
gboolean ret = FALSE;
Jid *jid = jid_create(connection_get_fulljid());
GList *keys = NULL;
GList *sender_device_id = g_hash_table_lookup(omemo_ctx.device_list, jid->barejid);
unsigned char *key;
unsigned char *iv;
unsigned char *ciphertext;
@ -643,50 +641,48 @@ omemo_on_message_send(ProfWin *win, const char *const message, gboolean request_
g_list_free_full(recipients, free);
for (device_ids_iter = sender_device_id; device_ids_iter != NULL; device_ids_iter = device_ids_iter->next) {
int res;
ciphertext_message *ciphertext;
session_cipher *cipher;
signal_protocol_address address = {
.name = jid->barejid,
.name_len = strlen(jid->barejid),
.device_id = GPOINTER_TO_INT(device_ids_iter->data)
};
if (!muc) {
GList *sender_device_id = g_hash_table_lookup(omemo_ctx.device_list, jid->barejid);
for (device_ids_iter = sender_device_id; device_ids_iter != NULL; device_ids_iter = device_ids_iter->next) {
int res;
ciphertext_message *ciphertext;
session_cipher *cipher;
signal_protocol_address address = {
.name = jid->barejid,
.name_len = strlen(jid->barejid),
.device_id = GPOINTER_TO_INT(device_ids_iter->data)
};
res = session_cipher_create(&cipher, omemo_ctx.store, &address, omemo_ctx.signal);
if (res != 0) {
log_error("OMEMO: cannot create cipher for %s device id %d", address.name, address.device_id);
continue;
}
res = session_cipher_create(&cipher, omemo_ctx.store, &address, omemo_ctx.signal);
if (res != 0) {
log_error("OMEMO: cannot create cipher for %s device id %d", address.name, address.device_id);
continue;
}
res = session_cipher_encrypt(cipher, key_tag, AES128_GCM_KEY_LENGTH + AES128_GCM_TAG_LENGTH, &ciphertext);
if (res != 0) {
log_error("OMEMO: cannot encrypt key for %s device id %d", address.name, address.device_id);
continue;
res = session_cipher_encrypt(cipher, key_tag, AES128_GCM_KEY_LENGTH + AES128_GCM_TAG_LENGTH, &ciphertext);
if (res != 0) {
log_error("OMEMO: cannot encrypt key for %s device id %d", address.name, address.device_id);
continue;
}
signal_buffer *buffer = ciphertext_message_get_serialized(ciphertext);
omemo_key_t *key = malloc(sizeof(omemo_key_t));
key->data = signal_buffer_data(buffer);
key->length = signal_buffer_len(buffer);
key->device_id = GPOINTER_TO_INT(device_ids_iter->data);
key->prekey = ciphertext_message_get_type(ciphertext) == CIPHERTEXT_PREKEY_TYPE;
keys = g_list_append(keys, key);
}
signal_buffer *buffer = ciphertext_message_get_serialized(ciphertext);
omemo_key_t *key = malloc(sizeof(omemo_key_t));
key->data = signal_buffer_data(buffer);
key->length = signal_buffer_len(buffer);
key->device_id = GPOINTER_TO_INT(device_ids_iter->data);
key->prekey = ciphertext_message_get_type(ciphertext) == CIPHERTEXT_PREKEY_TYPE;
keys = g_list_append(keys, key);
}
if (muc) {
ProfMucWin *mucwin = (ProfMucWin *)win;
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
char *id = message_send_chat_omemo(mucwin->roomjid, omemo_ctx.device_id, keys, iv, AES128_GCM_IV_LENGTH, ciphertext, ciphertext_len, request_receipt, TRUE);
free(id);
id = message_send_chat_omemo(mucwin->roomjid, omemo_ctx.device_id, keys, iv, AES128_GCM_IV_LENGTH, ciphertext, ciphertext_len, request_receipt, TRUE);
} else {
ProfChatWin *chatwin = (ProfChatWin *)win;
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
char *id = message_send_chat_omemo(chatwin->barejid, omemo_ctx.device_id, keys, iv, AES128_GCM_IV_LENGTH, ciphertext, ciphertext_len, request_receipt, FALSE);
chat_log_omemo_msg_out(chatwin->barejid, message);
chatwin_outgoing_msg(chatwin, message, id, PROF_MSG_OMEMO, request_receipt);
free(id);
id = message_send_chat_omemo(chatwin->barejid, omemo_ctx.device_id, keys, iv, AES128_GCM_IV_LENGTH, ciphertext, ciphertext_len, request_receipt, FALSE);
}
ret = TRUE;
out:
jid_destroy(jid);
@ -697,7 +693,7 @@ out:
gcry_free(tag);
gcry_free(key_tag);
return ret;
return id;
}
char *

View File

@ -40,5 +40,5 @@ void omemo_start_muc_sessions(const char *const roomjid);
void omemo_start_device_session(const char *const jid, uint32_t device_id, GList *prekeys, uint32_t signed_prekey_id, const unsigned char *const signed_prekey, size_t signed_prekey_len, const unsigned char *const signature, size_t signature_len, const unsigned char *const identity_key, size_t identity_key_len);
gboolean omemo_loaded(void);
gboolean omemo_on_message_send(ProfWin *win, const char *const message, gboolean request_receipt, gboolean muc);
char * omemo_on_message_send(ProfWin *win, const char *const message, gboolean request_receipt, gboolean muc);
char * omemo_on_message_recv(const char *const from, uint32_t sid, const unsigned char *const iv, size_t iv_len, GList *keys, const unsigned char *const payload, size_t payload_len, gboolean muc);

View File

@ -478,7 +478,7 @@ _mucwin_print_triggers(ProfWin *window, const char *const message, GList *trigge
}
void
mucwin_message(ProfMucWin *mucwin, const char *const nick, const char *const message, GSList *mentions, GList *triggers)
mucwin_outgoing_msg(ProfMucWin *mucwin, const char *const message, prof_enc_t enc_mode)
{
assert(mucwin != NULL);
@ -488,19 +488,43 @@ mucwin_message(ProfMucWin *mucwin, const char *const nick, const char *const mes
char ch = '-';
if (mucwin->message_char) {
ch = mucwin->message_char[0];
} else if (enc_mode == PROF_MSG_OTR) {
ch = prefs_get_otr_char();
} else if (enc_mode == PROF_MSG_PGP) {
ch = prefs_get_pgp_char();
} else if (enc_mode == PROF_MSG_OMEMO) {
ch = prefs_get_omemo_char();
}
if (g_strcmp0(nick, mynick) != 0) {
if (g_slist_length(mentions) > 0) {
_mucwin_print_mention(window, message, nick, mynick, mentions, &ch);
} else if (triggers) {
win_print_them(window, THEME_ROOMTRIGGER, ch, nick);
_mucwin_print_triggers(window, message, triggers);
} else {
win_println_them_message(window, ch, nick, "%s", message);
}
win_println_me_message(window, ch, mynick, "%s", message);
}
void
mucwin_incoming_msg(ProfMucWin *mucwin, const char *const nick, const char *const message, GSList *mentions, GList *triggers, prof_enc_t enc_mode)
{
assert(mucwin != NULL);
ProfWin *window = (ProfWin*)mucwin;
char *mynick = muc_nick(mucwin->roomjid);
char ch = '-';
if (mucwin->message_char) {
ch = mucwin->message_char[0];
} else if (enc_mode == PROF_MSG_OTR) {
ch = prefs_get_otr_char();
} else if (enc_mode == PROF_MSG_PGP) {
ch = prefs_get_pgp_char();
} else if (enc_mode == PROF_MSG_OMEMO) {
ch = prefs_get_omemo_char();
}
if (g_slist_length(mentions) > 0) {
_mucwin_print_mention(window, message, nick, mynick, mentions, &ch);
} else if (triggers) {
win_print_them(window, THEME_ROOMTRIGGER, ch, nick);
_mucwin_print_triggers(window, message, triggers);
} else {
win_println_me_message(window, ch, mynick, "%s", message);
win_println_them_message(window, ch, nick, "%s", message);
}
}

View File

@ -162,7 +162,8 @@ void mucwin_occupant_role_and_affiliation_change(ProfMucWin *mucwin, const char
const char *const role, const char *const affiliation, const char *const actor, const char *const reason);
void mucwin_roster(ProfMucWin *mucwin, GList *occupants, const char *const presence);
void mucwin_history(ProfMucWin *mucwin, const char *const nick, GDateTime *timestamp, const char *const message);
void mucwin_message(ProfMucWin *mucwin, const char *const nick, const char *const message, GSList *mentions, GList *triggers);
void mucwin_outgoing_msg(ProfMucWin *mucwin, const char *const message, prof_enc_t enc_mode);
void mucwin_incoming_msg(ProfMucWin *mucwin, const char *const nick, const char *const message, GSList *mentions, GList *triggers, prof_enc_t enc_mode);
void mucwin_subject(ProfMucWin *mucwin, const char *const nick, const char *const subject);
void mucwin_requires_config(ProfMucWin *mucwin);
void mucwin_info(ProfMucWin *mucwin);

View File

@ -197,6 +197,7 @@ win_create_muc(const char *const roomjid)
}
new_win->enctext = NULL;
new_win->message_char = NULL;
new_win->is_omemo = FALSE;
new_win->memcheck = PROFMUCWIN_MEMCHECK;

View File

@ -729,8 +729,11 @@ _handle_groupchat(xmpp_stanza_t *const stanza)
return;
}
// check omemo encryption
gboolean omemo = FALSE;
#ifdef HAVE_OMEMO
message = omemo_receive_message(stanza);
omemo = message != NULL;
#endif
if (!message) {
@ -744,10 +747,10 @@ _handle_groupchat(xmpp_stanza_t *const stanza)
// determine if the notifications happened whilst offline
GDateTime *timestamp = stanza_get_delay(stanza);
if (timestamp) {
sv_ev_room_history(jid->barejid, jid->resourcepart, timestamp, message);
sv_ev_room_history(jid->barejid, jid->resourcepart, timestamp, message, omemo);
g_date_time_unref(timestamp);
} else {
sv_ev_room_message(jid->barejid, jid->resourcepart, message);
sv_ev_room_message(jid->barejid, jid->resourcepart, message, omemo);
}
xmpp_free(ctx, message);