From 85dab7367be531ca611fb3fae995833f87f43565 Mon Sep 17 00:00:00 2001 From: JC Brand Date: Wed, 19 Dec 2018 08:14:58 +0100 Subject: [PATCH] Use `pubsub#access_model` to publish keys and devices publically --- dist/converse.js | 36 ++++++++----------- spec/omemo.js | 84 ++++++++++++++++++++++++++++++++++++++++++- src/converse-omemo.js | 40 +++++++++------------ 3 files changed, 114 insertions(+), 46 deletions(-) diff --git a/dist/converse.js b/dist/converse.js index 0d879b499..8134f9820 100644 --- a/dist/converse.js +++ b/dist/converse.js @@ -55970,6 +55970,7 @@ const _converse$env = _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_ Strophe = _converse$env.Strophe, moment = _converse$env.moment, sizzle = _converse$env.sizzle, + $build = _converse$env.$build, $iq = _converse$env.$iq, $msg = _converse$env.$msg, _ = _converse$env._, @@ -56758,24 +56759,21 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins publishBundle() { const signed_prekey = this.get('signed_prekey'); - const stanza = $iq({ - 'from': _converse.bare_jid, - 'type': 'set' - }).c('pubsub', { - 'xmlns': Strophe.NS.PUBSUB - }).c('publish', { - 'node': `${Strophe.NS.OMEMO_BUNDLES}:${this.get('device_id')}` - }).c('item').c('bundle', { + const node = `${Strophe.NS.OMEMO_BUNDLES}:${this.get('device_id')}`; + const item = $build('item').c('bundle', { 'xmlns': Strophe.NS.OMEMO }).c('signedPreKeyPublic', { 'signedPreKeyId': signed_prekey.id }).t(signed_prekey.pubKey).up().c('signedPreKeySignature').t(signed_prekey.signature).up().c('identityKey').t(this.get('identity_keypair').pubKey).up().c('prekeys'); - _.forEach(this.get('prekeys'), (prekey, id) => stanza.c('preKeyPublic', { + _.forEach(this.get('prekeys'), (prekey, id) => item.c('preKeyPublic', { 'preKeyId': id }).t(prekey.pubKey).up()); - return _converse.api.sendIQ(stanza); + const options = { + 'pubsub#access_model': 'open' + }; + return _converse.api.pubsub.publish(null, node, item, options); }, generateMissingPreKeys() { @@ -57013,20 +57011,16 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins }, publishDevices() { - const stanza = $iq({ - 'from': _converse.bare_jid, - 'type': 'set' - }).c('pubsub', { - 'xmlns': Strophe.NS.PUBSUB - }).c('publish', { - 'node': Strophe.NS.OMEMO_DEVICELIST - }).c('item').c('list', { + const item = $build('item').c('list', { 'xmlns': Strophe.NS.OMEMO }); - this.devices.each(device => stanza.c('device', { - 'id': device.get('id') + this.devices.each(d => item.c('device', { + 'id': d.get('id') }).up()); - return _converse.api.sendIQ(stanza); + const options = { + 'pubsub#access_model': 'open' + }; + return _converse.api.pubsub.publish(null, Strophe.NS.OMEMO_DEVICELIST, item, options, false); }, removeOwnDevices(device_ids) { diff --git a/spec/omemo.js b/spec/omemo.js index 5e6625808..1136dde72 100644 --- a/spec/omemo.js +++ b/spec/omemo.js @@ -34,6 +34,11 @@ } async function initializedOMEMO (_converse) { + await test_utils.waitUntilDiscoConfirmed( + _converse, _converse.bare_jid, + [{'category': 'pubsub', 'type': 'pep'}], + ['http://jabber.org/protocol/pubsub#publish-options'] + ); let iq_stanza = await test_utils.waitUntil(() => deviceListFetched(_converse, _converse.bare_jid)); let stanza = $iq({ 'from': _converse.bare_jid, @@ -427,6 +432,7 @@ _converse.connection.IQ_stanzas = []; _converse.connection._dataRecv(test_utils.createRequest(stanza)); await test_utils.waitUntil(() => _converse.omemo_store); + iq_stanza = await test_utils.waitUntil(() => bundleHasBeenPublished(_converse)); expect(iq_stanza.toLocaleString()).toBe( ``+ @@ -447,6 +453,16 @@ ``+ ``+ ``+ + ``+ + ``+ + ``+ + `http://jabber.org/protocol/pubsub#publish-options`+ + ``+ + ``+ + `open`+ + ``+ + ``+ + ``+ ``+ ``) const own_device = _converse.devicelists.get(_converse.bare_jid).devices.get(_converse.omemo_store.get('device_id')); @@ -461,6 +477,12 @@ null, ['rosterGroupsFetched'], {'allow_non_roster_messaging': true}, async function (done, _converse) { + await test_utils.waitUntilDiscoConfirmed( + _converse, _converse.bare_jid, + [{'category': 'pubsub', 'type': 'pep'}], + ['http://jabber.org/protocol/pubsub#publish-options'] + ); + test_utils.createContacts(_converse, 'current', 1); const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost'; @@ -592,6 +614,16 @@ ``+ ``+ ``+ + ``+ + ``+ + ``+ + `http://jabber.org/protocol/pubsub#publish-options`+ + ``+ + ``+ + `open`+ + ``+ + ``+ + ``+ ``+ ``); expect(_converse.devicelists.length).toBe(2); @@ -609,6 +641,12 @@ null, ['rosterGroupsFetched'], {}, async function (done, _converse) { + await test_utils.waitUntilDiscoConfirmed( + _converse, _converse.bare_jid, + [{'category': 'pubsub', 'type': 'pep'}], + ['http://jabber.org/protocol/pubsub#publish-options'] + ); + test_utils.createContacts(_converse, 'current'); const contact_jid = mock.cur_names[3].replace(/ /g,'.').toLowerCase() + '@localhost'; let iq_stanza = await test_utils.waitUntil(() => deviceListFetched(_converse, _converse.bare_jid)); @@ -753,6 +791,12 @@ null, ['rosterGroupsFetched', 'chatBoxesFetched'], {}, async function (done, _converse) { + await test_utils.waitUntilDiscoConfirmed( + _converse, _converse.bare_jid, + [{'category': 'pubsub', 'type': 'pep'}], + ['http://jabber.org/protocol/pubsub#publish-options'] + ); + _converse.NUM_PREKEYS = 2; // Restrict to 2, otherwise the resulting stanza is too large to easily test test_utils.createContacts(_converse, 'current', 1); @@ -797,6 +841,16 @@ ``+ ``+ ``+ + ``+ + ``+ + ``+ + `http://jabber.org/protocol/pubsub#publish-options`+ + ``+ + ``+ + `open`+ + ``+ + ``+ + ``+ ``+ ``) @@ -816,6 +870,12 @@ null, ['rosterGroupsFetched', 'chatBoxesFetched'], {}, async function (done, _converse) { + await test_utils.waitUntilDiscoConfirmed( + _converse, _converse.bare_jid, + [{'category': 'pubsub', 'type': 'pep'}], + ['http://jabber.org/protocol/pubsub#publish-options'] + ); + test_utils.createContacts(_converse, 'current', 1); _converse.emit('rosterContactsFetched'); const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost'; @@ -858,7 +918,17 @@ ``+ ``+ ``+ - ``+ + ``+ + ``+ + ``+ + `http://jabber.org/protocol/pubsub#publish-options`+ + ``+ + ``+ + `open`+ + ``+ + ``+ + ``+ + ``+ ``); stanza = $iq({ @@ -965,6 +1035,12 @@ null, ['rosterGroupsFetched', 'chatBoxesFetched'], {'view_mode': 'fullscreen'}, async function (done, _converse) { + await test_utils.waitUntilDiscoConfirmed( + _converse, _converse.bare_jid, + [{'category': 'pubsub', 'type': 'pep'}], + ['http://jabber.org/protocol/pubsub#publish-options'] + ); + // MEMO encryption works only in members-only conferences that are non-anonymous. const features = [ 'http://jabber.org/protocol/muc', @@ -1147,6 +1223,12 @@ null, ['rosterGroupsFetched', 'chatBoxesFetched'], {}, async function (done, _converse) { + await test_utils.waitUntilDiscoConfirmed( + _converse, _converse.bare_jid, + [{'category': 'pubsub', 'type': 'pep'}], + ['http://jabber.org/protocol/pubsub#publish-options'] + ); + test_utils.createContacts(_converse, 'current', 1); _converse.emit('rosterContactsFetched'); const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost'; diff --git a/src/converse-omemo.js b/src/converse-omemo.js index ce6135aa2..9d8c44627 100644 --- a/src/converse-omemo.js +++ b/src/converse-omemo.js @@ -9,7 +9,7 @@ import converse from "@converse/headless/converse-core"; import tpl_toolbar_omemo from "templates/toolbar_omemo.html"; -const { Backbone, Promise, Strophe, moment, sizzle, $iq, $msg, _, f, b64_sha1 } = converse.env; +const { Backbone, Promise, Strophe, moment, sizzle, $build, $iq, $msg, _, f, b64_sha1 } = converse.env; const u = converse.env.utils; Strophe.addNamespace('OMEMO_DEVICELIST', Strophe.NS.OMEMO+".devicelist"); @@ -750,23 +750,20 @@ converse.plugins.add('converse-omemo', { publishBundle () { const signed_prekey = this.get('signed_prekey'); - const stanza = $iq({ - 'from': _converse.bare_jid, - 'type': 'set' - }).c('pubsub', {'xmlns': Strophe.NS.PUBSUB}) - .c('publish', {'node': `${Strophe.NS.OMEMO_BUNDLES}:${this.get('device_id')}`}) - .c('item') - .c('bundle', {'xmlns': Strophe.NS.OMEMO}) - .c('signedPreKeyPublic', {'signedPreKeyId': signed_prekey.id}) - .t(signed_prekey.pubKey).up() - .c('signedPreKeySignature').t(signed_prekey.signature).up() - .c('identityKey').t(this.get('identity_keypair').pubKey).up() - .c('prekeys'); + const node = `${Strophe.NS.OMEMO_BUNDLES}:${this.get('device_id')}`; + const item = $build('item') + .c('bundle', {'xmlns': Strophe.NS.OMEMO}) + .c('signedPreKeyPublic', {'signedPreKeyId': signed_prekey.id}) + .t(signed_prekey.pubKey).up() + .c('signedPreKeySignature').t(signed_prekey.signature).up() + .c('identityKey').t(this.get('identity_keypair').pubKey).up() + .c('prekeys'); _.forEach( this.get('prekeys'), - (prekey, id) => stanza.c('preKeyPublic', {'preKeyId': id}).t(prekey.pubKey).up() + (prekey, id) => item.c('preKeyPublic', {'preKeyId': id}).t(prekey.pubKey).up() ); - return _converse.api.sendIQ(stanza); + const options = {'pubsub#access_model': 'open'}; + return _converse.api.pubsub.publish(null, node, item, options); }, generateMissingPreKeys () { @@ -967,15 +964,10 @@ converse.plugins.add('converse-omemo', { }, publishDevices () { - const stanza = $iq({ - 'from': _converse.bare_jid, - 'type': 'set' - }).c('pubsub', {'xmlns': Strophe.NS.PUBSUB}) - .c('publish', {'node': Strophe.NS.OMEMO_DEVICELIST}) - .c('item') - .c('list', {'xmlns': Strophe.NS.OMEMO}) - this.devices.each(device => stanza.c('device', {'id': device.get('id')}).up()); - return _converse.api.sendIQ(stanza); + const item = $build('item').c('list', {'xmlns': Strophe.NS.OMEMO}) + this.devices.each(d => item.c('device', {'id': d.get('id')}).up()); + const options = {'pubsub#access_model': 'open'}; + return _converse.api.pubsub.publish(null, Strophe.NS.OMEMO_DEVICELIST, item, options, false); }, removeOwnDevices (device_ids) {