From 0e65c68371f01b323bc662baca82cf654322c00e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Sat, 24 Aug 2019 00:13:41 +0200 Subject: [PATCH] Check for publish-options support and add them in devicelist and bundle set operations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ensure that publish-options are added at the end in the pubsub request, otherwise it seems to be invalid. Signed-off-by: Maxime “pep” Buquet --- slixmpp_omemo/__init__.py | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/slixmpp_omemo/__init__.py b/slixmpp_omemo/__init__.py index 711d3d4..f313ab2 100644 --- a/slixmpp_omemo/__init__.py +++ b/slixmpp_omemo/__init__.py @@ -241,13 +241,6 @@ class XEP_0384(BasePlugin): iq = self.xmpp.Iq(stype='set') - if publish_options: - options = _make_publish_options_form({ - 'pubsub#persist_items': True, - 'pubsub#access_model': 'open', - }) - iq['pubsub']['publish_options'] = options - publish = iq['pubsub']['publish'] publish['node'] = '%s:%d' % (OMEMO_BUNDLES_NS, self._device_id) payload = publish['item']['bundle'] @@ -268,6 +261,13 @@ class XEP_0384(BasePlugin): prekeys.append(prekey) payload['prekeys'] = prekeys + if publish_options: + options = _make_publish_options_form({ + 'pubsub#persist_items': True, + 'pubsub#access_model': 'open', + }) + iq['pubsub']['publish_options'] = options + return iq async def _publish_bundle(self) -> None: @@ -348,14 +348,19 @@ class XEP_0384(BasePlugin): payload = Devices() payload['devices'] = devices - options = _make_publish_options_form({ - 'pubsub#persist_items': True, - # Everybody will be able to encrypt for us, without having to add - # us into their roster. This obviously leaks the number of devices - # and the associated metadata of us pushing new device lists every - # so often. - 'pubsub#access_model': 'open', - }) + jid = self.xmpp.boundjid + disco = await self.xmpp['xep_0030'].get_info(jid.bare) + publish_options = PUBLISH_OPTIONS_NODE in disco['disco_info'].get_features() + + if publish_options: + options = _make_publish_options_form({ + 'pubsub#persist_items': True, + # Everybody will be able to encrypt for us, without having to add + # us into their roster. This obviously leaks the number of devices + # and the associated metadata of us pushing new device lists every + # so often. + 'pubsub#access_model': 'open', + }) await self.xmpp['xep_0060'].publish( own_jid.bare, OMEMO_DEVICES_NS, payload=payload, options=options,