comparison src/plugins/plugin_sec_otr.py @ 1170:2df6427a5299

plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
author souliane <souliane@mailoo.org>
date Fri, 05 Sep 2014 11:16:38 +0200
parents a3354063dfb6
children 0abce7f17782
comparison
equal deleted inserted replaced
1169:a3354063dfb6 1170:2df6427a5299
118 def disconnect(self): 118 def disconnect(self):
119 """Disconnect the session.""" 119 """Disconnect the session."""
120 if self.state != potr.context.STATE_PLAINTEXT: 120 if self.state != potr.context.STATE_PLAINTEXT:
121 super(Context, self).disconnect() 121 super(Context, self).disconnect()
122 122
123 def finish(self):
124 """Finish the session - avoid to send any message but the user still has to end the session himself."""
125 if self.state == potr.context.STATE_ENCRYPTED:
126 self.processTLVs([potr.proto.DisconnectTLV()])
127
123 128
124 class Account(potr.context.Account): 129 class Account(potr.context.Account):
125 #TODO: manage trusted keys: if a fingerprint is not used anymore, we have no way to remove it from database yet (same thing for a correspondent jid) 130 #TODO: manage trusted keys: if a fingerprint is not used anymore, we have no way to remove it from database yet (same thing for a correspondent jid)
126 131
127 def __init__(self, host, client): 132 def __init__(self, host, client):
201 host.bridge.addMethod("skipOTR", ".plugin", in_sign='s', out_sign='', method=self._skipOTR) 206 host.bridge.addMethod("skipOTR", ".plugin", in_sign='s', out_sign='', method=self._skipOTR)
202 host.importMenu((MAIN_MENU, D_("Start/Refresh")), self._startRefresh, security_limit=0, help_string=D_("Start or refresh an OTR session"), type_=C.MENU_SINGLE) 207 host.importMenu((MAIN_MENU, D_("Start/Refresh")), self._startRefresh, security_limit=0, help_string=D_("Start or refresh an OTR session"), type_=C.MENU_SINGLE)
203 host.importMenu((MAIN_MENU, D_("End session")), self._endSession, security_limit=0, help_string=D_("Finish an OTR session"), type_=C.MENU_SINGLE) 208 host.importMenu((MAIN_MENU, D_("End session")), self._endSession, security_limit=0, help_string=D_("Finish an OTR session"), type_=C.MENU_SINGLE)
204 host.importMenu((MAIN_MENU, D_("Authenticate")), self._authenticate, security_limit=0, help_string=D_("Authenticate user/see your fingerprint"), type_=C.MENU_SINGLE) 209 host.importMenu((MAIN_MENU, D_("Authenticate")), self._authenticate, security_limit=0, help_string=D_("Authenticate user/see your fingerprint"), type_=C.MENU_SINGLE)
205 host.importMenu((MAIN_MENU, D_("Drop private key")), self._dropPrivKey, security_limit=0, type_=C.MENU_SINGLE) 210 host.importMenu((MAIN_MENU, D_("Drop private key")), self._dropPrivKey, security_limit=0, type_=C.MENU_SINGLE)
211 host.trigger.add("presenceReceived", self.presenceReceivedTrigger)
206 212
207 def _fixPotr(self): 213 def _fixPotr(self):
208 # FIXME: potr fix for bad unicode handling 214 # FIXME: potr fix for bad unicode handling
209 # this method monkeypatch it, must be removed when potr 215 # this method monkeypatch it, must be removed when potr
210 # is fixed 216 # is fixed
455 return False 461 return False
456 else: 462 else:
457 log.debug(u"sending message unencrypted") 463 log.debug(u"sending message unencrypted")
458 return True 464 return True
459 465
466 def presenceReceivedTrigger(self, entity, show, priority, statuses, profile):
467 if show != "unavailable":
468 return
469 if not entity.resource:
470 entity.resource = self.host.memory.getLastResource(entity, profile) # FIXME: temporary and unsecure, must be changed when frontends are refactored
471 otrctx = self.context_managers[profile].getContextForUser(entity)
472 otrctx.disconnect()
473 return True