core (memore/encryption): new methods and checks:

Following methods are now available though bridge:
    - messageEncryptionStop
    - messageEncryptionGet: retrieve encryption data for a message session
    - encryptionPluginsGet: retrieve all registered encryption plugin

Following methods are available for internal use:
    - getPlugins: retrieve registerd plugins
    - getNSFromName: retrieve namespace from plugin name
    - getBridgeData: serialise session data (to be used with bridge)
    - markAsEncrypted: mark message data as encrypted (to be set by encryption plugin in MessageReceived trigger)

Behaviours improvments:
    - start and stop send messageEncryptionStarted and messageEncryptionStopped signals, and a message feedback
    - new "replace" arguments in start allows to replace a plugin if one is already running (instead of raising a ConflictError)
    - plugins declare themselves as "directed" (i.e. working with only one device at a time) or not.
      This is checked while dealing with jids, an exception is raised when a full jid is received for a non directed encryption.
    - use of new data_format (de)serialise
This commit is contained in:
Goffi 2018-08-11 18:24:55 +02:00
commit e4bda681b8
2 changed files with 310 additions and 54 deletions

View file

@ -113,6 +113,11 @@ class SAT(service.Service):
self.bridge.register_method("messageSend", self._messageSend)
self.bridge.register_method("messageEncryptionStart",
self._messageEncryptionStart)
self.bridge.register_method("messageEncryptionStop",
self._messageEncryptionStop)
self.bridge.register_method("messageEncryptionGet",
self._messageEncryptionGet)
self.bridge.register_method("encryptionPluginsGet", self._encryptionPluginsGet)
self.bridge.register_method("getConfig", self._getConfig)
self.bridge.register_method("setParam", self.setParam)
self.bridge.register_method("getParamA", self.memory.getStringParamA)
@ -657,6 +662,17 @@ class SAT(service.Service):
def registerEncryptionPlugin(self, *args, **kwargs):
return encryption.EncryptionHandler.registerPlugin(*args, **kwargs)
def _encryptionPluginsGet(self):
plugins = encryption.EncryptionHandler.getPlugins()
ret = []
for p in plugins:
ret.append({
u"name": p.name,
u"namespace": p.namespace,
u"priority": unicode(p.priority),
})
return ret
## XMPP methods ##
def _messageSend(self, to_jid_s, message, subject=None, mess_type="auto", extra=None,
@ -673,18 +689,28 @@ class SAT(service.Service):
{unicode(key): unicode(value) for key, value in extra.items()},
)
def _messageEncryptionStart(self, to_jid_s, encryption_ns,
def _messageEncryptionStart(self, to_jid_s, encryption_ns, replace=False,
profile_key=C.PROF_KEY_NONE):
client = self.getClient(profile_key)
to_jid = jid.JID(to_jid_s)
return client.encryption.start(to_jid, encryption_ns.strip() or None)
return client.encryption.start(to_jid, encryption_ns.strip() or None, replace)
def _messageEncryptionStop(self, to_jid_s, profile_key=C.PROF_KEY_NONE):
client = self.getClient(profile_key)
to_jid = jid.JID(to_jid_s)
return client.encryption.stop(to_jid)
def _messageEncryptionGet(self, to_jid_s, profile_key=C.PROF_KEY_NONE):
client = self.getClient(profile_key)
to_jid = jid.JID(to_jid_s)
session_data = client.encryption.getSession(to_jid)
return client.encryption.getBridgeData(session_data)
def _setPresence(self, to="", show="", statuses=None, profile_key=C.PROF_KEY_NONE):
return self.setPresence(jid.JID(to) if to else None, show, statuses, profile_key)
def setPresence(
self, to_jid=None, show="", statuses=None, profile_key=C.PROF_KEY_NONE
):
def setPresence(self, to_jid=None, show="", statuses=None,
profile_key=C.PROF_KEY_NONE):
"""Send our presence information"""
if statuses is None:
statuses = {}

View file

@ -61,7 +61,7 @@ class SatXMPPEntity(object):
self._progress_cb = {} # callback called when a progress is requested
# (key = progress id)
self.actions = {} # used to keep track of actions for retrieval (key = action_id)
self.encryption = encryption.EncryptionHandler(host_app)
self.encryption = encryption.EncryptionHandler(self)
## initialisation ##
@ -919,6 +919,8 @@ class SatMessageProtocol(xmppim.MessageProtocol):
data["extra"]["delay_sender"] = data["delay_sender"]
except KeyError:
pass
if C.MESS_KEY_ENCRYPTION in data:
data[u"extra"][u"encrypted"] = C.BOOL_TRUE
if data is not None:
self.host.bridge.messageNew(
data["uid"],