annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
1 #!/usr/bin/python
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
3
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
4 # Libervia plugin for OTR encryption
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Jérôme Poisson (goffi@goffi.org)
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
6 # Copyright (C) 2013, 2014 Adrien Cossa (souliane@mailoo.org)
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
7
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
8 # This program is free software: you can redistribute it and/or modify
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
9 # it under the terms of the GNU Affero General Public License as published by
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
10 # the Free Software Foundation, either version 3 of the License, or
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
11 # (at your option) any later version.
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
12
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
13 # This program is distributed in the hope that it will be useful,
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
16 # GNU Affero General Public License for more details.
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
17
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
18 # You should have received a copy of the GNU Affero General Public License
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
20
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
21 """
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
22 This file is adapted from sat.plugins.plugin.sec_otr. It offers browser-side OTR encryption using otr.js.
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
23 The text messages to display are mostly taken from the Pidgin OTR plugin (GPL 2.0, see http://otr.cypherpunks.ca).
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
24 """
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
25
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
26 from sat.core.i18n import _, D_
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
27 from sat.core.log import getLogger
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
28 from sat.core import exceptions
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
29 log = getLogger(__name__)
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
30
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
31 from constants import Const as C
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
32 import jid
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
33 import otrjs_wrapper as otr
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
34 import dialog
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
35
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
36 NS_OTR = "otr_plugin"
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
37 PRIVATE_KEY = "PRIVATE KEY"
523
5add182e7dd5 browser_side (plugin OTR): rename menus and replace 'buddy' with 'correspondent'
souliane <souliane@mailoo.org>
parents: 522
diff changeset
38 MAIN_MENU = D_('OTR encryption')
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
39 DIALOG_EOL = "<br />"
523
5add182e7dd5 browser_side (plugin OTR): rename menus and replace 'buddy' with 'correspondent'
souliane <souliane@mailoo.org>
parents: 522
diff changeset
40 AUTH_INFO_TXT = D_("Authenticating a correspondent helps ensure that the person you are talking to is who he or she claims to be.{eol}{eol}").format(eol=DIALOG_EOL)
5add182e7dd5 browser_side (plugin OTR): rename menus and replace 'buddy' with 'correspondent'
souliane <souliane@mailoo.org>
parents: 522
diff changeset
41 AUTH_FINGERPRINT_TXT = D_("<i>To verify the fingerprint, contact your correspondent via some other authenticated channel (i.e. not in this chat), such as the telephone or GPG-signed email. Each of you should tell your fingerprint to the other.</i>{eol}{eol}").format(eol=DIALOG_EOL)
5add182e7dd5 browser_side (plugin OTR): rename menus and replace 'buddy' with 'correspondent'
souliane <souliane@mailoo.org>
parents: 522
diff changeset
42 AUTH_QUEST_DEF = D_("<i>To authenticate using a question, pick a question whose answer is known only to you and your correspondent. Enter this question and this answer, then wait for your correspondent to enter the answer too. If the answers don't match, then you may be talking to an imposter.</i>{eol}{eol}").format(eol=DIALOG_EOL)
5add182e7dd5 browser_side (plugin OTR): rename menus and replace 'buddy' with 'correspondent'
souliane <souliane@mailoo.org>
parents: 522
diff changeset
43 AUTH_QUEST_ASK = D_("<i>Your correspondent is attempting to determine if he or she is really talking to you, or if it's someone pretending to be you. Your correspondent has asked a question, indicated below. To authenticate to your correspondent, enter the answer and click OK.</i>{eol}{eol}").format(eol=DIALOG_EOL)
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
44 AUTH_SECRET_TXT = D_("{eol}{eol}Enter secret answer here: (case sensitive){eol}").format(eol=DIALOG_EOL)
530
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
45 FEEDBACK_NOT_PRIVATE = D_("Your conversation with %s is not encrypted.")
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
46
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
47 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?").format(eol=DIALOG_EOL)
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
48
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
49 DEFAULT_POLICY_FLAGS = {
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
50 'ALLOW_V2': True,
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
51 'ALLOW_V3': True,
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
52 'REQUIRE_ENCRYPTION': False,
537
cd492c18b366 browser_side (plugin OTR): manage the plain text messages ourselves rather than leaving it to otr.js
souliane <souliane@mailoo.org>
parents: 536
diff changeset
53 'SEND_WHITESPACE_TAG': False,
cd492c18b366 browser_side (plugin OTR): manage the plain text messages ourselves rather than leaving it to otr.js
souliane <souliane@mailoo.org>
parents: 536
diff changeset
54 'WHITESPACE_START_AKE': False
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
55 }
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
56
536
048ae7314156 browser_side: temporary way to display the OTR state in the LiberviaWidget header
souliane <souliane@mailoo.org>
parents: 535
diff changeset
57 # list a couple of texts (untrusted, trusted) for each state
048ae7314156 browser_side: temporary way to display the OTR state in the LiberviaWidget header
souliane <souliane@mailoo.org>
parents: 535
diff changeset
58 OTR_MSG_STATES = {
048ae7314156 browser_side: temporary way to display the OTR state in the LiberviaWidget header
souliane <souliane@mailoo.org>
parents: 535
diff changeset
59 otr.context.STATE_PLAINTEXT: [_('none'), _('none')],
048ae7314156 browser_side: temporary way to display the OTR state in the LiberviaWidget header
souliane <souliane@mailoo.org>
parents: 535
diff changeset
60 otr.context.STATE_ENCRYPTED: [_('untrusted'), _('trusted')],
048ae7314156 browser_side: temporary way to display the OTR state in the LiberviaWidget header
souliane <souliane@mailoo.org>
parents: 535
diff changeset
61 otr.context.STATE_FINISHED: [_('finished'), _('finished')]
048ae7314156 browser_side: temporary way to display the OTR state in the LiberviaWidget header
souliane <souliane@mailoo.org>
parents: 535
diff changeset
62 }
048ae7314156 browser_side: temporary way to display the OTR state in the LiberviaWidget header
souliane <souliane@mailoo.org>
parents: 535
diff changeset
63
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
64
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
65 class Context(otr.context.Context):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
66
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
67 def __init__(self, host, account, other_jid):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
68 """
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
69
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
70 @param host (satWebFrontend)
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
71 @param account (Account)
523
5add182e7dd5 browser_side (plugin OTR): rename menus and replace 'buddy' with 'correspondent'
souliane <souliane@mailoo.org>
parents: 522
diff changeset
72 @param other_jid (JID): JID of the person your chat correspondent
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
73 """
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
74 super(Context, self).__init__(account, other_jid)
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
75 self.host = host
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
76
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
77 def getPolicy(self, key):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
78 """Get the value of the specified policy
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
79
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
80 @param key (str): a value in:
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
81 - ALLOW_V1 (apriori removed from otr.js)
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
82 - ALLOW_V2
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
83 - ALLOW_V3
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
84 - REQUIRE_ENCRYPTION
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
85 - SEND_WHITESPACE_TAG
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
86 - WHITESPACE_START_AKE
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
87 - ERROR_START_AKE
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
88 @return: str
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
89 """
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
90 if key in DEFAULT_POLICY_FLAGS:
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
91 return DEFAULT_POLICY_FLAGS[key]
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
92 else:
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
93 return False
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
94
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
95 def receiveMessageCb(self, msg, encrypted):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
96 assert isinstance(self.peer, jid.JID)
537
cd492c18b366 browser_side (plugin OTR): manage the plain text messages ourselves rather than leaving it to otr.js
souliane <souliane@mailoo.org>
parents: 536
diff changeset
97 if not encrypted:
cd492c18b366 browser_side (plugin OTR): manage the plain text messages ourselves rather than leaving it to otr.js
souliane <souliane@mailoo.org>
parents: 536
diff changeset
98 log.warning("A plain-text message has been handled by otr.js")
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
99 log.debug("message received (was %s): %s" % ('encrypted' if encrypted else 'plain', msg))
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
100 if not encrypted:
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
101 if self.state == otr.context.STATE_ENCRYPTED:
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
102 log.warning(u"Received unencrypted message in an encrypted context (from %(jid)s)" % {'jid': self.peer.full()})
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
103 feedback = _(u"WARNING: received unencrypted data in a supposedly encrypted context"),
535
331cb6ea0235 browser side (plugin otr): C.MESS_TYPE_INFO is used instead of "headline" for informational message
Goffi <goffi@goffi.org>
parents: 533
diff changeset
104 self.host.newMessageCb(self.peer, feedback, C.MESS_TYPE_INFO, self.host.whoami, {})
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
105 self.host.newMessageCb(self.peer, msg, "chat", self.host.whoami, {})
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
106
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
107 def sendMessageCb(self, msg, meta=None):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
108 assert isinstance(self.peer, jid.JID)
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
109 log.debug("message to send%s: %s" % ((' (attached meta data: %s)' % meta) if meta else '', msg))
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
110 self.host.bridge.call('sendMessage', (None, self.host.sendError), self.peer.full(), msg, '', 'chat', {'send_only': 'true'})
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
111
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
112 def messageErrorCb(self, error):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
113 log.error('error occured: %s' % error)
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
114
536
048ae7314156 browser_side: temporary way to display the OTR state in the LiberviaWidget header
souliane <souliane@mailoo.org>
parents: 535
diff changeset
115 @classmethod
048ae7314156 browser_side: temporary way to display the OTR state in the LiberviaWidget header
souliane <souliane@mailoo.org>
parents: 535
diff changeset
116 def getInfoText(self, state='', trust=''):
048ae7314156 browser_side: temporary way to display the OTR state in the LiberviaWidget header
souliane <souliane@mailoo.org>
parents: 535
diff changeset
117 if not state:
048ae7314156 browser_side: temporary way to display the OTR state in the LiberviaWidget header
souliane <souliane@mailoo.org>
parents: 535
diff changeset
118 state = OTR_MSG_STATES.keys()[0]
048ae7314156 browser_side: temporary way to display the OTR state in the LiberviaWidget header
souliane <souliane@mailoo.org>
parents: 535
diff changeset
119 return 'Encryption: %s' % OTR_MSG_STATES[state][1 if trust else 0]
048ae7314156 browser_side: temporary way to display the OTR state in the LiberviaWidget header
souliane <souliane@mailoo.org>
parents: 535
diff changeset
120
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
121 def setStateCb(self, msg_state, status):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
122 if status == otr.context.STATUS_AKE_INIT:
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
123 return
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
124
536
048ae7314156 browser_side: temporary way to display the OTR state in the LiberviaWidget header
souliane <souliane@mailoo.org>
parents: 535
diff changeset
125 other_jid_s = self.peer.full()
048ae7314156 browser_side: temporary way to display the OTR state in the LiberviaWidget header
souliane <souliane@mailoo.org>
parents: 535
diff changeset
126 feedback = _(u"Error: the state of the conversation with %s is unknown!")
048ae7314156 browser_side: temporary way to display the OTR state in the LiberviaWidget header
souliane <souliane@mailoo.org>
parents: 535
diff changeset
127 trust = self.getCurrentTrust()
048ae7314156 browser_side: temporary way to display the OTR state in the LiberviaWidget header
souliane <souliane@mailoo.org>
parents: 535
diff changeset
128
048ae7314156 browser_side: temporary way to display the OTR state in the LiberviaWidget header
souliane <souliane@mailoo.org>
parents: 535
diff changeset
129 if status == otr.context.STATUS_SEND_QUERY:
531
793f12d1f970 browser_side (plugin OTR): change some feedback messages
souliane <souliane@mailoo.org>
parents: 530
diff changeset
130 if msg_state == otr.context.STATE_ENCRYPTED:
793f12d1f970 browser_side (plugin OTR): change some feedback messages
souliane <souliane@mailoo.org>
parents: 530
diff changeset
131 feedback = _('Attempting to refresh the private conversation with %s...')
793f12d1f970 browser_side (plugin OTR): change some feedback messages
souliane <souliane@mailoo.org>
parents: 530
diff changeset
132 else:
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
133 feedback = _('Attempting to start a private conversation with %s...')
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
134
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
135 elif status == otr.context.STATUS_AKE_SUCCESS:
536
048ae7314156 browser_side: temporary way to display the OTR state in the LiberviaWidget header
souliane <souliane@mailoo.org>
parents: 535
diff changeset
136 trusted_str = _(u"Verified") if trust else _(u"Unverified")
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
137 if msg_state == otr.context.STATE_ENCRYPTED:
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
138 feedback = trusted_str + (u" conversation with %s started. Your client is not logging this conversation.")
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
139 else:
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
140 feedback = _("Error: successfully ake'd with %s but the conversation is not private!")
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
141
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
142 elif status == otr.context.STATUS_END_OTR:
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
143 if msg_state == otr.context.STATE_PLAINTEXT:
525
307f84fee972 browser_side (plugin OTR): avoid unecessary waiting time on menu callbacks when the private key or the context doesn't exist
souliane <souliane@mailoo.org>
parents: 524
diff changeset
144 feedback = FEEDBACK_NOT_PRIVATE
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
145 elif msg_state == otr.context.STATE_ENCRYPTED:
531
793f12d1f970 browser_side (plugin OTR): change some feedback messages
souliane <souliane@mailoo.org>
parents: 530
diff changeset
146 log.error(_("OTR session ended but the context's state is still 'encrypted'!"))
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
147 elif msg_state == otr.context.STATE_FINISHED:
531
793f12d1f970 browser_side (plugin OTR): change some feedback messages
souliane <souliane@mailoo.org>
parents: 530
diff changeset
148 feedback = _("%s has ended his/her private conversation with you; you should do the same.")
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
149
536
048ae7314156 browser_side: temporary way to display the OTR state in the LiberviaWidget header
souliane <souliane@mailoo.org>
parents: 535
diff changeset
150 self.host.newMessageCb(self.peer, feedback % other_jid_s, C.MESS_TYPE_INFO, self.host.whoami, {'header_info': Context.getInfoText(msg_state, trust)})
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
151
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
152 def setCurrentTrust(self, new_trust='', act='asked', type_='trust'):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
153 log.debug("setCurrentTrust: trust={trust}, act={act}, type={type}".format(type=type_, trust=new_trust, act=act))
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
154 title = (_("Authentication of {jid}") if act == "asked" else _("Authentication to {jid}")).format(jid=self.peer.full())
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
155 if type_ == 'abort':
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
156 msg = _("Authentication aborted.")
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
157 elif new_trust:
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
158 if act == "asked":
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
159 msg = _("Authentication successful.")
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
160 else:
523
5add182e7dd5 browser_side (plugin OTR): rename menus and replace 'buddy' with 'correspondent'
souliane <souliane@mailoo.org>
parents: 522
diff changeset
161 msg = _("Your correspondent has successfully authenticated you. You may want to authenticate your correspondent as well by asking your own question.")
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
162 else:
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
163 msg = _("Authentication failed.")
524
d41e850b31b9 browser_side (plugin OTR): limit the max width for all dialogs
souliane <souliane@mailoo.org>
parents: 523
diff changeset
164 dialog.InfoDialog(title, msg, AddStyleName="maxWidthLimit").show()
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
165 if act != "asked":
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
166 return
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
167 old_trust = self.getCurrentTrust()
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
168 otr.context.Context.setCurrentTrust(self, new_trust)
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
169 if old_trust != new_trust:
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
170 feedback = _("The privacy status of the current conversation is now: {state}").format(state='Private' if new_trust else 'Unverified')
536
048ae7314156 browser_side: temporary way to display the OTR state in the LiberviaWidget header
souliane <souliane@mailoo.org>
parents: 535
diff changeset
171 self.host.newMessageCb(self.peer, feedback, C.MESS_TYPE_INFO, self.host.whoami, {'header_info': Context.getInfoText(self.state, new_trust)})
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
172
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
173 def fingerprintAuthCb(self):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
174 """OTR v2 authentication using manual fingerprint comparison"""
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
175 priv_key = self.user.privkey
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
176
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
177 if priv_key is None: # OTR._authenticate should not let us arrive here
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
178 raise exceptions.InternalError
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
179 return
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
180
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
181 other_key = self.getCurrentKey()
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
182 if other_key is None:
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
183 # we have a private key, but not the fingerprint of our correspondent
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
184 msg = AUTH_INFO_TXT + ("Your fingerprint is:{eol}{fingerprint}{eol}{eol}Start an OTR conversation to have your correspondent one.").format(fingerprint=priv_key.fingerprint(), eol=DIALOG_EOL)
524
d41e850b31b9 browser_side (plugin OTR): limit the max width for all dialogs
souliane <souliane@mailoo.org>
parents: 523
diff changeset
185 dialog.InfoDialog(_("Fingerprint"), msg, AddStyleName="maxWidthLimit").show()
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
186 return
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
187
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
188 def setTrust(confirm):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
189 self.setCurrentTrust('fingerprint' if confirm else '')
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
190
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
191 text = AUTH_INFO_TXT + AUTH_FINGERPRINT_TXT + _("Fingerprint for you, {jid}:{eol}{fingerprint}{eol}{eol}").format(jid=self.host.whoami, fingerprint=priv_key.fingerprint(), eol=DIALOG_EOL)
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
192 text += _("Purported fingerprint for {jid}:{eol}{fingerprint}{eol}{eol}").format(jid=self.peer, fingerprint=other_key.fingerprint(), eol=DIALOG_EOL)
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
193 text += _("Did you verify that this is in fact the correct fingerprint for {jid}?").format(jid=self.peer)
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
194 title = _('Authentication of {jid}').format(jid=self.peer.full())
524
d41e850b31b9 browser_side (plugin OTR): limit the max width for all dialogs
souliane <souliane@mailoo.org>
parents: 523
diff changeset
195 dialog.ConfirmDialog(setTrust, text, title, AddStyleName="maxWidthLimit").show()
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
196
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
197 def smpAuthCb(self, type_, data, act=None):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
198 """OTR v3 authentication using the socialist millionaire protocol.
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
199
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
200 @param type_ (str): a value in ('question', 'trust', 'abort')
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
201 @param data (str, bool): this could be:
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
202 - a string containing the question if type_ is 'question'
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
203 - a boolean value telling if the authentication succeed when type_ is 'trust'
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
204 @param act (str): a value in ('asked', 'answered')
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
205 """
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
206 log.debug("smpAuthCb: type={type}, data={data}, act={act}".format(type=type_, data=data, act=act))
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
207 if act is None:
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
208 if type_ == 'question':
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
209 act = 'answered' # OTR._authenticate calls this method with act="asked"
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
210 elif type_ == 'abort':
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
211 act = 'asked' # smpAuthAbort triggers this method with act='answered' when needed
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
212
523
5add182e7dd5 browser_side (plugin OTR): rename menus and replace 'buddy' with 'correspondent'
souliane <souliane@mailoo.org>
parents: 522
diff changeset
213 # FIXME upstream: if the correspondent uses Pidgin and authenticate us via
5add182e7dd5 browser_side (plugin OTR): rename menus and replace 'buddy' with 'correspondent'
souliane <souliane@mailoo.org>
parents: 522
diff changeset
214 # fingerprints, we will reach this code... that's wrong, this method is for SMP!
5add182e7dd5 browser_side (plugin OTR): rename menus and replace 'buddy' with 'correspondent'
souliane <souliane@mailoo.org>
parents: 522
diff changeset
215 # There's probably a bug to fix in otr.js. Do it together with the issue that
5add182e7dd5 browser_side (plugin OTR): rename menus and replace 'buddy' with 'correspondent'
souliane <souliane@mailoo.org>
parents: 522
diff changeset
216 # make us need the dirty self.smpAuthAbort.
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
217 else:
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
218 log.error("FIXME: unmanaged ambiguous 'act' value in Context.smpAuthCb!")
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
219 title = (_("Authentication of {jid}") if act == "asked" else _("Authentication to {jid}")).format(jid=self.peer.full())
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
220 if type_ == 'question':
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
221 if act == 'asked':
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
222 def cb(question, answer=None):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
223 if question is False or not answer: # dialog cancelled or the answer is empty
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
224 return
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
225 self.smpAuthSecret(answer, question)
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
226 text = AUTH_INFO_TXT + AUTH_QUEST_DEF + _("Enter question here:{eol}").format(eol=DIALOG_EOL, question=data)
524
d41e850b31b9 browser_side (plugin OTR): limit the max width for all dialogs
souliane <souliane@mailoo.org>
parents: 523
diff changeset
227 dialog.PromptDialog(cb, [text, AUTH_SECRET_TXT], title=title, AddStyleName="maxWidthLimit").show()
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
228 else:
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
229 def cb(answer):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
230 if not answer: # dialog cancelled or the answer is empty
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
231 self.smpAuthAbort('answered')
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
232 return
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
233 self.smpAuthSecret(answer)
523
5add182e7dd5 browser_side (plugin OTR): rename menus and replace 'buddy' with 'correspondent'
souliane <souliane@mailoo.org>
parents: 522
diff changeset
234 text = AUTH_INFO_TXT + AUTH_QUEST_ASK + _("This is the question asked by your correspondent:{eol}{question}").format(eol=DIALOG_EOL, question=data)
524
d41e850b31b9 browser_side (plugin OTR): limit the max width for all dialogs
souliane <souliane@mailoo.org>
parents: 523
diff changeset
235 dialog.PromptDialog(cb, text + AUTH_SECRET_TXT, title=title, AddStyleName="maxWidthLimit").show()
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
236 elif type_ == 'trust':
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
237 self.setCurrentTrust('smp' if data else '', act)
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
238 elif type_ == 'abort':
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
239 self.setCurrentTrust('', act, 'abort')
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
240
529
9bfd71e2b35c plugin OTR: disconnect the active OTR sessions on profile disconnection
souliane <souliane@mailoo.org>
parents: 528
diff changeset
241 def disconnect(self):
9bfd71e2b35c plugin OTR: disconnect the active OTR sessions on profile disconnection
souliane <souliane@mailoo.org>
parents: 528
diff changeset
242 """Disconnect the session."""
9bfd71e2b35c plugin OTR: disconnect the active OTR sessions on profile disconnection
souliane <souliane@mailoo.org>
parents: 528
diff changeset
243 if self.state != otr.context.STATE_PLAINTEXT:
9bfd71e2b35c plugin OTR: disconnect the active OTR sessions on profile disconnection
souliane <souliane@mailoo.org>
parents: 528
diff changeset
244 super(Context, self).disconnect()
9bfd71e2b35c plugin OTR: disconnect the active OTR sessions on profile disconnection
souliane <souliane@mailoo.org>
parents: 528
diff changeset
245
530
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
246 def finish(self):
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
247 """Finish the session - avoid to send any message but the user still has to end the session himself."""
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
248 if self.state == otr.context.STATE_ENCRYPTED:
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
249 super(Context, self).finish()
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
250
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
251
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
252 class Account(otr.context.Account):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
253
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
254 def __init__(self, host):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
255 log.debug(u"new account: %s" % host.whoami.full())
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
256 if not host.whoami.resource:
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
257 log.warning("Account created without resource")
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
258 super(Account, self).__init__(host.whoami)
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
259 self.host = host
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
260
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
261 def loadPrivkey(self):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
262 return self.privkey
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
263
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
264 def savePrivkey(self):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
265 # TODO: serialize and encrypt the private key and save it to a HTML5 persistent storage
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
266 # We need to ask the user before saving the key (e.g. if he's not on his private machine)
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
267 # self.privkey.serializePrivateKey() --> encrypt --> store
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
268 if self.privkey is None:
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
269 raise exceptions.InternalError(_("Save is called but privkey is None !"))
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
270 pass
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
271
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
272 def saveTrusts(self):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
273 # TODO save the trusts as it would be done for the private key
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
274 pass
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
275
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
276
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
277 class ContextManager(object):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
278
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
279 def __init__(self, host):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
280 self.host = host
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
281 self.account = Account(host)
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
282 self.contexts = {}
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
283
528
ac66b8b11ab8 plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents: 525
diff changeset
284 def startContext(self, other_jid):
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
285 assert isinstance(other_jid, jid.JID)
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
286 # FIXME upstream: apparently pyjamas doesn't implement setdefault well, it ignores JID.__hash__ redefinition
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
287 #context = self.contexts.setdefault(other_jid, Context(self.host, self.account, other_jid))
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
288 if other_jid not in self.contexts:
528
ac66b8b11ab8 plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents: 525
diff changeset
289 self.contexts[other_jid] = Context(self.host, self.account, other_jid)
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
290 return self.contexts[other_jid]
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
291
530
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
292 def getContextForUser(self, other_jid, start=True):
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
293 """Get the context for the given JID
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
294
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
295 @param other_jid (JID): your correspondent
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
296 @param start (bool): start non-existing context if True
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
297 @return: Context
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
298 """
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
299 log.debug(u"getContextForUser [%s]" % other_jid)
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
300 if not other_jid.resource:
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
301 log.error("getContextForUser called with a bare jid")
528
ac66b8b11ab8 plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents: 525
diff changeset
302 if start:
ac66b8b11ab8 plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents: 525
diff changeset
303 return self.startContext(other_jid)
ac66b8b11ab8 plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents: 525
diff changeset
304 else:
ac66b8b11ab8 plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents: 525
diff changeset
305 return self.contexts.get(other_jid, None)
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
306
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
307
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
308 class OTR(object):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
309
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
310 def __init__(self, host):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
311 log.info(_(u"OTR plugin initialization"))
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
312 self.host = host
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
313 self.context_manager = None
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
314 self.last_resources = {}
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
315 self.host.bridge._registerMethods(["skipOTR"])
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
316
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
317 def inhibitMenus(self):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
318 """Tell the caller which dynamic menus should be inhibited"""
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
319 return ["OTR"] # menu categories name to inhibit
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
320
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
321 def extraMenus(self):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
322 # FIXME: handle help strings too
523
5add182e7dd5 browser_side (plugin OTR): rename menus and replace 'buddy' with 'correspondent'
souliane <souliane@mailoo.org>
parents: 522
diff changeset
323 return [(self._startRefresh, C.MENU_SINGLE, (MAIN_MENU, "Start / refresh"), (MAIN_MENU, D_("Start / refresh"))),
5add182e7dd5 browser_side (plugin OTR): rename menus and replace 'buddy' with 'correspondent'
souliane <souliane@mailoo.org>
parents: 522
diff changeset
324 (self._endSession, C.MENU_SINGLE, (MAIN_MENU, "Stop encryption"), (MAIN_MENU, D_("Stop encryption"))),
5add182e7dd5 browser_side (plugin OTR): rename menus and replace 'buddy' with 'correspondent'
souliane <souliane@mailoo.org>
parents: 522
diff changeset
325 (self._authenticate, C.MENU_SINGLE, (MAIN_MENU, "Authenticate correspondent"), (MAIN_MENU, D_("Authenticate correspondent"))),
5add182e7dd5 browser_side (plugin OTR): rename menus and replace 'buddy' with 'correspondent'
souliane <souliane@mailoo.org>
parents: 522
diff changeset
326 (self._dropPrivkey, C.MENU_SINGLE, (MAIN_MENU, "Drop your private key"), (MAIN_MENU, D_("Drop your private key")))]
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
327
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
328 def profileConnected(self):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
329 self.host.bridge.call('skipOTR', None)
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
330 self.context_manager = ContextManager(self.host)
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
331 # TODO: retrieve the encrypted private key from a HTML5 persistent storage,
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
332 # decrypt it, parse it with otr.crypt.PK.parsePrivateKey(privkey) and
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
333 # assign it to self.context_manager.account.privkey
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
334
529
9bfd71e2b35c plugin OTR: disconnect the active OTR sessions on profile disconnection
souliane <souliane@mailoo.org>
parents: 528
diff changeset
335 def profileDisconnected(self):
9bfd71e2b35c plugin OTR: disconnect the active OTR sessions on profile disconnection
souliane <souliane@mailoo.org>
parents: 528
diff changeset
336 for context in self.context_manager.contexts.values():
9bfd71e2b35c plugin OTR: disconnect the active OTR sessions on profile disconnection
souliane <souliane@mailoo.org>
parents: 528
diff changeset
337 context.disconnect()
9bfd71e2b35c plugin OTR: disconnect the active OTR sessions on profile disconnection
souliane <souliane@mailoo.org>
parents: 528
diff changeset
338
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
339 def fixResource(self, jid, cb):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
340 # FIXME: it's dirty, but libervia doesn't manage resources correctly now, refactoring is planed
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
341 if jid.resource:
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
342 cb(jid)
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
343 elif jid.bare in self.last_resources:
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
344 jid.resource = self.last_resources[jid.bare]
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
345 cb(jid)
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
346 else:
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
347 def gotResource(resource):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
348 jid.setResource(resource)
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
349 cb(jid)
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
350 self.host.bridge.call('getLastResource', gotResource, jid.full())
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
351
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
352 def messageReceivedTrigger(self, from_jid, msg, msg_type, to_jid, extra):
533
19fc2ebc02dd browser_side: management of new "info" newMessage type
Goffi <goffi@goffi.org>
parents: 531
diff changeset
353 if msg_type == C.MESS_TYPE_INFO:
19fc2ebc02dd browser_side: management of new "info" newMessage type
Goffi <goffi@goffi.org>
parents: 531
diff changeset
354 return True
537
cd492c18b366 browser_side (plugin OTR): manage the plain text messages ourselves rather than leaving it to otr.js
souliane <souliane@mailoo.org>
parents: 536
diff changeset
355
cd492c18b366 browser_side (plugin OTR): manage the plain text messages ourselves rather than leaving it to otr.js
souliane <souliane@mailoo.org>
parents: 536
diff changeset
356 tag = otr.proto.checkForOTR(msg)
cd492c18b366 browser_side (plugin OTR): manage the plain text messages ourselves rather than leaving it to otr.js
souliane <souliane@mailoo.org>
parents: 536
diff changeset
357 if tag is None or (tag == otr.context.WHITESPACE_TAG and not DEFAULT_POLICY_FLAGS['WHITESPACE_START_AKE']):
cd492c18b366 browser_side (plugin OTR): manage the plain text messages ourselves rather than leaving it to otr.js
souliane <souliane@mailoo.org>
parents: 536
diff changeset
358 return True # TODO: signal the user that the contact wants to speak OTR
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
359
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
360 def cb(jid):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
361 otrctx = self.context_manager.getContextForUser(jid)
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
362 otrctx.receiveMessage(msg)
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
363 return False # interrupt the main process
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
364
537
cd492c18b366 browser_side (plugin OTR): manage the plain text messages ourselves rather than leaving it to otr.js
souliane <souliane@mailoo.org>
parents: 536
diff changeset
365 other_jid = to_jid if from_jid.bare == self.host.whoami.bare else from_jid
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
366 self.fixResource(other_jid, cb)
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
367
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
368 def sendMessageTrigger(self, to_jid, msg, msg_type, extra):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
369 def cb(jid):
528
ac66b8b11ab8 plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents: 525
diff changeset
370 otrctx = self.context_manager.getContextForUser(jid, start=False)
ac66b8b11ab8 plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents: 525
diff changeset
371 if otrctx is not None and msg_type != 'groupchat' and otrctx.state != otr.context.STATE_PLAINTEXT:
ac66b8b11ab8 plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents: 525
diff changeset
372 if otrctx.state == otr.context.STATE_ENCRYPTED:
ac66b8b11ab8 plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents: 525
diff changeset
373 log.debug(u"encrypting message")
ac66b8b11ab8 plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents: 525
diff changeset
374 otrctx.sendMessage(msg)
ac66b8b11ab8 plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents: 525
diff changeset
375 self.host.newMessageCb(self.host.whoami, msg, msg_type, jid, extra)
ac66b8b11ab8 plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents: 525
diff changeset
376 else:
ac66b8b11ab8 plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents: 525
diff changeset
377 feedback = D_("Your message was not sent because your correspondent closed the encrypted conversation on his/her side. Either close your own side, or refresh the session.")
ac66b8b11ab8 plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents: 525
diff changeset
378 dialog.InfoDialog(_('Finished encrypted session'), feedback, AddStyleName="maxWidthLimit").show()
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
379 else:
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
380 log.debug(u"sending message unencrypted")
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
381 self.host.bridge.call('sendMessage', (None, self.host.sendError), to_jid.full(), msg, '', msg_type, extra)
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
382
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
383 if msg_type != 'groupchat':
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
384 self.fixResource(to_jid, cb)
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
385 else:
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
386 cb(to_jid)
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
387 return False # interrupt the main process
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
388
530
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
389 def presenceReceivedTrigger(self, entity, show, priority, statuses):
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
390 if show == "unavailable":
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
391 self.endSession(entity, finish=True)
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
392 return True
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
393
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
394 def endSession(self, other_jid, profile, finish=False):
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
395 """Finish or disconnect an OTR session
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
396
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
397 @param other_jid (JID): str
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
398 @param finish: if True, finish the session but do not disconnect it
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
399 @return: True if the session has been finished or disconnected, False if there was nothing to do
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
400 """
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
401 def cb(other_jid):
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
402 def not_available():
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
403 if not finish:
535
331cb6ea0235 browser side (plugin otr): C.MESS_TYPE_INFO is used instead of "headline" for informational message
Goffi <goffi@goffi.org>
parents: 533
diff changeset
404 self.host.newMessageCb(other_jid, FEEDBACK_NOT_PRIVATE % other_jid.full(), C.MESS_TYPE_INFO, self.host.whoami, {})
530
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
405
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
406 priv_key = self.context_manager.account.privkey
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
407 if priv_key is None:
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
408 not_available()
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
409 return
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
410
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
411 otrctx = self.context_manager.getContextForUser(other_jid, start=False)
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
412 if otrctx is None:
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
413 not_available()
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
414 return
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
415 if finish:
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
416 otrctx.finish()
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
417 else:
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
418 otrctx.disconnect()
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
419
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
420 self.fixResource(other_jid, cb)
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
421
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
422 # Menu callbacks
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
423
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
424 def _startRefresh(self, menu_data):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
425 """Start or refresh an OTR session
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
426
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
427 @param menu_data: %(menu_data)s
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
428 """
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
429 def cb(other_jid):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
430 otrctx = self.context_manager.getContextForUser(other_jid)
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
431 otrctx.sendQueryMessage()
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
432
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
433 try:
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
434 other_jid = menu_data['jid']
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
435 self.fixResource(other_jid, cb)
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
436 except KeyError:
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
437 log.error(_("jid key is not present !"))
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
438 return None
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
439
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
440 def _endSession(self, menu_data):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
441 """End an OTR session
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
442
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
443 @param menu_data: %(menu_data)s
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
444 """
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
445 try:
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
446 other_jid = menu_data['jid']
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
447 except KeyError:
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
448 log.error(_("jid key is not present !"))
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
449 return None
530
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
450 self.endSession(other_jid)
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
451
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
452 def _authenticate(self, menu_data, profile):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
453 """Authenticate other user and see our own fingerprint
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
454
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
455 @param menu_data: %(menu_data)s
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
456 @param profile: %(doc_profile)s
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
457 """
525
307f84fee972 browser_side (plugin OTR): avoid unecessary waiting time on menu callbacks when the private key or the context doesn't exist
souliane <souliane@mailoo.org>
parents: 524
diff changeset
458 def not_available():
307f84fee972 browser_side (plugin OTR): avoid unecessary waiting time on menu callbacks when the private key or the context doesn't exist
souliane <souliane@mailoo.org>
parents: 524
diff changeset
459 dialog.InfoDialog(_("No running session"), _("You must start a private conversation before authenticating your correspondent."), AddStyleName="maxWidthLimit").show()
307f84fee972 browser_side (plugin OTR): avoid unecessary waiting time on menu callbacks when the private key or the context doesn't exist
souliane <souliane@mailoo.org>
parents: 524
diff changeset
460
307f84fee972 browser_side (plugin OTR): avoid unecessary waiting time on menu callbacks when the private key or the context doesn't exist
souliane <souliane@mailoo.org>
parents: 524
diff changeset
461 priv_key = self.context_manager.account.privkey
307f84fee972 browser_side (plugin OTR): avoid unecessary waiting time on menu callbacks when the private key or the context doesn't exist
souliane <souliane@mailoo.org>
parents: 524
diff changeset
462 if priv_key is None:
307f84fee972 browser_side (plugin OTR): avoid unecessary waiting time on menu callbacks when the private key or the context doesn't exist
souliane <souliane@mailoo.org>
parents: 524
diff changeset
463 not_available()
307f84fee972 browser_side (plugin OTR): avoid unecessary waiting time on menu callbacks when the private key or the context doesn't exist
souliane <souliane@mailoo.org>
parents: 524
diff changeset
464 return
307f84fee972 browser_side (plugin OTR): avoid unecessary waiting time on menu callbacks when the private key or the context doesn't exist
souliane <souliane@mailoo.org>
parents: 524
diff changeset
465
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
466 def cb(to_jid):
528
ac66b8b11ab8 plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents: 525
diff changeset
467 otrctx = self.context_manager.getContextForUser(to_jid, start=False)
525
307f84fee972 browser_side (plugin OTR): avoid unecessary waiting time on menu callbacks when the private key or the context doesn't exist
souliane <souliane@mailoo.org>
parents: 524
diff changeset
468 if otrctx is None:
307f84fee972 browser_side (plugin OTR): avoid unecessary waiting time on menu callbacks when the private key or the context doesn't exist
souliane <souliane@mailoo.org>
parents: 524
diff changeset
469 not_available()
307f84fee972 browser_side (plugin OTR): avoid unecessary waiting time on menu callbacks when the private key or the context doesn't exist
souliane <souliane@mailoo.org>
parents: 524
diff changeset
470 return
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
471 otr_version = otrctx.getUsedVersion()
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
472 if otr_version == otr.context.OTR_VERSION_2:
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
473 otrctx.fingerprintAuthCb()
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
474 elif otr_version == otr.context.OTR_VERSION_3:
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
475 otrctx.smpAuthCb('question', None, 'asked')
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
476 else:
525
307f84fee972 browser_side (plugin OTR): avoid unecessary waiting time on menu callbacks when the private key or the context doesn't exist
souliane <souliane@mailoo.org>
parents: 524
diff changeset
477 not_available()
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
478
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
479 try:
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
480 to_jid = menu_data['jid']
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
481 self.fixResource(to_jid, cb)
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
482 except KeyError:
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
483 log.error(_("jid key is not present !"))
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
484 return None
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
485
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
486 def _dropPrivkey(self, menu_data, profile):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
487 """Drop our private Key
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
488
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
489 @param menu_data: %(menu_data)s
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
490 @param profile: %(doc_profile)s
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
491 """
525
307f84fee972 browser_side (plugin OTR): avoid unecessary waiting time on menu callbacks when the private key or the context doesn't exist
souliane <souliane@mailoo.org>
parents: 524
diff changeset
492 priv_key = self.context_manager.account.privkey
307f84fee972 browser_side (plugin OTR): avoid unecessary waiting time on menu callbacks when the private key or the context doesn't exist
souliane <souliane@mailoo.org>
parents: 524
diff changeset
493 if priv_key is None:
307f84fee972 browser_side (plugin OTR): avoid unecessary waiting time on menu callbacks when the private key or the context doesn't exist
souliane <souliane@mailoo.org>
parents: 524
diff changeset
494 # we have no private key yet
307f84fee972 browser_side (plugin OTR): avoid unecessary waiting time on menu callbacks when the private key or the context doesn't exist
souliane <souliane@mailoo.org>
parents: 524
diff changeset
495 dialog.InfoDialog(_("No private key"), _("You don't have any private key yet."), AddStyleName="maxWidthLimit").show()
307f84fee972 browser_side (plugin OTR): avoid unecessary waiting time on menu callbacks when the private key or the context doesn't exist
souliane <souliane@mailoo.org>
parents: 524
diff changeset
496 return
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
497
525
307f84fee972 browser_side (plugin OTR): avoid unecessary waiting time on menu callbacks when the private key or the context doesn't exist
souliane <souliane@mailoo.org>
parents: 524
diff changeset
498 def cb(to_jid):
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
499 def dropKey(confirm):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
500 if confirm:
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
501 # we end all sessions
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
502 for context in self.context_manager.contexts.values():
529
9bfd71e2b35c plugin OTR: disconnect the active OTR sessions on profile disconnection
souliane <souliane@mailoo.org>
parents: 528
diff changeset
503 context.disconnect()
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
504 self.context_manager.account.privkey = None
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
505 self.context_manager.account.getPrivkey() # as account.privkey are None, getPrivkey will generate a new key, and save it
524
d41e850b31b9 browser_side (plugin OTR): limit the max width for all dialogs
souliane <souliane@mailoo.org>
parents: 523
diff changeset
506 dialog.InfoDialog(_('Private key'), _("Your private key has been dropped."), AddStyleName="maxWidthLimit").show()
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
507
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
508 text = _(DROP_TXT)
524
d41e850b31b9 browser_side (plugin OTR): limit the max width for all dialogs
souliane <souliane@mailoo.org>
parents: 523
diff changeset
509 title = _('Drop your private key')
d41e850b31b9 browser_side (plugin OTR): limit the max width for all dialogs
souliane <souliane@mailoo.org>
parents: 523
diff changeset
510 dialog.ConfirmDialog(dropKey, text, title, AddStyleName="maxWidthLimit").show()
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
511
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
512 try:
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
513 to_jid = menu_data['jid']
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
514 self.fixResource(to_jid, cb)
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
515 except KeyError:
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
516 log.error(_("jid key is not present !"))
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
517 return None