@@ -16,8 +16,8 @@ from gajim.common.connection_handlers_events import MessageNotSentEvent
|
|||||||
from gajim.plugins.plugins_i18n import _
|
from gajim.plugins.plugins_i18n import _
|
||||||
|
|
||||||
from omemo.xmpp import (
|
from omemo.xmpp import (
|
||||||
NS_NOTIFY, NS_OMEMO, NS_EME, NS_HINTS, BundleInformationAnnouncement,
|
NS_NOTIFY, NS_OMEMO, NS_EME, NS_HINTS, NS_BUNDLES,
|
||||||
BundleInformationQuery, DevicelistQuery,
|
BundleInformationQuery, DevicelistQuery, make_bundle,
|
||||||
OmemoMessage, successful, unpack_device_bundle,
|
OmemoMessage, successful, unpack_device_bundle,
|
||||||
unpack_device_list_update, unpack_encrypted, NS_DEVICE_LIST)
|
unpack_device_list_update, unpack_encrypted, NS_DEVICE_LIST)
|
||||||
from omemo.omemo.state import OmemoState
|
from omemo.omemo.state import OmemoState
|
||||||
@@ -811,12 +811,16 @@ class OMEMOConnection:
|
|||||||
def publish_bundle(self):
|
def publish_bundle(self):
|
||||||
""" Publish our bundle information to the PEP node """
|
""" Publish our bundle information to the PEP node """
|
||||||
|
|
||||||
bundle_announce = BundleInformationAnnouncement(
|
bundle = make_bundle(self.omemo.bundle)
|
||||||
self.omemo.bundle, self.omemo.own_device_id)
|
node = '%s%s' % (NS_BUNDLES, self.omemo.own_device_id)
|
||||||
log.info('%s => Publishing bundle ...', self.account)
|
|
||||||
self.send_with_callback(bundle_announce, self.handle_publish_result)
|
|
||||||
|
|
||||||
def handle_publish_result(self, stanza):
|
log.info('%s => Publishing bundle ...', self.account)
|
||||||
|
|
||||||
|
con = app.connections[self.account]
|
||||||
|
con.get_module('PubSub').send_pb_publish(
|
||||||
|
'', node, bundle, 'current', cb=self.handle_publish_result)
|
||||||
|
|
||||||
|
def handle_publish_result(self, _con, stanza):
|
||||||
""" Log if publishing our bundle was successful
|
""" Log if publishing our bundle was successful
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
|
|||||||
@@ -43,13 +43,6 @@ NS_HINTS = 'urn:xmpp:hints'
|
|||||||
log = logging.getLogger('gajim.plugin_system.omemo')
|
log = logging.getLogger('gajim.plugin_system.omemo')
|
||||||
|
|
||||||
|
|
||||||
class PublishNode(Node):
|
|
||||||
def __init__(self, node_str, data):
|
|
||||||
assert node_str is not None and isinstance(data, Node)
|
|
||||||
Node.__init__(self, tag='publish', attrs={'node': node_str})
|
|
||||||
self.addChild('item').addChild(node=data)
|
|
||||||
|
|
||||||
|
|
||||||
class PubsubNode(Node):
|
class PubsubNode(Node):
|
||||||
def __init__(self, data):
|
def __init__(self, data):
|
||||||
assert isinstance(data, Node)
|
assert isinstance(data, Node)
|
||||||
@@ -88,39 +81,6 @@ class BundleInformationQuery(Iq):
|
|||||||
self.addChild(node=pubsub)
|
self.addChild(node=pubsub)
|
||||||
|
|
||||||
|
|
||||||
class BundleInformationAnnouncement(Iq):
|
|
||||||
def __init__(self, state_bundle, device_id):
|
|
||||||
id_ = app.get_an_id()
|
|
||||||
attrs = {'id': id_}
|
|
||||||
Iq.__init__(self, typ='set', attrs=attrs)
|
|
||||||
bundle_node = self.make_bundle_node(state_bundle)
|
|
||||||
publish = PublishNode(NS_BUNDLES + str(device_id), bundle_node)
|
|
||||||
pubsub = PubsubNode(publish)
|
|
||||||
self.addChild(node=pubsub)
|
|
||||||
|
|
||||||
def make_bundle_node(self, state_bundle):
|
|
||||||
result = Node('bundle', attrs={'xmlns': NS_OMEMO})
|
|
||||||
prekey_pub_node = result.addChild(
|
|
||||||
'signedPreKeyPublic',
|
|
||||||
attrs={'signedPreKeyId': state_bundle['signedPreKeyId']})
|
|
||||||
prekey_pub_node.addData(state_bundle['signedPreKeyPublic']
|
|
||||||
.decode('utf-8'))
|
|
||||||
|
|
||||||
prekey_sig_node = result.addChild('signedPreKeySignature')
|
|
||||||
prekey_sig_node.addData(state_bundle['signedPreKeySignature']
|
|
||||||
.decode('utf-8'))
|
|
||||||
|
|
||||||
identity_key_node = result.addChild('identityKey')
|
|
||||||
identity_key_node.addData(state_bundle['identityKey'].decode('utf-8'))
|
|
||||||
prekeys = result.addChild('prekeys')
|
|
||||||
|
|
||||||
for key in state_bundle['prekeys']:
|
|
||||||
prekeys.addChild('preKeyPublic',
|
|
||||||
attrs={'preKeyId': key[0]}) \
|
|
||||||
.addData(key[1].decode('utf-8'))
|
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
class DevicelistQuery(Iq):
|
class DevicelistQuery(Iq):
|
||||||
def __init__(self, contact_jid):
|
def __init__(self, contact_jid):
|
||||||
id_ = app.get_an_id()
|
id_ = app.get_an_id()
|
||||||
@@ -139,6 +99,29 @@ class DevicelistPEP(AbstractPEP):
|
|||||||
return ({}, [])
|
return ({}, [])
|
||||||
|
|
||||||
|
|
||||||
|
def make_bundle(state_bundle):
|
||||||
|
result = Node('bundle', attrs={'xmlns': NS_OMEMO})
|
||||||
|
prekey_pub_node = result.addChild(
|
||||||
|
'signedPreKeyPublic',
|
||||||
|
attrs={'signedPreKeyId': state_bundle['signedPreKeyId']})
|
||||||
|
prekey_pub_node.addData(state_bundle['signedPreKeyPublic']
|
||||||
|
.decode('utf-8'))
|
||||||
|
|
||||||
|
prekey_sig_node = result.addChild('signedPreKeySignature')
|
||||||
|
prekey_sig_node.addData(state_bundle['signedPreKeySignature']
|
||||||
|
.decode('utf-8'))
|
||||||
|
|
||||||
|
identity_key_node = result.addChild('identityKey')
|
||||||
|
identity_key_node.addData(state_bundle['identityKey'].decode('utf-8'))
|
||||||
|
prekeys = result.addChild('prekeys')
|
||||||
|
|
||||||
|
for key in state_bundle['prekeys']:
|
||||||
|
prekeys.addChild('preKeyPublic',
|
||||||
|
attrs={'preKeyId': key[0]}) \
|
||||||
|
.addData(key[1].decode('utf-8'))
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
@log_calls('OmemoPlugin')
|
@log_calls('OmemoPlugin')
|
||||||
def unpack_device_bundle(bundle, device_id):
|
def unpack_device_bundle(bundle, device_id):
|
||||||
pubsub = bundle.getTag('pubsub', namespace=NS_PUBSUB)
|
pubsub = bundle.getTag('pubsub', namespace=NS_PUBSUB)
|
||||||
|
|||||||
Reference in New Issue
Block a user