mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-30 10:26:22 +00:00
feat: Provide descriptive fallback messages for OMEMO decryption failures
If an incoming OMEMO message failed to decrypt (due to missing session keys or untrusted identities), Profanity would fall back to displaying the raw XMPP body. This usually contained a generic string like "This message is encrypted with OMEMO,". We wrote the detailed reason in the debug logs but the user only saw the fallback message and probably wondered *why* the message wasn't displayed properly. I'm unsure if we should display the fallback message as well though.
This commit is contained in:
@@ -350,7 +350,7 @@ out:
|
||||
}
|
||||
|
||||
char*
|
||||
omemo_receive_message(xmpp_stanza_t* const stanza, gboolean* trusted)
|
||||
omemo_receive_message(xmpp_stanza_t* const stanza, gboolean* trusted, omemo_error_t* error)
|
||||
{
|
||||
char* plaintext = NULL;
|
||||
const char* type = xmpp_stanza_get_type(stanza);
|
||||
@@ -360,6 +360,10 @@ omemo_receive_message(xmpp_stanza_t* const stanza, gboolean* trusted)
|
||||
char* iv_text = NULL;
|
||||
char* payload_text = NULL;
|
||||
|
||||
if (error) {
|
||||
*error = OMEMO_ERR_NONE;
|
||||
}
|
||||
|
||||
xmpp_stanza_t* encrypted = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_OMEMO);
|
||||
if (!encrypted) {
|
||||
return NULL;
|
||||
@@ -367,40 +371,64 @@ omemo_receive_message(xmpp_stanza_t* const stanza, gboolean* trusted)
|
||||
|
||||
xmpp_stanza_t* header = xmpp_stanza_get_child_by_name(encrypted, "header");
|
||||
if (!header) {
|
||||
if (error) {
|
||||
*error = OMEMO_ERR_OTHER;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* sid_text = xmpp_stanza_get_attribute(header, "sid");
|
||||
if (!sid_text) {
|
||||
if (error) {
|
||||
*error = OMEMO_ERR_OTHER;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
uint32_t sid = strtoul(sid_text, NULL, 10);
|
||||
|
||||
xmpp_stanza_t* iv = xmpp_stanza_get_child_by_name(header, "iv");
|
||||
if (!iv) {
|
||||
if (error) {
|
||||
*error = OMEMO_ERR_OTHER;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
iv_text = xmpp_stanza_get_text(iv);
|
||||
if (!iv_text) {
|
||||
if (error) {
|
||||
*error = OMEMO_ERR_OTHER;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
size_t iv_len;
|
||||
iv_raw = g_base64_decode(iv_text, &iv_len);
|
||||
if (!iv_raw) {
|
||||
if (error) {
|
||||
*error = OMEMO_ERR_OTHER;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
xmpp_stanza_t* payload = xmpp_stanza_get_child_by_name(encrypted, "payload");
|
||||
if (!payload) {
|
||||
if (error) {
|
||||
*error = OMEMO_ERR_OTHER;
|
||||
}
|
||||
goto quit;
|
||||
}
|
||||
payload_text = xmpp_stanza_get_text(payload);
|
||||
if (!payload_text) {
|
||||
if (error) {
|
||||
*error = OMEMO_ERR_OTHER;
|
||||
}
|
||||
goto quit;
|
||||
}
|
||||
size_t payload_len;
|
||||
payload_raw = g_base64_decode(payload_text, &payload_len);
|
||||
if (!payload_raw) {
|
||||
if (error) {
|
||||
*error = OMEMO_ERR_OTHER;
|
||||
}
|
||||
goto quit;
|
||||
}
|
||||
|
||||
@@ -439,7 +467,7 @@ omemo_receive_message(xmpp_stanza_t* const stanza, gboolean* trusted)
|
||||
|
||||
plaintext = omemo_on_message_recv(from, sid, iv_raw, iv_len,
|
||||
keys, payload_raw, payload_len,
|
||||
g_strcmp0(type, STANZA_TYPE_GROUPCHAT) == 0, trusted);
|
||||
g_strcmp0(type, STANZA_TYPE_GROUPCHAT) == 0, trusted, error);
|
||||
|
||||
if (keys) {
|
||||
g_list_free_full(keys, (GDestroyNotify)omemo_key_free);
|
||||
|
||||
Reference in New Issue
Block a user