Commit 85dab736 authored by JC Brand's avatar JC Brand

Use `pubsub#access_model` to publish keys and devices publically

parent 0b258003
......@@ -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) {
......@@ -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(
`<iq from="dummy@localhost" id="${iq_stanza.nodeTree.getAttribute("id")}" type="set" xmlns="jabber:client">`+
......@@ -447,6 +453,16 @@
`</bundle>`+
`</item>`+
`</publish>`+
`<publish-options>`+
`<x type="submit" xmlns="jabber:x:data">`+
`<field type="hidden" var="FORM_TYPE">`+
`<value>http://jabber.org/protocol/pubsub#publish-options</value>`+
`</field>`+
`<field var="pubsub#access_model">`+
`<value>open</value>`+
`</field>`+
`</x>`+
`</publish-options>`+
`</pubsub>`+
`</iq>`)
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 @@
`</list>`+
`</item>`+
`</publish>`+
`<publish-options>`+
`<x type="submit" xmlns="jabber:x:data">`+
`<field type="hidden" var="FORM_TYPE">`+
`<value>http://jabber.org/protocol/pubsub#publish-options</value>`+
`</field>`+
`<field var="pubsub#access_model">`+
`<value>open</value>`+
`</field>`+
`</x>`+
`</publish-options>`+
`</pubsub>`+
`</iq>`);
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 @@
`</bundle>`+
`</item>`+
`</publish>`+
`<publish-options>`+
`<x type="submit" xmlns="jabber:x:data">`+
`<field type="hidden" var="FORM_TYPE">`+
`<value>http://jabber.org/protocol/pubsub#publish-options</value>`+
`</field>`+
`<field var="pubsub#access_model">`+
`<value>open</value>`+
`</field>`+
`</x>`+
`</publish-options>`+
`</pubsub>`+
`</iq>`)
......@@ -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 @@
`</list>`+
`</item>`+
`</publish>`+
`</pubsub>`+
`<publish-options>`+
`<x type="submit" xmlns="jabber:x:data">`+
`<field type="hidden" var="FORM_TYPE">`+
`<value>http://jabber.org/protocol/pubsub#publish-options</value>`+
`</field>`+
`<field var="pubsub#access_model">`+
`<value>open</value>`+
`</field>`+
`</x>`+
`</publish-options>`+
`</pubsub>`+
`</iq>`);
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';
......
......@@ -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) {
......
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