comparison sat/core/sat_main.py @ 2658:4e130cc9bfc0

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
author Goffi <goffi@goffi.org>
date Sat, 11 Aug 2018 18:24:55 +0200
parents 712cb4ff3e13
children bc122b68eacd
comparison
equal deleted inserted replaced
2657:9190874a8ac5 2658:4e130cc9bfc0
111 ) 111 )
112 self.bridge.register_method("getWaitingSub", self.memory.getWaitingSub) 112 self.bridge.register_method("getWaitingSub", self.memory.getWaitingSub)
113 self.bridge.register_method("messageSend", self._messageSend) 113 self.bridge.register_method("messageSend", self._messageSend)
114 self.bridge.register_method("messageEncryptionStart", 114 self.bridge.register_method("messageEncryptionStart",
115 self._messageEncryptionStart) 115 self._messageEncryptionStart)
116 self.bridge.register_method("messageEncryptionStop",
117 self._messageEncryptionStop)
118 self.bridge.register_method("messageEncryptionGet",
119 self._messageEncryptionGet)
120 self.bridge.register_method("encryptionPluginsGet", self._encryptionPluginsGet)
116 self.bridge.register_method("getConfig", self._getConfig) 121 self.bridge.register_method("getConfig", self._getConfig)
117 self.bridge.register_method("setParam", self.setParam) 122 self.bridge.register_method("setParam", self.setParam)
118 self.bridge.register_method("getParamA", self.memory.getStringParamA) 123 self.bridge.register_method("getParamA", self.memory.getStringParamA)
119 self.bridge.register_method("asyncGetParamA", self.memory.asyncGetStringParamA) 124 self.bridge.register_method("asyncGetParamA", self.memory.asyncGetStringParamA)
120 self.bridge.register_method( 125 self.bridge.register_method(
655 ## Encryption ## 660 ## Encryption ##
656 661
657 def registerEncryptionPlugin(self, *args, **kwargs): 662 def registerEncryptionPlugin(self, *args, **kwargs):
658 return encryption.EncryptionHandler.registerPlugin(*args, **kwargs) 663 return encryption.EncryptionHandler.registerPlugin(*args, **kwargs)
659 664
665 def _encryptionPluginsGet(self):
666 plugins = encryption.EncryptionHandler.getPlugins()
667 ret = []
668 for p in plugins:
669 ret.append({
670 u"name": p.name,
671 u"namespace": p.namespace,
672 u"priority": unicode(p.priority),
673 })
674 return ret
675
660 ## XMPP methods ## 676 ## XMPP methods ##
661 677
662 def _messageSend(self, to_jid_s, message, subject=None, mess_type="auto", extra=None, 678 def _messageSend(self, to_jid_s, message, subject=None, mess_type="auto", extra=None,
663 profile_key=C.PROF_KEY_NONE,): 679 profile_key=C.PROF_KEY_NONE,):
664 client = self.getClient(profile_key) 680 client = self.getClient(profile_key)
671 subject, 687 subject,
672 mess_type, 688 mess_type,
673 {unicode(key): unicode(value) for key, value in extra.items()}, 689 {unicode(key): unicode(value) for key, value in extra.items()},
674 ) 690 )
675 691
676 def _messageEncryptionStart(self, to_jid_s, encryption_ns, 692 def _messageEncryptionStart(self, to_jid_s, encryption_ns, replace=False,
677 profile_key=C.PROF_KEY_NONE): 693 profile_key=C.PROF_KEY_NONE):
678 client = self.getClient(profile_key) 694 client = self.getClient(profile_key)
679 to_jid = jid.JID(to_jid_s) 695 to_jid = jid.JID(to_jid_s)
680 return client.encryption.start(to_jid, encryption_ns.strip() or None) 696 return client.encryption.start(to_jid, encryption_ns.strip() or None, replace)
697
698 def _messageEncryptionStop(self, to_jid_s, profile_key=C.PROF_KEY_NONE):
699 client = self.getClient(profile_key)
700 to_jid = jid.JID(to_jid_s)
701 return client.encryption.stop(to_jid)
702
703 def _messageEncryptionGet(self, to_jid_s, profile_key=C.PROF_KEY_NONE):
704 client = self.getClient(profile_key)
705 to_jid = jid.JID(to_jid_s)
706 session_data = client.encryption.getSession(to_jid)
707 return client.encryption.getBridgeData(session_data)
681 708
682 def _setPresence(self, to="", show="", statuses=None, profile_key=C.PROF_KEY_NONE): 709 def _setPresence(self, to="", show="", statuses=None, profile_key=C.PROF_KEY_NONE):
683 return self.setPresence(jid.JID(to) if to else None, show, statuses, profile_key) 710 return self.setPresence(jid.JID(to) if to else None, show, statuses, profile_key)
684 711
685 def setPresence( 712 def setPresence(self, to_jid=None, show="", statuses=None,
686 self, to_jid=None, show="", statuses=None, profile_key=C.PROF_KEY_NONE 713 profile_key=C.PROF_KEY_NONE):
687 ):
688 """Send our presence information""" 714 """Send our presence information"""
689 if statuses is None: 715 if statuses is None:
690 statuses = {} 716 statuses = {}
691 profile = self.memory.getProfileName(profile_key) 717 profile = self.memory.getProfileName(profile_key)
692 assert profile 718 assert profile