Mercurial > libervia-web
comparison src/browser/sat_browser/plugin_sec_otr.py @ 543:d02335553b5d
browser_side (plugin OTR): display OTR states with icons instead of a text
author | souliane <souliane@mailoo.org> |
---|---|
date | Mon, 08 Sep 2014 15:32:33 +0200 |
parents | e903a9f79172 |
children | ad18eb65b6db |
comparison
equal
deleted
inserted
replaced
542:fb20b1423143 | 543:d02335553b5d |
---|---|
94 'REQUIRE_ENCRYPTION': False, | 94 'REQUIRE_ENCRYPTION': False, |
95 'SEND_WHITESPACE_TAG': False, # FIXME: we need to complete sendMessageTrigger before turning this to True | 95 'SEND_WHITESPACE_TAG': False, # FIXME: we need to complete sendMessageTrigger before turning this to True |
96 'WHITESPACE_START_AKE': False, # FIXME: we need to complete messageReceivedTrigger before turning this to True | 96 'WHITESPACE_START_AKE': False, # FIXME: we need to complete messageReceivedTrigger before turning this to True |
97 } | 97 } |
98 | 98 |
99 # list a couple of texts (untrusted, trusted) for each state | 99 # list a couple of texts or htmls (untrusted, trusted) for each state |
100 OTR_MSG_STATES = { | 100 OTR_MSG_STATES = { |
101 otr.context.STATE_PLAINTEXT: [_('none'), _('none')], | 101 otr.context.STATE_PLAINTEXT: [ |
102 otr.context.STATE_ENCRYPTED: [_('untrusted'), _('trusted')], | 102 '<img src="media/icons/silk/lock_open.png" /><img src="media/icons/silk/key_delete.png" />', |
103 otr.context.STATE_FINISHED: [_('finished'), _('finished')] | 103 '<img src="media/icons/silk/lock_open.png" /><img src="media/icons/silk/key.png" />' |
104 ], | |
105 otr.context.STATE_ENCRYPTED: [ | |
106 '<img src="media/icons/silk/lock.png" /><img src="media/icons/silk/key_delete.png" />', | |
107 '<img src="media/icons/silk/lock.png" /><img src="media/icons/silk/key.png" />' | |
108 ], | |
109 otr.context.STATE_FINISHED: [ | |
110 '<img src="media/icons/silk/lock_break.png" /><img src="media/icons/silk/key_delete.png" />', | |
111 '<img src="media/icons/silk/lock_break.png" /><img src="media/icons/silk/key.png" />' | |
112 ] | |
104 } | 113 } |
105 | 114 |
106 | 115 |
107 class Context(otr.context.Context): | 116 class Context(otr.context.Context): |
108 | 117 |
151 self.host.bridge.call('sendMessage', (None, self.host.sendError), self.peer.full(), msg, '', 'chat', {'send_only': 'true'}) | 160 self.host.bridge.call('sendMessage', (None, self.host.sendError), self.peer.full(), msg, '', 'chat', {'send_only': 'true'}) |
152 | 161 |
153 def messageErrorCb(self, error): | 162 def messageErrorCb(self, error): |
154 log.error('error occured: %s' % error) | 163 log.error('error occured: %s' % error) |
155 | 164 |
156 @classmethod | |
157 def getInfoText(self, state='', trust=''): | |
158 if not state: | |
159 state = OTR_MSG_STATES.keys()[0] | |
160 return 'Encryption: %s' % OTR_MSG_STATES[state][1 if trust else 0] | |
161 | |
162 def setStateCb(self, msg_state, status): | 165 def setStateCb(self, msg_state, status): |
163 if status == otr.context.STATUS_AKE_INIT: | 166 if status == otr.context.STATUS_AKE_INIT: |
164 return | 167 return |
165 | 168 |
166 other_jid_s = self.peer.full() | 169 other_jid_s = self.peer.full() |
180 elif msg_state == otr.context.STATE_ENCRYPTED: | 183 elif msg_state == otr.context.STATE_ENCRYPTED: |
181 log.error(END_ENCRYPTED) | 184 log.error(END_ENCRYPTED) |
182 elif msg_state == otr.context.STATE_FINISHED: | 185 elif msg_state == otr.context.STATE_FINISHED: |
183 feedback = END_FINISHED | 186 feedback = END_FINISHED |
184 | 187 |
185 self.host.newMessageCb(self.peer, feedback.format(jid=other_jid_s), C.MESS_TYPE_INFO, self.host.whoami, {'header_info': Context.getInfoText(msg_state, trust)}) | 188 self.host.newMessageCb(self.peer, feedback.format(jid=other_jid_s), C.MESS_TYPE_INFO, self.host.whoami, {'header_info': OTR.getInfoText(msg_state, trust)}) |
186 | 189 |
187 def setCurrentTrust(self, new_trust='', act='asked', type_='trust'): | 190 def setCurrentTrust(self, new_trust='', act='asked', type_='trust'): |
188 log.debug("setCurrentTrust: trust={trust}, act={act}, type={type}".format(type=type_, trust=new_trust, act=act)) | 191 log.debug("setCurrentTrust: trust={trust}, act={act}, type={type}".format(type=type_, trust=new_trust, act=act)) |
189 title = (AUTH_OTHER_TITLE if act == "asked" else AUTH_US_TITLE).format(jid=self.peer.full()) | 192 title = (AUTH_OTHER_TITLE if act == "asked" else AUTH_US_TITLE).format(jid=self.peer.full()) |
190 old_trust = self.getCurrentTrust() | 193 old_trust = self.getCurrentTrust() |
203 if act != "asked": | 206 if act != "asked": |
204 return | 207 return |
205 otr.context.Context.setCurrentTrust(self, new_trust) | 208 otr.context.Context.setCurrentTrust(self, new_trust) |
206 if old_trust != new_trust: | 209 if old_trust != new_trust: |
207 feedback = AUTH_STATUS.format(state=(AUTH_TRUSTED if new_trust else AUTH_UNTRUSTED).lower()) | 210 feedback = AUTH_STATUS.format(state=(AUTH_TRUSTED if new_trust else AUTH_UNTRUSTED).lower()) |
208 self.host.newMessageCb(self.peer, feedback, C.MESS_TYPE_INFO, self.host.whoami, {'header_info': Context.getInfoText(self.state, new_trust)}) | 211 self.host.newMessageCb(self.peer, feedback, C.MESS_TYPE_INFO, self.host.whoami, {'header_info': OTR.getInfoText(self.state, new_trust)}) |
209 | 212 |
210 def fingerprintAuthCb(self): | 213 def fingerprintAuthCb(self): |
211 """OTR v2 authentication using manual fingerprint comparison""" | 214 """OTR v2 authentication using manual fingerprint comparison""" |
212 priv_key = self.user.privkey | 215 priv_key = self.user.privkey |
213 | 216 |
347 self.host = host | 350 self.host = host |
348 self.context_manager = None | 351 self.context_manager = None |
349 self.last_resources = {} | 352 self.last_resources = {} |
350 self.host.bridge._registerMethods(["skipOTR"]) | 353 self.host.bridge._registerMethods(["skipOTR"]) |
351 | 354 |
355 @classmethod | |
356 def getInfoText(self, state=otr.context.STATE_PLAINTEXT, trust=''): | |
357 if not state: | |
358 state = OTR_MSG_STATES.keys()[0] | |
359 return OTR_MSG_STATES[state][1 if trust else 0] | |
360 | |
352 def inhibitMenus(self): | 361 def inhibitMenus(self): |
353 """Tell the caller which dynamic menus should be inhibited""" | 362 """Tell the caller which dynamic menus should be inhibited""" |
354 return ["OTR"] # menu categories name to inhibit | 363 return ["OTR"] # menu categories name to inhibit |
355 | 364 |
356 def extraMenus(self): | 365 def extraMenus(self): |