comparison src/plugins/plugin_sec_otr.py @ 1970:200cd707a46d

plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass): - bridge methods/signals now all start with "muc" to follow new convention - internal method use client instead of profile to follow new convention - removed excetpions from plugin XEP-0045 in favor of core.exceptions, NotReady added - cleaned/simplified several part of the code. checkClient removed as it is not needed anymore - self.clients map removed, muc data are now stored directly in client - getRoomEntityNick and getRoomNicksOfUsers are removed as they don't look sane. /!\ This break all room game plugins for the moment - use of uuid4 instead of uuid1 for getUniqueName, as host ID and current time are used for uuid1
author Goffi <goffi@goffi.org>
date Mon, 27 Jun 2016 21:45:11 +0200
parents a2bc5089c2eb
children ca82c97db195
comparison
equal deleted inserted replaced
1969:5fbe09b9b568 1970:200cd707a46d
274 """Start or refresh an OTR session 274 """Start or refresh an OTR session
275 275
276 @param menu_data: %(menu_data)s 276 @param menu_data: %(menu_data)s
277 @param profile: %(doc_profile)s 277 @param profile: %(doc_profile)s
278 """ 278 """
279 client = self.host.getClient(profile)
279 try: 280 try:
280 to_jid = jid.JID(menu_data['jid']) 281 to_jid = jid.JID(menu_data['jid'])
281 if not to_jid.resource: 282 if not to_jid.resource:
282 to_jid.resource = self.host.memory.getMainResource(to_jid, profile) # FIXME: temporary and unsecure, must be changed when frontends are refactored 283 to_jid.resource = self.host.memory.getMainResource(client, to_jid) # FIXME: temporary and unsecure, must be changed when frontends are refactored
283 except KeyError: 284 except KeyError:
284 log.error(_("jid key is not present !")) 285 log.error(_("jid key is not present !"))
285 return defer.fail(exceptions.DataError) 286 return defer.fail(exceptions.DataError)
286 otrctx = self.context_managers[profile].getContextForUser(to_jid) 287 otrctx = self.context_managers[profile].getContextForUser(to_jid)
287 query = otrctx.messageSend(0, '?OTRv?') 288 query = otrctx.messageSend(0, '?OTRv?')
292 """End an OTR session 293 """End an OTR session
293 294
294 @param menu_data: %(menu_data)s 295 @param menu_data: %(menu_data)s
295 @param profile: %(doc_profile)s 296 @param profile: %(doc_profile)s
296 """ 297 """
298 client = self.host.getClient(profile)
297 try: 299 try:
298 to_jid = jid.JID(menu_data['jid']) 300 to_jid = jid.JID(menu_data['jid'])
299 if not to_jid.resource: 301 if not to_jid.resource:
300 to_jid.resource = self.host.memory.getMainResource(to_jid, profile) # FIXME: temporary and unsecure, must be changed when frontends are refactored 302 to_jid.resource = self.host.memory.getMainResource(client, to_jid) # FIXME: temporary and unsecure, must be changed when frontends are refactored
301 except KeyError: 303 except KeyError:
302 log.error(_("jid key is not present !")) 304 log.error(_("jid key is not present !"))
303 return defer.fail(exceptions.DataError) 305 return defer.fail(exceptions.DataError)
304 otrctx = self.context_managers[profile].getContextForUser(to_jid) 306 otrctx = self.context_managers[profile].getContextForUser(to_jid)
305 otrctx.disconnect() 307 otrctx.disconnect()
309 """Authenticate other user and see our own fingerprint 311 """Authenticate other user and see our own fingerprint
310 312
311 @param menu_data: %(menu_data)s 313 @param menu_data: %(menu_data)s
312 @param profile: %(doc_profile)s 314 @param profile: %(doc_profile)s
313 """ 315 """
316 client = self.host.getClient(profile)
314 try: 317 try:
315 to_jid = jid.JID(menu_data['jid']) 318 to_jid = jid.JID(menu_data['jid'])
316 if not to_jid.resource: 319 if not to_jid.resource:
317 to_jid.resource = self.host.memory.getMainResource(to_jid, profile) # FIXME: temporary and unsecure, must be changed when frontends are refactored 320 to_jid.resource = self.host.memory.getMainResource(client, to_jid) # FIXME: temporary and unsecure, must be changed when frontends are refactored
318 except KeyError: 321 except KeyError:
319 log.error(_("jid key is not present !")) 322 log.error(_("jid key is not present !"))
320 return defer.fail(exceptions.DataError) 323 return defer.fail(exceptions.DataError)
321 ctxMng = self.context_managers[profile] 324 ctxMng = self.context_managers[profile]
322 otrctx = ctxMng.getContextForUser(to_jid) 325 otrctx = ctxMng.getContextForUser(to_jid)
379 """Drop our private Key 382 """Drop our private Key
380 383
381 @param menu_data: %(menu_data)s 384 @param menu_data: %(menu_data)s
382 @param profile: %(doc_profile)s 385 @param profile: %(doc_profile)s
383 """ 386 """
387 client = self.host.getClient(profile)
384 try: 388 try:
385 to_jid = jid.JID(menu_data['jid']) 389 to_jid = jid.JID(menu_data['jid'])
386 if not to_jid.resource: 390 if not to_jid.resource:
387 to_jid.resource = self.host.memory.getMainResource(to_jid, profile) # FIXME: temporary and unsecure, must be changed when frontends are refactored 391 to_jid.resource = self.host.memory.getMainResource(client, to_jid) # FIXME: temporary and unsecure, must be changed when frontends are refactored
388 except KeyError: 392 except KeyError:
389 log.error(_("jid key is not present !")) 393 log.error(_("jid key is not present !"))
390 return defer.fail(exceptions.DataError) 394 return defer.fail(exceptions.DataError)
391 395
392 ctxMng = self.context_managers[profile] 396 ctxMng = self.context_managers[profile]
465 profile = client.profile 469 profile = client.profile
466 if profile in self.skipped_profiles: 470 if profile in self.skipped_profiles:
467 return True 471 return True
468 to_jid = copy.copy(mess_data['to']) 472 to_jid = copy.copy(mess_data['to'])
469 if mess_data['type'] != 'groupchat' and not to_jid.resource: 473 if mess_data['type'] != 'groupchat' and not to_jid.resource:
470 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 474 to_jid.resource = self.host.memory.getMainResource(client, to_jid) # FIXME: it's dirty, but frontends don't manage resources correctly now, refactoring is planed
471 otrctx = self.context_managers[profile].getContextForUser(to_jid) 475 otrctx = self.context_managers[profile].getContextForUser(to_jid)
472 if mess_data['type'] != 'groupchat' and otrctx.state != potr.context.STATE_PLAINTEXT: 476 if mess_data['type'] != 'groupchat' and otrctx.state != potr.context.STATE_PLAINTEXT:
473 if otrctx.state == potr.context.STATE_ENCRYPTED: 477 if otrctx.state == potr.context.STATE_ENCRYPTED:
474 log.debug(u"encrypting message") 478 log.debug(u"encrypting message")
475 try: 479 try:
494 else: 498 else:
495 log.debug(u"sending message unencrypted") 499 log.debug(u"sending message unencrypted")
496 return True 500 return True
497 501
498 def _presenceReceivedTrigger(self, entity, show, priority, statuses, profile): 502 def _presenceReceivedTrigger(self, entity, show, priority, statuses, profile):
503 client = self.host.getClient(profile)
499 if show != C.PRESENCE_UNAVAILABLE: 504 if show != C.PRESENCE_UNAVAILABLE:
500 return True 505 return True
501 if not entity.resource: 506 if not entity.resource:
502 try: 507 try:
503 entity.resource = self.host.memory.getMainResource(entity, profile) # FIXME: temporary and unsecure, must be changed when frontends are refactored 508 entity.resource = self.host.memory.getMainResource(client, entity) # FIXME: temporary and unsecure, must be changed when frontends are refactored
504 except exceptions.UnknownEntityError: 509 except exceptions.UnknownEntityError:
505 return True # entity was not connected 510 return True # entity was not connected
506 if entity in self.context_managers[profile].contexts: 511 if entity in self.context_managers[profile].contexts:
507 otrctx = self.context_managers[profile].getContextForUser(entity) 512 otrctx = self.context_managers[profile].getContextForUser(entity)
508 otrctx.disconnect() 513 otrctx.disconnect()