diff sat/plugins/plugin_xep_0234.py @ 3969:8e7d5796fb23

plugin XEP-0391: implement XEP-0391 (Jingle Encrypted Transports) + XEP-0396 (JET-OMEMO): rel 378
author Goffi <goffi@goffi.org>
date Mon, 31 Oct 2022 04:09:34 +0100
parents 3ef988734869
children 524856bd7b19
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0234.py	Mon Oct 31 04:04:32 2022 +0100
+++ b/sat/plugins/plugin_xep_0234.py	Mon Oct 31 04:09:34 2022 +0100
@@ -16,22 +16,24 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-import os.path
+from collections import namedtuple
 import mimetypes
-from collections import namedtuple
-from zope.interface import implementer
-from twisted.words.xish import domish
-from twisted.words.protocols.jabber import jid
-from twisted.python import failure
-from twisted.words.protocols.jabber.xmlstream import XMPPHandler
+import os.path
+
 from twisted.internet import defer
 from twisted.internet import reactor
 from twisted.internet import error as internet_error
+from twisted.python import failure
+from twisted.words.protocols.jabber import jid
+from twisted.words.protocols.jabber.xmlstream import XMPPHandler
+from twisted.words.xish import domish
 from wokkel import disco, iwokkel
-from sat.core.i18n import _, D_
+from zope.interface import implementer
+
+from sat.core import exceptions
 from sat.core.constants import Const as C
+from sat.core.i18n import D_, _
 from sat.core.log import getLogger
-from sat.core import exceptions
 from sat.tools import utils
 from sat.tools import stream
 from sat.tools.common import date_utils
@@ -329,6 +331,7 @@
             extra = {}
         if file_desc is not None:
             extra["file_desc"] = file_desc
+        encrypted = extra.pop("encrypted", False)
         await self._j.initiate(
             client,
             peer_jid,
@@ -344,6 +347,7 @@
                     },
                 }
             ],
+            encrypted = encrypted
         )
         return await progress_id_d
 
@@ -490,7 +494,7 @@
             )
         else:
             # we receive the file
-            return await self._fileReceivingRequestConf(
+            return await self._file_receiving_request_conf(
                 client, session, content_data, content_name, file_data, file_elt
             )
 
@@ -524,7 +528,7 @@
         log.warning(_("File continue is not implemented yet"))
         return False
 
-    async def _fileReceivingRequestConf(
+    async def _file_receiving_request_conf(
         self, client, session, content_data, content_name, file_data, file_elt
     ):
         """parse file_elt, and handle user permission/file opening"""
@@ -564,14 +568,17 @@
             client, session["peer_jid"], content_data, file_data, stream_object=True
         )
         if confirmed:
+            await self.host.trigger.asyncPoint(
+                "XEP-0234_file_receiving_request_conf",
+                client, session, content_data, file_elt
+            )
             args = [client, session, content_name, content_data]
             finished_d.addCallbacks(
                 self._finishedCb, self._finishedEb, args, None, args
             )
         return confirmed
 
-    @defer.inlineCallbacks
-    def jingleHandler(self, client, action, session, content_name, desc_elt):
+    async def jingleHandler(self, client, action, session, content_name, desc_elt):
         content_data = session["contents"][content_name]
         application_data = content_data["application_data"]
         if action in (self._j.A_ACCEPTED_ACK,):
@@ -617,7 +624,7 @@
                     self.host.bridge.progressError(
                         progress_id, C.PROGRESS_ERROR_FAILED, client.profile
                     )
-                    yield self._j.terminate(
+                    await self._j.terminate(
                         client, self._j.REASON_FAILED_APPLICATION, session)
                     raise e
             else:
@@ -637,9 +644,13 @@
             finished_d = content_data["finished_d"] = defer.Deferred()
             args = [client, session, content_name, content_data]
             finished_d.addCallbacks(self._finishedCb, self._finishedEb, args, None, args)
+            await self.host.trigger.asyncPoint(
+                "XEP-0234_jingle_handler",
+                client, session, content_data, desc_elt
+            )
         else:
             log.warning("FIXME: unmanaged action {}".format(action))
-        defer.returnValue(desc_elt)
+        return desc_elt
 
     def jingleSessionInfo(self, client, action, session, content_name, jingle_elt):
         """Called on session-info action