Mercurial > libervia-web
comparison src/browser/sat_browser/plugin_sec_otr.py @ 537:cd492c18b366
browser_side (plugin OTR): manage the plain text messages ourselves rather than leaving it to otr.js
author | souliane <souliane@mailoo.org> |
---|---|
date | Sun, 07 Sep 2014 19:28:27 +0200 |
parents | 048ae7314156 |
children | 3317e5d0ac1d |
comparison
equal
deleted
inserted
replaced
536:048ae7314156 | 537:cd492c18b366 |
---|---|
48 | 48 |
49 DEFAULT_POLICY_FLAGS = { | 49 DEFAULT_POLICY_FLAGS = { |
50 'ALLOW_V2': True, | 50 'ALLOW_V2': True, |
51 'ALLOW_V3': True, | 51 'ALLOW_V3': True, |
52 'REQUIRE_ENCRYPTION': False, | 52 'REQUIRE_ENCRYPTION': False, |
53 'SEND_WHITESPACE_TAG': False, | |
54 'WHITESPACE_START_AKE': False | |
53 } | 55 } |
54 | 56 |
55 # list a couple of texts (untrusted, trusted) for each state | 57 # list a couple of texts (untrusted, trusted) for each state |
56 OTR_MSG_STATES = { | 58 OTR_MSG_STATES = { |
57 otr.context.STATE_PLAINTEXT: [_('none'), _('none')], | 59 otr.context.STATE_PLAINTEXT: [_('none'), _('none')], |
90 else: | 92 else: |
91 return False | 93 return False |
92 | 94 |
93 def receiveMessageCb(self, msg, encrypted): | 95 def receiveMessageCb(self, msg, encrypted): |
94 assert isinstance(self.peer, jid.JID) | 96 assert isinstance(self.peer, jid.JID) |
97 if not encrypted: | |
98 log.warning("A plain-text message has been handled by otr.js") | |
95 log.debug("message received (was %s): %s" % ('encrypted' if encrypted else 'plain', msg)) | 99 log.debug("message received (was %s): %s" % ('encrypted' if encrypted else 'plain', msg)) |
96 if not encrypted: | 100 if not encrypted: |
97 if self.state == otr.context.STATE_ENCRYPTED: | 101 if self.state == otr.context.STATE_ENCRYPTED: |
98 log.warning(u"Received unencrypted message in an encrypted context (from %(jid)s)" % {'jid': self.peer.full()}) | 102 log.warning(u"Received unencrypted message in an encrypted context (from %(jid)s)" % {'jid': self.peer.full()}) |
99 feedback = _(u"WARNING: received unencrypted data in a supposedly encrypted context"), | 103 feedback = _(u"WARNING: received unencrypted data in a supposedly encrypted context"), |
346 self.host.bridge.call('getLastResource', gotResource, jid.full()) | 350 self.host.bridge.call('getLastResource', gotResource, jid.full()) |
347 | 351 |
348 def messageReceivedTrigger(self, from_jid, msg, msg_type, to_jid, extra): | 352 def messageReceivedTrigger(self, from_jid, msg, msg_type, to_jid, extra): |
349 if msg_type == C.MESS_TYPE_INFO: | 353 if msg_type == C.MESS_TYPE_INFO: |
350 return True | 354 return True |
351 other_jid = to_jid if from_jid.bare == self.host.whoami.bare else from_jid | 355 |
356 tag = otr.proto.checkForOTR(msg) | |
357 if tag is None or (tag == otr.context.WHITESPACE_TAG and not DEFAULT_POLICY_FLAGS['WHITESPACE_START_AKE']): | |
358 return True # TODO: signal the user that the contact wants to speak OTR | |
352 | 359 |
353 def cb(jid): | 360 def cb(jid): |
354 otrctx = self.context_manager.getContextForUser(jid) | 361 otrctx = self.context_manager.getContextForUser(jid) |
355 otrctx.receiveMessage(msg) | 362 otrctx.receiveMessage(msg) |
356 return False # interrupt the main process | 363 return False # interrupt the main process |
357 | 364 |
365 other_jid = to_jid if from_jid.bare == self.host.whoami.bare else from_jid | |
358 self.fixResource(other_jid, cb) | 366 self.fixResource(other_jid, cb) |
359 | 367 |
360 def sendMessageTrigger(self, to_jid, msg, msg_type, extra): | 368 def sendMessageTrigger(self, to_jid, msg, msg_type, extra): |
361 def cb(jid): | 369 def cb(jid): |
362 otrctx = self.context_manager.getContextForUser(jid, start=False) | 370 otrctx = self.context_manager.getContextForUser(jid, start=False) |