diff options
author | Paul Fariello <paul@fariello.eu> | 2019-06-07 23:53:44 +0200 |
---|---|---|
committer | Paul Fariello <paul@fariello.eu> | 2019-06-20 14:29:55 +0200 |
commit | a650ecc67d700ae14a1bd05ca6196533829ba5ce (patch) | |
tree | cf7ffbe8db598e9f313fc739757b9daf44a83ce3 /src | |
parent | 2604786cb6fcf1c541000a971c59d709ef12abf5 (diff) | |
download | profani-tty-a650ecc67d700ae14a1bd05ca6196533829ba5ce.tar.gz |
Add trusted state after OMEMO decryption
Use it to print message on red background if not trusted.
Diffstat (limited to 'src')
-rw-r--r-- | src/omemo/omemo.c | 2 | ||||
-rw-r--r-- | src/omemo/omemo.h | 2 | ||||
-rw-r--r-- | src/omemo/store.c | 12 | ||||
-rw-r--r-- | src/omemo/store.h | 1 | ||||
-rw-r--r-- | src/xmpp/message.c | 19 | ||||
-rw-r--r-- | src/xmpp/omemo.c | 4 | ||||
-rw-r--r-- | src/xmpp/omemo.h | 2 |
7 files changed, 24 insertions, 18 deletions
diff --git a/src/omemo/omemo.c b/src/omemo/omemo.c index 4b65aebb..ba17fe51 100644 --- a/src/omemo/omemo.c +++ b/src/omemo/omemo.c @@ -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; diff --git a/src/omemo/omemo.h b/src/omemo/omemo.h index 0a98c568..ae25b5ba 100644 --- a/src/omemo/omemo.h +++ b/src/omemo/omemo.h @@ -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); diff --git a/src/omemo/store.c b/src/omemo/store.c index 04704a0e..51d5e67a 100644 --- a/src/omemo/store.c +++ b/src/omemo/store.c @@ -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 diff --git a/src/omemo/store.h b/src/omemo/store.h index f3a9274a..628b1df9 100644 --- a/src/omemo/store.h +++ b/src/omemo/store.h @@ -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); diff --git a/src/xmpp/message.c b/src/xmpp/message.c index 9f0ffb2b..bb3733a6 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -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); diff --git a/src/xmpp/omemo.c b/src/xmpp/omemo.c index ccf3c55b..cfa3f84c 100644 --- a/src/xmpp/omemo.c +++ b/src/xmpp/omemo.c @@ -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); diff --git a/src/xmpp/omemo.h b/src/xmpp/omemo.h index f1fff7b7..8d796a02 100644 --- a/src/xmpp/omemo.h +++ b/src/xmpp/omemo.h @@ -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); |