1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Add trusted state after OMEMO decryption

Use it to print message on red background if not trusted.
This commit is contained in:
Paul Fariello 2019-06-07 23:53:44 +02:00
parent 2604786cb6
commit a650ecc67d
7 changed files with 24 additions and 18 deletions

View File

@ -832,7 +832,7 @@ out:
char *
omemo_on_message_recv(const char *const from_jid, 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)
const unsigned char *const payload, size_t payload_len, gboolean muc, gboolean *trusted)
{
unsigned char *plaintext = NULL;
Jid *sender = NULL;

View File

@ -91,4 +91,4 @@ void omemo_start_device_session(const char *const jid, uint32_t device_id, GList
gboolean omemo_loaded(void);
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);
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, gboolean *trusted);

View File

@ -395,10 +395,6 @@ is_trusted_identity(const signal_protocol_address *address, uint8_t *key_data,
int ret;
identity_key_store_t *identity_key_store = (identity_key_store_t *)user_data;
if (identity_key_store->recv) {
return true;
}
GHashTable *trusted = g_hash_table_lookup(identity_key_store->trusted, address->name);
if (!trusted) {
if (identity_key_store->recv) {
@ -416,7 +412,13 @@ is_trusted_identity(const signal_protocol_address *address, uint8_t *key_data,
signal_buffer_free(buffer);
return ret;
if (identity_key_store->recv) {
identity_key_store->trusted = ret;
return 1;
} else {
return ret;
}
}
int

View File

@ -49,6 +49,7 @@ typedef struct {
uint32_t registration_id;
GHashTable *trusted;
bool recv;
bool trusted;
} identity_key_store_t;
GHashTable * session_store_new(void);

View File

@ -749,8 +749,9 @@ _handle_groupchat(xmpp_stanza_t *const stanza)
// check omemo encryption
gboolean omemo = FALSE;
gboolean trusted = FALSE;
#ifdef HAVE_OMEMO
message = omemo_receive_message(stanza);
message = omemo_receive_message(stanza, &trusted);
omemo = message != NULL;
#endif
@ -765,10 +766,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, omemo);
sv_ev_room_history(jid->barejid, jid->resourcepart, timestamp, message, omemo, trusted);
g_date_time_unref(timestamp);
} else {
sv_ev_room_message(jid->barejid, jid->resourcepart, message, id, omemo);
sv_ev_room_message(jid->barejid, jid->resourcepart, message, id, omemo, trusted);
}
xmpp_free(ctx, message);
@ -907,8 +908,9 @@ _handle_carbons(xmpp_stanza_t *const stanza)
// check omemo encryption
gboolean omemo = FALSE;
gboolean trusted = FALSE;
#ifdef HAVE_OMEMO
message_txt = omemo_receive_message(message);
message_txt = omemo_receive_message(message, &trusted);
omemo = message_txt != NULL;
#endif
@ -945,11 +947,11 @@ _handle_carbons(xmpp_stanza_t *const stanza)
// if we are the recipient, treat as standard incoming message
if (g_strcmp0(my_jid->barejid, jid_to->barejid) == 0) {
sv_ev_incoming_carbon(jid_from->barejid, jid_from->resourcepart, message_txt, enc_message, omemo);
sv_ev_incoming_carbon(jid_from->barejid, jid_from->resourcepart, message_txt, enc_message, omemo, trusted);
// else treat as a sent message
} else {
sv_ev_outgoing_carbon(jid_to->barejid, message_txt, enc_message, omemo);
sv_ev_outgoing_carbon(jid_to->barejid, message_txt, enc_message, omemo, trusted);
}
xmpp_ctx_t *ctx = connection_get_ctx();
@ -981,8 +983,9 @@ _handle_chat(xmpp_stanza_t *const stanza)
// check omemo encryption
gboolean omemo = FALSE;
gboolean trusted = FALSE;
#ifdef HAVE_OMEMO
message = omemo_receive_message(stanza);
message = omemo_receive_message(stanza, &trusted);
omemo = message != NULL;
#endif
@ -1025,7 +1028,7 @@ _handle_chat(xmpp_stanza_t *const stanza)
if (x) {
enc_message = xmpp_stanza_get_text(x);
}
sv_ev_incoming_message(jid->barejid, jid->resourcepart, message, enc_message, timestamp, omemo);
sv_ev_incoming_message(jid->barejid, jid->resourcepart, message, enc_message, timestamp, omemo, trusted);
xmpp_free(ctx, enc_message);
_receipt_request_handler(stanza);

View File

@ -237,7 +237,7 @@ omemo_start_device_session_handle_bundle(xmpp_stanza_t *const stanza, void *cons
}
char *
omemo_receive_message(xmpp_stanza_t *const stanza)
omemo_receive_message(xmpp_stanza_t *const stanza, gboolean *trusted)
{
const char *type = xmpp_stanza_get_type(stanza);
@ -312,7 +312,7 @@ skip:
char *plaintext = omemo_on_message_recv(from, sid, iv_raw, iv_len,
keys, payload_raw, payload_len,
g_strcmp0(type, STANZA_TYPE_GROUPCHAT) == 0);
g_strcmp0(type, STANZA_TYPE_GROUPCHAT) == 0, trusted);
g_list_free_full(keys, (GDestroyNotify)omemo_key_free);
g_free(iv_raw);

View File

@ -8,4 +8,4 @@ void omemo_devicelist_request(const char * const jid);
void omemo_bundle_publish(gboolean first);
void omemo_bundle_request(const char * const jid, uint32_t device_id, ProfIqCallback func, ProfIqFreeCallback free_func, void *userdata);
int omemo_start_device_session_handle_bundle(xmpp_stanza_t *const stanza, void *const userdata);
char * omemo_receive_message(xmpp_stanza_t *const stanza);
char * omemo_receive_message(xmpp_stanza_t *const stanza, gboolean *trusted);