comparison src/browser/sat_browser/plugin_sec_otr.py @ 539:19b8af73e945

browser_side (plugin OTR): ask the user before accepting an OTR query
author souliane <souliane@mailoo.org>
date Sun, 07 Sep 2014 23:29:49 +0200
parents 3317e5d0ac1d
children 22358ffa26e4
comparison
equal deleted inserted replaced
538:3317e5d0ac1d 539:19b8af73e945
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")
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}")
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}")
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}")
86 QUERY_RECEIVED_CONFIRM = D_("Press OK to start now the encryption.")
82 87
83 DEFAULT_POLICY_FLAGS = { 88 DEFAULT_POLICY_FLAGS = {
84 'ALLOW_V2': True, 89 'ALLOW_V2': True,
85 'ALLOW_V3': True, 90 'ALLOW_V3': True,
86 'REQUIRE_ENCRYPTION': False, 91 'REQUIRE_ENCRYPTION': False,
87 'SEND_WHITESPACE_TAG': False, 92 'SEND_WHITESPACE_TAG': False, # FIXME: we need to complete sendMessageTrigger before turning this to True
88 'WHITESPACE_START_AKE': False 93 'WHITESPACE_START_AKE': False, # FIXME: we need to complete messageReceivedTrigger before turning this to True
89 } 94 }
90 95
91 # list a couple of texts (untrusted, trusted) for each state 96 # list a couple of texts (untrusted, trusted) for each state
92 OTR_MSG_STATES = { 97 OTR_MSG_STATES = {
93 otr.context.STATE_PLAINTEXT: [_('none'), _('none')], 98 otr.context.STATE_PLAINTEXT: [_('none'), _('none')],
380 if msg_type == C.MESS_TYPE_INFO: 385 if msg_type == C.MESS_TYPE_INFO:
381 return True 386 return True
382 387
383 tag = otr.proto.checkForOTR(msg) 388 tag = otr.proto.checkForOTR(msg)
384 if tag is None or (tag == otr.context.WHITESPACE_TAG and not DEFAULT_POLICY_FLAGS['WHITESPACE_START_AKE']): 389 if tag is None or (tag == otr.context.WHITESPACE_TAG and not DEFAULT_POLICY_FLAGS['WHITESPACE_START_AKE']):
385 return True # TODO: signal the user that the contact wants to speak OTR 390 return True
391
392 def decrypt(context):
393 context.receiveMessage(msg)
386 394
387 def cb(jid): 395 def cb(jid):
388 otrctx = self.context_manager.getContextForUser(jid) 396 otrctx = self.context_manager.getContextForUser(jid, start=False)
389 otrctx.receiveMessage(msg) 397
390 return False # interrupt the main process 398 if otrctx is None:
399 def confirm(confirm):
400 if confirm:
401 decrypt(self.context_manager.startContext(jid))
402 else:
403 # FIXME: plain text messages with whitespaces would be lost here when WHITESPACE_START_AKE is True
404 pass
405 key = self.context_manager.account.privkey
406 msg = QUERY_RECEIVED + (QUERY_RECEIVED_KEY if key else QUERY_RECEIVED_NO_KEY) + QUERY_RECEIVED_CONFIRM
407 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
409 decrypt(otrctx)
391 410
392 other_jid = to_jid if from_jid.bare == self.host.whoami.bare else from_jid 411 other_jid = to_jid if from_jid.bare == self.host.whoami.bare else from_jid
393 self.fixResource(other_jid, cb) 412 self.fixResource(other_jid, cb)
413 return False # interrupt the main process
394 414
395 def sendMessageTrigger(self, to_jid, msg, msg_type, extra): 415 def sendMessageTrigger(self, to_jid, msg, msg_type, extra):
396 def cb(jid): 416 def cb(jid):
397 otrctx = self.context_manager.getContextForUser(jid, start=False) 417 otrctx = self.context_manager.getContextForUser(jid, start=False)
398 if otrctx is not None and msg_type != 'groupchat' and otrctx.state != otr.context.STATE_PLAINTEXT: 418 if otrctx is not None and msg_type != 'groupchat' and otrctx.state != otr.context.STATE_PLAINTEXT: