Commit e3b2125e authored by Richard Bayerle's avatar Richard Bayerle
Browse files

Stop checking order of <key> and <iv> elements in header

This should fix compatibility issues with Dino.
parent 3ab199ce
Pipeline #30218 canceled with stages
......@@ -1364,9 +1364,9 @@ int omemo_message_get_encrypted_key(omemo_message * msg_p, uint32_t own_device_i
const char * key_b64 = (void *) 0;
size_t key_len = 0;
ret_val = expect_next_node(msg_p->header_node_p, mxmlGetFirstChild, KEY_NODE_NAME, &key_node_p);
if (ret_val) {
key_node_p = mxmlFindElement(msg_p->header_node_p, msg_p->header_node_p, KEY_NODE_NAME, NULL, NULL, MXML_DESCEND);
if (!key_node_p) {
// if there is not at least one key, skip the rest of the function
ret_val = 0;
*key_pp = (void *) 0;
goto cleanup;
......@@ -1377,6 +1377,7 @@ int omemo_message_get_encrypted_key(omemo_message * msg_p, uint32_t own_device_i
goto cleanup;
}
while (key_node_p) {
if (!strncmp(rid_string, mxmlElementGetAttr(key_node_p, KEY_NODE_RID_ATTR_NAME), strlen(rid_string))) {
key_b64 = mxmlGetOpaque(key_node_p);
......@@ -1438,8 +1439,9 @@ int omemo_message_export_decrypted(omemo_message * msg_p, uint8_t * key_p, size_
}
payload_p = g_base64_decode(payload_b64, &payload_len);
ret_val = expect_next_node(msg_p->header_node_p, mxmlGetLastChild, IV_NODE_NAME, &iv_node_p);
if (ret_val) {
iv_node_p = mxmlFindElement(msg_p->header_node_p, msg_p->header_node_p, IV_NODE_NAME, NULL, NULL, MXML_DESCEND);
if (!iv_node_p) {
ret_val = OMEMO_ERR_MALFORMED_XML;
goto cleanup;
}
......
......@@ -790,6 +790,35 @@ void test_message_get_encrypted_key(void ** state) {
omemo_message_destroy(msg_p);
}
void test_message_get_encrypted_key_after_iv(void ** state) {
(void) state;
char * msg = "<message to='bob@example.com' from='alice@example.com'>"
"<encrypted xmlns='urn:xmpp:omemo:0'>"
"<header sid='1111'>"
"<iv>BASE64ENCODED</iv>"
"<key rid='2222'>sWsAtQ==</key>"
"</header>"
"<payload>BASE64ENCODED</payload>"
"</encrypted>"
"<store xmlns='urn:xmpp:hints'/>"
"</message>";
omemo_message * msg_p;
assert_int_equal(omemo_message_prepare_decryption(msg, &msg_p), 0);
uint8_t * key_p;
size_t key_len;
assert_int_equal(omemo_message_get_encrypted_key(msg_p, 1111, &key_p, &key_len), 0);
assert_ptr_equal(key_p, (void *) 0);
assert_int_equal(omemo_message_get_encrypted_key(msg_p, 2222, &key_p, &key_len), 0);
assert_int_equal(key_len, 4);
assert_memory_equal(key_p, data, key_len);
omemo_message_destroy(msg_p);
}
void test_message_get_encrypted_key_no_keys(void ** state) {
(void) state;
......@@ -1324,6 +1353,7 @@ int main(void) {
cmocka_unit_test(test_message_prepare_encryption_with_extra_data),
cmocka_unit_test(test_message_get_key),
cmocka_unit_test(test_message_get_encrypted_key),
cmocka_unit_test(test_message_get_encrypted_key_after_iv),
cmocka_unit_test(test_message_get_encrypted_key_no_keys),
cmocka_unit_test(test_message_add_recipient),
cmocka_unit_test(test_message_export_encrypted),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment