Mercurial > libervia-web
annotate src/browser/sat_browser/plugin_sec_otr.py @ 707:dfe4b0291daa
server_side: remove unwanted "target" property in the HTTP to HTTPS link + use "<p>" instead of "<br>"
author | souliane <souliane@mailoo.org> |
---|---|
date | Sun, 07 Jun 2015 13:17:05 +0200 |
parents | 82123705474b |
children | f8a7a046ff9c |
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 |
685 | 5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015 Jérôme Poisson (goffi@goffi.org) |
6 # Copyright (C) 2013, 2014, 2015 Adrien Cossa (souliane@mailoo.org) | |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
7 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
8 # This program is free software: you can redistribute it and/or modify |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
9 # it under the terms of the GNU Affero General Public License as published by |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
10 # the Free Software Foundation, either version 3 of the License, or |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
11 # (at your option) any later version. |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
12 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
13 # This program is distributed in the hope that it will be useful, |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
16 # GNU Affero General Public License for more details. |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
17 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
18 # You should have received a copy of the GNU Affero General Public License |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
19 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
20 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
21 """ |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
22 This file is adapted from sat.plugins.plugin.sec_otr. It offers browser-side OTR encryption using otr.js. |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
23 The text messages to display are mostly taken from the Pidgin OTR plugin (GPL 2.0, see http://otr.cypherpunks.ca). |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
24 """ |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
25 |
663
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
26 from sat.core.log import getLogger |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
27 log = getLogger(__name__) |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
28 |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
29 from sat.core.i18n import _, D_ |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
30 from sat.core import exceptions |
681
3b185ccb70b4
browser side: updated trigger import according to backend renaming (sat.tools.misc is now sat.tools.trigger)
Goffi <goffi@goffi.org>
parents:
678
diff
changeset
|
31 from sat.tools import trigger |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
32 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
33 from constants import Const as C |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
584
diff
changeset
|
34 from sat_frontends.tools import jid |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
35 import otrjs_wrapper as otr |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
36 import dialog |
616
1c0d5a87c554
browser_side: add and use method displayWidget to harmonize widget's management in Libervia (not completely done, there are some issues)
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
37 import chat |
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
|
38 |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
39 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
40 NS_OTR = "otr_plugin" |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
41 PRIVATE_KEY = "PRIVATE KEY" |
678
2e087e093e7f
browser side(otr): restored menu hooks using new hook system
Goffi <goffi@goffi.org>
parents:
676
diff
changeset
|
42 MAIN_MENU = D_('OTR') # TODO: get this constant directly from backend's plugin |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
43 DIALOG_EOL = "<br />" |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
44 |
538
3317e5d0ac1d
browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents:
537
diff
changeset
|
45 AUTH_TRUSTED = D_("Verified") |
3317e5d0ac1d
browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents:
537
diff
changeset
|
46 AUTH_UNTRUSTED = D_("Unverified") |
3317e5d0ac1d
browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents:
537
diff
changeset
|
47 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
|
48 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
|
49 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
|
50 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
|
51 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
|
52 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
|
53 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
|
54 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
|
55 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
|
56 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
|
57 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
|
58 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
|
59 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
|
60 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
|
61 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
|
62 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
|
63 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
|
64 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
|
65 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
|
66 |
3317e5d0ac1d
browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents:
537
diff
changeset
|
67 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
|
68 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
|
69 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
|
70 |
3317e5d0ac1d
browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents:
537
diff
changeset
|
71 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
|
72 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
|
73 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
|
74 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
|
75 END_ENCRYPTED = D_("ERROR: the OTR session ended but the context is still supposedly encrypted!") |
663
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
76 END_PLAIN_NO_MORE = D_("Your conversation with {jid} is no more encrypted.") |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
77 END_PLAIN_HAS_NOT = D_("Your conversation with {jid} hasn't been encrypted.") |
538
3317e5d0ac1d
browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents:
537
diff
changeset
|
78 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
|
79 |
3317e5d0ac1d
browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents:
537
diff
changeset
|
80 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
|
81 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
|
82 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
|
83 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
|
84 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
|
85 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
|
86 |
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
|
87 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
|
88 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
|
89 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
|
90 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
|
91 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
|
92 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
|
93 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
|
94 |
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
|
95 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
|
96 ACTION_NA = D_("Your correspondent must be connected to start an OTR conversation with him.") |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
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, |
663
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
102 'SEND_WHITESPACE_TAG': False, # FIXME: we need to complete sendMessageTg before turning this to True |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
103 'WHITESPACE_START_AKE': False, # FIXME: we need to complete newMessageTg before turning this to True |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
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 |
663
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
123 unicode = str # FIXME: pyjamas workaround |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
124 |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
125 |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
126 class NotConnectedEntity(Exception): |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
127 pass |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
128 |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
129 |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
130 class Context(otr.context.Context): |
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 def __init__(self, host, account, other_jid): |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
133 """ |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
134 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
135 @param host (satWebFrontend) |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
136 @param account (Account) |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
584
diff
changeset
|
137 @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
|
138 """ |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
139 super(Context, self).__init__(account, other_jid) |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
140 self.host = host |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
141 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
142 def getPolicy(self, key): |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
143 """Get the value of the specified policy |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
144 |
662
ebb602d8b3f2
browser_side: replace all instances of 'str' with 'unicode'
souliane <souliane@mailoo.org>
parents:
624
diff
changeset
|
145 @param key (unicode): a value in: |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
146 - ALLOW_V1 (apriori removed from otr.js) |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
147 - ALLOW_V2 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
148 - ALLOW_V3 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
149 - REQUIRE_ENCRYPTION |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
150 - SEND_WHITESPACE_TAG |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
151 - WHITESPACE_START_AKE |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
152 - ERROR_START_AKE |
662
ebb602d8b3f2
browser_side: replace all instances of 'str' with 'unicode'
souliane <souliane@mailoo.org>
parents:
624
diff
changeset
|
153 @return: unicode |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
154 """ |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
155 if key in DEFAULT_POLICY_FLAGS: |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
156 return DEFAULT_POLICY_FLAGS[key] |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
157 else: |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
158 return False |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
159 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
160 def receiveMessageCb(self, msg, encrypted): |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
161 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
|
162 if not encrypted: |
694
82123705474b
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
163 log.warning(u"A plain-text message has been handled by otr.js") |
82123705474b
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
164 log.debug(u"message received (was %s): %s" % ('encrypted' if encrypted else 'plain', msg)) |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
165 if not encrypted: |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
166 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
|
167 log.warning(u"Received unencrypted message in an encrypted context (from %(jid)s)" % {'jid': self.peer}) |
663
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
168 self.host.newMessageHandler(unicode(self.peer), RECEIVE_PLAIN_IN_ENCRYPTED_CONTEXT, C.MESS_TYPE_INFO, unicode(self.host.whoami), {}) |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
169 self.host.newMessageHandler(unicode(self.peer), msg, C.MESS_TYPE_CHAT, unicode(self.host.whoami), {}) |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
170 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
171 def sendMessageCb(self, msg, meta=None): |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
172 assert isinstance(self.peer, jid.JID) |
694
82123705474b
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
173 log.debug(u"message to send%s: %s" % ((' (attached meta data: %s)' % meta) if meta else '', msg)) |
663
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
174 self.host.bridge.call('sendMessage', (None, self.host.sendError), unicode(self.peer), msg, '', C.MESS_TYPE_CHAT, {'send_only': 'true'}) |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
175 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
176 def messageErrorCb(self, error): |
694
82123705474b
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
177 log.error(u'error occured: %s' % error) |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
178 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
179 def setStateCb(self, msg_state, status): |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
180 if status == otr.context.STATUS_AKE_INIT: |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
181 return |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
182 |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
584
diff
changeset
|
183 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
|
184 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
|
185 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
|
186 |
048ae7314156
browser_side: temporary way to display the OTR state in the LiberviaWidget header
souliane <souliane@mailoo.org>
parents:
535
diff
changeset
|
187 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
|
188 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
|
189 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
190 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
|
191 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
|
192 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
|
193 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
194 elif status == otr.context.STATUS_END_OTR: |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
195 if msg_state == otr.context.STATE_PLAINTEXT: |
663
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
196 feedback = END_PLAIN_NO_MORE |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
197 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
|
198 log.error(END_ENCRYPTED) |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
199 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
|
200 feedback = END_FINISHED |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
201 |
663
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
202 self.host.newMessageHandler(unicode(self.peer), feedback.format(jid=other_jid_s), C.MESS_TYPE_INFO, unicode(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
|
203 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
204 def setCurrentTrust(self, new_trust='', act='asked', type_='trust'): |
694
82123705474b
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
205 log.debug(u"setCurrentTrust: trust={trust}, act={act}, type={type}".format(type=type_, trust=new_trust, act=act)) |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
584
diff
changeset
|
206 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
|
207 old_trust = self.getCurrentTrust() |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
208 if type_ == 'abort': |
538
3317e5d0ac1d
browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents:
537
diff
changeset
|
209 msg = AUTH_ABORTED_TXT |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
210 elif new_trust: |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
211 if act == "asked": |
538
3317e5d0ac1d
browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents:
537
diff
changeset
|
212 msg = AUTH_OTHER_OK |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
213 else: |
538
3317e5d0ac1d
browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents:
537
diff
changeset
|
214 msg = AUTH_US_OK |
3317e5d0ac1d
browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents:
537
diff
changeset
|
215 if not old_trust: |
3317e5d0ac1d
browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents:
537
diff
changeset
|
216 msg += " " + AUTH_OTHER_TOO |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
217 else: |
538
3317e5d0ac1d
browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents:
537
diff
changeset
|
218 msg = AUTH_FAILED_TXT |
524
d41e850b31b9
browser_side (plugin OTR): limit the max width for all dialogs
souliane <souliane@mailoo.org>
parents:
523
diff
changeset
|
219 dialog.InfoDialog(title, msg, AddStyleName="maxWidthLimit").show() |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
220 if act != "asked": |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
221 return |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
222 otr.context.Context.setCurrentTrust(self, new_trust) |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
223 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
|
224 feedback = AUTH_STATUS.format(state=(AUTH_TRUSTED if new_trust else AUTH_UNTRUSTED).lower()) |
663
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
225 self.host.newMessageHandler(unicode(self.peer), feedback, C.MESS_TYPE_INFO, unicode(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
|
226 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
227 def fingerprintAuthCb(self): |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
228 """OTR v2 authentication using manual fingerprint comparison""" |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
229 priv_key = self.user.privkey |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
230 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
231 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
|
232 raise exceptions.InternalError |
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 other_key = self.getCurrentKey() |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
236 if other_key is None: |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
237 # 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
|
238 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
|
239 dialog.InfoDialog(_("Fingerprint"), msg, AddStyleName="maxWidthLimit").show() |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
240 return |
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 setTrust(confirm): |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
243 self.setCurrentTrust('fingerprint' if confirm else '') |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
244 |
538
3317e5d0ac1d
browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents:
537
diff
changeset
|
245 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
|
246 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
|
247 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
|
248 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
249 def smpAuthCb(self, type_, data, act=None): |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
250 """OTR v3 authentication using the socialist millionaire protocol. |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
251 |
662
ebb602d8b3f2
browser_side: replace all instances of 'str' with 'unicode'
souliane <souliane@mailoo.org>
parents:
624
diff
changeset
|
252 @param type_ (unicode): a value in ('question', 'trust', 'abort') |
ebb602d8b3f2
browser_side: replace all instances of 'str' with 'unicode'
souliane <souliane@mailoo.org>
parents:
624
diff
changeset
|
253 @param data (unicode, bool): this could be: |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
254 - 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
|
255 - a boolean value telling if the authentication succeed when type_ is 'trust' |
662
ebb602d8b3f2
browser_side: replace all instances of 'str' with 'unicode'
souliane <souliane@mailoo.org>
parents:
624
diff
changeset
|
256 @param act (unicode): a value in ('asked', 'answered') |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
257 """ |
694
82123705474b
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
258 log.debug(u"smpAuthCb: type={type}, data={data}, act={act}".format(type=type_, data=data, act=act)) |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
259 if act is None: |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
260 if type_ == 'question': |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
261 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
|
262 elif type_ == 'abort': |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
263 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
|
264 |
523
5add182e7dd5
browser_side (plugin OTR): rename menus and replace 'buddy' with 'correspondent'
souliane <souliane@mailoo.org>
parents:
522
diff
changeset
|
265 # 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
|
266 # 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
|
267 # 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
|
268 # make us need the dirty self.smpAuthAbort. |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
269 else: |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
270 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
|
271 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
|
272 if type_ == 'question': |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
273 if act == 'asked': |
624
9092e624bb27
browser_side: fixes various issues
souliane <souliane@mailoo.org>
parents:
616
diff
changeset
|
274 def cb(result, question, answer=None): |
9092e624bb27
browser_side: fixes various issues
souliane <souliane@mailoo.org>
parents:
616
diff
changeset
|
275 if not result or not answer: # dialog cancelled or the answer is empty |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
276 return |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
277 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
|
278 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
|
279 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
|
280 else: |
624
9092e624bb27
browser_side: fixes various issues
souliane <souliane@mailoo.org>
parents:
616
diff
changeset
|
281 def cb(result, answer): |
9092e624bb27
browser_side: fixes various issues
souliane <souliane@mailoo.org>
parents:
616
diff
changeset
|
282 if not result or not answer: # dialog cancelled or the answer is empty |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
283 self.smpAuthAbort('answered') |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
284 return |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
285 self.smpAuthSecret(answer) |
538
3317e5d0ac1d
browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents:
537
diff
changeset
|
286 text = (AUTH_INFO_TXT + "<i>" + AUTH_QUEST_ANSWER_TXT + "</i>" + AUTH_QUEST_ANSWER).format(eol=DIALOG_EOL, question=data) |
624
9092e624bb27
browser_side: fixes various issues
souliane <souliane@mailoo.org>
parents:
616
diff
changeset
|
287 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
|
288 elif type_ == 'trust': |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
289 self.setCurrentTrust('smp' if data else '', act) |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
290 elif type_ == 'abort': |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
291 self.setCurrentTrust('', act, 'abort') |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
292 |
529
9bfd71e2b35c
plugin OTR: disconnect the active OTR sessions on profile disconnection
souliane <souliane@mailoo.org>
parents:
528
diff
changeset
|
293 def disconnect(self): |
9bfd71e2b35c
plugin OTR: disconnect the active OTR sessions on profile disconnection
souliane <souliane@mailoo.org>
parents:
528
diff
changeset
|
294 """Disconnect the session.""" |
9bfd71e2b35c
plugin OTR: disconnect the active OTR sessions on profile disconnection
souliane <souliane@mailoo.org>
parents:
528
diff
changeset
|
295 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
|
296 super(Context, self).disconnect() |
9bfd71e2b35c
plugin OTR: disconnect the active OTR sessions on profile disconnection
souliane <souliane@mailoo.org>
parents:
528
diff
changeset
|
297 |
530
1735aaeac652
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
529
diff
changeset
|
298 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
|
299 """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
|
300 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
|
301 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
|
302 |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
303 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
304 class Account(otr.context.Account): |
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 __init__(self, host): |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
584
diff
changeset
|
307 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
|
308 if not host.whoami.resource: |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
309 log.warning("Account created without resource") |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
310 super(Account, self).__init__(host.whoami) |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
311 self.host = host |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
312 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
313 def loadPrivkey(self): |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
314 return self.privkey |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
315 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
316 def savePrivkey(self): |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
317 # 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
|
318 # 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
|
319 # self.privkey.serializePrivateKey() --> encrypt --> store |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
320 if self.privkey is None: |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
321 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
|
322 pass |
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 saveTrusts(self): |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
325 # 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
|
326 pass |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
327 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
328 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
329 class ContextManager(object): |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
330 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
331 def __init__(self, host): |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
332 self.host = host |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
333 self.account = Account(host) |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
334 self.contexts = {} |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
335 |
528
ac66b8b11ab8
plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents:
525
diff
changeset
|
336 def startContext(self, other_jid): |
663
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
337 assert isinstance(other_jid, jid.JID) # never start an OTR session with a bare JID |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
338 # 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
|
339 #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
|
340 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
|
341 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
|
342 return self.contexts[other_jid] |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
343 |
530
1735aaeac652
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
529
diff
changeset
|
344 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
|
345 """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
|
346 |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
584
diff
changeset
|
347 @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
|
348 @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
|
349 @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
|
350 """ |
663
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
351 try: |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
352 other_jid = self.fixResource(other_jid) |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
353 except NotConnectedEntity: |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
354 log.debug(u"getContextForUser [%s]: not connected!" % other_jid) |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
355 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
|
356 log.debug(u"getContextForUser [%s]" % other_jid) |
528
ac66b8b11ab8
plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents:
525
diff
changeset
|
357 if start: |
ac66b8b11ab8
plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents:
525
diff
changeset
|
358 return self.startContext(other_jid) |
ac66b8b11ab8
plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents:
525
diff
changeset
|
359 else: |
ac66b8b11ab8
plugin OTR: fixes handling of the FINISHED state
souliane <souliane@mailoo.org>
parents:
525
diff
changeset
|
360 return self.contexts.get(other_jid, None) |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
361 |
665
6a8a1103ad10
browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents:
664
diff
changeset
|
362 def getContextsForBareUser(self, bare_jid): |
6a8a1103ad10
browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents:
664
diff
changeset
|
363 """Get all the contexts for the users sharing the given bare JID. |
6a8a1103ad10
browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents:
664
diff
changeset
|
364 |
6a8a1103ad10
browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents:
664
diff
changeset
|
365 @param bare_jid (jid.JID): bare JID |
6a8a1103ad10
browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents:
664
diff
changeset
|
366 @return: list[Context] |
6a8a1103ad10
browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents:
664
diff
changeset
|
367 """ |
6a8a1103ad10
browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents:
664
diff
changeset
|
368 return [context for other_jid, context in self.contexts.iteritems() if other_jid.bare == bare_jid] |
6a8a1103ad10
browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents:
664
diff
changeset
|
369 |
663
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
370 def fixResource(self, other_jid): |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
371 """Return the full JID in case the resource of the given JID is missing. |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
372 |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
373 @param other_jid (jid.JID): JID to check |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
374 @return jid.JID |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
375 """ |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
376 if other_jid.resource: |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
377 return other_jid |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
378 clist = self.host.contact_list |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
379 if clist.getCache(other_jid.bare, C.PRESENCE_SHOW) is None: |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
380 raise NotConnectedEntity |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
381 return clist.getFullJid(other_jid) |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
382 |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
383 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
384 class OTR(object): |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
385 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
386 def __init__(self, host): |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
387 log.info(_(u"OTR plugin initialization")) |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
388 self.host = host |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
389 self.context_manager = None |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
390 self.host.bridge._registerMethods(["skipOTR"]) |
681
3b185ccb70b4
browser side: updated trigger import according to backend renaming (sat.tools.misc is now sat.tools.trigger)
Goffi <goffi@goffi.org>
parents:
678
diff
changeset
|
391 self.host.trigger.add("newMessageTrigger", self.newMessageTg, priority=trigger.TriggerManager.MAX_PRIORITY) |
3b185ccb70b4
browser side: updated trigger import according to backend renaming (sat.tools.misc is now sat.tools.trigger)
Goffi <goffi@goffi.org>
parents:
678
diff
changeset
|
392 self.host.trigger.add("sendMessageTrigger", self.sendMessageTg, priority=trigger.TriggerManager.MAX_PRIORITY) |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
393 |
665
6a8a1103ad10
browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents:
664
diff
changeset
|
394 # FIXME: workaround for a pyjamas issue: calling hash on a class method always return a different value if that method is defined directly within the class (with the "def" keyword) |
6a8a1103ad10
browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents:
664
diff
changeset
|
395 self._profilePluggedListener = self.profilePluggedListener |
6a8a1103ad10
browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents:
664
diff
changeset
|
396 self._gotMenusListener = self.gotMenusListener |
6a8a1103ad10
browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents:
664
diff
changeset
|
397 # FIXME: these listeners are never removed, can't be removed by themselves (it modifies the list while looping), maybe need a 'one_shot' argument |
6a8a1103ad10
browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents:
664
diff
changeset
|
398 self.host.addListener('profilePlugged', self._profilePluggedListener) |
678
2e087e093e7f
browser side(otr): restored menu hooks using new hook system
Goffi <goffi@goffi.org>
parents:
676
diff
changeset
|
399 self.host.addListener('gotMenus', self._gotMenusListener) |
665
6a8a1103ad10
browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents:
664
diff
changeset
|
400 |
543
d02335553b5d
browser_side (plugin OTR): display OTR states with icons instead of a text
souliane <souliane@mailoo.org>
parents:
541
diff
changeset
|
401 @classmethod |
d02335553b5d
browser_side (plugin OTR): display OTR states with icons instead of a text
souliane <souliane@mailoo.org>
parents:
541
diff
changeset
|
402 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
|
403 """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
|
404 |
662
ebb602d8b3f2
browser_side: replace all instances of 'str' with 'unicode'
souliane <souliane@mailoo.org>
parents:
624
diff
changeset
|
405 @param state (unicode): message state |
ebb602d8b3f2
browser_side: replace all instances of 'str' with 'unicode'
souliane <souliane@mailoo.org>
parents:
624
diff
changeset
|
406 @param trust (unicode): trust |
ebb602d8b3f2
browser_side: replace all instances of 'str' with 'unicode'
souliane <souliane@mailoo.org>
parents:
624
diff
changeset
|
407 @return: unicode |
559
77372641e05d
browser_side (plugin OTR): display the correct icons on opening the window + auto-open on accepted invitation
souliane <souliane@mailoo.org>
parents:
557
diff
changeset
|
408 """ |
543
d02335553b5d
browser_side (plugin OTR): display OTR states with icons instead of a text
souliane <souliane@mailoo.org>
parents:
541
diff
changeset
|
409 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
|
410 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
|
411 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
|
412 |
663
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
413 def getInfoTextForUser(self, other_jid): |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
414 """Get the current info text for a conversation. |
559
77372641e05d
browser_side (plugin OTR): display the correct icons on opening the window + auto-open on accepted invitation
souliane <souliane@mailoo.org>
parents:
557
diff
changeset
|
415 |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
584
diff
changeset
|
416 @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
|
417 """ |
663
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
418 otrctx = self.context_manager.getContextForUser(other_jid, start=False) |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
419 if otrctx is None: |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
420 return OTR.getInfoText() |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
421 else: |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
422 return OTR.getInfoText(otrctx.state, otrctx.getCurrentTrust()) |
559
77372641e05d
browser_side (plugin OTR): display the correct icons on opening the window + auto-open on accepted invitation
souliane <souliane@mailoo.org>
parents:
557
diff
changeset
|
423 |
678
2e087e093e7f
browser side(otr): restored menu hooks using new hook system
Goffi <goffi@goffi.org>
parents:
676
diff
changeset
|
424 def gotMenusListener(self,): |
2e087e093e7f
browser side(otr): restored menu hooks using new hook system
Goffi <goffi@goffi.org>
parents:
676
diff
changeset
|
425 # TODO: get menus paths to hook directly from backend's OTR plugin |
2e087e093e7f
browser side(otr): restored menu hooks using new hook system
Goffi <goffi@goffi.org>
parents:
676
diff
changeset
|
426 self.host.menus.addMenuHook(C.MENU_SINGLE, (MAIN_MENU, D_(u"Start/Refresh")), callback=self._startRefresh) |
2e087e093e7f
browser side(otr): restored menu hooks using new hook system
Goffi <goffi@goffi.org>
parents:
676
diff
changeset
|
427 self.host.menus.addMenuHook(C.MENU_SINGLE, (MAIN_MENU, D_(u"End session")), callback=self._endSession) |
2e087e093e7f
browser side(otr): restored menu hooks using new hook system
Goffi <goffi@goffi.org>
parents:
676
diff
changeset
|
428 self.host.menus.addMenuHook(C.MENU_SINGLE, (MAIN_MENU, D_(u"Authenticate")), callback=self._authenticate) |
2e087e093e7f
browser side(otr): restored menu hooks using new hook system
Goffi <goffi@goffi.org>
parents:
676
diff
changeset
|
429 self.host.menus.addMenuHook(C.MENU_SINGLE, (MAIN_MENU, D_(u"Drop private key")), callback=self._dropPrivkey) |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
430 |
665
6a8a1103ad10
browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents:
664
diff
changeset
|
431 def profilePluggedListener(self, profile): |
6a8a1103ad10
browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents:
664
diff
changeset
|
432 # FIXME: workaround for a pyjamas issue: calling hash on a class method always return a different value if that method is defined directly within the class (with the "def" keyword) |
6a8a1103ad10
browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents:
664
diff
changeset
|
433 self._presenceListener = self.presenceListener |
6a8a1103ad10
browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents:
664
diff
changeset
|
434 self._disconnectListener = self.disconnectListener |
6a8a1103ad10
browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents:
664
diff
changeset
|
435 self.host.addListener('presence', self._presenceListener, [C.PROF_KEY_NONE]) |
6a8a1103ad10
browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents:
664
diff
changeset
|
436 # FIXME: this listener is never removed, can't be removed by itself (it modifies the list while looping), maybe need a 'one_shot' argument |
6a8a1103ad10
browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents:
664
diff
changeset
|
437 self.host.addListener('disconnect', self._disconnectListener, [C.PROF_KEY_NONE]) |
6a8a1103ad10
browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents:
664
diff
changeset
|
438 |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
439 self.host.bridge.call('skipOTR', None) |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
440 self.context_manager = ContextManager(self.host) |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
441 # 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
|
442 # 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
|
443 # assign it to self.context_manager.account.privkey |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
444 |
665
6a8a1103ad10
browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents:
664
diff
changeset
|
445 def disconnectListener(self, profile): |
6a8a1103ad10
browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents:
664
diff
changeset
|
446 """Things to do just before the profile disconnection""" |
6a8a1103ad10
browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents:
664
diff
changeset
|
447 self.host.removeListener('presence', self._presenceListener) |
663
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
448 |
529
9bfd71e2b35c
plugin OTR: disconnect the active OTR sessions on profile disconnection
souliane <souliane@mailoo.org>
parents:
528
diff
changeset
|
449 for context in self.context_manager.contexts.values(): |
665
6a8a1103ad10
browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents:
664
diff
changeset
|
450 context.disconnect() # FIXME: no time to send the message before the profile has been disconnected |
6a8a1103ad10
browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents:
664
diff
changeset
|
451 |
6a8a1103ad10
browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents:
664
diff
changeset
|
452 def presenceListener(self, entity, show, priority, statuses, profile): |
6a8a1103ad10
browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents:
664
diff
changeset
|
453 if show == C.PRESENCE_UNAVAILABLE: |
6a8a1103ad10
browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents:
664
diff
changeset
|
454 self.endSession(entity, disconnect=False) |
529
9bfd71e2b35c
plugin OTR: disconnect the active OTR sessions on profile disconnection
souliane <souliane@mailoo.org>
parents:
528
diff
changeset
|
455 |
663
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
456 def newMessageTg(self, from_jid, msg, msg_type, to_jid, extra, profile): |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
457 if msg_type != C.MESS_TYPE_CHAT: |
533
19fc2ebc02dd
browser_side: management of new "info" newMessage type
Goffi <goffi@goffi.org>
parents:
531
diff
changeset
|
458 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
|
459 |
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
|
460 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
|
461 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
|
462 return True |
19b8af73e945
browser_side (plugin OTR): ask the user before accepting an OTR query
souliane <souliane@mailoo.org>
parents:
538
diff
changeset
|
463 |
663
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
464 other_jid = to_jid if from_jid.bare == self.host.whoami.bare else from_jid |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
465 otrctx = self.context_manager.getContextForUser(other_jid, start=False) |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
466 if otrctx is None: |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
467 def confirm(confirm): |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
468 if confirm: |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
469 self.host.displayWidget(chat.Chat, other_jid) |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
470 self.context_manager.startContext(other_jid).receiveMessage(msg) |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
471 else: |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
472 # FIXME: plain text messages with whitespaces would be lost here when WHITESPACE_START_AKE is True |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
473 pass |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
474 key = self.context_manager.account.privkey |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
475 question = QUERY_RECEIVED + QUERY_SLOWDOWN + (QUERY_KEY if key else QUERY_NO_KEY) + QUERY_CONFIRM |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
476 dialog.ConfirmDialog(confirm, question.format(jid=other_jid, eol=DIALOG_EOL), QUERY_TITLE, AddStyleName="maxWidthLimit").show() |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
477 else: # do not ask for user confirmation if the context exist |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
478 otrctx.receiveMessage(msg) |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
479 |
539
19b8af73e945
browser_side (plugin OTR): ask the user before accepting an OTR query
souliane <souliane@mailoo.org>
parents:
538
diff
changeset
|
480 return False # interrupt the main process |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
481 |
663
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
482 def sendMessageTg(self, to_jid, message, subject, mess_type, extra, callback, errback, profile_key): |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
483 if mess_type != C.MESS_TYPE_CHAT: |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
484 return True |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
485 |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
486 otrctx = self.context_manager.getContextForUser(to_jid, start=False) |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
487 if otrctx is not None and otrctx.state != otr.context.STATE_PLAINTEXT: |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
488 if otrctx.state == otr.context.STATE_ENCRYPTED: |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
489 log.debug(u"encrypting message") |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
490 otrctx.sendMessage(message) |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
491 self.host.newMessageHandler(unicode(self.host.whoami), message, mess_type, unicode(to_jid), extra) |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
492 else: |
663
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
493 feedback = SEND_PLAIN_IN_FINISHED_CONTEXT |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
494 dialog.InfoDialog(FINISHED_CONTEXT_TITLE.format(jid=to_jid), feedback, AddStyleName="maxWidthLimit").show() |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
495 return False # interrupt the main process |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
496 |
663
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
497 log.debug(u"sending message unencrypted") |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
498 return True |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
499 |
665
6a8a1103ad10
browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents:
664
diff
changeset
|
500 def endSession(self, other_jid, disconnect=True): |
530
1735aaeac652
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
529
diff
changeset
|
501 """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
|
502 |
663
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
503 @param other_jid (jid.JID): other JID |
665
6a8a1103ad10
browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents:
664
diff
changeset
|
504 @param disconnect (bool): if False, finish the session but do not disconnect it |
530
1735aaeac652
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
529
diff
changeset
|
505 """ |
663
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
506 # checking for private key existence is not needed, context checking is enough |
665
6a8a1103ad10
browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents:
664
diff
changeset
|
507 if other_jid.resource: |
6a8a1103ad10
browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents:
664
diff
changeset
|
508 contexts = [self.context_manager.getContextForUser(other_jid, start=False)] |
6a8a1103ad10
browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents:
664
diff
changeset
|
509 else: # contact disconnected itself so we need to terminate the OTR session but the Chat panel lost its resource |
6a8a1103ad10
browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents:
664
diff
changeset
|
510 contexts = self.context_manager.getContextsForBareUser(other_jid) |
6a8a1103ad10
browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents:
664
diff
changeset
|
511 for otrctx in contexts: |
6a8a1103ad10
browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents:
664
diff
changeset
|
512 if otrctx is None or otrctx.state == otr.context.STATE_PLAINTEXT: |
6a8a1103ad10
browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents:
664
diff
changeset
|
513 if disconnect: |
6a8a1103ad10
browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents:
664
diff
changeset
|
514 self.host.newMessageHandler(unicode(other_jid), END_PLAIN_HAS_NOT.format(jid=other_jid), C.MESS_TYPE_INFO, unicode(self.host.whoami), {}) |
6a8a1103ad10
browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents:
664
diff
changeset
|
515 return |
6a8a1103ad10
browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents:
664
diff
changeset
|
516 if disconnect: |
6a8a1103ad10
browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents:
664
diff
changeset
|
517 otrctx.disconnect() |
6a8a1103ad10
browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents:
664
diff
changeset
|
518 else: |
6a8a1103ad10
browser_side: OTR uses 'profilePlugged', 'disconnect' and 'gotMenus' listeners
souliane <souliane@mailoo.org>
parents:
664
diff
changeset
|
519 otrctx.finish() |
530
1735aaeac652
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
529
diff
changeset
|
520 |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
521 # Menu callbacks |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
522 |
678
2e087e093e7f
browser side(otr): restored menu hooks using new hook system
Goffi <goffi@goffi.org>
parents:
676
diff
changeset
|
523 def _startRefresh(self, caller, menu_data, profile): |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
524 """Start or refresh an OTR session |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
525 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
526 @param menu_data: %(menu_data)s |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
527 """ |
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
|
528 def query(other_jid): |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
529 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
|
530 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
|
531 otrctx.sendQueryMessage() |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
532 |
678
2e087e093e7f
browser side(otr): restored menu hooks using new hook system
Goffi <goffi@goffi.org>
parents:
676
diff
changeset
|
533 other_jid = jid.JID(menu_data['jid']) |
663
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
534 clist = self.host.contact_list |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
535 if clist.getCache(other_jid.bare, C.PRESENCE_SHOW) is None: |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
536 dialog.InfoDialog(ACTION_NA_TITLE, ACTION_NA, AddStyleName="maxWidthLimit").show() |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
537 return |
541
e903a9f79172
browser_side (plugin OTR): also ask for a confirmation if the user has no private key and initiates an OTR session
souliane <souliane@mailoo.org>
parents:
540
diff
changeset
|
538 |
663
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
539 key = self.context_manager.account.privkey |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
540 if key is None: |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
541 def confirm(confirm): |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
542 if confirm: |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
543 query(other_jid) |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
544 msg = QUERY_SEND + QUERY_SLOWDOWN + QUERY_NO_KEY + QUERY_CONFIRM |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
545 dialog.ConfirmDialog(confirm, msg.format(jid=other_jid, eol=DIALOG_EOL), QUERY_TITLE, AddStyleName="maxWidthLimit").show() |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
546 else: # on query reception we ask always, if we initiate we just ask the first time |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
547 query(other_jid) |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
548 |
678
2e087e093e7f
browser side(otr): restored menu hooks using new hook system
Goffi <goffi@goffi.org>
parents:
676
diff
changeset
|
549 def _endSession(self, caller, menu_data, profile): |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
550 """End an OTR session |
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 @param menu_data: %(menu_data)s |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
553 """ |
678
2e087e093e7f
browser side(otr): restored menu hooks using new hook system
Goffi <goffi@goffi.org>
parents:
676
diff
changeset
|
554 self.endSession(jid.JID(menu_data['jid'])) |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
555 |
678
2e087e093e7f
browser side(otr): restored menu hooks using new hook system
Goffi <goffi@goffi.org>
parents:
676
diff
changeset
|
556 def _authenticate(self, caller, menu_data, profile): |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
557 """Authenticate other user and see our own fingerprint |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
558 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
559 @param menu_data: %(menu_data)s |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
560 @param profile: %(doc_profile)s |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
561 """ |
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
|
562 def not_available(): |
538
3317e5d0ac1d
browser_side (plugin OTR): put all the text messages into constants
souliane <souliane@mailoo.org>
parents:
537
diff
changeset
|
563 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
|
564 |
678
2e087e093e7f
browser side(otr): restored menu hooks using new hook system
Goffi <goffi@goffi.org>
parents:
676
diff
changeset
|
565 to_jid = jid.JID(menu_data['jid']) |
663
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
566 |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
567 # checking for private key existence is not needed, context checking is enough |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
568 otrctx = self.context_manager.getContextForUser(to_jid, start=False) |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
569 if otrctx is None or otrctx.state != otr.context.STATE_ENCRYPTED: |
525
307f84fee972
browser_side (plugin OTR): avoid unecessary waiting time on menu callbacks when the private key or the context doesn't exist
souliane <souliane@mailoo.org>
parents:
524
diff
changeset
|
570 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
|
571 return |
663
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
572 otr_version = otrctx.getUsedVersion() |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
573 if otr_version == otr.context.OTR_VERSION_2: |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
574 otrctx.fingerprintAuthCb() |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
575 elif otr_version == otr.context.OTR_VERSION_3: |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
576 otrctx.smpAuthCb('question', None, 'asked') |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
577 else: |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
578 not_available() |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
579 |
678
2e087e093e7f
browser side(otr): restored menu hooks using new hook system
Goffi <goffi@goffi.org>
parents:
676
diff
changeset
|
580 def _dropPrivkey(self, caller, menu_data, profile): |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
581 """Drop our private Key |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
582 |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
583 @param menu_data: %(menu_data)s |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
584 @param profile: %(doc_profile)s |
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
585 """ |
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
|
586 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
|
587 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
|
588 # 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
|
589 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
|
590 return |
522
0de69fec24e9
browser and server sides: OTR plugin, first draft
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
591 |
663
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
592 def dropKey(confirm): |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
593 if confirm: |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
594 # we end all sessions |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
595 for context in self.context_manager.contexts.values(): |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
596 context.disconnect() |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
597 self.context_manager.contexts.clear() |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
598 self.context_manager.account.privkey = None |
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
599 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
|
600 |
663
423182fea41c
browser_side: fixes OTR using the new resource system and proper triggers (send and receive message) or listener (presence update)
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
601 dialog.ConfirmDialog(dropKey, KEY_DROP_TXT.format(eol=DIALOG_EOL), KEY_DROP_TITLE, AddStyleName="maxWidthLimit").show() |