Commit a72e81c3 authored by Maxime Buquet's avatar Maxime Buquet

xep_0384: Add publish-options when publishing devices and bundles

Signed-off-by: Maxime Buquet's avatarMaxime “pep” Buquet <>
parent e9717cd6
......@@ -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'
for var, value in fields.items():
options.add_field(var=var, value=value)
return options
# XXX: This should probably be moved in plugins/
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]:
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