diff sat/core/sat_main.py @ 2733:e347e32aa07f

core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods: - encryptionNamespaceGet retrieves algorithm namespace from its short name - encryptionTrustUIGet retrieves trust mangement XMLUI from encryption plugin - new markAsUntrusted internal helper method, to add untrusted flag to message data
author Goffi <goffi@goffi.org>
date Wed, 02 Jan 2019 18:22:30 +0100
parents 1ecceac3df96
children 378188abe941
line wrap: on
line diff
--- a/sat/core/sat_main.py	Thu Dec 27 11:40:04 2018 +0100
+++ b/sat/core/sat_main.py	Wed Jan 02 18:22:30 2019 +0100
@@ -122,7 +122,10 @@
                                     self._messageEncryptionStop)
         self.bridge.register_method("messageEncryptionGet",
                                     self._messageEncryptionGet)
+        self.bridge.register_method("encryptionNamespaceGet",
+                                    self._encryptionNamespaceGet)
         self.bridge.register_method("encryptionPluginsGet", self._encryptionPluginsGet)
+        self.bridge.register_method("encryptionTrustUIGet", self._encryptionTrustUIGet)
         self.bridge.register_method("getConfig", self._getConfig)
         self.bridge.register_method("setParam", self.setParam)
         self.bridge.register_method("getParamA", self.memory.getStringParamA)
@@ -670,6 +673,26 @@
     def registerEncryptionPlugin(self, *args, **kwargs):
         return encryption.EncryptionHandler.registerPlugin(*args, **kwargs)
 
+    def _messageEncryptionStart(self, to_jid_s, namespace, 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, namespace 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 _encryptionNamespaceGet(self, name):
+        return encryption.EncryptionHandler.getNSFromName(name)
+
     def _encryptionPluginsGet(self):
         plugins = encryption.EncryptionHandler.getPlugins()
         ret = []
@@ -681,6 +704,13 @@
                 })
         return ret
 
+    def _encryptionTrustUIGet(self, to_jid_s, namespace, profile_key):
+        client = self.getClient(profile_key)
+        to_jid = jid.JID(to_jid_s)
+        d = client.encryption.getTrustUI(to_jid, namespace=namespace or None)
+        d.addCallback(lambda xmlui: xmlui.toXml())
+        return d
+
     ## XMPP methods ##
 
     def _messageSend(self, to_jid_s, message, subject=None, mess_type="auto", extra=None,
@@ -697,23 +727,6 @@
             {unicode(key): unicode(value) for key, value in extra.items()},
         )
 
-    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, 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)
 
@@ -1051,7 +1064,7 @@
             with_data(bool): True if the callback use the optional data dict
             force_id(unicode): id to avoid generated id. Can lead to name conflict, avoid
                                if possible
-            one_shot(bool): True to delete callback once it have been called
+            one_shot(bool): True to delete callback once it has been called
         @return: id of the registered callback
         """
         callback_id = kwargs.pop("force_id", None)