Skip to content

Commit

Permalink
Compose KeyTransport message correctly
Browse files Browse the repository at this point in the history
Simply calling omemo_message_create() cannot compose a valid
KeyTransport message, which should at least have an ordinary "message"
node, so we should first make up such message without a "body", then
let omemo_message_prepare_encryption() of libomemo hamdle such case:

gkdr/libomemo#33

Signed-off-by: HardenedVault <[email protected]>
  • Loading branch information
root-hardenedvault committed Feb 11, 2021
1 parent d7edc8f commit 27cceca
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/lurch.c
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,9 @@ static void lurch_pep_bundle_for_keytransport(JabberStream * js_p, const char *
lurch_addr laddr = {0};
axc_buf * key_ct_buf_p = (void *) 0;
char * msg_xml = (void *) 0;
int len = 0;
xmlnode * msg_node_p = (void *) 0;
char * msg_id = (void *) 0;
void * jabber_handle_p = purple_plugins_find_with_id("prpl-jabber");

uname = lurch_util_uname_strip(purple_account_get_username(purple_connection_get_account(js_p->gc)));
Expand Down Expand Up @@ -842,9 +844,21 @@ static void lurch_pep_bundle_for_keytransport(JabberStream * js_p, const char *
goto cleanup;
}

ret_val = omemo_message_create(own_id, &crypto, &msg_p);
//compose a message without body as template
msg_node_p = xmlnode_new("message");
xmlnode_set_attrib(msg_node_p, "type", "chat");
msg_id = jabber_get_next_id(js_p);
xmlnode_set_attrib(msg_node_p, "id", msg_id);
xmlnode_set_attrib(msg_node_p, "to", from);

msg_xml = xmlnode_to_str(msg_node_p, &len);
ret_val = omemo_message_prepare_encryption(msg_xml, own_id, &crypto, OMEMO_STRIP_ALL, &msg_p);
xmlnode_free(msg_node_p);
msg_node_p = (void *) 0;
g_free(msg_xml);
msg_xml = (void *) 0;
if (ret_val) {
err_msg_dbg = g_strdup_printf("failed to create omemo msg");
err_msg_dbg = g_strdup_printf("failed to create omemo key transport msg for %s", from);
goto cleanup;
}

Expand Down Expand Up @@ -891,6 +905,7 @@ static void lurch_pep_bundle_for_keytransport(JabberStream * js_p, const char *
}
g_free(laddr.jid);
g_free(uname);
g_free(msg_id);
axc_context_destroy_all(axc_ctx_p);
omemo_message_destroy(msg_p);
axc_buf_free(key_ct_buf_p);
Expand Down

0 comments on commit 27cceca

Please sign in to comment.