xep_0384: Add publish-options when publishing devices and bundles
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
parent
e9717cd652
commit
a72e81c329
1 changed files with 33 additions and 2 deletions
|
@ -18,6 +18,7 @@ import json
|
||||||
import base64
|
import base64
|
||||||
import asyncio
|
import asyncio
|
||||||
from slixmpp.plugins.xep_0060.stanza import Items, EventItems
|
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.plugins.base import BasePlugin, register_plugin
|
||||||
from slixmpp.exceptions import IqError, IqTimeout
|
from slixmpp.exceptions import IqError, IqTimeout
|
||||||
from slixmpp.stanza import Message, Iq
|
from slixmpp.stanza import Message, Iq
|
||||||
|
@ -113,6 +114,21 @@ def _generate_encrypted_payload(encrypted) -> Encrypted:
|
||||||
return tag
|
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?
|
# XXX: This should probably be moved in plugins/base.py?
|
||||||
class PluginCouldNotLoad(Exception): pass
|
class PluginCouldNotLoad(Exception): pass
|
||||||
|
|
||||||
|
@ -152,7 +168,7 @@ class XEP_0384(BasePlugin):
|
||||||
|
|
||||||
name = 'xep_0384'
|
name = 'xep_0384'
|
||||||
description = 'XEP-0384 OMEMO'
|
description = 'XEP-0384 OMEMO'
|
||||||
dependencies = {'xep_0060', 'xep_0163'}
|
dependencies = {'xep_0004', 'xep_0060', 'xep_0163'}
|
||||||
default_config = {
|
default_config = {
|
||||||
'data_dir': None,
|
'data_dir': None,
|
||||||
'storage_backend': None,
|
'storage_backend': None,
|
||||||
|
@ -216,7 +232,13 @@ class XEP_0384(BasePlugin):
|
||||||
def _generate_bundle_iq(self) -> Iq:
|
def _generate_bundle_iq(self) -> Iq:
|
||||||
bundle = self._omemo.public_bundle.serialize(self.omemo_backend)
|
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 = self.xmpp.Iq(stype='set')
|
||||||
|
iq['pubsub']['publish_options'] = options
|
||||||
publish = iq['pubsub']['publish']
|
publish = iq['pubsub']['publish']
|
||||||
publish['node'] = '%s:%d' % (OMEMO_BUNDLES_NS, self._device_id)
|
publish['node'] = '%s:%d' % (OMEMO_BUNDLES_NS, self._device_id)
|
||||||
payload = publish['item']['bundle']
|
payload = publish['item']['bundle']
|
||||||
|
@ -314,8 +336,17 @@ class XEP_0384(BasePlugin):
|
||||||
payload = Devices()
|
payload = Devices()
|
||||||
payload['devices'] = 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(
|
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]:
|
def get_device_list(self, jid: JID) -> List[str]:
|
||||||
|
|
Loading…
Reference in a new issue