xep_0384: Add publish-options when publishing devices and bundles

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2019-02-24 12:23:39 +00:00
parent e9717cd652
commit a72e81c329
Signed by: pep
GPG key ID: DEDA74AEECA9D0F2

View file

@ -18,6 +18,7 @@ import json
import base64
import asyncio
from slixmpp.plugins.xep_0060.stanza import Items, EventItems
from slixmpp.plugins.xep_0004 import Form
from slixmpp.plugins.base import BasePlugin, register_plugin
from slixmpp.exceptions import IqError, IqTimeout
from slixmpp.stanza import Message, Iq
@ -113,6 +114,21 @@ def _generate_encrypted_payload(encrypted) -> Encrypted:
return tag
def _make_publish_options_form(fields: Dict[str, Any]) -> Form:
options = Form()
options['type'] = 'submit'
options.add_field(
var='FORM_TYPE',
ftype='hidden',
value='http://jabber.org/protocol/pubsub#publish-options',
)
for var, value in fields.items():
options.add_field(var=var, value=value)
return options
# XXX: This should probably be moved in plugins/base.py?
class PluginCouldNotLoad(Exception): pass
@ -152,7 +168,7 @@ class XEP_0384(BasePlugin):
name = 'xep_0384'
description = 'XEP-0384 OMEMO'
dependencies = {'xep_0060', 'xep_0163'}
dependencies = {'xep_0004', 'xep_0060', 'xep_0163'}
default_config = {
'data_dir': None,
'storage_backend': None,
@ -216,7 +232,13 @@ class XEP_0384(BasePlugin):
def _generate_bundle_iq(self) -> Iq:
bundle = self._omemo.public_bundle.serialize(self.omemo_backend)
options = _make_publish_options_form({
'pubsub#persist_items': True,
'pubsub#access_model': 'open',
})
iq = self.xmpp.Iq(stype='set')
iq['pubsub']['publish_options'] = options
publish = iq['pubsub']['publish']
publish['node'] = '%s:%d' % (OMEMO_BUNDLES_NS, self._device_id)
payload = publish['item']['bundle']
@ -314,8 +336,17 @@ 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',
})
await self.xmpp['xep_0060'].publish(
own_jid.bare, OMEMO_DEVICES_NS, payload=payload,
own_jid.bare, OMEMO_DEVICES_NS, payload=payload, options=options,
)
def get_device_list(self, jid: JID) -> List[str]: