Mercurial > libervia-backend
comparison sat/core/xmpp.py @ 2646:712cb4ff3e13
core: new EncryptionHandler class which manage encrypted session as a core feature:
Plugin handling encryption can now register using host.registerEncryptionPlugin, and an encryption session can now be started using messageEncryptionStart bridge method.
This will make encryption handling more easy, as we now know if a session is clear or e2e encrypted, and which plugin handle it.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 29 Jul 2018 19:22:56 +0200 |
parents | f2cf1daa42cb |
children | 3a8e7ec4648a |
comparison
equal
deleted
inserted
replaced
2645:f2cf1daa42cb | 2646:712cb4ff3e13 |
---|---|
32 from wokkel import delay | 32 from wokkel import delay |
33 from sat.core.log import getLogger | 33 from sat.core.log import getLogger |
34 | 34 |
35 log = getLogger(__name__) | 35 log = getLogger(__name__) |
36 from sat.core import exceptions | 36 from sat.core import exceptions |
37 from sat.memory import encryption | |
37 from zope.interface import implements | 38 from zope.interface import implements |
38 import time | 39 import time |
39 import calendar | 40 import calendar |
40 import uuid | 41 import uuid |
41 import sys | 42 import sys |
58 # Key: (full_jid,message_id) Value: uid | 59 # Key: (full_jid,message_id) Value: uid |
59 self.conn_deferred = defer.Deferred() | 60 self.conn_deferred = defer.Deferred() |
60 self._progress_cb = {} # callback called when a progress is requested | 61 self._progress_cb = {} # callback called when a progress is requested |
61 # (key = progress id) | 62 # (key = progress id) |
62 self.actions = {} # used to keep track of actions for retrieval (key = action_id) | 63 self.actions = {} # used to keep track of actions for retrieval (key = action_id) |
64 self.encryption = encryption.EncryptionHandler(host_app) | |
63 | 65 |
64 ## initialisation ## | 66 ## initialisation ## |
65 | 67 |
66 @defer.inlineCallbacks | 68 @defer.inlineCallbacks |
67 def _callConnectionTriggers(self): | 69 def _callConnectionTriggers(self): |
401 @param uid(unicode, None): unique id: | 403 @param uid(unicode, None): unique id: |
402 should be unique at least in this XMPP session | 404 should be unique at least in this XMPP session |
403 if None, an uuid will be generated | 405 if None, an uuid will be generated |
404 @param no_trigger (bool): if True, sendMessage[suffix] trigger will no be used | 406 @param no_trigger (bool): if True, sendMessage[suffix] trigger will no be used |
405 useful when a message need to be sent without any modification | 407 useful when a message need to be sent without any modification |
408 /!\ this will also skip encryption methods! | |
406 """ | 409 """ |
407 if subject is None: | 410 if subject is None: |
408 subject = {} | 411 subject = {} |
409 if extra is None: | 412 if extra is None: |
410 extra = {} | 413 extra = {} |
453 # the triggers from frontend, and no_trigger do the same | 456 # the triggers from frontend, and no_trigger do the same |
454 # thing internally, this could be unified | 457 # thing internally, this could be unified |
455 send_only = data["extra"].get("send_only", False) | 458 send_only = data["extra"].get("send_only", False) |
456 | 459 |
457 if not no_trigger and not send_only: | 460 if not no_trigger and not send_only: |
461 # is the session encrypted? If so we indicate it in data | |
462 self.encryption.setEncryptionFlag(data) | |
463 | |
458 if not self.host_app.trigger.point( | 464 if not self.host_app.trigger.point( |
459 "sendMessage" + self.trigger_suffix, | 465 "sendMessage" + self.trigger_suffix, |
460 self, | 466 self, |
461 data, | 467 data, |
462 pre_xml_treatments, | 468 pre_xml_treatments, |