comparison src/browser/sat_browser/plugin_sec_otr.py @ 541:e903a9f79172

browser_side (plugin OTR): also ask for a confirmation if the user has no private key and initiates an OTR session
author souliane <souliane@mailoo.org>
date Sun, 07 Sep 2014 23:58:10 +0200
parents 22358ffa26e4
children d02335553b5d
comparison
equal deleted inserted replaced
540:22358ffa26e4 541:e903a9f79172
77 KEY_NA_TXT = D_("You don't have any private key yet.") 77 KEY_NA_TXT = D_("You don't have any private key yet.")
78 KEY_DROP_TITLE = D_('Drop your private key') 78 KEY_DROP_TITLE = D_('Drop your private key')
79 KEY_DROP_TXT = D_("You private key is used to encrypt messages for your correspondent, nobody except you must know it, if you are in doubt, you should drop it!{eol}{eol}Are you sure you want to drop your private key?") 79 KEY_DROP_TXT = D_("You private key is used to encrypt messages for your correspondent, nobody except you must know it, if you are in doubt, you should drop it!{eol}{eol}Are you sure you want to drop your private key?")
80 KEY_DROPPED_TXT = D_("Your private key has been dropped.") 80 KEY_DROPPED_TXT = D_("Your private key has been dropped.")
81 81
82 QUERY_TITLE = D_("Invitation to encrypt") 82 QUERY_TITLE = D_("Going encrypted")
83 QUERY_RECEIVED = D_("{jid} is willing to start with you an OTR encrypted conversation. This end-to-end encryption is computed by your web browser and you may experience slowdowns.{eol}{eol}") 83 QUERY_RECEIVED = D_("{jid} is willing to start with you an OTR encrypted conversation.{eol}{eol}")
84 QUERY_RECEIVED_NO_KEY = D_("This will take up to 10 seconds to generate your single use private key and start the conversation. In a future version of Libervia, your private key will be safely and persistently stored, so you will have to generate it only once.{eol}{eol}") 84 QUERY_SEND = D_("You are about to start an OTR encrypted conversation with {jid}.{eol}{eol}")
85 QUERY_RECEIVED_KEY = D_("You already have a private key, but to start the conversation will still require a couple of seconds.{eol}{eol}") 85 QUERY_SLOWDOWN = D_("This end-to-end encryption is computed by your web browser and you may experience slowdowns.{eol}{eol}")
86 QUERY_RECEIVED_CONFIRM = D_("Press OK to start now the encryption.") 86 QUERY_NO_KEY = D_("This will take up to 10 seconds to generate your single use private key and start the conversation. In a future version of Libervia, your private key will be safely and persistently stored, so you will have to generate it only once.{eol}{eol}")
87 QUERY_KEY = D_("You already have a private key, but to start the conversation will still require a couple of seconds.{eol}{eol}")
88 QUERY_CONFIRM = D_("Press OK to start now the encryption.")
89
87 90
88 DEFAULT_POLICY_FLAGS = { 91 DEFAULT_POLICY_FLAGS = {
89 'ALLOW_V2': True, 92 'ALLOW_V2': True,
90 'ALLOW_V3': True, 93 'ALLOW_V3': True,
91 'REQUIRE_ENCRYPTION': False, 94 'REQUIRE_ENCRYPTION': False,
392 def decrypt(context): 395 def decrypt(context):
393 context.receiveMessage(msg) 396 context.receiveMessage(msg)
394 397
395 def cb(jid): 398 def cb(jid):
396 otrctx = self.context_manager.getContextForUser(jid, start=False) 399 otrctx = self.context_manager.getContextForUser(jid, start=False)
397
398 if otrctx is None: 400 if otrctx is None:
399 def confirm(confirm): 401 def confirm(confirm):
400 if confirm: 402 if confirm:
401 decrypt(self.context_manager.startContext(jid)) 403 decrypt(self.context_manager.startContext(jid))
402 else: 404 else:
403 # FIXME: plain text messages with whitespaces would be lost here when WHITESPACE_START_AKE is True 405 # FIXME: plain text messages with whitespaces would be lost here when WHITESPACE_START_AKE is True
404 pass 406 pass
405 key = self.context_manager.account.privkey 407 key = self.context_manager.account.privkey
406 msg = QUERY_RECEIVED + (QUERY_RECEIVED_KEY if key else QUERY_RECEIVED_NO_KEY) + QUERY_RECEIVED_CONFIRM 408 msg = QUERY_RECEIVED + QUERY_SLOWDOWN + (QUERY_KEY if key else QUERY_NO_KEY) + QUERY_CONFIRM
407 dialog.ConfirmDialog(confirm, msg.format(jid=jid.full(), eol=DIALOG_EOL), QUERY_TITLE, AddStyleName="maxWidthLimit").show() 409 dialog.ConfirmDialog(confirm, msg.format(jid=jid.full(), eol=DIALOG_EOL), QUERY_TITLE, AddStyleName="maxWidthLimit").show()
408 else: # do not ask if the context exist 410 else: # do not ask if the context exist
409 decrypt(otrctx) 411 decrypt(otrctx)
410 412
411 other_jid = to_jid if from_jid.bare == self.host.whoami.bare else from_jid 413 other_jid = to_jid if from_jid.bare == self.host.whoami.bare else from_jid
471 def _startRefresh(self, menu_data): 473 def _startRefresh(self, menu_data):
472 """Start or refresh an OTR session 474 """Start or refresh an OTR session
473 475
474 @param menu_data: %(menu_data)s 476 @param menu_data: %(menu_data)s
475 """ 477 """
476 def cb(other_jid): 478 def query(other_jid):
477 otrctx = self.context_manager.getContextForUser(other_jid) 479 otrctx = self.context_manager.getContextForUser(other_jid)
478 otrctx.sendQueryMessage() 480 otrctx.sendQueryMessage()
481
482 def cb(jid):
483 key = self.context_manager.account.privkey
484 if key is None:
485 def confirm(confirm):
486 if confirm:
487 query(jid)
488 msg = QUERY_SEND + QUERY_SLOWDOWN + QUERY_NO_KEY + QUERY_CONFIRM
489 dialog.ConfirmDialog(confirm, msg.format(jid=jid.full(), eol=DIALOG_EOL), QUERY_TITLE, AddStyleName="maxWidthLimit").show()
490 else: # on query reception we ask always, if we initiate we just ask the first time
491 query(jid)
479 492
480 try: 493 try:
481 other_jid = menu_data['jid'] 494 other_jid = menu_data['jid']
482 self.fixResource(other_jid, cb) 495 self.fixResource(other_jid, cb)
483 except KeyError: 496 except KeyError:
484 log.error(_("jid key is not present !")) 497 log.error(_("jid key is not present !"))
485 return None
486 498
487 def _endSession(self, menu_data): 499 def _endSession(self, menu_data):
488 """End an OTR session 500 """End an OTR session
489 501
490 @param menu_data: %(menu_data)s 502 @param menu_data: %(menu_data)s