Mercurial > libervia-web
comparison src/browser/sat_browser/plugin_sec_otr.py @ 536:048ae7314156
browser_side: temporary way to display the OTR state in the LiberviaWidget header
author | souliane <souliane@mailoo.org> |
---|---|
date | Sun, 07 Sep 2014 16:40:33 +0200 |
parents | 331cb6ea0235 |
children | cd492c18b366 |
comparison
equal
deleted
inserted
replaced
535:331cb6ea0235 | 536:048ae7314156 |
---|---|
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 } | 53 } |
54 | 54 |
55 # list a couple of texts (untrusted, trusted) for each state | |
56 OTR_MSG_STATES = { | |
57 otr.context.STATE_PLAINTEXT: [_('none'), _('none')], | |
58 otr.context.STATE_ENCRYPTED: [_('untrusted'), _('trusted')], | |
59 otr.context.STATE_FINISHED: [_('finished'), _('finished')] | |
60 } | |
61 | |
55 | 62 |
56 class Context(otr.context.Context): | 63 class Context(otr.context.Context): |
57 | 64 |
58 def __init__(self, host, account, other_jid): | 65 def __init__(self, host, account, other_jid): |
59 """ | 66 """ |
99 self.host.bridge.call('sendMessage', (None, self.host.sendError), self.peer.full(), msg, '', 'chat', {'send_only': 'true'}) | 106 self.host.bridge.call('sendMessage', (None, self.host.sendError), self.peer.full(), msg, '', 'chat', {'send_only': 'true'}) |
100 | 107 |
101 def messageErrorCb(self, error): | 108 def messageErrorCb(self, error): |
102 log.error('error occured: %s' % error) | 109 log.error('error occured: %s' % error) |
103 | 110 |
111 @classmethod | |
112 def getInfoText(self, state='', trust=''): | |
113 if not state: | |
114 state = OTR_MSG_STATES.keys()[0] | |
115 return 'Encryption: %s' % OTR_MSG_STATES[state][1 if trust else 0] | |
116 | |
104 def setStateCb(self, msg_state, status): | 117 def setStateCb(self, msg_state, status): |
118 if status == otr.context.STATUS_AKE_INIT: | |
119 return | |
120 | |
105 other_jid_s = self.peer.full() | 121 other_jid_s = self.peer.full() |
106 feedback = _(u"Error: the state of the conversation with %s is unknown!") | 122 feedback = _(u"Error: the state of the conversation with %s is unknown!") |
107 | 123 trust = self.getCurrentTrust() |
108 if status == otr.context.STATUS_AKE_INIT: | 124 |
109 return | 125 if status == otr.context.STATUS_SEND_QUERY: |
110 | |
111 elif status == otr.context.STATUS_SEND_QUERY: | |
112 if msg_state == otr.context.STATE_ENCRYPTED: | 126 if msg_state == otr.context.STATE_ENCRYPTED: |
113 feedback = _('Attempting to refresh the private conversation with %s...') | 127 feedback = _('Attempting to refresh the private conversation with %s...') |
114 else: | 128 else: |
115 feedback = _('Attempting to start a private conversation with %s...') | 129 feedback = _('Attempting to start a private conversation with %s...') |
116 | 130 |
117 elif status == otr.context.STATUS_AKE_SUCCESS: | 131 elif status == otr.context.STATUS_AKE_SUCCESS: |
118 trusted_str = _(u"Verified") if self.getCurrentTrust() else _(u"Unverified") | 132 trusted_str = _(u"Verified") if trust else _(u"Unverified") |
119 if msg_state == otr.context.STATE_ENCRYPTED: | 133 if msg_state == otr.context.STATE_ENCRYPTED: |
120 feedback = trusted_str + (u" conversation with %s started. Your client is not logging this conversation.") | 134 feedback = trusted_str + (u" conversation with %s started. Your client is not logging this conversation.") |
121 else: | 135 else: |
122 feedback = _("Error: successfully ake'd with %s but the conversation is not private!") | 136 feedback = _("Error: successfully ake'd with %s but the conversation is not private!") |
123 | 137 |
127 elif msg_state == otr.context.STATE_ENCRYPTED: | 141 elif msg_state == otr.context.STATE_ENCRYPTED: |
128 log.error(_("OTR session ended but the context's state is still 'encrypted'!")) | 142 log.error(_("OTR session ended but the context's state is still 'encrypted'!")) |
129 elif msg_state == otr.context.STATE_FINISHED: | 143 elif msg_state == otr.context.STATE_FINISHED: |
130 feedback = _("%s has ended his/her private conversation with you; you should do the same.") | 144 feedback = _("%s has ended his/her private conversation with you; you should do the same.") |
131 | 145 |
132 self.host.newMessageCb(self.peer, feedback % other_jid_s, C.MESS_TYPE_INFO, self.host.whoami, {}) | 146 self.host.newMessageCb(self.peer, feedback % other_jid_s, C.MESS_TYPE_INFO, self.host.whoami, {'header_info': Context.getInfoText(msg_state, trust)}) |
133 | 147 |
134 def setCurrentTrust(self, new_trust='', act='asked', type_='trust'): | 148 def setCurrentTrust(self, new_trust='', act='asked', type_='trust'): |
135 log.debug("setCurrentTrust: trust={trust}, act={act}, type={type}".format(type=type_, trust=new_trust, act=act)) | 149 log.debug("setCurrentTrust: trust={trust}, act={act}, type={type}".format(type=type_, trust=new_trust, act=act)) |
136 title = (_("Authentication of {jid}") if act == "asked" else _("Authentication to {jid}")).format(jid=self.peer.full()) | 150 title = (_("Authentication of {jid}") if act == "asked" else _("Authentication to {jid}")).format(jid=self.peer.full()) |
137 if type_ == 'abort': | 151 if type_ == 'abort': |
148 return | 162 return |
149 old_trust = self.getCurrentTrust() | 163 old_trust = self.getCurrentTrust() |
150 otr.context.Context.setCurrentTrust(self, new_trust) | 164 otr.context.Context.setCurrentTrust(self, new_trust) |
151 if old_trust != new_trust: | 165 if old_trust != new_trust: |
152 feedback = _("The privacy status of the current conversation is now: {state}").format(state='Private' if new_trust else 'Unverified') | 166 feedback = _("The privacy status of the current conversation is now: {state}").format(state='Private' if new_trust else 'Unverified') |
153 self.host.newMessageCb(self.peer, feedback, C.MESS_TYPE_INFO, self.host.whoami, {}) | 167 self.host.newMessageCb(self.peer, feedback, C.MESS_TYPE_INFO, self.host.whoami, {'header_info': Context.getInfoText(self.state, new_trust)}) |
154 | 168 |
155 def fingerprintAuthCb(self): | 169 def fingerprintAuthCb(self): |
156 """OTR v2 authentication using manual fingerprint comparison""" | 170 """OTR v2 authentication using manual fingerprint comparison""" |
157 priv_key = self.user.privkey | 171 priv_key = self.user.privkey |
158 | 172 |