comparison src/plugins/plugin_sec_otr.py @ 1146:1ac5ea74dbdf

plugin OTR: remove unnecessary attribute SatXMPPClient.otr_priv_key
author souliane <souliane@mailoo.org>
date Mon, 01 Sep 2014 16:05:28 +0200
parents 2481fa96ac1c
children 736f1dd6e142
comparison
equal deleted inserted replaced
1145:4e1a0a1523f1 1146:1ac5ea74dbdf
127 self.host = host 127 self.host = host
128 self.client = client 128 self.client = client
129 129
130 def loadPrivkey(self): 130 def loadPrivkey(self):
131 log.debug(u"loadPrivkey") 131 log.debug(u"loadPrivkey")
132 return self.client.otr_priv_key 132 return self.privkey
133 133
134 def savePrivkey(self): 134 def savePrivkey(self):
135 log.debug(u"savePrivkey") 135 log.debug(u"savePrivkey")
136 if self.privkey is None: 136 if self.privkey is None:
137 raise exceptions.InternalError(_("Save is called but privkey is None !")) 137 raise exceptions.InternalError(_("Save is called but privkey is None !"))
220 client.otr_data = persistent.PersistentBinaryDict(NS_OTR, profile) 220 client.otr_data = persistent.PersistentBinaryDict(NS_OTR, profile)
221 yield client.otr_data.load() 221 yield client.otr_data.load()
222 encrypted_priv_key = client.otr_data.get(PRIVATE_KEY, None) 222 encrypted_priv_key = client.otr_data.get(PRIVATE_KEY, None)
223 if encrypted_priv_key is not None: 223 if encrypted_priv_key is not None:
224 priv_key = yield self.host.memory.decryptValue(encrypted_priv_key, profile) 224 priv_key = yield self.host.memory.decryptValue(encrypted_priv_key, profile)
225 client.otr_priv_key = potr.crypt.PK.parsePrivateKey(priv_key.decode('hex'))[0] 225 ctxMng.account.privkey = potr.crypt.PK.parsePrivateKey(priv_key.decode('hex'))[0]
226 else: 226 else:
227 client.otr_priv_key = None 227 ctxMng.account.privkey = None
228 ctxMng.account.loadTrusts() 228 ctxMng.account.loadTrusts()
229 229
230 def _startRefresh(self, menu_data, profile): 230 def _startRefresh(self, menu_data, profile):
231 """Start or refresh an OTR session 231 """Start or refresh an OTR session
232 232
273 if not to_jid.resource: 273 if not to_jid.resource:
274 to_jid.resource = self.host.memory.getLastResource(to_jid, profile) # FIXME: temporary and unsecure, must be changed when frontends are refactored 274 to_jid.resource = self.host.memory.getLastResource(to_jid, profile) # FIXME: temporary and unsecure, must be changed when frontends are refactored
275 except KeyError: 275 except KeyError:
276 log.error(_("jid key is not present !")) 276 log.error(_("jid key is not present !"))
277 return defer.fail(exceptions.DataError) 277 return defer.fail(exceptions.DataError)
278 otrctx = self.context_managers[profile].getContextForUser(to_jid) 278 ctxMng = self.context_managers[profile]
279 279 otrctx = ctxMng.getContextForUser(to_jid)
280 priv_key = otrctx.user.client.otr_priv_key 280 priv_key = ctxMng.account.privkey
281 281
282 if priv_key is None: 282 if priv_key is None:
283 # we have no private key yet 283 # we have no private key yet
284 dialog = xml_tools.XMLUI(C.XMLUI_DIALOG, 284 dialog = xml_tools.XMLUI(C.XMLUI_DIALOG,
285 dialog_opt = {C.XMLUI_DATA_TYPE: C.XMLUI_DIALOG_MESSAGE, 285 dialog_opt = {C.XMLUI_DATA_TYPE: C.XMLUI_DIALOG_MESSAGE,
344 to_jid.resource = self.host.memory.getLastResource(to_jid, profile) # FIXME: temporary and unsecure, must be changed when frontends are refactored 344 to_jid.resource = self.host.memory.getLastResource(to_jid, profile) # FIXME: temporary and unsecure, must be changed when frontends are refactored
345 except KeyError: 345 except KeyError:
346 log.error(_("jid key is not present !")) 346 log.error(_("jid key is not present !"))
347 return defer.fail(exceptions.DataError) 347 return defer.fail(exceptions.DataError)
348 348
349 client = self.host.getClient(profile) 349 ctxMng = self.context_managers[profile]
350 if client.otr_priv_key is None: 350 if ctxMng.account.privkey is None:
351 return {'xmlui': xml_tools.note(_("You don't have a private key yet !")).toXml()} 351 return {'xmlui': xml_tools.note(_("You don't have a private key yet !")).toXml()}
352 352
353 def dropKey(data, profile): 353 def dropKey(data, profile):
354 if C.bool(data['answer']): 354 if C.bool(data['answer']):
355 # we end all sessions 355 # we end all sessions
356 ctxMng = self.context_managers[profile]
357 for context in ctxMng.contexts.values(): 356 for context in ctxMng.contexts.values():
358 if context.state not in (potr.context.STATE_FINISHED, potr.context.STATE_PLAINTEXT): 357 if context.state not in (potr.context.STATE_FINISHED, potr.context.STATE_PLAINTEXT):
359 context.disconnect() 358 context.disconnect()
360 client.otr_priv_key = None
361 ctxMng.account.privkey = None 359 ctxMng.account.privkey = None
362 ctxMng.account.getPrivkey() # as client.otr_priv_key and account.privkey are None, getPrivkey will generate a new key, and save it 360 ctxMng.account.getPrivkey() # as account.privkey is None, getPrivkey will generate a new key, and save it
363 return {'xmlui': xml_tools.note(_("Your private key has been dropped")).toXml()} 361 return {'xmlui': xml_tools.note(_("Your private key has been dropped")).toXml()}
364 return {} 362 return {}
365 363
366 submit_id = self.host.registerCallback(dropKey, with_data=True, one_shot=True) 364 submit_id = self.host.registerCallback(dropKey, with_data=True, one_shot=True)
367 365