comparison src/browser/sat_browser/plugin_sec_otr.py @ 529:9bfd71e2b35c

plugin OTR: disconnect the active OTR sessions on profile disconnection
author souliane <souliane@mailoo.org>
date Fri, 05 Sep 2014 11:41:40 +0200
parents ac66b8b11ab8
children 1735aaeac652
comparison
equal deleted inserted replaced
528:ac66b8b11ab8 529:9bfd71e2b35c
218 elif type_ == 'trust': 218 elif type_ == 'trust':
219 self.setCurrentTrust('smp' if data else '', act) 219 self.setCurrentTrust('smp' if data else '', act)
220 elif type_ == 'abort': 220 elif type_ == 'abort':
221 self.setCurrentTrust('', act, 'abort') 221 self.setCurrentTrust('', act, 'abort')
222 222
223 def disconnect(self):
224 """Disconnect the session."""
225 if self.state != otr.context.STATE_PLAINTEXT:
226 super(Context, self).disconnect()
227
223 228
224 class Account(otr.context.Account): 229 class Account(otr.context.Account):
225 230
226 def __init__(self, host): 231 def __init__(self, host):
227 log.debug(u"new account: %s" % host.whoami.full()) 232 log.debug(u"new account: %s" % host.whoami.full())
295 self.host.bridge.call('skipOTR', None) 300 self.host.bridge.call('skipOTR', None)
296 self.context_manager = ContextManager(self.host) 301 self.context_manager = ContextManager(self.host)
297 # TODO: retrieve the encrypted private key from a HTML5 persistent storage, 302 # TODO: retrieve the encrypted private key from a HTML5 persistent storage,
298 # decrypt it, parse it with otr.crypt.PK.parsePrivateKey(privkey) and 303 # decrypt it, parse it with otr.crypt.PK.parsePrivateKey(privkey) and
299 # assign it to self.context_manager.account.privkey 304 # assign it to self.context_manager.account.privkey
305
306 def profileDisconnected(self):
307 for context in self.context_manager.contexts.values():
308 context.disconnect()
300 309
301 def fixResource(self, jid, cb): 310 def fixResource(self, jid, cb):
302 # FIXME: it's dirty, but libervia doesn't manage resources correctly now, refactoring is planed 311 # FIXME: it's dirty, but libervia doesn't manage resources correctly now, refactoring is planed
303 if jid.resource: 312 if jid.resource:
304 cb(jid) 313 cb(jid)
435 def cb(to_jid): 444 def cb(to_jid):
436 def dropKey(confirm): 445 def dropKey(confirm):
437 if confirm: 446 if confirm:
438 # we end all sessions 447 # we end all sessions
439 for context in self.context_manager.contexts.values(): 448 for context in self.context_manager.contexts.values():
440 if context.state not in (otr.context.STATE_FINISHED, otr.context.STATE_PLAINTEXT): 449 context.disconnect()
441 context.disconnect()
442 self.context_manager.account.privkey = None 450 self.context_manager.account.privkey = None
443 self.context_manager.account.getPrivkey() # as account.privkey are None, getPrivkey will generate a new key, and save it 451 self.context_manager.account.getPrivkey() # as account.privkey are None, getPrivkey will generate a new key, and save it
444 dialog.InfoDialog(_('Private key'), _("Your private key has been dropped."), AddStyleName="maxWidthLimit").show() 452 dialog.InfoDialog(_('Private key'), _("Your private key has been dropped."), AddStyleName="maxWidthLimit").show()
445 453
446 text = _(DROP_TXT) 454 text = _(DROP_TXT)