2013-04-13 20:33:06 +00:00
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
This plugin implements `Off The Record messaging`_.
|
|
|
|
|
|
2015-07-20 18:26:23 +00:00
|
|
|
|
This is a plugin used to encrypt a one-to-one conversation using the OTR
|
2013-04-13 20:33:06 +00:00
|
|
|
|
encryption method. You can use it if you want good privacy, deniability,
|
2013-08-07 18:55:21 +00:00
|
|
|
|
authentication, and strong secrecy. Without this encryption, your messages
|
|
|
|
|
are encrypted **at least** from your client (poezio) to your server. The
|
|
|
|
|
message is decrypted by your server and you cannot control the encryption
|
|
|
|
|
method of your messages from your server to your contact’s server (unless
|
|
|
|
|
you are your own server’s administrator), nor from your contact’s server
|
|
|
|
|
to your contact’s client.
|
2013-04-13 20:33:06 +00:00
|
|
|
|
|
|
|
|
|
This plugin does end-to-end encryption. This means that **only** your contact can
|
|
|
|
|
decrypt your messages, and it is fully encrypted during **all** its travel
|
|
|
|
|
through the internet.
|
|
|
|
|
|
|
|
|
|
Note that if you are having an encrypted conversation with a contact, you can
|
2015-07-20 18:26:23 +00:00
|
|
|
|
**not** send XHTML-IM messages to them (or correct messages, or anything more than
|
|
|
|
|
raw text). All formatting will be removed and be replaced by plain text messages.
|
2013-08-07 18:55:21 +00:00
|
|
|
|
|
|
|
|
|
This is a limitation of the OTR protocol, and it will never be fixed. Some clients
|
|
|
|
|
like Pidgin-OTR try do do magic stuff with html unescaping inside the OTR body, and
|
|
|
|
|
it is not pretty.
|
2013-04-13 20:33:06 +00:00
|
|
|
|
|
2013-08-04 13:30:03 +00:00
|
|
|
|
Installation
|
|
|
|
|
------------
|
2013-04-13 20:33:06 +00:00
|
|
|
|
|
2014-06-14 20:01:25 +00:00
|
|
|
|
To use the OTR plugin, you must first install pure-python-otr and pycrypto
|
|
|
|
|
(for python3).
|
2013-04-13 20:33:06 +00:00
|
|
|
|
|
2013-08-04 13:30:03 +00:00
|
|
|
|
You have to install it from the git because a few issues were
|
|
|
|
|
found with the python3 compatibility while writing this plugin,
|
|
|
|
|
and the fixes did not make it into a stable release yet.
|
2013-04-13 20:33:06 +00:00
|
|
|
|
|
2013-08-04 13:30:03 +00:00
|
|
|
|
Install the python module:
|
2013-04-13 20:33:06 +00:00
|
|
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
|
2013-08-04 13:30:03 +00:00
|
|
|
|
git clone https://github.com/afflux/pure-python-otr.git
|
|
|
|
|
cd pure-python-otr
|
|
|
|
|
python3 setup.py install --user
|
2013-04-13 20:33:06 +00:00
|
|
|
|
|
2014-09-26 11:54:50 +00:00
|
|
|
|
You can also use pip in a virtualenv (built-in as pyvenv_ with python since 3.3)
|
|
|
|
|
with the requirements.txt at the root of the poezio directory.
|
2013-04-13 20:33:06 +00:00
|
|
|
|
|
2018-08-12 10:59:40 +00:00
|
|
|
|
Important details
|
|
|
|
|
-----------------
|
|
|
|
|
|
|
|
|
|
The OTR session is considered for a full JID (e.g. toto@example/**client1**),
|
|
|
|
|
but the trust is set with a bare JID (e.g. toto@example). This is important
|
|
|
|
|
in the case of Private Chats (in a chatroom), since you cannot always get the
|
|
|
|
|
real JID of your contact (or check if the same nick is used by different people).
|
|
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
|
|
This also means that you cannot have an OTR session in the "common"
|
|
|
|
|
conversation tab, which is not locked to a specific JID. After activating
|
|
|
|
|
the plugin, you need to open a session with a full JID to be able to use
|
|
|
|
|
OTR.
|
2013-04-13 20:33:06 +00:00
|
|
|
|
|
2013-08-04 13:30:03 +00:00
|
|
|
|
Usage
|
|
|
|
|
-----
|
2013-04-13 20:33:06 +00:00
|
|
|
|
|
2018-08-12 10:59:40 +00:00
|
|
|
|
Command added to Static Conversation Tabs (opened with ``/message foo@bar/baz`` or
|
|
|
|
|
by expanding a contact in the roster) and Private Tabs:
|
2013-04-13 20:33:06 +00:00
|
|
|
|
|
2013-08-04 13:30:03 +00:00
|
|
|
|
.. glossary::
|
2013-04-13 20:33:06 +00:00
|
|
|
|
|
2013-08-04 13:30:03 +00:00
|
|
|
|
/otr
|
2013-08-07 18:55:21 +00:00
|
|
|
|
**Usage:** ``/otr [start|refresh|end|fpr|ourfpr|trust|untrust]``
|
2013-04-13 20:33:06 +00:00
|
|
|
|
|
2013-08-07 18:55:21 +00:00
|
|
|
|
This command is used to manage an OTR private session.
|
2013-04-13 20:33:06 +00:00
|
|
|
|
|
2013-08-07 18:55:21 +00:00
|
|
|
|
- The ``start`` (or ``refresh``) command starts or refreshs a private OTR session
|
|
|
|
|
- The ``end`` command ends a private OTR session
|
2014-02-18 23:39:51 +00:00
|
|
|
|
- The ``fpr`` command gives you the fingerprint of the key of the remote entity
|
2013-08-07 18:55:21 +00:00
|
|
|
|
- The ``ourfpr`` command gives you the fingerprint of your own key
|
|
|
|
|
- The ``trust`` command marks the current remote key as trusted for the current remote JID
|
|
|
|
|
- The ``untrust`` command removes that trust
|
2014-01-29 15:41:57 +00:00
|
|
|
|
- Finally, the ``drop`` command is used if you want to delete your private key (not recoverable).
|
|
|
|
|
|
|
|
|
|
.. warning::
|
|
|
|
|
|
2014-05-18 13:11:32 +00:00
|
|
|
|
With ``drop``, the private key is only removed from the filesystem,
|
|
|
|
|
*NOT* with multiple rewrites in a secure manner, you should do that
|
|
|
|
|
yourself if you want to be sure.
|
2013-04-13 20:33:06 +00:00
|
|
|
|
|
2014-12-30 21:00:02 +00:00
|
|
|
|
/otrsmp
|
|
|
|
|
**Usage:** ``/otrsmp <ask|answer|abort> [question] [secret]``
|
|
|
|
|
|
|
|
|
|
Verify the identify of your contact by using a pre-defined secret.
|
|
|
|
|
|
|
|
|
|
- The ``abort`` command aborts an ongoing verification
|
|
|
|
|
- The ``ask`` command start a verification, with a question or not
|
2015-01-11 12:50:45 +00:00
|
|
|
|
- The ``answer`` command sends back the answer and finishes the verification
|
2013-04-13 20:33:06 +00:00
|
|
|
|
|
2015-01-11 12:50:45 +00:00
|
|
|
|
Managing trust
|
|
|
|
|
--------------
|
2013-04-13 20:33:06 +00:00
|
|
|
|
|
2015-01-11 12:50:45 +00:00
|
|
|
|
An OTR conversation can be started with a simple ``/otr start`` and the
|
|
|
|
|
conversation will be encrypted. However it is very often useful to check
|
|
|
|
|
that your are talking to the right person.
|
2013-04-13 20:33:06 +00:00
|
|
|
|
|
2015-01-11 12:50:45 +00:00
|
|
|
|
To this end, two actions are available, and a message explaining both
|
|
|
|
|
will be prompted each time an **untrusted** conversation is started:
|
2013-04-13 20:33:06 +00:00
|
|
|
|
|
2015-01-11 12:50:45 +00:00
|
|
|
|
- Checking the knowledge of a shared secret through the use of :term:`/otrsmp`
|
|
|
|
|
- Exchanging fingerprints (``/otr fpr`` and ``/otr ourfpr``) out of band (in a secure channel) to check that both match,
|
|
|
|
|
then use ``/otr trust`` to add then to the list of trusted fingerprints for this JID.
|
2013-04-13 20:33:06 +00:00
|
|
|
|
|
2013-08-07 18:55:21 +00:00
|
|
|
|
Files
|
|
|
|
|
-----
|
|
|
|
|
|
|
|
|
|
This plugin creates trust files complatible with libotr and the files produced by gajim.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The files are located in :file:`$XDG_DATA_HOME/poezio/otr/` by default (so
|
|
|
|
|
:file:`~/.local/share/poezio/otr` in most cases).
|
|
|
|
|
|
|
|
|
|
Two files are created:
|
|
|
|
|
|
|
|
|
|
- An account_jid.key3 (:file:`example@example.com.key3`) file, which contains the private key
|
|
|
|
|
- An account_jid.fpr (:file:`example@example.com.fpr`) file, which contains the list of trusted
|
|
|
|
|
(or untrusted) JIDs and keys.
|
|
|
|
|
|
|
|
|
|
Configuration
|
|
|
|
|
-------------
|
|
|
|
|
|
|
|
|
|
.. glossary::
|
|
|
|
|
:sorted:
|
|
|
|
|
|
2014-04-29 23:55:23 +00:00
|
|
|
|
decode_xhtml
|
|
|
|
|
**Default:** ``true``
|
|
|
|
|
|
|
|
|
|
Decode embedded XHTML.
|
|
|
|
|
|
2014-12-08 19:06:11 +00:00
|
|
|
|
decode_entities
|
2014-12-16 19:46:45 +00:00
|
|
|
|
**Default:** ``true``
|
2014-12-08 19:06:11 +00:00
|
|
|
|
|
|
|
|
|
Decode XML and HTML entities (like ``&``) even when the
|
|
|
|
|
document isn't valid (if it is valid, it will be decoded even
|
|
|
|
|
without this option).
|
|
|
|
|
|
2014-12-16 19:46:45 +00:00
|
|
|
|
decode_newlines
|
|
|
|
|
**Default:** ``true``
|
|
|
|
|
|
|
|
|
|
Decode ``<br/>`` and ``<br>`` tags even when the document
|
|
|
|
|
isn't valid (if it is valid, it will be decoded even
|
|
|
|
|
without this option for ``<br/>``, and ``<br>`` will make
|
|
|
|
|
the document invalid anyway).
|
|
|
|
|
|
2013-08-07 18:55:21 +00:00
|
|
|
|
keys_dir
|
|
|
|
|
**Default:** ``$XDG_DATA_HOME/poezio/otr``
|
|
|
|
|
|
|
|
|
|
The directory in which you want keys and fpr to be stored.
|
|
|
|
|
|
2015-01-03 15:23:34 +00:00
|
|
|
|
require_encryption
|
2013-08-07 18:55:21 +00:00
|
|
|
|
**Default:** ``false``
|
|
|
|
|
|
2015-01-03 15:23:34 +00:00
|
|
|
|
If ``true``, prevents you from sending unencrypted messages, and tries
|
|
|
|
|
to establish OTR sessions when receiving unencrypted messages.
|
2013-08-07 18:55:21 +00:00
|
|
|
|
|
2014-10-12 20:08:28 +00:00
|
|
|
|
timeout
|
|
|
|
|
**Default:** ``3``
|
|
|
|
|
|
|
|
|
|
The number of seconds poezio will wait until notifying you
|
|
|
|
|
that the OTR session was not established. A negative or null
|
|
|
|
|
value will disable this notification.
|
|
|
|
|
|
2014-01-29 15:41:57 +00:00
|
|
|
|
log
|
2015-01-03 15:23:34 +00:00
|
|
|
|
**Default:** ``false``
|
2014-01-29 15:41:57 +00:00
|
|
|
|
|
|
|
|
|
Log conversations (OTR start/end marker, and messages).
|
|
|
|
|
|
2015-01-03 15:23:34 +00:00
|
|
|
|
The :term:`require_encryption`, :term:`decode_xhtml`, :term:`decode_entities`
|
2014-04-29 23:55:23 +00:00
|
|
|
|
and :term:`log` configuration parameters are tab-specific.
|
2013-04-13 20:33:06 +00:00
|
|
|
|
|
2013-08-04 13:30:03 +00:00
|
|
|
|
.. _Off The Record messaging: http://wiki.xmpp.org/web/OTR
|
2014-09-26 11:54:50 +00:00
|
|
|
|
.. _pyvenv: https://docs.python.org/3/using/scripts.html#pyvenv-creating-virtual-environments
|
2012-03-25 21:40:22 +00:00
|
|
|
|
|
2013-08-04 13:30:03 +00:00
|
|
|
|
"""
|
2014-09-26 11:54:50 +00:00
|
|
|
|
|
2014-05-18 13:11:32 +00:00
|
|
|
|
from gettext import gettext as _
|
2012-03-25 21:40:22 +00:00
|
|
|
|
import logging
|
2013-08-04 13:30:03 +00:00
|
|
|
|
|
2012-03-25 21:40:22 +00:00
|
|
|
|
log = logging.getLogger(__name__)
|
2013-08-04 13:30:03 +00:00
|
|
|
|
import os
|
2014-12-08 19:06:11 +00:00
|
|
|
|
import html
|
2013-08-04 21:45:12 +00:00
|
|
|
|
import curses
|
2018-08-08 22:45:10 +00:00
|
|
|
|
from pathlib import Path
|
2013-08-04 21:45:12 +00:00
|
|
|
|
|
2018-08-08 22:45:10 +00:00
|
|
|
|
import potr
|
2013-08-07 18:55:21 +00:00
|
|
|
|
from potr.context import NotEncryptedError, UnencryptedMessage, ErrorReceived, NotOTRMessage,\
|
|
|
|
|
STATE_ENCRYPTED, STATE_PLAINTEXT, STATE_FINISHED, Context, Account, crypt
|
2012-03-25 21:40:22 +00:00
|
|
|
|
|
2016-06-27 23:10:52 +00:00
|
|
|
|
from poezio import common
|
2018-07-04 10:53:02 +00:00
|
|
|
|
from poezio import xdg
|
2018-08-12 10:59:40 +00:00
|
|
|
|
from poezio import xhtml
|
2016-06-27 23:10:52 +00:00
|
|
|
|
from poezio.common import safeJID
|
|
|
|
|
from poezio.config import config
|
|
|
|
|
from poezio.plugin import BasePlugin
|
2018-08-12 10:59:40 +00:00
|
|
|
|
from poezio.roster import roster
|
|
|
|
|
from poezio.tabs import StaticConversationTab, PrivateTab
|
2016-06-27 23:10:52 +00:00
|
|
|
|
from poezio.theming import get_theme, dump_tuple
|
|
|
|
|
from poezio.decorators import command_args_parser
|
2016-08-21 13:27:53 +00:00
|
|
|
|
from poezio.core.structs import Completion
|
2013-08-04 13:30:03 +00:00
|
|
|
|
|
|
|
|
|
POLICY_FLAGS = {
|
2018-08-15 11:13:17 +00:00
|
|
|
|
'ALLOW_V1': False,
|
|
|
|
|
'ALLOW_V2': True,
|
2015-01-03 15:23:34 +00:00
|
|
|
|
'REQUIRE_ENCRYPTION': False,
|
|
|
|
|
'SEND_TAG': True,
|
|
|
|
|
'WHITESPACE_START_AKE': True,
|
|
|
|
|
'ERROR_START_AKE': True
|
2013-08-04 13:30:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
2018-08-15 11:13:17 +00:00
|
|
|
|
OTR_TUTORIAL = _("""%(info)sThis contact has not yet been verified.
|
2014-12-30 21:00:02 +00:00
|
|
|
|
You have several methods of authentication available:
|
|
|
|
|
|
|
|
|
|
1) Verify each other's fingerprints using a secure (and different) channel:
|
|
|
|
|
Your fingerprint: %(normal)s%(our_fpr)s%(info)s
|
|
|
|
|
%(jid_c)s%(jid)s%(info)s's fingerprint: %(normal)s%(remote_fpr)s%(info)s
|
|
|
|
|
Then use the command: /otr trust
|
|
|
|
|
|
|
|
|
|
2) SMP pre-shared secret you both know:
|
|
|
|
|
/otrsmp ask <secret>
|
|
|
|
|
|
|
|
|
|
3) SMP pre-shared secret you both know with a question:
|
|
|
|
|
/otrsmp ask <question> <secret>
|
|
|
|
|
""")
|
|
|
|
|
|
2015-01-03 15:23:34 +00:00
|
|
|
|
OTR_NOT_ENABLED = _('%(jid_c)s%(jid)s%(info)s did not enable '
|
2015-01-03 16:33:59 +00:00
|
|
|
|
'OTR after %(secs)s seconds.')
|
2015-01-03 15:23:34 +00:00
|
|
|
|
|
|
|
|
|
MESSAGE_NOT_SENT = _('%(info)sYour message to %(jid_c)s%(jid)s%(info)s was'
|
|
|
|
|
' not sent because your configuration requires an '
|
|
|
|
|
'encrypted session.\nWait until it is established or '
|
|
|
|
|
'change your configuration.')
|
|
|
|
|
|
2018-08-12 10:59:40 +00:00
|
|
|
|
INCOMPATIBLE_TAB = _('%(info)sYour message to %(jid_c)s%(jid)s%(info)s was'
|
|
|
|
|
' not sent because your configuration requires an '
|
|
|
|
|
'encrypted session and the current tab is a bare-jid '
|
|
|
|
|
'one, with which you cannot open or use an OTR session.'
|
|
|
|
|
' You need to open a fulljid tab with /message if you '
|
|
|
|
|
'want to use OTR.%(help)s')
|
|
|
|
|
|
|
|
|
|
TAB_HELP_RESOURCE = _('\nChoose the relevant one among the following:%s')
|
|
|
|
|
|
2015-01-03 15:23:34 +00:00
|
|
|
|
OTR_REQUEST = _('%(info)sOTR request to %(jid_c)s%(jid)s%(info)s sent.')
|
|
|
|
|
|
|
|
|
|
OTR_OWN_FPR = _('%(info)sYour OTR key fingerprint is '
|
|
|
|
|
'%(normal)s%(fpr)s%(info)s.')
|
|
|
|
|
|
|
|
|
|
OTR_REMOTE_FPR = _('%(info)sThe key fingerprint for %(jid_c)s'
|
|
|
|
|
'%(jid)s%(info)s is %(normal)s%(fpr)s%(info)s.')
|
|
|
|
|
|
2018-08-15 11:13:17 +00:00
|
|
|
|
OTR_NO_FPR = _('%(jid_c)s%(jid)s%(info)s has no' ' key currently in use.')
|
2015-01-03 15:23:34 +00:00
|
|
|
|
|
|
|
|
|
OTR_START_TRUSTED = _('%(info)sStarted a \x19btrusted\x19o%(info)s '
|
|
|
|
|
'OTR conversation with %(jid_c)s%(jid)s')
|
|
|
|
|
|
|
|
|
|
OTR_REFRESH_TRUSTED = _('%(info)sRefreshed \x19btrusted\x19o%(info)s'
|
|
|
|
|
' OTR conversation with %(jid_c)s%(jid)s')
|
|
|
|
|
|
|
|
|
|
OTR_START_UNTRUSTED = _('%(info)sStarted an \x19buntrusted\x19o%(info)s'
|
|
|
|
|
' OTR conversation with %(jid_c)s%(jid)s')
|
|
|
|
|
|
|
|
|
|
OTR_REFRESH_UNTRUSTED = _('%(info)sRefreshed \x19buntrusted\x19o%(info)s'
|
|
|
|
|
' OTR conversation with %(jid_c)s%(jid)s')
|
|
|
|
|
|
|
|
|
|
OTR_END = _('%(info)sEnded OTR conversation with %(jid_c)s%(jid)s')
|
|
|
|
|
|
|
|
|
|
SMP_REQUESTED = _('%(jid_c)s%(jid)s%(info)s has requested SMP verification'
|
|
|
|
|
'%(q)s%(info)s.\nAnswer with: /otrsmp answer <secret>')
|
|
|
|
|
|
|
|
|
|
SMP_INITIATED = _('%(info)sInitiated SMP request with '
|
|
|
|
|
'%(jid_c)s%(jid)s%(info)s.')
|
|
|
|
|
|
|
|
|
|
SMP_PROGRESS = _('%(info)sSMP progressing.')
|
|
|
|
|
|
|
|
|
|
SMP_RECIPROCATE = _('%(info)sYou may want to authenticate your peer by asking'
|
|
|
|
|
' your own question: /otrsmp ask [question] <secret>')
|
|
|
|
|
|
|
|
|
|
SMP_SUCCESS = _('%(info)sSMP Verification \x19bsucceeded\x19o%(info)s.')
|
|
|
|
|
|
|
|
|
|
SMP_FAIL = _('%(info)sSMP Verification \x19bfailed\x19o%(info)s.')
|
|
|
|
|
|
|
|
|
|
SMP_ABORTED_PEER = _('%(info)sSMP aborted by peer.')
|
|
|
|
|
|
|
|
|
|
SMP_ABORTED = _('%(info)sSMP aborted.')
|
|
|
|
|
|
|
|
|
|
MESSAGE_UNENCRYPTED = _('%(info)sThe following message from %(jid_c)s%(jid)s'
|
|
|
|
|
'%(info)s was \x19bnot\x19o%(info)s encrypted:\x19o\n'
|
|
|
|
|
'%(msg)s')
|
|
|
|
|
|
|
|
|
|
MESSAGE_UNREADABLE = _('%(info)sAn encrypted message from %(jid_c)s%(jid)s'
|
|
|
|
|
'%(info)s was received but is unreadable, as you are'
|
|
|
|
|
' not currently communicating privately.')
|
|
|
|
|
|
|
|
|
|
MESSAGE_INVALID = _('%(info)sThe message from %(jid_c)s%(jid)s%(info)s'
|
|
|
|
|
' could not be decrypted.')
|
|
|
|
|
|
|
|
|
|
OTR_ERROR = _('%(info)sReceived the following error from '
|
|
|
|
|
'%(jid_c)s%(jid)s%(info)s:\x19o %(err)s')
|
|
|
|
|
|
2019-03-09 14:36:32 +00:00
|
|
|
|
POTR_ERROR = _('%(info)sAn unspecified error in the OTR plugin occurred:\n'
|
2015-01-03 15:23:34 +00:00
|
|
|
|
'%(exc)s')
|
|
|
|
|
|
|
|
|
|
TRUST_ADDED = _('%(info)sYou added %(jid_c)s%(bare_jid)s%(info)s with key '
|
|
|
|
|
'\x19o%(key)s%(info)s to your trusted list.')
|
|
|
|
|
|
|
|
|
|
TRUST_REMOVED = _('%(info)sYou removed %(jid_c)s%(bare_jid)s%(info)s with '
|
|
|
|
|
'key \x19o%(key)s%(info)s from your trusted list.')
|
|
|
|
|
|
|
|
|
|
KEY_DROPPED = _('%(info)sPrivate key dropped.')
|
|
|
|
|
|
2018-08-12 10:59:40 +00:00
|
|
|
|
|
2013-08-04 21:45:12 +00:00
|
|
|
|
def hl(tab):
|
2015-01-03 15:23:34 +00:00
|
|
|
|
"""
|
|
|
|
|
Make a tab beep and change its status.
|
|
|
|
|
"""
|
2013-08-04 21:45:12 +00:00
|
|
|
|
if tab.state != 'current':
|
|
|
|
|
tab.state = 'private'
|
|
|
|
|
|
2019-04-28 00:02:49 +00:00
|
|
|
|
conv_jid = tab.jid
|
2013-08-04 21:45:12 +00:00
|
|
|
|
if 'private' in config.get('beep_on', 'highlight private').split():
|
2018-08-15 11:13:17 +00:00
|
|
|
|
if not config.get_by_tabname(
|
|
|
|
|
'disable_beep', conv_jid.bare, default=False):
|
2013-08-04 21:45:12 +00:00
|
|
|
|
curses.beep()
|
|
|
|
|
|
2018-08-15 11:13:17 +00:00
|
|
|
|
|
2013-08-04 13:30:03 +00:00
|
|
|
|
class PoezioContext(Context):
|
2015-01-03 15:23:34 +00:00
|
|
|
|
"""
|
|
|
|
|
OTR context, specific to a conversation with a contact
|
|
|
|
|
|
|
|
|
|
Overrides methods from potr.context.Context
|
|
|
|
|
"""
|
2018-08-15 11:13:17 +00:00
|
|
|
|
|
2013-08-04 13:30:03 +00:00
|
|
|
|
def __init__(self, account, peer, xmpp, core):
|
|
|
|
|
super(PoezioContext, self).__init__(account, peer)
|
|
|
|
|
self.xmpp = xmpp
|
|
|
|
|
self.core = core
|
|
|
|
|
self.flags = {}
|
2013-08-05 17:45:35 +00:00
|
|
|
|
self.trustName = safeJID(peer).bare
|
2014-12-30 21:00:02 +00:00
|
|
|
|
self.in_smp = False
|
|
|
|
|
self.smp_own = False
|
2015-01-03 15:23:34 +00:00
|
|
|
|
self.log = 0
|
2013-08-04 13:30:03 +00:00
|
|
|
|
|
|
|
|
|
def getPolicy(self, key):
|
|
|
|
|
if key in self.flags:
|
|
|
|
|
return self.flags[key]
|
|
|
|
|
else:
|
|
|
|
|
return False
|
|
|
|
|
|
2014-12-30 21:00:02 +00:00
|
|
|
|
def reset_smp(self):
|
|
|
|
|
self.in_smp = False
|
|
|
|
|
self.smp_own = False
|
|
|
|
|
|
2013-08-04 13:30:03 +00:00
|
|
|
|
def inject(self, msg, appdata=None):
|
2018-08-15 11:13:17 +00:00
|
|
|
|
message = self.xmpp.make_message(
|
|
|
|
|
mto=self.peer, mbody=msg.decode('ascii'), mtype='chat')
|
2016-09-20 06:02:45 +00:00
|
|
|
|
message['eme']['namespace'] = 'urn:xmpp:otr:0'
|
2013-08-11 21:32:44 +00:00
|
|
|
|
message.enable('carbon_private')
|
2016-06-04 17:37:57 +00:00
|
|
|
|
message.enable('no-copy')
|
|
|
|
|
message.enable('no-permanent-store')
|
2013-08-11 21:32:44 +00:00
|
|
|
|
message.send()
|
2013-08-04 13:30:03 +00:00
|
|
|
|
|
|
|
|
|
def setState(self, newstate):
|
2015-01-03 15:23:34 +00:00
|
|
|
|
format_dict = {
|
|
|
|
|
'jid_c': '\x19%s}' % dump_tuple(get_theme().COLOR_MUC_JID),
|
|
|
|
|
'info': '\x19%s}' % dump_tuple(get_theme().COLOR_INFORMATION_TEXT),
|
|
|
|
|
'normal': '\x19%s}' % dump_tuple(get_theme().COLOR_NORMAL_TEXT),
|
|
|
|
|
'jid': self.peer,
|
|
|
|
|
'bare_jid': safeJID(self.peer).bare
|
|
|
|
|
}
|
2014-05-18 13:11:32 +00:00
|
|
|
|
|
2018-08-08 22:45:10 +00:00
|
|
|
|
tab = self.core.tabs.by_name(self.peer)
|
2013-08-04 13:30:03 +00:00
|
|
|
|
if not tab:
|
2018-08-12 10:59:40 +00:00
|
|
|
|
tab = None
|
2013-08-04 13:30:03 +00:00
|
|
|
|
if self.state == STATE_ENCRYPTED:
|
2014-12-30 21:00:02 +00:00
|
|
|
|
if newstate == STATE_ENCRYPTED and tab:
|
2013-08-04 13:30:03 +00:00
|
|
|
|
log.debug('OTR conversation with %s refreshed', self.peer)
|
2014-12-30 21:00:02 +00:00
|
|
|
|
if self.getCurrentTrust():
|
2015-01-03 15:23:34 +00:00
|
|
|
|
msg = OTR_REFRESH_TRUSTED % format_dict
|
2014-12-30 21:00:02 +00:00
|
|
|
|
tab.add_message(msg, typ=self.log)
|
|
|
|
|
else:
|
2015-01-03 15:23:34 +00:00
|
|
|
|
msg = OTR_REFRESH_UNTRUSTED % format_dict
|
2014-12-30 21:00:02 +00:00
|
|
|
|
tab.add_message(msg, typ=self.log)
|
|
|
|
|
hl(tab)
|
2013-08-04 13:30:03 +00:00
|
|
|
|
elif newstate == STATE_FINISHED or newstate == STATE_PLAINTEXT:
|
|
|
|
|
log.debug('OTR conversation with %s finished', self.peer)
|
|
|
|
|
if tab:
|
2015-01-03 15:23:34 +00:00
|
|
|
|
tab.add_message(OTR_END % format_dict, typ=self.log)
|
2013-08-04 21:45:12 +00:00
|
|
|
|
hl(tab)
|
2014-12-30 21:00:02 +00:00
|
|
|
|
elif newstate == STATE_ENCRYPTED and tab:
|
|
|
|
|
if self.getCurrentTrust():
|
2015-01-03 15:23:34 +00:00
|
|
|
|
tab.add_message(OTR_START_TRUSTED % format_dict, typ=self.log)
|
2014-12-30 21:00:02 +00:00
|
|
|
|
else:
|
2015-01-03 15:23:34 +00:00
|
|
|
|
format_dict['our_fpr'] = self.user.getPrivkey()
|
|
|
|
|
format_dict['remote_fpr'] = self.getCurrentKey()
|
|
|
|
|
tab.add_message(OTR_TUTORIAL % format_dict, typ=0)
|
2018-08-15 11:13:17 +00:00
|
|
|
|
tab.add_message(
|
|
|
|
|
OTR_START_UNTRUSTED % format_dict, typ=self.log)
|
2014-12-30 21:00:02 +00:00
|
|
|
|
hl(tab)
|
2013-08-04 13:30:03 +00:00
|
|
|
|
|
2018-08-15 11:13:17 +00:00
|
|
|
|
log.debug('Set encryption state of %s to %s', self.peer,
|
|
|
|
|
states[newstate])
|
2013-08-04 13:30:03 +00:00
|
|
|
|
super(PoezioContext, self).setState(newstate)
|
|
|
|
|
if tab:
|
|
|
|
|
self.core.refresh_window()
|
|
|
|
|
self.core.doupdate()
|
|
|
|
|
|
2018-08-15 11:13:17 +00:00
|
|
|
|
|
2013-08-04 13:30:03 +00:00
|
|
|
|
class PoezioAccount(Account):
|
2015-01-03 15:23:34 +00:00
|
|
|
|
"""
|
|
|
|
|
OTR Account, keeps track of a specific account (ours)
|
|
|
|
|
|
|
|
|
|
Redefines the load/save methods from potr.context.Account
|
|
|
|
|
"""
|
2013-08-04 13:30:03 +00:00
|
|
|
|
|
|
|
|
|
def __init__(self, jid, key_dir):
|
2015-01-03 16:33:59 +00:00
|
|
|
|
super(PoezioAccount, self).__init__(jid, 'xmpp', 0)
|
2013-08-04 13:30:03 +00:00
|
|
|
|
self.key_dir = os.path.join(key_dir, jid)
|
|
|
|
|
|
|
|
|
|
def load_privkey(self):
|
|
|
|
|
try:
|
|
|
|
|
with open(self.key_dir + '.key3', 'rb') as keyfile:
|
|
|
|
|
return potr.crypt.PK.parsePrivateKey(keyfile.read())[0]
|
|
|
|
|
except:
|
|
|
|
|
log.error('Error in load_privkey', exc_info=True)
|
|
|
|
|
|
2013-08-04 22:08:11 +00:00
|
|
|
|
def drop_privkey(self):
|
|
|
|
|
try:
|
|
|
|
|
os.remove(self.key_dir + '.key3')
|
|
|
|
|
except:
|
2018-08-15 11:13:17 +00:00
|
|
|
|
log.exception('Error in drop_privkey (removing %s)',
|
|
|
|
|
self.key_dir + '.key3')
|
2013-08-04 22:08:11 +00:00
|
|
|
|
self.privkey = None
|
|
|
|
|
|
2013-08-04 13:30:03 +00:00
|
|
|
|
def save_privkey(self):
|
|
|
|
|
try:
|
|
|
|
|
with open(self.key_dir + '.key3', 'xb') as keyfile:
|
|
|
|
|
keyfile.write(self.getPrivkey().serializePrivateKey())
|
|
|
|
|
except:
|
|
|
|
|
log.error('Error in save_privkey', exc_info=True)
|
|
|
|
|
|
2013-08-05 17:45:35 +00:00
|
|
|
|
def load_trusts(self):
|
|
|
|
|
try:
|
|
|
|
|
with open(self.key_dir + '.fpr', 'r') as fpr_fd:
|
|
|
|
|
for line in fpr_fd:
|
|
|
|
|
ctx, acc, proto, fpr, trust = line[:-1].split('\t')
|
|
|
|
|
|
|
|
|
|
if acc != self.name or proto != 'xmpp':
|
|
|
|
|
continue
|
|
|
|
|
jid = safeJID(ctx).bare
|
|
|
|
|
if not jid:
|
|
|
|
|
continue
|
|
|
|
|
self.setTrust(jid, fpr, trust)
|
|
|
|
|
except:
|
|
|
|
|
log.error('Error in load_trusts', exc_info=True)
|
|
|
|
|
|
2013-08-04 13:30:03 +00:00
|
|
|
|
def save_trusts(self):
|
2013-08-05 17:45:35 +00:00
|
|
|
|
try:
|
|
|
|
|
with open(self.key_dir + '.fpr', 'w') as fpr_fd:
|
|
|
|
|
for uid, trusts in self.trusts.items():
|
|
|
|
|
for fpr, trustVal in trusts.items():
|
2018-08-15 11:13:17 +00:00
|
|
|
|
fpr_fd.write('\t'.join((uid, self.name, 'xmpp', fpr,
|
|
|
|
|
trustVal)))
|
2013-08-05 17:45:35 +00:00
|
|
|
|
fpr_fd.write('\n')
|
|
|
|
|
except:
|
|
|
|
|
log.exception('Error in save_trusts', exc_info=True)
|
2013-08-04 13:30:03 +00:00
|
|
|
|
|
|
|
|
|
saveTrusts = save_trusts
|
2013-08-05 17:45:35 +00:00
|
|
|
|
loadTrusts = load_trusts
|
2013-08-04 13:30:03 +00:00
|
|
|
|
loadPrivkey = load_privkey
|
|
|
|
|
savePrivkey = save_privkey
|
|
|
|
|
|
2018-08-15 11:13:17 +00:00
|
|
|
|
|
2013-08-04 13:30:03 +00:00
|
|
|
|
states = {
|
2015-01-03 15:23:34 +00:00
|
|
|
|
STATE_PLAINTEXT: 'plaintext',
|
|
|
|
|
STATE_ENCRYPTED: 'encrypted',
|
|
|
|
|
STATE_FINISHED: 'finished',
|
2013-08-04 13:30:03 +00:00
|
|
|
|
}
|
2012-03-25 21:40:22 +00:00
|
|
|
|
|
2013-08-04 13:30:03 +00:00
|
|
|
|
|
2018-08-15 11:13:17 +00:00
|
|
|
|
class Plugin(BasePlugin):
|
2012-03-25 21:40:22 +00:00
|
|
|
|
def init(self):
|
2013-08-04 13:30:03 +00:00
|
|
|
|
# set the default values from the config
|
2018-07-04 10:53:02 +00:00
|
|
|
|
keys_dir = self.config.get('keys_dir', '')
|
2018-08-15 11:13:17 +00:00
|
|
|
|
otr_dir = Path(
|
|
|
|
|
keys_dir).expanduser() if keys_dir else xdg.DATA_HOME / 'otr'
|
2013-08-04 13:30:03 +00:00
|
|
|
|
try:
|
2018-08-08 22:45:10 +00:00
|
|
|
|
otr_dir.mkdir(parents=True, exist_ok=True)
|
2013-08-06 20:30:03 +00:00
|
|
|
|
except OSError as e:
|
2018-08-15 11:13:17 +00:00
|
|
|
|
self.api.information(
|
|
|
|
|
'The OTR-specific folder could not '
|
|
|
|
|
'be created: %s. Poezio will be unable '
|
|
|
|
|
'to save keys and trusts' % e, 'OTR')
|
2013-08-06 20:30:03 +00:00
|
|
|
|
|
2018-08-08 22:45:10 +00:00
|
|
|
|
except Exception as e:
|
2018-08-15 11:13:17 +00:00
|
|
|
|
self.api.information(
|
|
|
|
|
'The OTR-specific folder could not '
|
|
|
|
|
'be created. Poezio will be unable '
|
|
|
|
|
'to save keys and trusts', 'OTR')
|
2012-03-25 21:40:22 +00:00
|
|
|
|
|
2018-08-15 11:13:17 +00:00
|
|
|
|
self.api.add_event_handler('conversation_msg',
|
|
|
|
|
self.on_conversation_msg)
|
2013-08-04 13:30:03 +00:00
|
|
|
|
self.api.add_event_handler('private_msg', self.on_conversation_msg)
|
2018-08-15 11:13:17 +00:00
|
|
|
|
self.api.add_event_handler('conversation_say_after',
|
|
|
|
|
self.on_conversation_say)
|
|
|
|
|
self.api.add_event_handler('private_say_after',
|
|
|
|
|
self.on_conversation_say)
|
2013-08-05 17:45:35 +00:00
|
|
|
|
|
2018-08-15 11:13:17 +00:00
|
|
|
|
StaticConversationTab.add_information_element(
|
|
|
|
|
'otr', self.display_encryption_status)
|
|
|
|
|
PrivateTab.add_information_element('otr',
|
|
|
|
|
self.display_encryption_status)
|
2013-08-05 17:45:35 +00:00
|
|
|
|
|
2016-08-28 19:33:28 +00:00
|
|
|
|
self.core.xmpp.plugin['xep_0030'].add_feature('urn:xmpp:otr:0')
|
|
|
|
|
|
2018-07-04 10:53:02 +00:00
|
|
|
|
self.account = PoezioAccount(self.core.xmpp.boundjid.bare, otr_dir)
|
2013-08-05 17:45:35 +00:00
|
|
|
|
self.account.load_trusts()
|
2013-08-04 13:30:03 +00:00
|
|
|
|
self.contexts = {}
|
2014-12-30 21:00:02 +00:00
|
|
|
|
usage = '<start|refresh|end|fpr|ourfpr|drop|trust|untrust>'
|
2013-08-04 13:36:29 +00:00
|
|
|
|
shortdesc = 'Manage an OTR conversation'
|
2013-08-05 17:45:35 +00:00
|
|
|
|
desc = ('Manage an OTR conversation.\n'
|
|
|
|
|
'start/refresh: Start or refresh a conversation\n'
|
|
|
|
|
'end: End a conversation\n'
|
|
|
|
|
'fpr: Show the fingerprint of the key of the remote user\n'
|
|
|
|
|
'ourfpr: Show the fingerprint of your own key\n'
|
|
|
|
|
'drop: Remove the current key (FOREVER)\n'
|
|
|
|
|
'trust: Set this key for this contact as trusted\n'
|
|
|
|
|
'untrust: Remove the trust for the key of this contact\n')
|
2014-12-30 21:00:02 +00:00
|
|
|
|
smp_usage = '<abort|ask|answer> [question] [answer]'
|
|
|
|
|
smp_short = 'Identify a contact'
|
2018-08-15 11:13:17 +00:00
|
|
|
|
smp_desc = (
|
|
|
|
|
'Verify the identify of your contact by using a pre-defined secret.\n'
|
|
|
|
|
'abort: Abort an ongoing verification\n'
|
|
|
|
|
'ask: Start a verification, with a question or not\n'
|
|
|
|
|
'answer: Finish a verification\n')
|
|
|
|
|
|
|
|
|
|
self.api.add_tab_command(
|
|
|
|
|
StaticConversationTab,
|
|
|
|
|
'otrsmp',
|
|
|
|
|
self.command_smp,
|
|
|
|
|
help=smp_desc,
|
|
|
|
|
usage=smp_usage,
|
|
|
|
|
short=smp_short,
|
|
|
|
|
completion=self.completion_smp)
|
|
|
|
|
self.api.add_tab_command(
|
|
|
|
|
PrivateTab,
|
|
|
|
|
'otrsmp',
|
|
|
|
|
self.command_smp,
|
|
|
|
|
help=smp_desc,
|
|
|
|
|
usage=smp_usage,
|
|
|
|
|
short=smp_short,
|
|
|
|
|
completion=self.completion_smp)
|
|
|
|
|
|
|
|
|
|
self.api.add_tab_command(
|
|
|
|
|
StaticConversationTab,
|
|
|
|
|
'otr',
|
|
|
|
|
self.command_otr,
|
|
|
|
|
help=desc,
|
|
|
|
|
usage=usage,
|
|
|
|
|
short=shortdesc,
|
|
|
|
|
completion=self.completion_otr)
|
|
|
|
|
self.api.add_tab_command(
|
|
|
|
|
PrivateTab,
|
|
|
|
|
'otr',
|
|
|
|
|
self.command_otr,
|
|
|
|
|
help=desc,
|
|
|
|
|
usage=usage,
|
|
|
|
|
short=shortdesc,
|
|
|
|
|
completion=self.completion_otr)
|
2012-03-25 21:40:22 +00:00
|
|
|
|
|
|
|
|
|
def cleanup(self):
|
2014-05-19 21:58:15 +00:00
|
|
|
|
for context in self.contexts.values():
|
|
|
|
|
context.disconnect()
|
|
|
|
|
|
2016-08-28 19:33:28 +00:00
|
|
|
|
self.core.xmpp.plugin['xep_0030'].del_feature(feature='urn:xmpp:otr:0')
|
|
|
|
|
|
2018-08-12 10:59:40 +00:00
|
|
|
|
StaticConversationTab.remove_information_element('otr')
|
2013-08-04 13:30:03 +00:00
|
|
|
|
PrivateTab.remove_information_element('otr')
|
|
|
|
|
|
|
|
|
|
def get_context(self, jid):
|
2015-01-03 15:23:34 +00:00
|
|
|
|
"""
|
|
|
|
|
Retrieve or create an OTR context
|
|
|
|
|
"""
|
2016-02-13 13:48:14 +00:00
|
|
|
|
jid = safeJID(jid)
|
2017-10-08 14:36:10 +00:00
|
|
|
|
if jid.full not in self.contexts:
|
2013-08-04 13:30:03 +00:00
|
|
|
|
flags = POLICY_FLAGS.copy()
|
2018-08-15 11:13:17 +00:00
|
|
|
|
require = self.config.get_by_tabname(
|
|
|
|
|
'require_encryption', jid.bare, default=False)
|
2015-01-03 15:23:34 +00:00
|
|
|
|
flags['REQUIRE_ENCRYPTION'] = require
|
2018-08-15 11:13:17 +00:00
|
|
|
|
logging_policy = self.config.get_by_tabname(
|
|
|
|
|
'log', jid.bare, default=False)
|
|
|
|
|
self.contexts[jid.full] = PoezioContext(self.account, jid.full,
|
|
|
|
|
self.core.xmpp, self.core)
|
2016-02-13 13:48:14 +00:00
|
|
|
|
self.contexts[jid.full].log = 1 if logging_policy else 0
|
|
|
|
|
self.contexts[jid.full].flags = flags
|
|
|
|
|
return self.contexts[jid.full]
|
2013-08-04 13:30:03 +00:00
|
|
|
|
|
|
|
|
|
def on_conversation_msg(self, msg, tab):
|
2015-01-03 15:23:34 +00:00
|
|
|
|
"""
|
|
|
|
|
Message received
|
|
|
|
|
"""
|
|
|
|
|
format_dict = {
|
|
|
|
|
'jid_c': '\x19%s}' % dump_tuple(get_theme().COLOR_MUC_JID),
|
2018-08-15 11:13:17 +00:00
|
|
|
|
'info': '\x19%s}' % dump_tuple(get_theme().COLOR_INFORMATION_TEXT),
|
2015-01-03 15:23:34 +00:00
|
|
|
|
'jid': msg['from']
|
|
|
|
|
}
|
2013-08-04 13:30:03 +00:00
|
|
|
|
try:
|
|
|
|
|
ctx = self.get_context(msg['from'])
|
|
|
|
|
txt, tlvs = ctx.receiveMessage(msg["body"].encode('utf-8'))
|
2014-12-30 21:00:02 +00:00
|
|
|
|
|
2015-01-03 15:23:34 +00:00
|
|
|
|
# SMP
|
2014-12-30 21:00:02 +00:00
|
|
|
|
if tlvs:
|
2015-01-03 15:23:34 +00:00
|
|
|
|
self.handle_tlvs(tlvs, ctx, tab, format_dict)
|
2013-08-04 13:30:03 +00:00
|
|
|
|
except UnencryptedMessage as err:
|
|
|
|
|
# received an unencrypted message inside an OTR session
|
2015-01-03 15:23:34 +00:00
|
|
|
|
self.unencrypted_message_received(err, ctx, msg, tab, format_dict)
|
2015-01-11 12:50:45 +00:00
|
|
|
|
self.otr_start(tab, tab.name, format_dict)
|
2015-01-03 15:23:34 +00:00
|
|
|
|
return
|
|
|
|
|
except NotOTRMessage as err:
|
|
|
|
|
# ignore non-otr messages
|
|
|
|
|
# if we expected an OTR message, we would have
|
|
|
|
|
# got an UnencryptedMesssage
|
|
|
|
|
# but do an additional check because of a bug with potr and py3k
|
2018-08-15 11:13:17 +00:00
|
|
|
|
if ctx.state != STATE_PLAINTEXT or ctx.getPolicy(
|
|
|
|
|
'REQUIRE_ENCRYPTION'):
|
|
|
|
|
self.unencrypted_message_received(err, ctx, msg, tab,
|
|
|
|
|
format_dict)
|
2015-01-11 12:50:45 +00:00
|
|
|
|
self.otr_start(tab, tab.name, format_dict)
|
2013-08-04 13:30:03 +00:00
|
|
|
|
return
|
|
|
|
|
except ErrorReceived as err:
|
|
|
|
|
# Received an OTR error
|
2018-08-15 11:24:11 +00:00
|
|
|
|
proto_error = err.args[0].error # pylint: disable=no-member
|
|
|
|
|
format_dict['err'] = proto_error.decode('utf-8', errors='replace')
|
2015-01-03 15:23:34 +00:00
|
|
|
|
tab.add_message(OTR_ERROR % format_dict, typ=0)
|
2013-08-04 13:30:03 +00:00
|
|
|
|
del msg['body']
|
2013-08-07 18:55:21 +00:00
|
|
|
|
del msg['html']
|
2013-08-04 21:45:12 +00:00
|
|
|
|
hl(tab)
|
2013-08-04 13:30:03 +00:00
|
|
|
|
self.core.refresh_window()
|
|
|
|
|
return
|
|
|
|
|
except NotEncryptedError as err:
|
2015-01-03 15:23:34 +00:00
|
|
|
|
# Encrypted message received, but unreadable as we do not have
|
|
|
|
|
# an OTR session in place.
|
|
|
|
|
text = MESSAGE_UNREADABLE % format_dict
|
|
|
|
|
tab.add_message(text, jid=msg['from'], typ=0)
|
2013-08-04 21:45:12 +00:00
|
|
|
|
hl(tab)
|
2013-08-04 13:30:03 +00:00
|
|
|
|
del msg['body']
|
2013-08-07 18:55:21 +00:00
|
|
|
|
del msg['html']
|
|
|
|
|
self.core.refresh_window()
|
|
|
|
|
return
|
|
|
|
|
except crypt.InvalidParameterError:
|
2015-01-03 15:23:34 +00:00
|
|
|
|
# Malformed OTR payload and stuff
|
|
|
|
|
text = MESSAGE_INVALID % format_dict
|
|
|
|
|
tab.add_message(text, jid=msg['from'], typ=0)
|
2013-08-07 18:55:21 +00:00
|
|
|
|
hl(tab)
|
|
|
|
|
del msg['body']
|
|
|
|
|
del msg['html']
|
2013-08-04 13:30:03 +00:00
|
|
|
|
self.core.refresh_window()
|
2012-03-25 21:40:22 +00:00
|
|
|
|
return
|
2015-01-03 15:23:34 +00:00
|
|
|
|
except Exception:
|
|
|
|
|
# Unexpected error
|
|
|
|
|
import traceback
|
|
|
|
|
exc = traceback.format_exc()
|
|
|
|
|
format_dict['exc'] = exc
|
|
|
|
|
tab.add_message(POTR_ERROR % format_dict, typ=0)
|
2013-12-28 15:27:49 +00:00
|
|
|
|
log.error('Unspecified error in the OTR plugin', exc_info=True)
|
2013-08-04 13:30:03 +00:00
|
|
|
|
return
|
2015-01-03 15:23:34 +00:00
|
|
|
|
# No error, proceed with the message
|
|
|
|
|
self.encrypted_message_received(msg, ctx, tab, txt)
|
|
|
|
|
|
|
|
|
|
def handle_tlvs(self, tlvs, ctx, tab, format_dict):
|
|
|
|
|
"""
|
|
|
|
|
If the message had a TLV, it means we received part of an SMP
|
|
|
|
|
exchange.
|
|
|
|
|
"""
|
|
|
|
|
smp1q = get_tlv(tlvs, potr.proto.SMP1QTLV)
|
|
|
|
|
smp1 = get_tlv(tlvs, potr.proto.SMP1TLV)
|
|
|
|
|
smp2 = get_tlv(tlvs, potr.proto.SMP2TLV)
|
|
|
|
|
smp3 = get_tlv(tlvs, potr.proto.SMP3TLV)
|
|
|
|
|
smp4 = get_tlv(tlvs, potr.proto.SMP4TLV)
|
|
|
|
|
abort = get_tlv(tlvs, potr.proto.SMPABORTTLV)
|
|
|
|
|
if abort:
|
|
|
|
|
ctx.reset_smp()
|
|
|
|
|
tab.add_message(SMP_ABORTED_PEER % format_dict, typ=0)
|
|
|
|
|
elif ctx.in_smp and not ctx.smpIsValid():
|
|
|
|
|
ctx.reset_smp()
|
|
|
|
|
tab.add_message(SMP_ABORTED % format_dict, typ=0)
|
|
|
|
|
elif smp1 or smp1q:
|
|
|
|
|
# Received an SMP request (with a question or not)
|
|
|
|
|
if smp1q:
|
|
|
|
|
try:
|
2018-08-15 11:13:17 +00:00
|
|
|
|
question = ' with question: \x19o' + smp1q.msg.decode(
|
|
|
|
|
'utf-8')
|
2015-01-03 15:23:34 +00:00
|
|
|
|
except UnicodeDecodeError:
|
2018-08-15 11:13:17 +00:00
|
|
|
|
self.api.information(
|
|
|
|
|
'The peer sent a question but it had a wrong encoding',
|
|
|
|
|
'Error')
|
2015-01-03 15:23:34 +00:00
|
|
|
|
question = ''
|
|
|
|
|
else:
|
|
|
|
|
question = ''
|
|
|
|
|
ctx.in_smp = True
|
|
|
|
|
# we did not initiate it
|
|
|
|
|
ctx.smp_own = False
|
|
|
|
|
format_dict['q'] = question
|
|
|
|
|
tab.add_message(SMP_REQUESTED % format_dict, typ=0)
|
|
|
|
|
elif smp2:
|
|
|
|
|
# SMP reply received
|
|
|
|
|
if not ctx.in_smp:
|
|
|
|
|
ctx.reset_smp()
|
|
|
|
|
else:
|
|
|
|
|
tab.add_message(SMP_PROGRESS % format_dict, typ=0)
|
|
|
|
|
elif smp3 or smp4:
|
|
|
|
|
# Type 4 (SMP message 3) or 5 (SMP message 4) TLVs received
|
|
|
|
|
# in both cases it is the final message of the SMP exchange
|
|
|
|
|
if ctx.smpIsSuccess():
|
|
|
|
|
tab.add_message(SMP_SUCCESS % format_dict, typ=0)
|
|
|
|
|
if not ctx.getCurrentTrust():
|
|
|
|
|
tab.add_message(SMP_RECIPROCATE % format_dict, typ=0)
|
|
|
|
|
else:
|
|
|
|
|
tab.add_message(SMP_FAIL % format_dict, typ=0)
|
|
|
|
|
ctx.reset_smp()
|
2015-01-11 12:50:45 +00:00
|
|
|
|
hl(tab)
|
2015-01-03 15:23:34 +00:00
|
|
|
|
self.core.refresh_window()
|
2013-08-04 13:30:03 +00:00
|
|
|
|
|
2015-01-03 15:23:34 +00:00
|
|
|
|
def unencrypted_message_received(self, err, ctx, msg, tab, format_dict):
|
|
|
|
|
"""
|
|
|
|
|
An unencrypted message was received while we expected it to be
|
|
|
|
|
encrypted. Display it with a warning.
|
|
|
|
|
"""
|
|
|
|
|
format_dict['msg'] = err.args[0].decode('utf-8')
|
|
|
|
|
text = MESSAGE_UNENCRYPTED % format_dict
|
|
|
|
|
tab.add_message(text, jid=msg['from'], typ=ctx.log)
|
|
|
|
|
del msg['body']
|
|
|
|
|
del msg['html']
|
|
|
|
|
hl(tab)
|
|
|
|
|
self.core.refresh_window()
|
|
|
|
|
|
|
|
|
|
def encrypted_message_received(self, msg, ctx, tab, txt):
|
|
|
|
|
"""
|
|
|
|
|
A properly encrypted message was received, so we add it to the
|
|
|
|
|
buffer, and try to format it according to the configuration.
|
|
|
|
|
"""
|
2013-08-04 13:30:03 +00:00
|
|
|
|
# remove xhtml
|
|
|
|
|
del msg['html']
|
|
|
|
|
del msg['body']
|
|
|
|
|
|
|
|
|
|
if not txt:
|
|
|
|
|
return
|
|
|
|
|
if isinstance(tab, PrivateTab):
|
|
|
|
|
user = tab.parent_muc.get_user_by_name(msg['from'].resource)
|
2014-05-22 20:07:49 +00:00
|
|
|
|
nick_color = None
|
2012-03-25 21:40:22 +00:00
|
|
|
|
else:
|
2013-08-04 13:30:03 +00:00
|
|
|
|
user = None
|
2014-05-22 20:07:49 +00:00
|
|
|
|
nick_color = get_theme().COLOR_REMOTE_USER
|
2013-08-04 13:30:03 +00:00
|
|
|
|
|
|
|
|
|
body = txt.decode()
|
2018-08-15 11:13:17 +00:00
|
|
|
|
decode_entities = self.config.get_by_tabname(
|
|
|
|
|
'decode_entities', msg['from'].bare, default=True)
|
|
|
|
|
decode_newlines = self.config.get_by_tabname(
|
|
|
|
|
'decode_newlines', msg['from'].bare, default=True)
|
|
|
|
|
if self.config.get_by_tabname(
|
|
|
|
|
'decode_xhtml', msg['from'].bare, default=True):
|
2014-04-29 23:55:23 +00:00
|
|
|
|
try:
|
|
|
|
|
body = xhtml.xhtml_to_poezio_colors(body, force=True)
|
2014-12-16 19:46:45 +00:00
|
|
|
|
except Exception:
|
2014-12-08 19:06:11 +00:00
|
|
|
|
if decode_entities:
|
|
|
|
|
body = html.unescape(body)
|
2014-12-16 19:46:45 +00:00
|
|
|
|
if decode_newlines:
|
|
|
|
|
body = body.replace('<br/>', '\n').replace('<br>', '\n')
|
|
|
|
|
else:
|
|
|
|
|
if decode_entities:
|
|
|
|
|
body = html.unescape(body)
|
|
|
|
|
if decode_newlines:
|
|
|
|
|
body = body.replace('<br/>', '\n').replace('<br>', '\n')
|
2018-08-15 11:13:17 +00:00
|
|
|
|
tab.add_message(
|
|
|
|
|
body,
|
|
|
|
|
nickname=tab.nick,
|
|
|
|
|
jid=msg['from'],
|
|
|
|
|
forced_user=user,
|
|
|
|
|
typ=ctx.log,
|
|
|
|
|
nick_color=nick_color)
|
2013-08-04 21:45:12 +00:00
|
|
|
|
hl(tab)
|
2013-08-04 13:30:03 +00:00
|
|
|
|
self.core.refresh_window()
|
|
|
|
|
del msg['body']
|
2012-03-25 21:40:22 +00:00
|
|
|
|
|
2014-12-08 01:09:33 +00:00
|
|
|
|
def find_encrypted_context_with_matching(self, bare_jid):
|
2015-01-03 15:23:34 +00:00
|
|
|
|
"""
|
|
|
|
|
Find an OTR session from a bare JID.
|
|
|
|
|
"""
|
2014-12-08 01:09:33 +00:00
|
|
|
|
for ctx in self.contexts:
|
2018-08-15 11:13:17 +00:00
|
|
|
|
if safeJID(
|
|
|
|
|
ctx
|
|
|
|
|
).bare == bare_jid and self.contexts[ctx].state == STATE_ENCRYPTED:
|
2014-12-08 01:09:33 +00:00
|
|
|
|
return self.contexts[ctx]
|
|
|
|
|
return None
|
|
|
|
|
|
2013-08-04 13:30:03 +00:00
|
|
|
|
def on_conversation_say(self, msg, tab):
|
2012-03-25 21:40:22 +00:00
|
|
|
|
"""
|
2013-08-04 13:30:03 +00:00
|
|
|
|
On message sent
|
2012-03-25 21:40:22 +00:00
|
|
|
|
"""
|
2018-08-12 10:59:40 +00:00
|
|
|
|
name = tab.name
|
2019-04-28 00:02:49 +00:00
|
|
|
|
jid = tab.jid
|
2014-12-08 01:09:33 +00:00
|
|
|
|
|
2015-01-03 15:23:34 +00:00
|
|
|
|
format_dict = {
|
|
|
|
|
'jid_c': '\x19%s}' % dump_tuple(get_theme().COLOR_MUC_JID),
|
|
|
|
|
'info': '\x19%s}' % dump_tuple(get_theme().COLOR_INFORMATION_TEXT),
|
|
|
|
|
'jid': name,
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-12 10:59:40 +00:00
|
|
|
|
ctx = self.find_encrypted_context_with_matching(jid)
|
2016-02-02 19:03:17 +00:00
|
|
|
|
default_ctx = self.get_context(name)
|
|
|
|
|
|
|
|
|
|
if ctx is None:
|
|
|
|
|
ctx = default_ctx
|
|
|
|
|
|
2018-08-12 10:59:40 +00:00
|
|
|
|
if is_relevant(tab) and ctx and ctx.state == STATE_ENCRYPTED:
|
2013-08-04 13:30:03 +00:00
|
|
|
|
ctx.sendMessage(0, msg['body'].encode('utf-8'))
|
2014-04-17 18:39:01 +00:00
|
|
|
|
if not tab.send_chat_state('active'):
|
|
|
|
|
tab.send_chat_state('inactive', always_send=True)
|
|
|
|
|
|
2018-08-15 11:13:17 +00:00
|
|
|
|
tab.add_message(
|
|
|
|
|
msg['body'],
|
|
|
|
|
nickname=self.core.own_nick or tab.own_nick,
|
|
|
|
|
nick_color=get_theme().COLOR_OWN_NICK,
|
|
|
|
|
identifier=msg['id'],
|
|
|
|
|
jid=self.core.xmpp.boundjid,
|
|
|
|
|
typ=ctx.log)
|
2013-08-04 13:30:03 +00:00
|
|
|
|
# remove everything from the message so that it doesn’t get sent
|
|
|
|
|
del msg['body']
|
|
|
|
|
del msg['replace']
|
|
|
|
|
del msg['html']
|
2018-08-12 10:59:40 +00:00
|
|
|
|
elif is_relevant(tab) and ctx and ctx.getPolicy('REQUIRE_ENCRYPTION'):
|
|
|
|
|
warning_msg = MESSAGE_NOT_SENT % format_dict
|
|
|
|
|
tab.add_message(warning_msg, typ=0)
|
2015-01-03 15:23:34 +00:00
|
|
|
|
del msg['body']
|
|
|
|
|
del msg['replace']
|
|
|
|
|
del msg['html']
|
2015-01-11 12:50:45 +00:00
|
|
|
|
self.otr_start(tab, name, format_dict)
|
2018-08-12 10:59:40 +00:00
|
|
|
|
elif not is_relevant(tab) and ctx and (
|
2018-08-15 11:13:17 +00:00
|
|
|
|
ctx.state == STATE_ENCRYPTED
|
|
|
|
|
or ctx.getPolicy('REQUIRE_ENCRYPTION')):
|
2019-04-28 00:02:49 +00:00
|
|
|
|
contact = roster[tab.jid.bare]
|
2018-08-12 10:59:40 +00:00
|
|
|
|
res = []
|
|
|
|
|
if contact:
|
|
|
|
|
res = [resource.jid for resource in contact.resources]
|
|
|
|
|
help_msg = ''
|
|
|
|
|
if res:
|
2018-08-15 11:13:17 +00:00
|
|
|
|
help_msg = TAB_HELP_RESOURCE % ''.join(
|
|
|
|
|
('\n - /message %s' % jid) for jid in res)
|
2018-08-12 10:59:40 +00:00
|
|
|
|
format_dict['help'] = help_msg
|
|
|
|
|
warning_msg = INCOMPATIBLE_TAB % format_dict
|
|
|
|
|
tab.add_message(warning_msg, typ=0)
|
|
|
|
|
del msg['body']
|
|
|
|
|
del msg['replace']
|
|
|
|
|
del msg['html']
|
2012-03-25 21:40:22 +00:00
|
|
|
|
|
|
|
|
|
def display_encryption_status(self, jid):
|
2015-01-03 15:23:34 +00:00
|
|
|
|
"""
|
|
|
|
|
Returns the text to display in the infobar (the OTR status)
|
|
|
|
|
"""
|
2013-08-04 13:30:03 +00:00
|
|
|
|
context = self.get_context(jid)
|
2014-12-08 01:09:33 +00:00
|
|
|
|
if safeJID(jid).bare == jid and context.state != STATE_ENCRYPTED:
|
|
|
|
|
ctx = self.find_encrypted_context_with_matching(jid)
|
|
|
|
|
if ctx:
|
|
|
|
|
context = ctx
|
2013-08-04 13:30:03 +00:00
|
|
|
|
state = states[context.state]
|
2014-12-30 21:00:02 +00:00
|
|
|
|
trust = 'trusted' if context.getCurrentTrust() else 'untrusted'
|
|
|
|
|
|
|
|
|
|
return ' OTR: %s (%s)' % (state, trust)
|
2013-08-04 13:30:03 +00:00
|
|
|
|
|
|
|
|
|
def command_otr(self, arg):
|
2012-03-25 21:40:22 +00:00
|
|
|
|
"""
|
2013-08-04 13:30:03 +00:00
|
|
|
|
/otr [start|refresh|end|fpr|ourfpr]
|
2012-03-25 21:40:22 +00:00
|
|
|
|
"""
|
2014-12-30 21:00:02 +00:00
|
|
|
|
args = common.shell_split(arg)
|
|
|
|
|
if not args:
|
2016-03-31 22:24:58 +00:00
|
|
|
|
return self.core.command.help('otr')
|
2014-12-30 21:00:02 +00:00
|
|
|
|
action = args.pop(0)
|
2013-08-04 13:30:03 +00:00
|
|
|
|
tab = self.api.current_tab()
|
2019-04-28 00:02:49 +00:00
|
|
|
|
name = tab.jid.full
|
2015-01-03 15:23:34 +00:00
|
|
|
|
format_dict = {
|
|
|
|
|
'jid_c': '\x19%s}' % dump_tuple(get_theme().COLOR_MUC_JID),
|
|
|
|
|
'info': '\x19%s}' % dump_tuple(get_theme().COLOR_INFORMATION_TEXT),
|
|
|
|
|
'normal': '\x19%s}' % dump_tuple(get_theme().COLOR_NORMAL_TEXT),
|
2019-04-28 00:02:49 +00:00
|
|
|
|
'jid': tab.jid.full,
|
|
|
|
|
'bare_jid': tab.jid.bare,
|
2015-01-03 15:23:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-08-15 11:13:17 +00:00
|
|
|
|
if action == 'end': # close the session
|
2013-08-04 13:30:03 +00:00
|
|
|
|
context = self.get_context(name)
|
|
|
|
|
context.disconnect()
|
2014-12-30 21:00:02 +00:00
|
|
|
|
elif action == 'start' or action == 'refresh':
|
2015-01-11 12:50:45 +00:00
|
|
|
|
self.otr_start(tab, name, format_dict)
|
2014-12-30 21:00:02 +00:00
|
|
|
|
elif action == 'ourfpr':
|
2015-01-03 15:23:34 +00:00
|
|
|
|
format_dict['fpr'] = self.account.getPrivkey()
|
|
|
|
|
tab.add_message(OTR_OWN_FPR % format_dict, typ=0)
|
2014-12-30 21:00:02 +00:00
|
|
|
|
elif action == 'fpr':
|
2013-08-18 20:32:26 +00:00
|
|
|
|
if name in self.contexts:
|
|
|
|
|
ctx = self.contexts[name]
|
2014-10-12 20:23:45 +00:00
|
|
|
|
if ctx.getCurrentKey() is not None:
|
2015-01-03 15:23:34 +00:00
|
|
|
|
format_dict['fpr'] = ctx.getCurrentKey()
|
|
|
|
|
tab.add_message(OTR_REMOTE_FPR % format_dict, typ=0)
|
2014-10-12 20:23:45 +00:00
|
|
|
|
else:
|
2015-01-03 15:23:34 +00:00
|
|
|
|
tab.add_message(OTR_NO_FPR % format_dict, typ=0)
|
2014-12-30 21:00:02 +00:00
|
|
|
|
elif action == 'drop':
|
2013-08-04 22:08:11 +00:00
|
|
|
|
# drop the privkey (and obviously, end the current conversations before that)
|
|
|
|
|
for context in self.contexts.values():
|
|
|
|
|
if context.state not in (STATE_FINISHED, STATE_PLAINTEXT):
|
|
|
|
|
context.disconnect()
|
|
|
|
|
self.account.drop_privkey()
|
2015-01-03 15:23:34 +00:00
|
|
|
|
tab.add_message(KEY_DROPPED % format_dict, typ=0)
|
2014-12-30 21:00:02 +00:00
|
|
|
|
elif action == 'trust':
|
2013-08-05 17:45:35 +00:00
|
|
|
|
ctx = self.get_context(name)
|
|
|
|
|
key = ctx.getCurrentKey()
|
|
|
|
|
if key:
|
|
|
|
|
fpr = key.cfingerprint()
|
|
|
|
|
else:
|
|
|
|
|
return
|
2013-08-07 18:55:21 +00:00
|
|
|
|
if not ctx.getCurrentTrust():
|
2015-01-03 15:23:34 +00:00
|
|
|
|
format_dict['key'] = key
|
2013-08-07 18:55:21 +00:00
|
|
|
|
ctx.setTrust(fpr, 'verified')
|
|
|
|
|
self.account.saveTrusts()
|
2015-01-03 15:23:34 +00:00
|
|
|
|
tab.add_message(TRUST_ADDED % format_dict, typ=0)
|
2014-12-30 21:00:02 +00:00
|
|
|
|
elif action == 'untrust':
|
2013-08-05 17:45:35 +00:00
|
|
|
|
ctx = self.get_context(name)
|
|
|
|
|
key = ctx.getCurrentKey()
|
|
|
|
|
if key:
|
|
|
|
|
fpr = key.cfingerprint()
|
|
|
|
|
else:
|
|
|
|
|
return
|
2013-08-07 18:55:21 +00:00
|
|
|
|
if ctx.getCurrentTrust():
|
2015-01-03 15:23:34 +00:00
|
|
|
|
format_dict['key'] = key
|
2013-08-07 18:55:21 +00:00
|
|
|
|
ctx.setTrust(fpr, '')
|
|
|
|
|
self.account.saveTrusts()
|
2015-01-03 15:23:34 +00:00
|
|
|
|
tab.add_message(TRUST_REMOVED % format_dict, typ=0)
|
2013-08-07 18:55:21 +00:00
|
|
|
|
self.core.refresh_window()
|
2013-08-04 13:30:03 +00:00
|
|
|
|
|
2015-01-11 12:50:45 +00:00
|
|
|
|
def otr_start(self, tab, name, format_dict):
|
|
|
|
|
"""
|
|
|
|
|
Start an otr conversation with a contact
|
|
|
|
|
"""
|
|
|
|
|
secs = self.config.get('timeout', 3)
|
2018-08-15 11:13:17 +00:00
|
|
|
|
|
2015-01-11 12:50:45 +00:00
|
|
|
|
def notify_otr_timeout():
|
2015-03-18 12:36:10 +00:00
|
|
|
|
tab_name = tab.name
|
2018-08-12 10:59:40 +00:00
|
|
|
|
otr = self.find_encrypted_context_with_matching(tab_name)
|
2015-01-11 12:50:45 +00:00
|
|
|
|
if otr.state != STATE_ENCRYPTED:
|
|
|
|
|
format_dict['secs'] = secs
|
|
|
|
|
text = OTR_NOT_ENABLED % format_dict
|
|
|
|
|
tab.add_message(text, typ=0)
|
|
|
|
|
self.core.refresh_window()
|
2018-08-15 11:13:17 +00:00
|
|
|
|
|
2015-01-11 12:50:45 +00:00
|
|
|
|
if secs > 0:
|
|
|
|
|
event = self.api.create_delayed_event(secs, notify_otr_timeout)
|
|
|
|
|
self.api.add_timed_event(event)
|
2015-04-08 17:47:21 +00:00
|
|
|
|
body = self.get_context(name).sendMessage(0, b'?OTRv?').decode()
|
2015-01-11 12:50:45 +00:00
|
|
|
|
self.core.xmpp.send_message(mto=name, mtype='chat', mbody=body)
|
|
|
|
|
tab.add_message(OTR_REQUEST % format_dict, typ=0)
|
|
|
|
|
|
2015-01-03 15:23:34 +00:00
|
|
|
|
@staticmethod
|
|
|
|
|
def completion_otr(the_input):
|
|
|
|
|
"""
|
|
|
|
|
Completion for /otr
|
|
|
|
|
"""
|
2014-05-18 13:11:32 +00:00
|
|
|
|
comp = ['start', 'fpr', 'ourfpr', 'refresh', 'end', 'trust', 'untrust']
|
2016-08-21 13:27:53 +00:00
|
|
|
|
return Completion(the_input.new_completion, comp, 1, quotify=False)
|
2012-03-25 21:40:22 +00:00
|
|
|
|
|
2014-12-30 21:00:02 +00:00
|
|
|
|
@command_args_parser.quoted(1, 2)
|
|
|
|
|
def command_smp(self, args):
|
|
|
|
|
"""
|
|
|
|
|
/otrsmp <ask|answer|abort> [question] [secret]
|
|
|
|
|
"""
|
|
|
|
|
if args is None or not args:
|
2016-03-31 22:24:58 +00:00
|
|
|
|
return self.core.command.help('otrsmp')
|
2014-12-30 21:00:02 +00:00
|
|
|
|
length = len(args)
|
|
|
|
|
action = args.pop(0)
|
|
|
|
|
if length == 2:
|
|
|
|
|
question = None
|
|
|
|
|
secret = args.pop(0).encode('utf-8')
|
|
|
|
|
elif length == 3:
|
|
|
|
|
question = args.pop(0).encode('utf-8')
|
|
|
|
|
secret = args.pop(0).encode('utf-8')
|
|
|
|
|
else:
|
|
|
|
|
question = secret = None
|
|
|
|
|
|
|
|
|
|
tab = self.api.current_tab()
|
2019-04-28 00:02:49 +00:00
|
|
|
|
name = tab.jid.full
|
2015-01-03 15:23:34 +00:00
|
|
|
|
format_dict = {
|
|
|
|
|
'jid_c': '\x19%s}' % dump_tuple(get_theme().COLOR_MUC_JID),
|
|
|
|
|
'info': '\x19%s}' % dump_tuple(get_theme().COLOR_INFORMATION_TEXT),
|
2019-04-28 00:02:49 +00:00
|
|
|
|
'jid': tab.jid.full,
|
|
|
|
|
'bare_jid': tab.jid.bare,
|
2015-01-03 15:23:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-30 21:00:02 +00:00
|
|
|
|
ctx = self.get_context(name)
|
|
|
|
|
if ctx.state != STATE_ENCRYPTED:
|
2015-01-03 15:23:34 +00:00
|
|
|
|
self.api.information('The current conversation is not encrypted',
|
|
|
|
|
'Error')
|
|
|
|
|
return
|
2014-12-30 21:00:02 +00:00
|
|
|
|
|
|
|
|
|
if action == 'ask':
|
|
|
|
|
ctx.in_smp = True
|
|
|
|
|
ctx.smp_own = True
|
|
|
|
|
if question:
|
|
|
|
|
ctx.smpInit(secret, question)
|
|
|
|
|
else:
|
|
|
|
|
ctx.smpInit(secret)
|
2015-01-03 15:23:34 +00:00
|
|
|
|
tab.add_message(SMP_INITIATED % format_dict, typ=0)
|
2014-12-30 21:00:02 +00:00
|
|
|
|
elif action == 'answer':
|
|
|
|
|
ctx.smpGotSecret(secret)
|
|
|
|
|
elif action == 'abort':
|
|
|
|
|
if ctx.in_smp:
|
|
|
|
|
ctx.smpAbort()
|
2015-01-03 15:23:34 +00:00
|
|
|
|
tab.add_message(SMP_ABORTED % format_dict, typ=0)
|
2014-12-30 21:00:02 +00:00
|
|
|
|
self.core.refresh_window()
|
|
|
|
|
|
2015-01-03 15:23:34 +00:00
|
|
|
|
@staticmethod
|
|
|
|
|
def completion_smp(the_input):
|
|
|
|
|
"""Completion for /otrsmp"""
|
2014-12-30 21:00:02 +00:00
|
|
|
|
if the_input.get_argument_position() == 1:
|
2018-08-15 11:13:17 +00:00
|
|
|
|
return Completion(
|
|
|
|
|
the_input.new_completion, ['ask', 'answer', 'abort'],
|
|
|
|
|
1,
|
|
|
|
|
quotify=False)
|
|
|
|
|
|
2014-12-30 21:00:02 +00:00
|
|
|
|
|
|
|
|
|
def get_tlv(tlvs, cls):
|
2015-01-03 15:23:34 +00:00
|
|
|
|
"""Find the instance of a class in a list"""
|
2014-12-30 21:00:02 +00:00
|
|
|
|
for tlv in tlvs:
|
|
|
|
|
if isinstance(tlv, cls):
|
|
|
|
|
return tlv
|
2018-08-12 10:59:40 +00:00
|
|
|
|
|
2018-08-15 11:13:17 +00:00
|
|
|
|
|
2018-08-12 10:59:40 +00:00
|
|
|
|
def is_relevant(tab):
|
|
|
|
|
"""Check if a tab should be concerned with OTR"""
|
|
|
|
|
return isinstance(tab, (StaticConversationTab, PrivateTab))
|