annotate src/browser/sat_browser/plugin_sec_otr.py @ 914:0c0551967bdf

server, browser: partial Libervia fix Libervia was broken following the refactorings. This commit partially fixes it : Libervia is starting, avatar, blog and message are working again, but not everything is restablished yet. following things have been fixed/changed: - new dependency: shortuuid - D-Bus bridge is working again - fixed naming in several bridge methods - register method changed to register_signal - fixed Chat widget, which was not working anymore since the refactoring - avatar now use avatarGet. Cache dir is accessible using a session specific uuid, to avoid cache leak (i.e. accessing cache of other profiles) - server: new uuid attribute in session data Browser code is not fully working yet, notably OTR and contact list are not fully fixed.
author Goffi <goffi@goffi.org>
date Sun, 26 Feb 2017 18:32:47 +0100
parents e8b133b77aa4
children fd4eae654182
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
818
f8a7a046ff9c copyright update
Goffi <goffi@goffi.org>
parents: 694
diff changeset
5 # Copyright (C) 2009-2016 Jérôme Poisson (goffi@goffi.org)
f8a7a046ff9c copyright update
Goffi <goffi@goffi.org>
parents: 694
diff changeset
6 # Copyright (C) 2013-2016 Adrien Cossa (souliane@mailoo.org)
522
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
663
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
26 from sat.core.log import getLogger
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
27 log = getLogger(__name__)
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
28
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
29 from sat.core.i18n import _, D_
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
30 from sat.core import exceptions
681
3b185ccb70b4 browser side: updated trigger import according to backend renaming (sat.tools.misc is now sat.tools.trigger)
Goffi <goffi@goffi.org>
parents: 678
diff changeset
31 from sat.tools import trigger
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
32
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
33 from constants import Const as C
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
34 from sat_frontends.tools import jid
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
35 import otrjs_wrapper as otr
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
36 import dialog
616
1c0d5a87c554 browser_side: add and use method displayWidget to harmonize widget's management in Libervia (not completely done, there are some issues)
souliane <souliane@mailoo.org>
parents: 589
diff changeset
37 import chat
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 909
diff changeset
38 import uuid
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 909
diff changeset
39 import time
559
77372641e05d browser_side (plugin OTR): display the correct icons on opening the window + auto-open on accepted invitation
souliane <souliane@mailoo.org>
parents: 557
diff changeset
40
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
41
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
42 NS_OTR = "otr_plugin"
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
43 PRIVATE_KEY = "PRIVATE KEY"
678
2e087e093e7f browser side(otr): restored menu hooks using new hook system
Goffi <goffi@goffi.org>
parents: 676
diff changeset
44 MAIN_MENU = D_('OTR') # TODO: get this constant directly from backend's plugin
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
45 DIALOG_EOL = "<br />"
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
46
538
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
47 AUTH_TRUSTED = D_("Verified")
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
48 AUTH_UNTRUSTED = D_("Unverified")
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
49 AUTH_OTHER_TITLE = D_("Authentication of {jid}")
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
50 AUTH_US_TITLE = D_("Authentication to {jid}")
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
51 AUTH_TRUST_NA_TITLE = D_("Authentication requirement")
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
52 AUTH_TRUST_NA_TXT = D_("You must start an OTR conversation before authenticating your correspondent.")
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
53 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}")
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
54 AUTH_FINGERPRINT_YOURS = D_("Your fingerprint is:{eol}{fingerprint}{eol}{eol}Start an OTR conversation to have your correspondent one.")
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
55 AUTH_FINGERPRINT_TXT = D_("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.{eol}{eol}")
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
56 AUTH_FINGERPRINT_VERIFY = D_("Fingerprint for you, {you}:{eol}{your_fp}{eol}{eol}Purported fingerprint for {other}:{eol}{other_fp}{eol}{eol}Did you verify that this is in fact the correct fingerprint for {other}?")
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
57 AUTH_QUEST_DEFINE_TXT = D_("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.{eol}{eol}")
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
58 AUTH_QUEST_DEFINE = D_("Enter question here:{eol}")
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
59 AUTH_QUEST_ANSWER_TXT = D_("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.{eol}{eol}")
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
60 AUTH_QUEST_ANSWER = D_("This is the question asked by your correspondent:{eol}{question}")
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
61 AUTH_SECRET_INPUT = D_("{eol}{eol}Enter secret answer here: (case sensitive){eol}")
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
62 AUTH_ABORTED_TXT = D_("Authentication aborted.")
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
63 AUTH_FAILED_TXT = D_("Authentication failed.")
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
64 AUTH_OTHER_OK = D_("Authentication successful.")
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
65 AUTH_US_OK = D_("Your correspondent has successfully authenticated you.")
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
66 AUTH_OTHER_TOO = D_("You may want to authenticate your correspondent as well by asking your own question.")
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
67 AUTH_STATUS = D_("The current conversation is now {state}.")
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
68
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
69 FINISHED_CONTEXT_TITLE = D_('Finished OTR conversation with {jid}')
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
70 SEND_PLAIN_IN_FINISHED_CONTEXT = D_("Your message was not sent because your correspondent closed the OTR conversation on his/her side. Either close your own side, or refresh the session.")
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
71 RECEIVE_PLAIN_IN_ENCRYPTED_CONTEXT = D_("WARNING: received unencrypted data in a supposedly encrypted context!")
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
72
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
73 QUERY_ENCRYPTED = D_('Attempting to refresh the OTR conversation with {jid}...')
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
74 QUERY_NOT_ENCRYPTED = D_('Attempting to start an OTR conversation with {jid}...')
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
75 AKE_ENCRYPTED = D_(" conversation with {jid} started. Your client is not logging this conversation.")
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
76 AKE_NOT_ENCRYPTED = D_("ERROR: successfully ake'd with {jid} but the conversation is not encrypted!")
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
77 END_ENCRYPTED = D_("ERROR: the OTR session ended but the context is still supposedly encrypted!")
663
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
78 END_PLAIN_NO_MORE = D_("Your conversation with {jid} is no more encrypted.")
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
79 END_PLAIN_HAS_NOT = D_("Your conversation with {jid} hasn't been encrypted.")
538
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
80 END_FINISHED = D_("{jid} has ended his or her private conversation with you; you should do the same.")
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
81
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
82 KEY_TITLE = D_('Private key')
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
83 KEY_NA_TITLE = D_("No private key")
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
84 KEY_NA_TXT = D_("You don't have any private key yet.")
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
85 KEY_DROP_TITLE = D_('Drop your private key')
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
86 KEY_DROP_TXT = D_("You private key is used to encrypt messages for your correspondent, nobody except you must know it, if you are in doubt, you should drop it!{eol}{eol}Are you sure you want to drop your private key?")
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
87 KEY_DROPPED_TXT = D_("Your private key has been dropped.")
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
88
541
e903a9f79172 browser_side (plugin OTR): also ask for a confirmation if the user has no private key and initiates an OTR session
souliane <souliane@mailoo.org>
parents: 540
diff changeset
89 QUERY_TITLE = D_("Going encrypted")
e903a9f79172 browser_side (plugin OTR): also ask for a confirmation if the user has no private key and initiates an OTR session
souliane <souliane@mailoo.org>
parents: 540
diff changeset
90 QUERY_RECEIVED = D_("{jid} is willing to start with you an OTR encrypted conversation.{eol}{eol}")
e903a9f79172 browser_side (plugin OTR): also ask for a confirmation if the user has no private key and initiates an OTR session
souliane <souliane@mailoo.org>
parents: 540
diff changeset
91 QUERY_SEND = D_("You are about to start an OTR encrypted conversation with {jid}.{eol}{eol}")
e903a9f79172 browser_side (plugin OTR): also ask for a confirmation if the user has no private key and initiates an OTR session
souliane <souliane@mailoo.org>
parents: 540
diff changeset
92 QUERY_SLOWDOWN = D_("This end-to-end encryption is computed by your web browser and you may experience slowdowns.{eol}{eol}")
e903a9f79172 browser_side (plugin OTR): also ask for a confirmation if the user has no private key and initiates an OTR session
souliane <souliane@mailoo.org>
parents: 540
diff changeset
93 QUERY_NO_KEY = D_("This will take up to 10 seconds to generate your single use private key and start the conversation. In a future version of Libervia, your private key will be safely and persistently stored, so you will have to generate it only once.{eol}{eol}")
e903a9f79172 browser_side (plugin OTR): also ask for a confirmation if the user has no private key and initiates an OTR session
souliane <souliane@mailoo.org>
parents: 540
diff changeset
94 QUERY_KEY = D_("You already have a private key, but to start the conversation will still require a couple of seconds.{eol}{eol}")
e903a9f79172 browser_side (plugin OTR): also ask for a confirmation if the user has no private key and initiates an OTR session
souliane <souliane@mailoo.org>
parents: 540
diff changeset
95 QUERY_CONFIRM = D_("Press OK to start now the encryption.")
e903a9f79172 browser_side (plugin OTR): also ask for a confirmation if the user has no private key and initiates an OTR session
souliane <souliane@mailoo.org>
parents: 540
diff changeset
96
544
ad18eb65b6db browser_side (plugin OTR): forbid to start an OTR session if the contact is not connected
souliane <souliane@mailoo.org>
parents: 543
diff changeset
97 ACTION_NA_TITLE = D_("Impossible action")
ad18eb65b6db browser_side (plugin OTR): forbid to start an OTR session if the contact is not connected
souliane <souliane@mailoo.org>
parents: 543
diff changeset
98 ACTION_NA = D_("Your correspondent must be connected to start an OTR conversation with him.")
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
99
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
100 DEFAULT_POLICY_FLAGS = {
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
101 'ALLOW_V2': True,
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
102 'ALLOW_V3': True,
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
103 'REQUIRE_ENCRYPTION': False,
663
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
104 'SEND_WHITESPACE_TAG': False, # FIXME: we need to complete sendMessageTg before turning this to True
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
105 'WHITESPACE_START_AKE': False, # FIXME: we need to complete newMessageTg before turning this to True
522
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
543
d02335553b5d browser_side (plugin OTR): display OTR states with icons instead of a text
souliane <souliane@mailoo.org>
parents: 541
diff changeset
108 # list a couple of texts or htmls (untrusted, trusted) for each state
536
048ae7314156 browser_side: temporary way to display the OTR state in the LiberviaWidget header
souliane <souliane@mailoo.org>
parents: 535
diff changeset
109 OTR_MSG_STATES = {
543
d02335553b5d browser_side (plugin OTR): display OTR states with icons instead of a text
souliane <souliane@mailoo.org>
parents: 541
diff changeset
110 otr.context.STATE_PLAINTEXT: [
d02335553b5d browser_side (plugin OTR): display OTR states with icons instead of a text
souliane <souliane@mailoo.org>
parents: 541
diff changeset
111 '<img src="media/icons/silk/lock_open.png" /><img src="media/icons/silk/key_delete.png" />',
d02335553b5d browser_side (plugin OTR): display OTR states with icons instead of a text
souliane <souliane@mailoo.org>
parents: 541
diff changeset
112 '<img src="media/icons/silk/lock_open.png" /><img src="media/icons/silk/key.png" />'
d02335553b5d browser_side (plugin OTR): display OTR states with icons instead of a text
souliane <souliane@mailoo.org>
parents: 541
diff changeset
113 ],
d02335553b5d browser_side (plugin OTR): display OTR states with icons instead of a text
souliane <souliane@mailoo.org>
parents: 541
diff changeset
114 otr.context.STATE_ENCRYPTED: [
d02335553b5d browser_side (plugin OTR): display OTR states with icons instead of a text
souliane <souliane@mailoo.org>
parents: 541
diff changeset
115 '<img src="media/icons/silk/lock.png" /><img src="media/icons/silk/key_delete.png" />',
d02335553b5d browser_side (plugin OTR): display OTR states with icons instead of a text
souliane <souliane@mailoo.org>
parents: 541
diff changeset
116 '<img src="media/icons/silk/lock.png" /><img src="media/icons/silk/key.png" />'
d02335553b5d browser_side (plugin OTR): display OTR states with icons instead of a text
souliane <souliane@mailoo.org>
parents: 541
diff changeset
117 ],
d02335553b5d browser_side (plugin OTR): display OTR states with icons instead of a text
souliane <souliane@mailoo.org>
parents: 541
diff changeset
118 otr.context.STATE_FINISHED: [
d02335553b5d browser_side (plugin OTR): display OTR states with icons instead of a text
souliane <souliane@mailoo.org>
parents: 541
diff changeset
119 '<img src="media/icons/silk/lock_break.png" /><img src="media/icons/silk/key_delete.png" />',
d02335553b5d browser_side (plugin OTR): display OTR states with icons instead of a text
souliane <souliane@mailoo.org>
parents: 541
diff changeset
120 '<img src="media/icons/silk/lock_break.png" /><img src="media/icons/silk/key.png" />'
d02335553b5d browser_side (plugin OTR): display OTR states with icons instead of a text
souliane <souliane@mailoo.org>
parents: 541
diff changeset
121 ]
536
048ae7314156 browser_side: temporary way to display the OTR state in the LiberviaWidget header
souliane <souliane@mailoo.org>
parents: 535
diff changeset
122 }
048ae7314156 browser_side: temporary way to display the OTR state in the LiberviaWidget header
souliane <souliane@mailoo.org>
parents: 535
diff changeset
123
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
124
663
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
125 unicode = str # FIXME: pyjamas workaround
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
126
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
127
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
128 class NotConnectedEntity(Exception):
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
129 pass
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
130
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
131
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
132 class Context(otr.context.Context):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
133
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
134 def __init__(self, host, account, other_jid):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
135 """
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
136
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
137 @param host (satWebFrontend)
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
138 @param account (Account)
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
139 @param other_jid (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
140 """
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
141 super(Context, self).__init__(account, other_jid)
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
142 self.host = host
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
143
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
144 def getPolicy(self, key):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
145 """Get the value of the specified policy
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
146
662
ebb602d8b3f2 browser_side: replace all instances of 'str' with 'unicode'
souliane <souliane@mailoo.org>
parents: 624
diff changeset
147 @param key (unicode): a value in:
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
148 - ALLOW_V1 (apriori removed from otr.js)
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
149 - ALLOW_V2
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
150 - ALLOW_V3
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
151 - REQUIRE_ENCRYPTION
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
152 - SEND_WHITESPACE_TAG
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
153 - WHITESPACE_START_AKE
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
154 - ERROR_START_AKE
662
ebb602d8b3f2 browser_side: replace all instances of 'str' with 'unicode'
souliane <souliane@mailoo.org>
parents: 624
diff changeset
155 @return: unicode
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
156 """
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
157 if key in DEFAULT_POLICY_FLAGS:
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
158 return DEFAULT_POLICY_FLAGS[key]
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
159 else:
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
160 return False
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
161
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
162 def receiveMessageCb(self, msg, encrypted):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
163 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
164 if not encrypted:
694
82123705474b massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 685
diff changeset
165 log.warning(u"A plain-text message has been handled by otr.js")
82123705474b massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 685
diff changeset
166 log.debug(u"message received (was %s): %s" % ('encrypted' if encrypted else 'plain', msg))
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 909
diff changeset
167 uuid_ = str(uuid.uuid4()) # FIXME
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
168 if not encrypted:
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
169 if self.state == otr.context.STATE_ENCRYPTED:
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
170 log.warning(u"Received unencrypted message in an encrypted context (from %(jid)s)" % {'jid': self.peer})
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 909
diff changeset
171 self.host.newMessageHandler(uuid_, time.time(), unicode(self.peer), unicode(self.host.whoami), {'': RECEIVE_PLAIN_IN_ENCRYPTED_CONTEXT}, {}, C.MESS_TYPE_INFO, {})
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 909
diff changeset
172 self.host.newMessageHandler(uuid_, time.time(), unicode(self.peer), unicode(self.host.whoami), {'': msg}, {}, C.MESS_TYPE_CHAT, {})
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
173
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
174 def sendMessageCb(self, msg, meta=None):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
175 assert isinstance(self.peer, jid.JID)
694
82123705474b massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 685
diff changeset
176 log.debug(u"message to send%s: %s" % ((' (attached meta data: %s)' % meta) if meta else '', msg))
663
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
177 self.host.bridge.call('sendMessage', (None, self.host.sendError), unicode(self.peer), msg, '', C.MESS_TYPE_CHAT, {'send_only': 'true'})
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
178
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
179 def messageErrorCb(self, error):
694
82123705474b massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 685
diff changeset
180 log.error(u'error occured: %s' % error)
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
181
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
182 def setStateCb(self, msg_state, status):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
183 if status == otr.context.STATUS_AKE_INIT:
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
184 return
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
185
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
186 other_jid_s = self.peer
536
048ae7314156 browser_side: temporary way to display the OTR state in the LiberviaWidget header
souliane <souliane@mailoo.org>
parents: 535
diff changeset
187 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
188 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
189
048ae7314156 browser_side: temporary way to display the OTR state in the LiberviaWidget header
souliane <souliane@mailoo.org>
parents: 535
diff changeset
190 if status == otr.context.STATUS_SEND_QUERY:
538
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
191 feedback = QUERY_ENCRYPTED if msg_state == otr.context.STATE_ENCRYPTED else QUERY_NOT_ENCRYPTED
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
192
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
193 elif status == otr.context.STATUS_AKE_SUCCESS:
538
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
194 trusted_str = AUTH_TRUSTED if trust else AUTH_UNTRUSTED
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
195 feedback = (trusted_str + AKE_ENCRYPTED) if msg_state == otr.context.STATE_ENCRYPTED else AKE_NOT_ENCRYPTED
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 elif status == otr.context.STATUS_END_OTR:
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
198 if msg_state == otr.context.STATE_PLAINTEXT:
663
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
199 feedback = END_PLAIN_NO_MORE
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
200 elif msg_state == otr.context.STATE_ENCRYPTED:
538
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
201 log.error(END_ENCRYPTED)
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
202 elif msg_state == otr.context.STATE_FINISHED:
538
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
203 feedback = END_FINISHED
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
204
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 909
diff changeset
205 uuid_ = str(uuid.uuid4()) # FIXME
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 909
diff changeset
206 self.host.newMessageHandler(uuid_, time.time(), unicode(self.peer), unicode(self.host.whoami), {'': feedback.format(jid=other_jid_s)}, {}, C.MESS_TYPE_INFO, {'header_info': OTR.getInfoText(msg_state, trust)})
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
207
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
208 def setCurrentTrust(self, new_trust='', act='asked', type_='trust'):
694
82123705474b massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 685
diff changeset
209 log.debug(u"setCurrentTrust: trust={trust}, act={act}, type={type}".format(type=type_, trust=new_trust, act=act))
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
210 title = (AUTH_OTHER_TITLE if act == "asked" else AUTH_US_TITLE).format(jid=self.peer)
538
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
211 old_trust = self.getCurrentTrust()
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
212 if type_ == 'abort':
538
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
213 msg = AUTH_ABORTED_TXT
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
214 elif new_trust:
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
215 if act == "asked":
538
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
216 msg = AUTH_OTHER_OK
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
217 else:
538
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
218 msg = AUTH_US_OK
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
219 if not old_trust:
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
220 msg += " " + AUTH_OTHER_TOO
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
221 else:
538
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
222 msg = AUTH_FAILED_TXT
524
d41e850b31b9 browser_side (plugin OTR): limit the max width for all dialogs
souliane <souliane@mailoo.org>
parents: 523
diff changeset
223 dialog.InfoDialog(title, msg, AddStyleName="maxWidthLimit").show()
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
224 if act != "asked":
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
225 return
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
226 otr.context.Context.setCurrentTrust(self, new_trust)
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
227 if old_trust != new_trust:
538
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
228 feedback = AUTH_STATUS.format(state=(AUTH_TRUSTED if new_trust else AUTH_UNTRUSTED).lower())
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 909
diff changeset
229 uuid_ = str(uuid.uuid4()) # FIXME
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 909
diff changeset
230 self.host.newMessageHandler(uuid_, time.time(), unicode(self.peer), unicode(self.host.whoami), {'': feedback}, {}, C.MESS_TYPE_INFO, {'header_info': OTR.getInfoText(self.state, new_trust)})
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
231
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
232 def fingerprintAuthCb(self):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
233 """OTR v2 authentication using manual fingerprint comparison"""
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
234 priv_key = self.user.privkey
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
235
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
236 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
237 raise exceptions.InternalError
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
238 return
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
239
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
240 other_key = self.getCurrentKey()
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
241 if other_key is None:
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
242 # we have a private key, but not the fingerprint of our correspondent
538
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
243 msg = (AUTH_INFO_TXT + AUTH_FINGERPRINT_YOURS).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
244 dialog.InfoDialog(_("Fingerprint"), msg, AddStyleName="maxWidthLimit").show()
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
245 return
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
246
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
247 def setTrust(confirm):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
248 self.setCurrentTrust('fingerprint' if confirm else '')
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
249
538
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
250 text = (AUTH_INFO_TXT + "<i>" + AUTH_FINGERPRINT_TXT + "</i>" + AUTH_FINGERPRINT_VERIFY).format(you=self.host.whoami, your_fp=priv_key.fingerprint(), other=self.peer, other_fp=other_key.fingerprint(), eol=DIALOG_EOL)
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
251 title = AUTH_OTHER_TITLE.format(jid=self.peer)
524
d41e850b31b9 browser_side (plugin OTR): limit the max width for all dialogs
souliane <souliane@mailoo.org>
parents: 523
diff changeset
252 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
253
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
254 def smpAuthCb(self, type_, data, act=None):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
255 """OTR v3 authentication using the socialist millionaire protocol.
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
256
662
ebb602d8b3f2 browser_side: replace all instances of 'str' with 'unicode'
souliane <souliane@mailoo.org>
parents: 624
diff changeset
257 @param type_ (unicode): a value in ('question', 'trust', 'abort')
ebb602d8b3f2 browser_side: replace all instances of 'str' with 'unicode'
souliane <souliane@mailoo.org>
parents: 624
diff changeset
258 @param data (unicode, bool): this could be:
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
259 - 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
260 - a boolean value telling if the authentication succeed when type_ is 'trust'
662
ebb602d8b3f2 browser_side: replace all instances of 'str' with 'unicode'
souliane <souliane@mailoo.org>
parents: 624
diff changeset
261 @param act (unicode): a value in ('asked', 'answered')
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
262 """
694
82123705474b massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 685
diff changeset
263 log.debug(u"smpAuthCb: type={type}, data={data}, act={act}".format(type=type_, data=data, act=act))
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
264 if act is None:
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
265 if type_ == 'question':
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
266 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
267 elif type_ == 'abort':
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
268 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
269
523
5add182e7dd5 browser_side (plugin OTR): rename menus and replace 'buddy' with 'correspondent'
souliane <souliane@mailoo.org>
parents: 522
diff changeset
270 # 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
271 # 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
272 # 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
273 # make us need the dirty self.smpAuthAbort.
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
274 else:
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
275 log.error("FIXME: unmanaged ambiguous 'act' value in Context.smpAuthCb!")
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
276 title = (AUTH_OTHER_TITLE if act == "asked" else AUTH_US_TITLE).format(jid=self.peer)
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
277 if type_ == 'question':
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
278 if act == 'asked':
624
9092e624bb27 browser_side: fixes various issues
souliane <souliane@mailoo.org>
parents: 616
diff changeset
279 def cb(result, question, answer=None):
9092e624bb27 browser_side: fixes various issues
souliane <souliane@mailoo.org>
parents: 616
diff changeset
280 if not result or not answer: # dialog cancelled or the answer is empty
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
281 return
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
282 self.smpAuthSecret(answer, question)
538
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
283 text = (AUTH_INFO_TXT + "<i>" + AUTH_QUEST_DEFINE_TXT + "</i>" + AUTH_QUEST_DEFINE).format(eol=DIALOG_EOL)
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
284 dialog.PromptDialog(cb, [text, AUTH_SECRET_INPUT.format(eol=DIALOG_EOL)], title=title, AddStyleName="maxWidthLimit").show()
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
285 else:
624
9092e624bb27 browser_side: fixes various issues
souliane <souliane@mailoo.org>
parents: 616
diff changeset
286 def cb(result, answer):
9092e624bb27 browser_side: fixes various issues
souliane <souliane@mailoo.org>
parents: 616
diff changeset
287 if not result or not answer: # dialog cancelled or the answer is empty
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
288 self.smpAuthAbort('answered')
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
289 return
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
290 self.smpAuthSecret(answer)
538
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
291 text = (AUTH_INFO_TXT + "<i>" + AUTH_QUEST_ANSWER_TXT + "</i>" + AUTH_QUEST_ANSWER).format(eol=DIALOG_EOL, question=data)
624
9092e624bb27 browser_side: fixes various issues
souliane <souliane@mailoo.org>
parents: 616
diff changeset
292 dialog.PromptDialog(cb, [text + AUTH_SECRET_INPUT.format(eol=DIALOG_EOL)], title=title, AddStyleName="maxWidthLimit").show()
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
293 elif type_ == 'trust':
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
294 self.setCurrentTrust('smp' if data else '', act)
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
295 elif type_ == 'abort':
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
296 self.setCurrentTrust('', act, 'abort')
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
297
529
9bfd71e2b35c plugin OTR: disconnect the active OTR sessions on profile disconnection
souliane <souliane@mailoo.org>
parents: 528
diff changeset
298 def disconnect(self):
9bfd71e2b35c plugin OTR: disconnect the active OTR sessions on profile disconnection
souliane <souliane@mailoo.org>
parents: 528
diff changeset
299 """Disconnect the session."""
9bfd71e2b35c plugin OTR: disconnect the active OTR sessions on profile disconnection
souliane <souliane@mailoo.org>
parents: 528
diff changeset
300 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
301 super(Context, self).disconnect()
9bfd71e2b35c plugin OTR: disconnect the active OTR sessions on profile disconnection
souliane <souliane@mailoo.org>
parents: 528
diff changeset
302
530
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
303 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
304 """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
305 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
306 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
307
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
308
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
309 class Account(otr.context.Account):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
310
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
311 def __init__(self, host):
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
312 log.debug(u"new account: %s" % host.whoami)
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
313 if not host.whoami.resource:
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
314 log.warning("Account created without resource")
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
315 super(Account, self).__init__(host.whoami)
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
316 self.host = host
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
317
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
318 def loadPrivkey(self):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
319 return self.privkey
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 savePrivkey(self):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
322 # 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
323 # 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
324 # self.privkey.serializePrivateKey() --> encrypt --> store
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
325 if self.privkey is None:
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
326 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
327 pass
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
328
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
329 def saveTrusts(self):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
330 # 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
331 pass
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
332
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
333
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
334 class ContextManager(object):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
335
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
336 def __init__(self, host):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
337 self.host = host
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
338 self.account = Account(host)
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
339 self.contexts = {}
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
340
528
ac66b8b11ab8 plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents: 525
diff changeset
341 def startContext(self, other_jid):
663
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
342 assert isinstance(other_jid, jid.JID) # never start an OTR session with a bare JID
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
343 # 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
344 #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
345 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
346 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
347 return self.contexts[other_jid]
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
348
530
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
349 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
350 """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
351
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
352 @param other_jid (jid.JID): your correspondent
530
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
353 @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
354 @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
355 """
663
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
356 try:
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
357 other_jid = self.fixResource(other_jid)
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
358 except NotConnectedEntity:
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
359 log.debug(u"getContextForUser [%s]: not connected!" % other_jid)
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
360 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
361 log.debug(u"getContextForUser [%s]" % other_jid)
528
ac66b8b11ab8 plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents: 525
diff changeset
362 if start:
ac66b8b11ab8 plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents: 525
diff changeset
363 return self.startContext(other_jid)
ac66b8b11ab8 plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents: 525
diff changeset
364 else:
ac66b8b11ab8 plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents: 525
diff changeset
365 return self.contexts.get(other_jid, None)
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
366
665
6a8a1103ad10 browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents: 664
diff changeset
367 def getContextsForBareUser(self, bare_jid):
6a8a1103ad10 browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents: 664
diff changeset
368 """Get all the contexts for the users sharing the given bare JID.
6a8a1103ad10 browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents: 664
diff changeset
369
6a8a1103ad10 browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents: 664
diff changeset
370 @param bare_jid (jid.JID): bare JID
6a8a1103ad10 browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents: 664
diff changeset
371 @return: list[Context]
6a8a1103ad10 browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents: 664
diff changeset
372 """
6a8a1103ad10 browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents: 664
diff changeset
373 return [context for other_jid, context in self.contexts.iteritems() if other_jid.bare == bare_jid]
6a8a1103ad10 browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents: 664
diff changeset
374
663
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
375 def fixResource(self, other_jid):
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
376 """Return the full JID in case the resource of the given JID is missing.
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
377
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
378 @param other_jid (jid.JID): JID to check
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
379 @return jid.JID
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
380 """
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
381 if other_jid.resource:
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
382 return other_jid
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
383 clist = self.host.contact_list
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
384 if clist.getCache(other_jid.bare, C.PRESENCE_SHOW) is None:
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
385 raise NotConnectedEntity
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
386 return clist.getFullJid(other_jid)
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
387
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
388
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
389 class OTR(object):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
390
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
391 def __init__(self, host):
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
392 log.info(_(u"OTR plugin initialization"))
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
393 self.host = host
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
394 self.context_manager = None
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
395 self.host.bridge._registerMethods(["skipOTR"])
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 909
diff changeset
396 self.host.trigger.add("messageNewTrigger", self.newMessageTg, priority=trigger.TriggerManager.MAX_PRIORITY)
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 909
diff changeset
397 self.host.trigger.add("messageSendTrigger", self.sendMessageTg, priority=trigger.TriggerManager.MAX_PRIORITY)
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
398
665
6a8a1103ad10 browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents: 664
diff changeset
399 # FIXME: workaround for a pyjamas issue: calling hash on a class method always return a different value if that method is defined directly within the class (with the "def" keyword)
6a8a1103ad10 browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents: 664
diff changeset
400 self._profilePluggedListener = self.profilePluggedListener
6a8a1103ad10 browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents: 664
diff changeset
401 self._gotMenusListener = self.gotMenusListener
6a8a1103ad10 browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents: 664
diff changeset
402 # FIXME: these listeners are never removed, can't be removed by themselves (it modifies the list while looping), maybe need a 'one_shot' argument
6a8a1103ad10 browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents: 664
diff changeset
403 self.host.addListener('profilePlugged', self._profilePluggedListener)
678
2e087e093e7f browser side(otr): restored menu hooks using new hook system
Goffi <goffi@goffi.org>
parents: 676
diff changeset
404 self.host.addListener('gotMenus', self._gotMenusListener)
665
6a8a1103ad10 browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents: 664
diff changeset
405
543
d02335553b5d browser_side (plugin OTR): display OTR states with icons instead of a text
souliane <souliane@mailoo.org>
parents: 541
diff changeset
406 @classmethod
d02335553b5d browser_side (plugin OTR): display OTR states with icons instead of a text
souliane <souliane@mailoo.org>
parents: 541
diff changeset
407 def getInfoText(self, state=otr.context.STATE_PLAINTEXT, trust=''):
559
77372641e05d browser_side (plugin OTR): display the correct icons on opening the window + auto-open on accepted invitation
souliane <souliane@mailoo.org>
parents: 557
diff changeset
408 """Get the widget info text for a certain message state and trust.
77372641e05d browser_side (plugin OTR): display the correct icons on opening the window + auto-open on accepted invitation
souliane <souliane@mailoo.org>
parents: 557
diff changeset
409
662
ebb602d8b3f2 browser_side: replace all instances of 'str' with 'unicode'
souliane <souliane@mailoo.org>
parents: 624
diff changeset
410 @param state (unicode): message state
ebb602d8b3f2 browser_side: replace all instances of 'str' with 'unicode'
souliane <souliane@mailoo.org>
parents: 624
diff changeset
411 @param trust (unicode): trust
ebb602d8b3f2 browser_side: replace all instances of 'str' with 'unicode'
souliane <souliane@mailoo.org>
parents: 624
diff changeset
412 @return: unicode
559
77372641e05d browser_side (plugin OTR): display the correct icons on opening the window + auto-open on accepted invitation
souliane <souliane@mailoo.org>
parents: 557
diff changeset
413 """
543
d02335553b5d browser_side (plugin OTR): display OTR states with icons instead of a text
souliane <souliane@mailoo.org>
parents: 541
diff changeset
414 if not state:
d02335553b5d browser_side (plugin OTR): display OTR states with icons instead of a text
souliane <souliane@mailoo.org>
parents: 541
diff changeset
415 state = OTR_MSG_STATES.keys()[0]
d02335553b5d browser_side (plugin OTR): display OTR states with icons instead of a text
souliane <souliane@mailoo.org>
parents: 541
diff changeset
416 return OTR_MSG_STATES[state][1 if trust else 0]
d02335553b5d browser_side (plugin OTR): display OTR states with icons instead of a text
souliane <souliane@mailoo.org>
parents: 541
diff changeset
417
663
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
418 def getInfoTextForUser(self, other_jid):
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
419 """Get the current info text for a conversation.
559
77372641e05d browser_side (plugin OTR): display the correct icons on opening the window + auto-open on accepted invitation
souliane <souliane@mailoo.org>
parents: 557
diff changeset
420
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
421 @param other_jid (jid.JID): JID of the correspondant
559
77372641e05d browser_side (plugin OTR): display the correct icons on opening the window + auto-open on accepted invitation
souliane <souliane@mailoo.org>
parents: 557
diff changeset
422 """
663
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
423 otrctx = self.context_manager.getContextForUser(other_jid, start=False)
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
424 if otrctx is None:
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
425 return OTR.getInfoText()
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
426 else:
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
427 return OTR.getInfoText(otrctx.state, otrctx.getCurrentTrust())
559
77372641e05d browser_side (plugin OTR): display the correct icons on opening the window + auto-open on accepted invitation
souliane <souliane@mailoo.org>
parents: 557
diff changeset
428
678
2e087e093e7f browser side(otr): restored menu hooks using new hook system
Goffi <goffi@goffi.org>
parents: 676
diff changeset
429 def gotMenusListener(self,):
2e087e093e7f browser side(otr): restored menu hooks using new hook system
Goffi <goffi@goffi.org>
parents: 676
diff changeset
430 # TODO: get menus paths to hook directly from backend's OTR plugin
2e087e093e7f browser side(otr): restored menu hooks using new hook system
Goffi <goffi@goffi.org>
parents: 676
diff changeset
431 self.host.menus.addMenuHook(C.MENU_SINGLE, (MAIN_MENU, D_(u"Start/Refresh")), callback=self._startRefresh)
2e087e093e7f browser side(otr): restored menu hooks using new hook system
Goffi <goffi@goffi.org>
parents: 676
diff changeset
432 self.host.menus.addMenuHook(C.MENU_SINGLE, (MAIN_MENU, D_(u"End session")), callback=self._endSession)
2e087e093e7f browser side(otr): restored menu hooks using new hook system
Goffi <goffi@goffi.org>
parents: 676
diff changeset
433 self.host.menus.addMenuHook(C.MENU_SINGLE, (MAIN_MENU, D_(u"Authenticate")), callback=self._authenticate)
2e087e093e7f browser side(otr): restored menu hooks using new hook system
Goffi <goffi@goffi.org>
parents: 676
diff changeset
434 self.host.menus.addMenuHook(C.MENU_SINGLE, (MAIN_MENU, D_(u"Drop private key")), callback=self._dropPrivkey)
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
435
665
6a8a1103ad10 browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents: 664
diff changeset
436 def profilePluggedListener(self, profile):
6a8a1103ad10 browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents: 664
diff changeset
437 # FIXME: workaround for a pyjamas issue: calling hash on a class method always return a different value if that method is defined directly within the class (with the "def" keyword)
6a8a1103ad10 browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents: 664
diff changeset
438 self._presenceListener = self.presenceListener
6a8a1103ad10 browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents: 664
diff changeset
439 self._disconnectListener = self.disconnectListener
6a8a1103ad10 browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents: 664
diff changeset
440 self.host.addListener('presence', self._presenceListener, [C.PROF_KEY_NONE])
6a8a1103ad10 browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents: 664
diff changeset
441 # FIXME: this listener is never removed, can't be removed by itself (it modifies the list while looping), maybe need a 'one_shot' argument
6a8a1103ad10 browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents: 664
diff changeset
442 self.host.addListener('disconnect', self._disconnectListener, [C.PROF_KEY_NONE])
6a8a1103ad10 browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents: 664
diff changeset
443
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
444 self.host.bridge.call('skipOTR', None)
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
445 self.context_manager = ContextManager(self.host)
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
446 # 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
447 # 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
448 # assign it to self.context_manager.account.privkey
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
449
665
6a8a1103ad10 browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents: 664
diff changeset
450 def disconnectListener(self, profile):
6a8a1103ad10 browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents: 664
diff changeset
451 """Things to do just before the profile disconnection"""
6a8a1103ad10 browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents: 664
diff changeset
452 self.host.removeListener('presence', self._presenceListener)
663
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
453
529
9bfd71e2b35c plugin OTR: disconnect the active OTR sessions on profile disconnection
souliane <souliane@mailoo.org>
parents: 528
diff changeset
454 for context in self.context_manager.contexts.values():
665
6a8a1103ad10 browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents: 664
diff changeset
455 context.disconnect() # FIXME: no time to send the message before the profile has been disconnected
6a8a1103ad10 browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents: 664
diff changeset
456
6a8a1103ad10 browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents: 664
diff changeset
457 def presenceListener(self, entity, show, priority, statuses, profile):
6a8a1103ad10 browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents: 664
diff changeset
458 if show == C.PRESENCE_UNAVAILABLE:
6a8a1103ad10 browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents: 664
diff changeset
459 self.endSession(entity, disconnect=False)
529
9bfd71e2b35c plugin OTR: disconnect the active OTR sessions on profile disconnection
souliane <souliane@mailoo.org>
parents: 528
diff changeset
460
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 909
diff changeset
461 def newMessageTg(self, uid, timestamp, from_jid, to_jid, msg, subject, msg_type, extra, profile):
663
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
462 if msg_type != C.MESS_TYPE_CHAT:
533
19fc2ebc02dd browser_side: management of new "info" newMessage type
Goffi <goffi@goffi.org>
parents: 531
diff changeset
463 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
464
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 909
diff changeset
465 try:
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 909
diff changeset
466 msg = msg.values()[0] # FIXME: Q&D fix for message refactoring, message is now a dict
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 909
diff changeset
467 except IndexError:
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 909
diff changeset
468 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
469 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
470 if tag is None or (tag == otr.context.WHITESPACE_TAG and not DEFAULT_POLICY_FLAGS['WHITESPACE_START_AKE']):
539
19b8af73e945 browser_side (plugin OTR): ask the user before accepting an OTR query
souliane <souliane@mailoo.org>
parents: 538
diff changeset
471 return True
19b8af73e945 browser_side (plugin OTR): ask the user before accepting an OTR query
souliane <souliane@mailoo.org>
parents: 538
diff changeset
472
663
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
473 other_jid = to_jid if from_jid.bare == self.host.whoami.bare else from_jid
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
474 otrctx = self.context_manager.getContextForUser(other_jid, start=False)
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
475 if otrctx is None:
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
476 def confirm(confirm):
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
477 if confirm:
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
478 self.host.displayWidget(chat.Chat, other_jid)
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
479 self.context_manager.startContext(other_jid).receiveMessage(msg)
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
480 else:
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
481 # FIXME: plain text messages with whitespaces would be lost here when WHITESPACE_START_AKE is True
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
482 pass
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
483 key = self.context_manager.account.privkey
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
484 question = QUERY_RECEIVED + QUERY_SLOWDOWN + (QUERY_KEY if key else QUERY_NO_KEY) + QUERY_CONFIRM
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
485 dialog.ConfirmDialog(confirm, question.format(jid=other_jid, eol=DIALOG_EOL), QUERY_TITLE, AddStyleName="maxWidthLimit").show()
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
486 else: # do not ask for user confirmation if the context exist
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
487 otrctx.receiveMessage(msg)
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
488
539
19b8af73e945 browser_side (plugin OTR): ask the user before accepting an OTR query
souliane <souliane@mailoo.org>
parents: 538
diff changeset
489 return False # interrupt the main process
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
490
663
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
491 def sendMessageTg(self, to_jid, message, subject, mess_type, extra, callback, errback, profile_key):
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
492 if mess_type != C.MESS_TYPE_CHAT:
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
493 return True
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
494
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
495 otrctx = self.context_manager.getContextForUser(to_jid, start=False)
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
496 if otrctx is not None and otrctx.state != otr.context.STATE_PLAINTEXT:
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
497 if otrctx.state == otr.context.STATE_ENCRYPTED:
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
498 log.debug(u"encrypting message")
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
499 otrctx.sendMessage(message)
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 909
diff changeset
500 uuid_ = str(uuid.uuid4()) # FIXME
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 909
diff changeset
501 self.host.newMessageHandler(uuid_, time.time(), unicode(self.host.whoami), unicode(to_jid), {'': message}, {}, mess_type, extra)
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
502 else:
663
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
503 feedback = SEND_PLAIN_IN_FINISHED_CONTEXT
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
504 dialog.InfoDialog(FINISHED_CONTEXT_TITLE.format(jid=to_jid), feedback, AddStyleName="maxWidthLimit").show()
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
505 return False # interrupt the main process
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
506
663
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
507 log.debug(u"sending message unencrypted")
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
508 return True
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
509
665
6a8a1103ad10 browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents: 664
diff changeset
510 def endSession(self, other_jid, disconnect=True):
530
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
511 """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
512
663
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
513 @param other_jid (jid.JID): other JID
665
6a8a1103ad10 browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents: 664
diff changeset
514 @param disconnect (bool): if False, finish the session but do not disconnect it
530
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
515 """
663
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
516 # checking for private key existence is not needed, context checking is enough
665
6a8a1103ad10 browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents: 664
diff changeset
517 if other_jid.resource:
6a8a1103ad10 browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents: 664
diff changeset
518 contexts = [self.context_manager.getContextForUser(other_jid, start=False)]
6a8a1103ad10 browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents: 664
diff changeset
519 else: # contact disconnected itself so we need to terminate the OTR session but the Chat panel lost its resource
6a8a1103ad10 browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents: 664
diff changeset
520 contexts = self.context_manager.getContextsForBareUser(other_jid)
6a8a1103ad10 browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents: 664
diff changeset
521 for otrctx in contexts:
6a8a1103ad10 browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents: 664
diff changeset
522 if otrctx is None or otrctx.state == otr.context.STATE_PLAINTEXT:
6a8a1103ad10 browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents: 664
diff changeset
523 if disconnect:
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 909
diff changeset
524 uuid_ = str(uuid.uuid4()) # FIXME
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 909
diff changeset
525 self.host.newMessageHandler(uuid_, time.time(), unicode(other_jid), unicode(self.host.whoami), {'': END_PLAIN_HAS_NOT.format(jid=other_jid)}, {}, C.MESS_TYPE_INFO, {})
665
6a8a1103ad10 browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents: 664
diff changeset
526 return
6a8a1103ad10 browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents: 664
diff changeset
527 if disconnect:
6a8a1103ad10 browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents: 664
diff changeset
528 otrctx.disconnect()
6a8a1103ad10 browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents: 664
diff changeset
529 else:
6a8a1103ad10 browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents: 664
diff changeset
530 otrctx.finish()
530
1735aaeac652 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 529
diff changeset
531
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
532 # Menu callbacks
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
533
678
2e087e093e7f browser side(otr): restored menu hooks using new hook system
Goffi <goffi@goffi.org>
parents: 676
diff changeset
534 def _startRefresh(self, caller, menu_data, profile):
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
535 """Start or refresh an OTR session
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
536
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
537 @param menu_data: %(menu_data)s
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
538 """
541
e903a9f79172 browser_side (plugin OTR): also ask for a confirmation if the user has no private key and initiates an OTR session
souliane <souliane@mailoo.org>
parents: 540
diff changeset
539 def query(other_jid):
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
540 otrctx = self.context_manager.getContextForUser(other_jid)
556
3aef7c5c7d3a browser_side (plugin OTR): popup a big warning if the correspondent's resource is unknown while trying to start/use an OTR session
souliane <souliane@mailoo.org>
parents: 544
diff changeset
541 if otrctx:
3aef7c5c7d3a browser_side (plugin OTR): popup a big warning if the correspondent's resource is unknown while trying to start/use an OTR session
souliane <souliane@mailoo.org>
parents: 544
diff changeset
542 otrctx.sendQueryMessage()
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
543
678
2e087e093e7f browser side(otr): restored menu hooks using new hook system
Goffi <goffi@goffi.org>
parents: 676
diff changeset
544 other_jid = jid.JID(menu_data['jid'])
663
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
545 clist = self.host.contact_list
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
546 if clist.getCache(other_jid.bare, C.PRESENCE_SHOW) is None:
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
547 dialog.InfoDialog(ACTION_NA_TITLE, ACTION_NA, AddStyleName="maxWidthLimit").show()
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
548 return
541
e903a9f79172 browser_side (plugin OTR): also ask for a confirmation if the user has no private key and initiates an OTR session
souliane <souliane@mailoo.org>
parents: 540
diff changeset
549
663
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
550 key = self.context_manager.account.privkey
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
551 if key is None:
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
552 def confirm(confirm):
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
553 if confirm:
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
554 query(other_jid)
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
555 msg = QUERY_SEND + QUERY_SLOWDOWN + QUERY_NO_KEY + QUERY_CONFIRM
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
556 dialog.ConfirmDialog(confirm, msg.format(jid=other_jid, eol=DIALOG_EOL), QUERY_TITLE, AddStyleName="maxWidthLimit").show()
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
557 else: # on query reception we ask always, if we initiate we just ask the first time
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
558 query(other_jid)
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
559
678
2e087e093e7f browser side(otr): restored menu hooks using new hook system
Goffi <goffi@goffi.org>
parents: 676
diff changeset
560 def _endSession(self, caller, menu_data, profile):
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
561 """End an OTR session
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
562
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
563 @param menu_data: %(menu_data)s
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
564 """
678
2e087e093e7f browser side(otr): restored menu hooks using new hook system
Goffi <goffi@goffi.org>
parents: 676
diff changeset
565 self.endSession(jid.JID(menu_data['jid']))
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
566
678
2e087e093e7f browser side(otr): restored menu hooks using new hook system
Goffi <goffi@goffi.org>
parents: 676
diff changeset
567 def _authenticate(self, caller, menu_data, profile):
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
568 """Authenticate other user and see our own fingerprint
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
569
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
570 @param menu_data: %(menu_data)s
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
571 @param profile: %(doc_profile)s
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
572 """
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
573 def not_available():
538
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
574 dialog.InfoDialog(AUTH_TRUST_NA_TITLE, AUTH_TRUST_NA_TXT, AddStyleName="maxWidthLimit").show()
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
575
678
2e087e093e7f browser side(otr): restored menu hooks using new hook system
Goffi <goffi@goffi.org>
parents: 676
diff changeset
576 to_jid = jid.JID(menu_data['jid'])
663
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
577
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
578 # checking for private key existence is not needed, context checking is enough
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
579 otrctx = self.context_manager.getContextForUser(to_jid, start=False)
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
580 if otrctx is None or otrctx.state != otr.context.STATE_ENCRYPTED:
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
581 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
582 return
663
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
583 otr_version = otrctx.getUsedVersion()
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
584 if otr_version == otr.context.OTR_VERSION_2:
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
585 otrctx.fingerprintAuthCb()
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
586 elif otr_version == otr.context.OTR_VERSION_3:
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
587 otrctx.smpAuthCb('question', None, 'asked')
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
588 else:
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
589 not_available()
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
590
678
2e087e093e7f browser side(otr): restored menu hooks using new hook system
Goffi <goffi@goffi.org>
parents: 676
diff changeset
591 def _dropPrivkey(self, caller, menu_data, profile):
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
592 """Drop our private Key
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
593
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
594 @param menu_data: %(menu_data)s
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
595 @param profile: %(doc_profile)s
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
596 """
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
597 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
598 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
599 # we have no private key yet
538
3317e5d0ac1d browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents: 537
diff changeset
600 dialog.InfoDialog(KEY_NA_TITLE, KEY_NA_TXT, AddStyleName="maxWidthLimit").show()
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
601 return
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
602
663
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
603 def dropKey(confirm):
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
604 if confirm:
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
605 # we end all sessions
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
606 for context in self.context_manager.contexts.values():
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
607 context.disconnect()
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
608 self.context_manager.contexts.clear()
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
609 self.context_manager.account.privkey = None
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
610 dialog.InfoDialog(KEY_TITLE, KEY_DROPPED_TXT, AddStyleName="maxWidthLimit").show()
522
0de69fec24e9 browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
611
663
423182fea41c browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents: 662
diff changeset
612 dialog.ConfirmDialog(dropKey, KEY_DROP_TXT.format(eol=DIALOG_EOL), KEY_DROP_TITLE, AddStyleName="maxWidthLimit").show()