comparison 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
comparison
equal deleted inserted replaced
2732:e55f871fa9db 2733:e347e32aa07f
120 self._messageEncryptionStart) 120 self._messageEncryptionStart)
121 self.bridge.register_method("messageEncryptionStop", 121 self.bridge.register_method("messageEncryptionStop",
122 self._messageEncryptionStop) 122 self._messageEncryptionStop)
123 self.bridge.register_method("messageEncryptionGet", 123 self.bridge.register_method("messageEncryptionGet",
124 self._messageEncryptionGet) 124 self._messageEncryptionGet)
125 self.bridge.register_method("encryptionNamespaceGet",
126 self._encryptionNamespaceGet)
125 self.bridge.register_method("encryptionPluginsGet", self._encryptionPluginsGet) 127 self.bridge.register_method("encryptionPluginsGet", self._encryptionPluginsGet)
128 self.bridge.register_method("encryptionTrustUIGet", self._encryptionTrustUIGet)
126 self.bridge.register_method("getConfig", self._getConfig) 129 self.bridge.register_method("getConfig", self._getConfig)
127 self.bridge.register_method("setParam", self.setParam) 130 self.bridge.register_method("setParam", self.setParam)
128 self.bridge.register_method("getParamA", self.memory.getStringParamA) 131 self.bridge.register_method("getParamA", self.memory.getStringParamA)
129 self.bridge.register_method("asyncGetParamA", self.memory.asyncGetStringParamA) 132 self.bridge.register_method("asyncGetParamA", self.memory.asyncGetStringParamA)
130 self.bridge.register_method( 133 self.bridge.register_method(
668 ## Encryption ## 671 ## Encryption ##
669 672
670 def registerEncryptionPlugin(self, *args, **kwargs): 673 def registerEncryptionPlugin(self, *args, **kwargs):
671 return encryption.EncryptionHandler.registerPlugin(*args, **kwargs) 674 return encryption.EncryptionHandler.registerPlugin(*args, **kwargs)
672 675
676 def _messageEncryptionStart(self, to_jid_s, namespace, replace=False,
677 profile_key=C.PROF_KEY_NONE):
678 client = self.getClient(profile_key)
679 to_jid = jid.JID(to_jid_s)
680 return client.encryption.start(to_jid, namespace or None, replace)
681
682 def _messageEncryptionStop(self, to_jid_s, profile_key=C.PROF_KEY_NONE):
683 client = self.getClient(profile_key)
684 to_jid = jid.JID(to_jid_s)
685 return client.encryption.stop(to_jid)
686
687 def _messageEncryptionGet(self, to_jid_s, profile_key=C.PROF_KEY_NONE):
688 client = self.getClient(profile_key)
689 to_jid = jid.JID(to_jid_s)
690 session_data = client.encryption.getSession(to_jid)
691 return client.encryption.getBridgeData(session_data)
692
693 def _encryptionNamespaceGet(self, name):
694 return encryption.EncryptionHandler.getNSFromName(name)
695
673 def _encryptionPluginsGet(self): 696 def _encryptionPluginsGet(self):
674 plugins = encryption.EncryptionHandler.getPlugins() 697 plugins = encryption.EncryptionHandler.getPlugins()
675 ret = [] 698 ret = []
676 for p in plugins: 699 for p in plugins:
677 ret.append({ 700 ret.append({
678 u"name": p.name, 701 u"name": p.name,
679 u"namespace": p.namespace, 702 u"namespace": p.namespace,
680 u"priority": unicode(p.priority), 703 u"priority": unicode(p.priority),
681 }) 704 })
682 return ret 705 return ret
706
707 def _encryptionTrustUIGet(self, to_jid_s, namespace, profile_key):
708 client = self.getClient(profile_key)
709 to_jid = jid.JID(to_jid_s)
710 d = client.encryption.getTrustUI(to_jid, namespace=namespace or None)
711 d.addCallback(lambda xmlui: xmlui.toXml())
712 return d
683 713
684 ## XMPP methods ## 714 ## XMPP methods ##
685 715
686 def _messageSend(self, to_jid_s, message, subject=None, mess_type="auto", extra=None, 716 def _messageSend(self, to_jid_s, message, subject=None, mess_type="auto", extra=None,
687 profile_key=C.PROF_KEY_NONE,): 717 profile_key=C.PROF_KEY_NONE,):
694 message, 724 message,
695 subject, 725 subject,
696 mess_type, 726 mess_type,
697 {unicode(key): unicode(value) for key, value in extra.items()}, 727 {unicode(key): unicode(value) for key, value in extra.items()},
698 ) 728 )
699
700 def _messageEncryptionStart(self, to_jid_s, encryption_ns, replace=False,
701 profile_key=C.PROF_KEY_NONE):
702 client = self.getClient(profile_key)
703 to_jid = jid.JID(to_jid_s)
704 return client.encryption.start(to_jid, encryption_ns.strip() or None, replace)
705
706 def _messageEncryptionStop(self, to_jid_s, profile_key=C.PROF_KEY_NONE):
707 client = self.getClient(profile_key)
708 to_jid = jid.JID(to_jid_s)
709 return client.encryption.stop(to_jid)
710
711 def _messageEncryptionGet(self, to_jid_s, profile_key=C.PROF_KEY_NONE):
712 client = self.getClient(profile_key)
713 to_jid = jid.JID(to_jid_s)
714 session_data = client.encryption.getSession(to_jid)
715 return client.encryption.getBridgeData(session_data)
716 729
717 def _setPresence(self, to="", show="", statuses=None, profile_key=C.PROF_KEY_NONE): 730 def _setPresence(self, to="", show="", statuses=None, profile_key=C.PROF_KEY_NONE):
718 return self.setPresence(jid.JID(to) if to else None, show, statuses, profile_key) 731 return self.setPresence(jid.JID(to) if to else None, show, statuses, profile_key)
719 732
720 def setPresence(self, to_jid=None, show="", statuses=None, 733 def setPresence(self, to_jid=None, show="", statuses=None,
1049 @param callback(callable): method to call 1062 @param callback(callable): method to call
1050 @param kwargs: can contain: 1063 @param kwargs: can contain:
1051 with_data(bool): True if the callback use the optional data dict 1064 with_data(bool): True if the callback use the optional data dict
1052 force_id(unicode): id to avoid generated id. Can lead to name conflict, avoid 1065 force_id(unicode): id to avoid generated id. Can lead to name conflict, avoid
1053 if possible 1066 if possible
1054 one_shot(bool): True to delete callback once it have been called 1067 one_shot(bool): True to delete callback once it has been called
1055 @return: id of the registered callback 1068 @return: id of the registered callback
1056 """ 1069 """
1057 callback_id = kwargs.pop("force_id", None) 1070 callback_id = kwargs.pop("force_id", None)
1058 if callback_id is None: 1071 if callback_id is None:
1059 callback_id = str(uuid.uuid4()) 1072 callback_id = str(uuid.uuid4())