Mercurial > libervia-web
annotate src/browser/sat_browser/plugin_sec_otr.py @ 613:deddd1cd8aa5 frontends_multi_profiles
browser side: added a base_location property to get location of current Libervia instance
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 10 Feb 2015 20:42:39 +0100 |
parents | a5019e62c3e9 |
children | 1c0d5a87c554 |
rev | line source |
---|---|
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1 #!/usr/bin/python |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
3 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
4 # Libervia plugin for OTR encryption |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Jérôme Poisson (goffi@goffi.org) |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
6 # Copyright (C) 2013, 2014 Adrien Cossa (souliane@mailoo.org) |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
7 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
8 # This program is free software: you can redistribute it and/or modify |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
9 # it under the terms of the GNU Affero General Public License as published by |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
10 # the Free Software Foundation, either version 3 of the License, or |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
11 # (at your option) any later version. |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
12 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
13 # This program is distributed in the hope that it will be useful, |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
16 # GNU Affero General Public License for more details. |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
17 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
18 # You should have received a copy of the GNU Affero General Public License |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
19 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
20 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
21 """ |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
22 This file is adapted from sat.plugins.plugin.sec_otr. It offers browser-side OTR encryption using otr.js. |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
23 The text messages to display are mostly taken from the Pidgin OTR plugin (GPL 2.0, see http://otr.cypherpunks.ca). |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
24 """ |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
25 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
26 from sat.core.i18n import _, D_ |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
27 from sat.core.log import getLogger |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
28 from sat.core import exceptions |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
29 log = getLogger(__name__) |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
30 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
31 from constants import Const as C |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
584
diff
changeset
|
32 from sat_frontends.tools import jid |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
33 import otrjs_wrapper as otr |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
34 import dialog |
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
|
35 import panels |
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
|
36 |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
37 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
38 NS_OTR = "otr_plugin" |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
39 PRIVATE_KEY = "PRIVATE KEY" |
523
5add182e7dd5
browser_side (plugin OTR): rename menus and replace 'buddy' with 'correspondent'
souliane <souliane@mailoo.org>
parents:
522
diff
changeset
|
40 MAIN_MENU = D_('OTR encryption') |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
41 DIALOG_EOL = "<br />" |
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
|
42 DIALOG_USERS_ML = D_("<a href='mailto:users@salut-a-toi.org?subject={subject}&body=Please give us some hints about how to reproduce the bug (your browser name and version, what you did and what happened)'>users@salut-a-toi.org</a>") |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
43 |
538
3317e5d0ac1d
browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents:
537
diff
changeset
|
44 AUTH_TRUSTED = D_("Verified") |
3317e5d0ac1d
browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents:
537
diff
changeset
|
45 AUTH_UNTRUSTED = D_("Unverified") |
3317e5d0ac1d
browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents:
537
diff
changeset
|
46 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
|
47 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
|
48 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
|
49 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
|
50 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
|
51 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
|
52 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
|
53 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
|
54 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
|
55 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
|
56 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
|
57 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
|
58 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
|
59 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
|
60 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
|
61 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
|
62 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
|
63 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
|
64 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
|
65 |
3317e5d0ac1d
browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents:
537
diff
changeset
|
66 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
|
67 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
|
68 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
|
69 |
3317e5d0ac1d
browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents:
537
diff
changeset
|
70 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
|
71 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
|
72 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
|
73 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
|
74 END_ENCRYPTED = D_("ERROR: the OTR session ended but the context is still supposedly encrypted!") |
3317e5d0ac1d
browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents:
537
diff
changeset
|
75 END_PLAIN = D_("Your conversation with {jid} is no more or hasn't been encrypted.") |
3317e5d0ac1d
browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents:
537
diff
changeset
|
76 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
|
77 |
3317e5d0ac1d
browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents:
537
diff
changeset
|
78 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
|
79 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
|
80 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
|
81 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
|
82 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
|
83 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
|
84 |
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
|
85 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
|
86 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
|
87 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
|
88 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
|
89 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
|
90 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
|
91 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
|
92 |
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
|
93 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
|
94 ACTION_NA = D_("Your correspondent must be connected to start an OTR conversation with him.") |
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
|
95 RESOURCE_ISSUE_TITLE = D_("Security issue") |
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
|
96 RESOURCE_ISSUE = D_("Your correspondent's resource is unknown!{eol}{eol}You should stop any OTR conversation with {jid} to avoid sending him unencrypted messages in an encrypted context.{eol}{eol}Please report the bug to the users mailing list: {users_ml}.") |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
97 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
98 DEFAULT_POLICY_FLAGS = { |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
99 'ALLOW_V2': True, |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
100 'ALLOW_V3': True, |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
101 'REQUIRE_ENCRYPTION': False, |
539
19b8af73e945
browser_side (plugin OTR): ask the user before accepting an OTR query
souliane <souliane@mailoo.org>
parents:
538
diff
changeset
|
102 'SEND_WHITESPACE_TAG': False, # FIXME: we need to complete sendMessageTrigger before turning this to True |
19b8af73e945
browser_side (plugin OTR): ask the user before accepting an OTR query
souliane <souliane@mailoo.org>
parents:
538
diff
changeset
|
103 'WHITESPACE_START_AKE': False, # FIXME: we need to complete messageReceivedTrigger before turning this to True |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
104 } |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
105 |
543
d02335553b5d
browser_side (plugin OTR): display OTR states with icons instead of a text
souliane <souliane@mailoo.org>
parents:
541
diff
changeset
|
106 # 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
|
107 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
|
108 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
|
109 '<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
|
110 '<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
|
111 ], |
d02335553b5d
browser_side (plugin OTR): display OTR states with icons instead of a text
souliane <souliane@mailoo.org>
parents:
541
diff
changeset
|
112 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
|
113 '<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
|
114 '<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
|
115 ], |
d02335553b5d
browser_side (plugin OTR): display OTR states with icons instead of a text
souliane <souliane@mailoo.org>
parents:
541
diff
changeset
|
116 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
|
117 '<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
|
118 '<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
|
119 ] |
536
048ae7314156
browser_side: temporary way to display the OTR state in the LiberviaWidget header
souliane <souliane@mailoo.org>
parents:
535
diff
changeset
|
120 } |
048ae7314156
browser_side: temporary way to display the OTR state in the LiberviaWidget header
souliane <souliane@mailoo.org>
parents:
535
diff
changeset
|
121 |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
122 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
123 class Context(otr.context.Context): |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
124 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
125 def __init__(self, host, account, other_jid): |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
126 """ |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
127 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
128 @param host (satWebFrontend) |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
129 @param account (Account) |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
584
diff
changeset
|
130 @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
|
131 """ |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
132 super(Context, self).__init__(account, other_jid) |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
133 self.host = host |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
134 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
135 def getPolicy(self, key): |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
136 """Get the value of the specified policy |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
137 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
138 @param key (str): a value in: |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
139 - ALLOW_V1 (apriori removed from otr.js) |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
140 - ALLOW_V2 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
141 - ALLOW_V3 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
142 - REQUIRE_ENCRYPTION |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
143 - SEND_WHITESPACE_TAG |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
144 - WHITESPACE_START_AKE |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
145 - ERROR_START_AKE |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
146 @return: str |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
147 """ |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
148 if key in DEFAULT_POLICY_FLAGS: |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
149 return DEFAULT_POLICY_FLAGS[key] |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
150 else: |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
151 return False |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
152 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
153 def receiveMessageCb(self, msg, encrypted): |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
154 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
|
155 if not encrypted: |
cd492c18b366
browser_side (plugin OTR): manage the plain text messages ourselves rather than leaving it to otr.js
souliane <souliane@mailoo.org>
parents:
536
diff
changeset
|
156 log.warning("A plain-text message has been handled by otr.js") |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
157 log.debug("message received (was %s): %s" % ('encrypted' if encrypted else 'plain', msg)) |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
158 if not encrypted: |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
159 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
|
160 log.warning(u"Received unencrypted message in an encrypted context (from %(jid)s)" % {'jid': self.peer}) |
538
3317e5d0ac1d
browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents:
537
diff
changeset
|
161 self.host.newMessageCb(self.peer, RECEIVE_PLAIN_IN_ENCRYPTED_CONTEXT, C.MESS_TYPE_INFO, self.host.whoami, {}) |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
162 self.host.newMessageCb(self.peer, msg, "chat", self.host.whoami, {}) |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
163 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
164 def sendMessageCb(self, msg, meta=None): |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
165 assert isinstance(self.peer, jid.JID) |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
166 log.debug("message to send%s: %s" % ((' (attached meta data: %s)' % meta) if meta else '', msg)) |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
584
diff
changeset
|
167 self.host.bridge.call('sendMessage', (None, self.host.sendError), self.peer, msg, '', 'chat', {'send_only': 'true'}) |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
168 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
169 def messageErrorCb(self, error): |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
170 log.error('error occured: %s' % error) |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
171 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
172 def setStateCb(self, msg_state, status): |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
173 if status == otr.context.STATUS_AKE_INIT: |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
174 return |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
175 |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
584
diff
changeset
|
176 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
|
177 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
|
178 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
|
179 |
048ae7314156
browser_side: temporary way to display the OTR state in the LiberviaWidget header
souliane <souliane@mailoo.org>
parents:
535
diff
changeset
|
180 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
|
181 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
|
182 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
183 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
|
184 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
|
185 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
|
186 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
187 elif status == otr.context.STATUS_END_OTR: |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
188 if msg_state == otr.context.STATE_PLAINTEXT: |
538
3317e5d0ac1d
browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents:
537
diff
changeset
|
189 feedback = END_PLAIN |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
190 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
|
191 log.error(END_ENCRYPTED) |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
192 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
|
193 feedback = END_FINISHED |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
194 |
543
d02335553b5d
browser_side (plugin OTR): display OTR states with icons instead of a text
souliane <souliane@mailoo.org>
parents:
541
diff
changeset
|
195 self.host.newMessageCb(self.peer, feedback.format(jid=other_jid_s), C.MESS_TYPE_INFO, self.host.whoami, {'header_info': OTR.getInfoText(msg_state, trust)}) |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
196 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
197 def setCurrentTrust(self, new_trust='', act='asked', type_='trust'): |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
198 log.debug("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
|
199 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
|
200 old_trust = self.getCurrentTrust() |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
201 if type_ == 'abort': |
538
3317e5d0ac1d
browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents:
537
diff
changeset
|
202 msg = AUTH_ABORTED_TXT |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
203 elif new_trust: |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
204 if act == "asked": |
538
3317e5d0ac1d
browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents:
537
diff
changeset
|
205 msg = AUTH_OTHER_OK |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
206 else: |
538
3317e5d0ac1d
browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents:
537
diff
changeset
|
207 msg = AUTH_US_OK |
3317e5d0ac1d
browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents:
537
diff
changeset
|
208 if not old_trust: |
3317e5d0ac1d
browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents:
537
diff
changeset
|
209 msg += " " + AUTH_OTHER_TOO |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
210 else: |
538
3317e5d0ac1d
browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents:
537
diff
changeset
|
211 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
|
212 dialog.InfoDialog(title, msg, AddStyleName="maxWidthLimit").show() |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
213 if act != "asked": |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
214 return |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
215 otr.context.Context.setCurrentTrust(self, new_trust) |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
216 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
|
217 feedback = AUTH_STATUS.format(state=(AUTH_TRUSTED if new_trust else AUTH_UNTRUSTED).lower()) |
543
d02335553b5d
browser_side (plugin OTR): display OTR states with icons instead of a text
souliane <souliane@mailoo.org>
parents:
541
diff
changeset
|
218 self.host.newMessageCb(self.peer, feedback, C.MESS_TYPE_INFO, self.host.whoami, {'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
|
219 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
220 def fingerprintAuthCb(self): |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
221 """OTR v2 authentication using manual fingerprint comparison""" |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
222 priv_key = self.user.privkey |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
223 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
224 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
|
225 raise exceptions.InternalError |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
226 return |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
227 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
228 other_key = self.getCurrentKey() |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
229 if other_key is None: |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
230 # 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
|
231 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
|
232 dialog.InfoDialog(_("Fingerprint"), msg, AddStyleName="maxWidthLimit").show() |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
233 return |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
234 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
235 def setTrust(confirm): |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
236 self.setCurrentTrust('fingerprint' if confirm else '') |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
237 |
538
3317e5d0ac1d
browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents:
537
diff
changeset
|
238 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
|
239 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
|
240 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
|
241 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
242 def smpAuthCb(self, type_, data, act=None): |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
243 """OTR v3 authentication using the socialist millionaire protocol. |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
244 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
245 @param type_ (str): a value in ('question', 'trust', 'abort') |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
246 @param data (str, bool): this could be: |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
247 - 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
|
248 - a boolean value telling if the authentication succeed when type_ is 'trust' |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
249 @param act (str): a value in ('asked', 'answered') |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
250 """ |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
251 log.debug("smpAuthCb: type={type}, data={data}, act={act}".format(type=type_, data=data, act=act)) |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
252 if act is None: |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
253 if type_ == 'question': |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
254 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
|
255 elif type_ == 'abort': |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
256 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
|
257 |
523
5add182e7dd5
browser_side (plugin OTR): rename menus and replace 'buddy' with 'correspondent'
souliane <souliane@mailoo.org>
parents:
522
diff
changeset
|
258 # 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
|
259 # 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
|
260 # 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
|
261 # make us need the dirty self.smpAuthAbort. |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
262 else: |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
263 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
|
264 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
|
265 if type_ == 'question': |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
266 if act == 'asked': |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
267 def cb(question, answer=None): |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
268 if question is False or not answer: # dialog cancelled or the answer is empty |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
269 return |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
270 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
|
271 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
|
272 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
|
273 else: |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
274 def cb(answer): |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
275 if not answer: # dialog cancelled or the answer is empty |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
276 self.smpAuthAbort('answered') |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
277 return |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
278 self.smpAuthSecret(answer) |
538
3317e5d0ac1d
browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents:
537
diff
changeset
|
279 text = (AUTH_INFO_TXT + "<i>" + AUTH_QUEST_ANSWER_TXT + "</i>" + AUTH_QUEST_ANSWER).format(eol=DIALOG_EOL, question=data) |
3317e5d0ac1d
browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents:
537
diff
changeset
|
280 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
|
281 elif type_ == 'trust': |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
282 self.setCurrentTrust('smp' if data else '', act) |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
283 elif type_ == 'abort': |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
284 self.setCurrentTrust('', act, 'abort') |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
285 |
529
9bfd71e2b35c
plugin OTR: disconnect the active OTR sessions on profile disconnection
souliane <souliane@mailoo.org>
parents:
528
diff
changeset
|
286 def disconnect(self): |
9bfd71e2b35c
plugin OTR: disconnect the active OTR sessions on profile disconnection
souliane <souliane@mailoo.org>
parents:
528
diff
changeset
|
287 """Disconnect the session.""" |
9bfd71e2b35c
plugin OTR: disconnect the active OTR sessions on profile disconnection
souliane <souliane@mailoo.org>
parents:
528
diff
changeset
|
288 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
|
289 super(Context, self).disconnect() |
9bfd71e2b35c
plugin OTR: disconnect the active OTR sessions on profile disconnection
souliane <souliane@mailoo.org>
parents:
528
diff
changeset
|
290 |
530
1735aaeac652
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
529
diff
changeset
|
291 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
|
292 """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
|
293 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
|
294 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
|
295 |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
296 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
297 class Account(otr.context.Account): |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
298 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
299 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
|
300 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
|
301 if not host.whoami.resource: |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
302 log.warning("Account created without resource") |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
303 super(Account, self).__init__(host.whoami) |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
304 self.host = host |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
305 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
306 def loadPrivkey(self): |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
307 return self.privkey |
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 def savePrivkey(self): |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
310 # 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
|
311 # 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
|
312 # self.privkey.serializePrivateKey() --> encrypt --> store |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
313 if self.privkey is None: |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
314 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
|
315 pass |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
316 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
317 def saveTrusts(self): |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
318 # 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
|
319 pass |
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 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
322 class ContextManager(object): |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
323 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
324 def __init__(self, host): |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
325 self.host = host |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
326 self.account = Account(host) |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
327 self.contexts = {} |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
328 |
528
ac66b8b11ab8
plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents:
525
diff
changeset
|
329 def startContext(self, other_jid): |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
330 assert isinstance(other_jid, jid.JID) |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
331 # 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
|
332 #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
|
333 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
|
334 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
|
335 return self.contexts[other_jid] |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
336 |
530
1735aaeac652
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
529
diff
changeset
|
337 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
|
338 """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
|
339 |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
584
diff
changeset
|
340 @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
|
341 @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
|
342 @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
|
343 """ |
1735aaeac652
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
529
diff
changeset
|
344 log.debug(u"getContextForUser [%s]" % other_jid) |
1735aaeac652
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
529
diff
changeset
|
345 if not other_jid.resource: |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
346 log.error("getContextForUser called with a bare jid") |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
584
diff
changeset
|
347 running_sessions = [jid_.bareJID() for jid_ in self.contexts.keys() if self.contexts[jid_].state == otr.context.STATE_ENCRYPTED] |
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
|
348 if start or (other_jid in running_sessions): |
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
|
349 users_ml = DIALOG_USERS_ML.format(subject=D_("OTR issue in Libervia: getContextForUser called with a bare jid in an encrypted context")) |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
584
diff
changeset
|
350 text = RESOURCE_ISSUE.format(eol=DIALOG_EOL, jid=other_jid, users_ml=users_ml) |
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
|
351 dialog.InfoDialog(RESOURCE_ISSUE_TITLE, text, AddStyleName="maxWidthLimit").show() |
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
|
352 return None # never start an OTR session with a bare JID |
528
ac66b8b11ab8
plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents:
525
diff
changeset
|
353 if start: |
ac66b8b11ab8
plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents:
525
diff
changeset
|
354 return self.startContext(other_jid) |
ac66b8b11ab8
plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents:
525
diff
changeset
|
355 else: |
ac66b8b11ab8
plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents:
525
diff
changeset
|
356 return self.contexts.get(other_jid, None) |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
357 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
358 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
359 class OTR(object): |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
360 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
361 def __init__(self, host): |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
362 log.info(_(u"OTR plugin initialization")) |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
363 self.host = host |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
364 self.context_manager = None |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
365 self.last_resources = {} |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
366 self.host.bridge._registerMethods(["skipOTR"]) |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
367 |
543
d02335553b5d
browser_side (plugin OTR): display OTR states with icons instead of a text
souliane <souliane@mailoo.org>
parents:
541
diff
changeset
|
368 @classmethod |
d02335553b5d
browser_side (plugin OTR): display OTR states with icons instead of a text
souliane <souliane@mailoo.org>
parents:
541
diff
changeset
|
369 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
|
370 """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
|
371 |
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
|
372 @param state (str): message state |
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
|
373 @param trust (str): 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
|
374 @return: str |
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
|
375 """ |
543
d02335553b5d
browser_side (plugin OTR): display OTR states with icons instead of a text
souliane <souliane@mailoo.org>
parents:
541
diff
changeset
|
376 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
|
377 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
|
378 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
|
379 |
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
|
380 def infoTextCallback(self, other_jid, cb): |
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
|
381 """Get the current info text for a conversation and run a callback. |
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
|
382 |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
584
diff
changeset
|
383 @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
|
384 @paam cb (callable): method to be called with the computed info text |
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
|
385 """ |
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
|
386 def gotResource(other_jid): |
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
|
387 otrctx = self.context_manager.getContextForUser(other_jid, start=False) |
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
|
388 if otrctx is None: |
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
|
389 cb(OTR.getInfoText()) |
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
|
390 else: |
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
|
391 cb(OTR.getInfoText(otrctx.state, otrctx.getCurrentTrust())) |
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
|
392 |
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
|
393 self.fixResource(other_jid, gotResource) |
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
|
394 |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
395 def inhibitMenus(self): |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
396 """Tell the caller which dynamic menus should be inhibited""" |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
397 return ["OTR"] # menu categories name to inhibit |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
398 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
399 def extraMenus(self): |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
400 # FIXME: handle help strings too |
523
5add182e7dd5
browser_side (plugin OTR): rename menus and replace 'buddy' with 'correspondent'
souliane <souliane@mailoo.org>
parents:
522
diff
changeset
|
401 return [(self._startRefresh, C.MENU_SINGLE, (MAIN_MENU, "Start / refresh"), (MAIN_MENU, D_("Start / refresh"))), |
5add182e7dd5
browser_side (plugin OTR): rename menus and replace 'buddy' with 'correspondent'
souliane <souliane@mailoo.org>
parents:
522
diff
changeset
|
402 (self._endSession, C.MENU_SINGLE, (MAIN_MENU, "Stop encryption"), (MAIN_MENU, D_("Stop encryption"))), |
5add182e7dd5
browser_side (plugin OTR): rename menus and replace 'buddy' with 'correspondent'
souliane <souliane@mailoo.org>
parents:
522
diff
changeset
|
403 (self._authenticate, C.MENU_SINGLE, (MAIN_MENU, "Authenticate correspondent"), (MAIN_MENU, D_("Authenticate correspondent"))), |
5add182e7dd5
browser_side (plugin OTR): rename menus and replace 'buddy' with 'correspondent'
souliane <souliane@mailoo.org>
parents:
522
diff
changeset
|
404 (self._dropPrivkey, C.MENU_SINGLE, (MAIN_MENU, "Drop your private key"), (MAIN_MENU, D_("Drop your private key")))] |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
405 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
406 def profileConnected(self): |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
407 self.host.bridge.call('skipOTR', None) |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
408 self.context_manager = ContextManager(self.host) |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
409 # 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
|
410 # 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
|
411 # assign it to self.context_manager.account.privkey |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
412 |
529
9bfd71e2b35c
plugin OTR: disconnect the active OTR sessions on profile disconnection
souliane <souliane@mailoo.org>
parents:
528
diff
changeset
|
413 def profileDisconnected(self): |
9bfd71e2b35c
plugin OTR: disconnect the active OTR sessions on profile disconnection
souliane <souliane@mailoo.org>
parents:
528
diff
changeset
|
414 for context in self.context_manager.contexts.values(): |
9bfd71e2b35c
plugin OTR: disconnect the active OTR sessions on profile disconnection
souliane <souliane@mailoo.org>
parents:
528
diff
changeset
|
415 context.disconnect() |
9bfd71e2b35c
plugin OTR: disconnect the active OTR sessions on profile disconnection
souliane <souliane@mailoo.org>
parents:
528
diff
changeset
|
416 |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
584
diff
changeset
|
417 def fixResource(self, jid_, cb): |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
418 # FIXME: it's dirty, but libervia doesn't manage resources correctly now, refactoring is planed |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
584
diff
changeset
|
419 if jid_.resource: |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
584
diff
changeset
|
420 self.last_resources[jid_.bare] = jid_.resource |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
584
diff
changeset
|
421 cb(jid_) |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
584
diff
changeset
|
422 elif jid_.bare in self.last_resources: |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
584
diff
changeset
|
423 # FIXME: to be removed: must use new resource system |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
584
diff
changeset
|
424 # jid_.setResource(self.last_resources[jid_.bare]) |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
584
diff
changeset
|
425 cb(jid_) |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
426 else: |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
584
diff
changeset
|
427 pass # FIXME: to be removed: must use new resource system |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
584
diff
changeset
|
428 # def gotResource(resource): |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
584
diff
changeset
|
429 # if resource: |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
584
diff
changeset
|
430 # jid_.setResource(resource) |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
584
diff
changeset
|
431 # self.last_resources[jid_.bare] = jid_.resource |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
584
diff
changeset
|
432 # cb(jid_) |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
584
diff
changeset
|
433 # |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
584
diff
changeset
|
434 # self.host.bridge.call('getLastResource', gotResource, jid_) |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
435 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
436 def messageReceivedTrigger(self, from_jid, msg, msg_type, to_jid, extra): |
533
19fc2ebc02dd
browser_side: management of new "info" newMessage type
Goffi <goffi@goffi.org>
parents:
531
diff
changeset
|
437 if msg_type == C.MESS_TYPE_INFO: |
19fc2ebc02dd
browser_side: management of new "info" newMessage type
Goffi <goffi@goffi.org>
parents:
531
diff
changeset
|
438 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
|
439 |
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
|
440 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
|
441 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
|
442 return True |
19b8af73e945
browser_side (plugin OTR): ask the user before accepting an OTR query
souliane <souliane@mailoo.org>
parents:
538
diff
changeset
|
443 |
19b8af73e945
browser_side (plugin OTR): ask the user before accepting an OTR query
souliane <souliane@mailoo.org>
parents:
538
diff
changeset
|
444 def decrypt(context): |
19b8af73e945
browser_side (plugin OTR): ask the user before accepting an OTR query
souliane <souliane@mailoo.org>
parents:
538
diff
changeset
|
445 context.receiveMessage(msg) |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
446 |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
584
diff
changeset
|
447 def cb(jid_): |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
584
diff
changeset
|
448 otrctx = self.context_manager.getContextForUser(jid_, start=False) |
539
19b8af73e945
browser_side (plugin OTR): ask the user before accepting an OTR query
souliane <souliane@mailoo.org>
parents:
538
diff
changeset
|
449 if otrctx is None: |
19b8af73e945
browser_side (plugin OTR): ask the user before accepting an OTR query
souliane <souliane@mailoo.org>
parents:
538
diff
changeset
|
450 def confirm(confirm): |
19b8af73e945
browser_side (plugin OTR): ask the user before accepting an OTR query
souliane <souliane@mailoo.org>
parents:
538
diff
changeset
|
451 if confirm: |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
584
diff
changeset
|
452 self.host.getOrCreateLiberviaWidget(panels.ChatPanel, {'item': jid_}) |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
584
diff
changeset
|
453 decrypt(self.context_manager.startContext(jid_)) |
539
19b8af73e945
browser_side (plugin OTR): ask the user before accepting an OTR query
souliane <souliane@mailoo.org>
parents:
538
diff
changeset
|
454 else: |
19b8af73e945
browser_side (plugin OTR): ask the user before accepting an OTR query
souliane <souliane@mailoo.org>
parents:
538
diff
changeset
|
455 # FIXME: plain text messages with whitespaces would be lost here when WHITESPACE_START_AKE is True |
19b8af73e945
browser_side (plugin OTR): ask the user before accepting an OTR query
souliane <souliane@mailoo.org>
parents:
538
diff
changeset
|
456 pass |
19b8af73e945
browser_side (plugin OTR): ask the user before accepting an OTR query
souliane <souliane@mailoo.org>
parents:
538
diff
changeset
|
457 key = self.context_manager.account.privkey |
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
|
458 msg = QUERY_RECEIVED + QUERY_SLOWDOWN + (QUERY_KEY if key else QUERY_NO_KEY) + QUERY_CONFIRM |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
584
diff
changeset
|
459 dialog.ConfirmDialog(confirm, msg.format(jid=jid_, eol=DIALOG_EOL), QUERY_TITLE, AddStyleName="maxWidthLimit").show() |
539
19b8af73e945
browser_side (plugin OTR): ask the user before accepting an OTR query
souliane <souliane@mailoo.org>
parents:
538
diff
changeset
|
460 else: # do not ask if the context exist |
19b8af73e945
browser_side (plugin OTR): ask the user before accepting an OTR query
souliane <souliane@mailoo.org>
parents:
538
diff
changeset
|
461 decrypt(otrctx) |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
462 |
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
|
463 other_jid = to_jid if from_jid.bare == self.host.whoami.bare else from_jid |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
464 self.fixResource(other_jid, cb) |
539
19b8af73e945
browser_side (plugin OTR): ask the user before accepting an OTR query
souliane <souliane@mailoo.org>
parents:
538
diff
changeset
|
465 return False # interrupt the main process |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
466 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
467 def sendMessageTrigger(self, to_jid, msg, msg_type, extra): |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
584
diff
changeset
|
468 def cb(jid_): |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
584
diff
changeset
|
469 otrctx = self.context_manager.getContextForUser(jid_, start=False) |
583
4c6c61696ba0
plugin sec_otr: improvement when sending a message to a MUC
souliane <souliane@mailoo.org>
parents:
574
diff
changeset
|
470 if otrctx is not None and otrctx.state != otr.context.STATE_PLAINTEXT: |
528
ac66b8b11ab8
plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents:
525
diff
changeset
|
471 if otrctx.state == otr.context.STATE_ENCRYPTED: |
ac66b8b11ab8
plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents:
525
diff
changeset
|
472 log.debug(u"encrypting message") |
ac66b8b11ab8
plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents:
525
diff
changeset
|
473 otrctx.sendMessage(msg) |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
584
diff
changeset
|
474 self.host.newMessageCb(self.host.whoami, msg, msg_type, jid_, extra) |
528
ac66b8b11ab8
plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents:
525
diff
changeset
|
475 else: |
538
3317e5d0ac1d
browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents:
537
diff
changeset
|
476 feedback = SEND_PLAIN_IN_FINISHED_CONTEXT |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
584
diff
changeset
|
477 dialog.InfoDialog(FINISHED_CONTEXT_TITLE.format(jid=to_jid), feedback, AddStyleName="maxWidthLimit").show() |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
478 else: |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
479 log.debug(u"sending message unencrypted") |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
584
diff
changeset
|
480 self.host.bridge.call('sendMessage', (None, self.host.sendError), to_jid, msg, '', msg_type, extra) |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
481 |
583
4c6c61696ba0
plugin sec_otr: improvement when sending a message to a MUC
souliane <souliane@mailoo.org>
parents:
574
diff
changeset
|
482 if msg_type == 'groupchat': |
4c6c61696ba0
plugin sec_otr: improvement when sending a message to a MUC
souliane <souliane@mailoo.org>
parents:
574
diff
changeset
|
483 return True |
4c6c61696ba0
plugin sec_otr: improvement when sending a message to a MUC
souliane <souliane@mailoo.org>
parents:
574
diff
changeset
|
484 self.fixResource(to_jid, cb) |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
485 return False # interrupt the main process |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
486 |
530
1735aaeac652
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
529
diff
changeset
|
487 def presenceReceivedTrigger(self, entity, show, priority, statuses): |
1735aaeac652
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
529
diff
changeset
|
488 if show == "unavailable": |
1735aaeac652
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
529
diff
changeset
|
489 self.endSession(entity, finish=True) |
1735aaeac652
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
529
diff
changeset
|
490 return True |
1735aaeac652
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
529
diff
changeset
|
491 |
1735aaeac652
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
529
diff
changeset
|
492 def endSession(self, other_jid, profile, finish=False): |
1735aaeac652
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
529
diff
changeset
|
493 """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
|
494 |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
584
diff
changeset
|
495 @param other_jid (jid.JID): str |
530
1735aaeac652
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
529
diff
changeset
|
496 @param finish: if True, finish the session but do not disconnect it |
1735aaeac652
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
529
diff
changeset
|
497 @return: True if the session has been finished or disconnected, False if there was nothing to do |
1735aaeac652
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
529
diff
changeset
|
498 """ |
1735aaeac652
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
529
diff
changeset
|
499 def cb(other_jid): |
1735aaeac652
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
529
diff
changeset
|
500 def not_available(): |
1735aaeac652
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
529
diff
changeset
|
501 if not finish: |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
584
diff
changeset
|
502 self.host.newMessageCb(other_jid, END_PLAIN.format(jid=other_jid), C.MESS_TYPE_INFO, self.host.whoami, {}) |
530
1735aaeac652
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
529
diff
changeset
|
503 |
1735aaeac652
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
529
diff
changeset
|
504 priv_key = self.context_manager.account.privkey |
1735aaeac652
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
529
diff
changeset
|
505 if priv_key is None: |
1735aaeac652
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
529
diff
changeset
|
506 not_available() |
1735aaeac652
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
529
diff
changeset
|
507 return |
1735aaeac652
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
529
diff
changeset
|
508 |
1735aaeac652
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
529
diff
changeset
|
509 otrctx = self.context_manager.getContextForUser(other_jid, start=False) |
1735aaeac652
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
529
diff
changeset
|
510 if otrctx is None: |
1735aaeac652
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
529
diff
changeset
|
511 not_available() |
1735aaeac652
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
529
diff
changeset
|
512 return |
1735aaeac652
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
529
diff
changeset
|
513 if finish: |
1735aaeac652
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
529
diff
changeset
|
514 otrctx.finish() |
1735aaeac652
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
529
diff
changeset
|
515 else: |
1735aaeac652
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
529
diff
changeset
|
516 otrctx.disconnect() |
1735aaeac652
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
529
diff
changeset
|
517 |
1735aaeac652
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
529
diff
changeset
|
518 self.fixResource(other_jid, cb) |
1735aaeac652
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
529
diff
changeset
|
519 |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
520 # Menu callbacks |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
521 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
522 def _startRefresh(self, menu_data): |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
523 """Start or refresh an OTR session |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
524 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
525 @param menu_data: %(menu_data)s |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
526 """ |
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
|
527 def query(other_jid): |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
528 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
|
529 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
|
530 otrctx.sendQueryMessage() |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
531 |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
584
diff
changeset
|
532 def cb(jid_): |
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
|
533 key = self.context_manager.account.privkey |
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
|
534 if key is None: |
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
|
535 def confirm(confirm): |
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
|
536 if confirm: |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
584
diff
changeset
|
537 query(jid_) |
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
|
538 msg = QUERY_SEND + QUERY_SLOWDOWN + QUERY_NO_KEY + QUERY_CONFIRM |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
584
diff
changeset
|
539 dialog.ConfirmDialog(confirm, msg.format(jid=jid_, eol=DIALOG_EOL), QUERY_TITLE, AddStyleName="maxWidthLimit").show() |
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
|
540 else: # on query reception we ask always, if we initiate we just ask the first time |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
584
diff
changeset
|
541 query(jid_) |
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
|
542 |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
543 try: |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
544 other_jid = menu_data['jid'] |
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
|
545 if other_jid.bare not in self.host.contact_panel.connected: |
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
|
546 dialog.InfoDialog(ACTION_NA_TITLE, ACTION_NA, AddStyleName="maxWidthLimit").show() |
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
|
547 return |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
548 self.fixResource(other_jid, cb) |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
549 except KeyError: |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
550 log.error(_("jid key is not present !")) |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
551 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
552 def _endSession(self, menu_data): |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
553 """End an OTR session |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
554 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
555 @param menu_data: %(menu_data)s |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
556 """ |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
557 try: |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
558 other_jid = menu_data['jid'] |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
559 except KeyError: |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
560 log.error(_("jid key is not present !")) |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
561 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
|
562 self.endSession(other_jid) |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
563 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
564 def _authenticate(self, menu_data, profile): |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
565 """Authenticate other user and see our own fingerprint |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
566 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
567 @param menu_data: %(menu_data)s |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
568 @param profile: %(doc_profile)s |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
569 """ |
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
|
570 def not_available(): |
538
3317e5d0ac1d
browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents:
537
diff
changeset
|
571 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
|
572 |
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 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
|
574 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
|
575 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
|
576 return |
307f84fee972
browser_side (plugin OTR): avoid unecessary waiting time on menu callbacks when the private key or the context doesn't exist
souliane <souliane@mailoo.org>
parents:
524
diff
changeset
|
577 |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
578 def cb(to_jid): |
528
ac66b8b11ab8
plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents:
525
diff
changeset
|
579 otrctx = self.context_manager.getContextForUser(to_jid, start=False) |
525
307f84fee972
browser_side (plugin OTR): avoid unecessary waiting time on menu callbacks when the private key or the context doesn't exist
souliane <souliane@mailoo.org>
parents:
524
diff
changeset
|
580 if otrctx is None: |
307f84fee972
browser_side (plugin OTR): avoid unecessary waiting time on menu callbacks when the private key or the context doesn't exist
souliane <souliane@mailoo.org>
parents:
524
diff
changeset
|
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 |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
583 otr_version = otrctx.getUsedVersion() |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
584 if otr_version == otr.context.OTR_VERSION_2: |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
585 otrctx.fingerprintAuthCb() |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
586 elif otr_version == otr.context.OTR_VERSION_3: |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
587 otrctx.smpAuthCb('question', None, 'asked') |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
588 else: |
525
307f84fee972
browser_side (plugin OTR): avoid unecessary waiting time on menu callbacks when the private key or the context doesn't exist
souliane <souliane@mailoo.org>
parents:
524
diff
changeset
|
589 not_available() |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
590 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
591 try: |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
592 to_jid = menu_data['jid'] |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
593 self.fixResource(to_jid, cb) |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
594 except KeyError: |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
595 log.error(_("jid key is not present !")) |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
596 return None |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
597 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
598 def _dropPrivkey(self, menu_data, profile): |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
599 """Drop our private Key |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
600 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
601 @param menu_data: %(menu_data)s |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
602 @param profile: %(doc_profile)s |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
603 """ |
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
|
604 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
|
605 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
|
606 # 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
|
607 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
|
608 return |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
609 |
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
|
610 def cb(to_jid): |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
611 def dropKey(confirm): |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
612 if confirm: |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
613 # we end all sessions |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
614 for context in self.context_manager.contexts.values(): |
529
9bfd71e2b35c
plugin OTR: disconnect the active OTR sessions on profile disconnection
souliane <souliane@mailoo.org>
parents:
528
diff
changeset
|
615 context.disconnect() |
540
22358ffa26e4
browser_side (plugin OTR): really clean everything on key drop
souliane <souliane@mailoo.org>
parents:
539
diff
changeset
|
616 self.context_manager.contexts.clear() |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
617 self.context_manager.account.privkey = None |
538
3317e5d0ac1d
browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents:
537
diff
changeset
|
618 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
|
619 |
538
3317e5d0ac1d
browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents:
537
diff
changeset
|
620 dialog.ConfirmDialog(dropKey, KEY_DROP_TXT.format(eol=DIALOG_EOL), KEY_DROP_TITLE, AddStyleName="maxWidthLimit").show() |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
621 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
622 try: |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
623 to_jid = menu_data['jid'] |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
624 self.fixResource(to_jid, cb) |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
625 except KeyError: |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
626 log.error(_("jid key is not present !")) |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
627 return None |