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 * char *
omemo_on_message_recv(const char *const from_jid, uint32_t sid, 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 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; unsigned char *plaintext = NULL;
Jid *sender = 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); gboolean omemo_loaded(void);
char * 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); 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; int ret;
identity_key_store_t *identity_key_store = (identity_key_store_t *)user_data; 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); GHashTable *trusted = g_hash_table_lookup(identity_key_store->trusted, address->name);
if (!trusted) { if (!trusted) {
if (identity_key_store->recv) { if (identity_key_store->recv) {
@ -416,8 +412,14 @@ is_trusted_identity(const signal_protocol_address *address, uint8_t *key_data,
signal_buffer_free(buffer); signal_buffer_free(buffer);
if (identity_key_store->recv) {
identity_key_store->trusted = ret;
return 1;
} else {
return ret; return ret;
} }
}
int int
store_sender_key(const signal_protocol_sender_key_name *sender_key_name, store_sender_key(const signal_protocol_sender_key_name *sender_key_name,

View File

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

View File

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

View File

@ -237,7 +237,7 @@ omemo_start_device_session_handle_bundle(xmpp_stanza_t *const stanza, void *cons
} }
char * 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); 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, char *plaintext = omemo_on_message_recv(from, sid, iv_raw, iv_len,
keys, payload_raw, payload_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_list_free_full(keys, (GDestroyNotify)omemo_key_free);
g_free(iv_raw); 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_publish(gboolean first);
void omemo_bundle_request(const char * const jid, uint32_t device_id, ProfIqCallback func, ProfIqFreeCallback free_func, void *userdata); 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); 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);