comparison src/plugins/plugin_sec_otr.py @ 1290:faa1129559b8 frontends_multi_profiles

core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit): /!\ not finished, everything is still instable ! - bridge: DBus bridge has been modified to allow blocking call to be called in the same way as asynchronous calls - bridge: calls with a callback and no errback are now possible, default errback log the error - constants: removed hack to manage presence without OrderedDict, as an OrderedDict like class has been implemented in Libervia - core: getLastResource has been removed and replaced by getMainResource (there is a global better management of resources) - various style improvments: use of constants when possible, fixed variable overlaps, import of module instead of direct class import - frontends: printInfo and printMessage methods in (Quick)Chat are more generic (use of extra instead of timestamp) - frontends: bridge creation and option parsing (command line arguments) are now specified by the frontend in QuickApp __init__ - frontends: ProfileManager manage a more complete plug sequence (some stuff formerly manage in contact_list have moved to ProfileManager) - quick_frontend (quick_widgets): QuickWidgetsManager is now iterable (all widgets are then returned), or can return an iterator on a specific class (return all widgets of this class) with getWidgets - frontends: tools.jid can now be used in Pyjamas, with some care - frontends (XMLUI): profile is now managed - core (memory): big improvment on entities cache management (and specially resource management) - core (params/exceptions): added PermissionError - various fixes and improvments, check diff for more details
author Goffi <goffi@goffi.org>
date Sat, 24 Jan 2015 01:00:29 +0100
parents 3be9d8ab2e15
children 069ad98b360d
comparison
equal deleted inserted replaced
1289:653f2e2eea31 1290:faa1129559b8
27 log = getLogger(__name__) 27 log = getLogger(__name__)
28 from sat.tools import xml_tools 28 from sat.tools import xml_tools
29 from twisted.words.protocols.jabber import jid 29 from twisted.words.protocols.jabber import jid
30 from twisted.python import failure 30 from twisted.python import failure
31 from twisted.internet import defer 31 from twisted.internet import defer
32 from sat.memory import persistent
32 import potr 33 import potr
33 from sat.memory import persistent 34 import copy
34 35
35 NS_OTR = "otr_plugin" 36 NS_OTR = "otr_plugin"
36 PRIVATE_KEY = "PRIVATE KEY" 37 PRIVATE_KEY = "PRIVATE KEY"
37 MAIN_MENU = D_('OTR') 38 MAIN_MENU = D_('OTR')
38 AUTH_TXT = D_("To authenticate your correspondent, you need to give your below fingerprint *BY AN EXTERNAL CANAL* (i.e. not in this chat), and check that the one he give you is the same as below. If there is a mismatch, there can be a spy between you !") 39 AUTH_TXT = D_("To authenticate your correspondent, you need to give your below fingerprint *BY AN EXTERNAL CANAL* (i.e. not in this chat), and check that the one he give you is the same as below. If there is a mismatch, there can be a spy between you !")
267 @param profile: %(doc_profile)s 268 @param profile: %(doc_profile)s
268 """ 269 """
269 try: 270 try:
270 to_jid = jid.JID(menu_data['jid']) 271 to_jid = jid.JID(menu_data['jid'])
271 if not to_jid.resource: 272 if not to_jid.resource:
272 to_jid.resource = self.host.memory.getLastResource(to_jid, profile) # FIXME: temporary and unsecure, must be changed when frontends are refactored 273 to_jid.resource = self.host.memory.getMainResource(to_jid, profile) # FIXME: temporary and unsecure, must be changed when frontends are refactored
273 except KeyError: 274 except KeyError:
274 log.error(_("jid key is not present !")) 275 log.error(_("jid key is not present !"))
275 return defer.fail(exceptions.DataError) 276 return defer.fail(exceptions.DataError)
276 otrctx = self.context_managers[profile].getContextForUser(to_jid) 277 otrctx = self.context_managers[profile].getContextForUser(to_jid)
277 query = otrctx.sendMessage(0, '?OTRv?') 278 query = otrctx.sendMessage(0, '?OTRv?')
285 @param profile: %(doc_profile)s 286 @param profile: %(doc_profile)s
286 """ 287 """
287 try: 288 try:
288 to_jid = jid.JID(menu_data['jid']) 289 to_jid = jid.JID(menu_data['jid'])
289 if not to_jid.resource: 290 if not to_jid.resource:
290 to_jid.resource = self.host.memory.getLastResource(to_jid, profile) # FIXME: temporary and unsecure, must be changed when frontends are refactored 291 to_jid.resource = self.host.memory.getMainResource(to_jid, profile) # FIXME: temporary and unsecure, must be changed when frontends are refactored
291 except KeyError: 292 except KeyError:
292 log.error(_("jid key is not present !")) 293 log.error(_("jid key is not present !"))
293 return defer.fail(exceptions.DataError) 294 return defer.fail(exceptions.DataError)
294 otrctx = self.context_managers[profile].getContextForUser(to_jid) 295 otrctx = self.context_managers[profile].getContextForUser(to_jid)
295 otrctx.disconnect() 296 otrctx.disconnect()
302 @param profile: %(doc_profile)s 303 @param profile: %(doc_profile)s
303 """ 304 """
304 try: 305 try:
305 to_jid = jid.JID(menu_data['jid']) 306 to_jid = jid.JID(menu_data['jid'])
306 if not to_jid.resource: 307 if not to_jid.resource:
307 to_jid.resource = self.host.memory.getLastResource(to_jid, profile) # FIXME: temporary and unsecure, must be changed when frontends are refactored 308 to_jid.resource = self.host.memory.getMainResource(to_jid, profile) # FIXME: temporary and unsecure, must be changed when frontends are refactored
308 except KeyError: 309 except KeyError:
309 log.error(_("jid key is not present !")) 310 log.error(_("jid key is not present !"))
310 return defer.fail(exceptions.DataError) 311 return defer.fail(exceptions.DataError)
311 ctxMng = self.context_managers[profile] 312 ctxMng = self.context_managers[profile]
312 otrctx = ctxMng.getContextForUser(to_jid) 313 otrctx = ctxMng.getContextForUser(to_jid)
372 @param profile: %(doc_profile)s 373 @param profile: %(doc_profile)s
373 """ 374 """
374 try: 375 try:
375 to_jid = jid.JID(menu_data['jid']) 376 to_jid = jid.JID(menu_data['jid'])
376 if not to_jid.resource: 377 if not to_jid.resource:
377 to_jid.resource = self.host.memory.getLastResource(to_jid, profile) # FIXME: temporary and unsecure, must be changed when frontends are refactored 378 to_jid.resource = self.host.memory.getMainResource(to_jid, profile) # FIXME: temporary and unsecure, must be changed when frontends are refactored
378 except KeyError: 379 except KeyError:
379 log.error(_("jid key is not present !")) 380 log.error(_("jid key is not present !"))
380 return defer.fail(exceptions.DataError) 381 return defer.fail(exceptions.DataError)
381 382
382 ctxMng = self.context_managers[profile] 383 ctxMng = self.context_managers[profile]
445 return True 446 return True
446 447
447 def sendMessageTrigger(self, mess_data, pre_xml_treatments, post_xml_treatments, profile): 448 def sendMessageTrigger(self, mess_data, pre_xml_treatments, post_xml_treatments, profile):
448 if profile in self.skipped_profiles: 449 if profile in self.skipped_profiles:
449 return True 450 return True
450 to_jid = mess_data['to'] 451 to_jid = copy.copy(mess_data['to'])
451 if mess_data['type'] != 'groupchat' and not to_jid.resource: 452 if mess_data['type'] != 'groupchat' and not to_jid.resource:
452 to_jid.resource = self.host.memory.getLastResource(to_jid, profile) # FIXME: it's dirty, but frontends don't manage resources correctly now, refactoring is planed 453 to_jid.resource = self.host.memory.getMainResource(to_jid, profile) # FIXME: it's dirty, but frontends don't manage resources correctly now, refactoring is planed
453 otrctx = self.context_managers[profile].getContextForUser(to_jid) 454 otrctx = self.context_managers[profile].getContextForUser(to_jid)
454 if mess_data['type'] != 'groupchat' and otrctx.state != potr.context.STATE_PLAINTEXT: 455 if mess_data['type'] != 'groupchat' and otrctx.state != potr.context.STATE_PLAINTEXT:
455 if otrctx.state == potr.context.STATE_ENCRYPTED: 456 if otrctx.state == potr.context.STATE_ENCRYPTED:
456 log.debug(u"encrypting message") 457 log.debug(u"encrypting message")
457 otrctx.sendMessage(0, mess_data['message'].encode('utf-8')) 458 otrctx.sendMessage(0, mess_data['message'].encode('utf-8'))
473 474
474 def presenceReceivedTrigger(self, entity, show, priority, statuses, profile): 475 def presenceReceivedTrigger(self, entity, show, priority, statuses, profile):
475 if show != "unavailable": 476 if show != "unavailable":
476 return True 477 return True
477 if not entity.resource: 478 if not entity.resource:
478 entity.resource = self.host.memory.getLastResource(entity, profile) # FIXME: temporary and unsecure, must be changed when frontends are refactored 479 entity.resource = self.host.memory.getMainResource(entity, profile) # FIXME: temporary and unsecure, must be changed when frontends are refactored
479 otrctx = self.context_managers[profile].getContextForUser(entity) 480 otrctx = self.context_managers[profile].getContextForUser(entity)
480 otrctx.disconnect() 481 otrctx.disconnect()
481 return True 482 return True