diff --git a/spec/omemo.js b/spec/omemo.js index 55a4064c9..cd53526b9 100644 --- a/spec/omemo.js +++ b/spec/omemo.js @@ -16,7 +16,7 @@ function (done, _converse) { var sent_stanza; - let iq_stanza; + let iq_stanza, view; test_utils.createContacts(_converse, 'current', 1); _converse.emit('rosterContactsFetched'); const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost'; @@ -70,7 +70,7 @@ const devicelist = _converse.devicelists.create({'jid': contact_jid}); expect(devicelist.devices.length).toBe(1); - const view = _converse.chatboxviews.get(contact_jid); + view = _converse.chatboxviews.get(contact_jid); view.model.set('omemo_active', true); const textarea = view.el.querySelector('.chat-textarea'); @@ -167,8 +167,20 @@ .c('encrypted', {'xmlns': Strophe.NS.OMEMO}) .c('header', {'sid': '555'}) .c('key', {'rid': _converse.omemo_store.get('device_id')}).t('c1ph3R73X7').up() - .c('iv').t('1234'); + .c('iv').t('1234') + .up().up() + .c('payload').t('M04R-c1ph3R73X7'); _converse.connection._dataRecv(test_utils.createRequest(stanza)); + + expect(view.model.messages.length).toBe(2); + const last_msg = view.model.messages.at(1), + encrypted = last_msg.get('encrypted'); + + expect(encrypted instanceof Object).toBe(true); + expect(encrypted.device_id).toBe('555'); + expect(encrypted.iv).toBe('1234'); + expect(encrypted.key).toBe('c1ph3R73X7'); + expect(encrypted.payload).toBe('M04R-c1ph3R73X7'); done(); }); })); diff --git a/src/converse-chatboxes.js b/src/converse-chatboxes.js index e1bfb3f7f..376b500e3 100644 --- a/src/converse-chatboxes.js +++ b/src/converse-chatboxes.js @@ -480,11 +480,7 @@ if (attrs.type === 'groupchat') { attrs.from = stanza.getAttribute('from'); attrs.nick = Strophe.unescapeNode(Strophe.getResourceFromJid(attrs.from)); - if (Strophe.getResourceFromJid(attrs.from) === this.get('nick')) { - attrs.sender = 'me'; - } else { - attrs.sender = 'them'; - } + attrs.sender = attrs.nick === this.get('nick') ? 'me': 'them'; } else { attrs.from = Strophe.getBareJidFromJid(stanza.getAttribute('from')); if (attrs.from === _converse.bare_jid) { diff --git a/src/converse-omemo.js b/src/converse-omemo.js index 149cb9ff5..2e7d1b154 100644 --- a/src/converse-omemo.js +++ b/src/converse-omemo.js @@ -134,16 +134,14 @@ encrypted = sizzle(`encrypted[xmlns="${Strophe.NS.OMEMO}"]`, original_stanza).pop(); if (encrypted) { - const header = encrypted.firstElementChild; - if (header.nodeName != "header") { - throw new Error("Error parsing encrypted OMEMO message. Wrong format"); - } - const key = sizzle(`key[rid="${_converse.omemo_store.get('device_id')}"]`, encrypted).pop(); + const header = encrypted.querySelector('header'), + key = sizzle(`key[rid="${_converse.omemo_store.get('device_id')}"]`, encrypted).pop(); if (key) { attrs['encrypted'] = { 'device_id': header.getAttribute('sid'), 'iv': header.querySelector('iv').textContent, - 'key': key.textContent + 'key': key.textContent, + 'payload': _.get(encrypted.querySelector('payload'), 'textContent', null) } if (key.getAttribute('prekey') === 'true') { // TODO: