2019-06-22 11:54:00 +00:00
|
|
|
# Copyright (C) 2019 Philipp Hörist <philipp AT hoerist.com>
|
|
|
|
# Copyright (C) 2019 Pavel R. <pd at narayana dot im>
|
2022-10-06 00:57:18 +00:00
|
|
|
# Copyright (C) 2022 Bohdan Horbeshko <bodqhrohro@gmail.com>
|
2019-06-22 11:54:00 +00:00
|
|
|
|
|
|
|
# This file is part of Gajim OTR Plugin.
|
|
|
|
#
|
|
|
|
# Gajim OTR Plugin is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published
|
|
|
|
# by the Free Software Foundation; version 3 only.
|
|
|
|
#
|
|
|
|
# This software is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You can always obtain full license text at <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
# TODO: Fingerprints authentication GUI
|
|
|
|
# TODO: SMP authentication GUI
|
2019-06-25 14:21:08 +00:00
|
|
|
ERROR = None
|
2019-06-22 11:54:00 +00:00
|
|
|
|
|
|
|
import logging
|
|
|
|
from gajim.plugins import GajimPlugin
|
2019-06-24 11:36:33 +00:00
|
|
|
from gajim.common import app
|
2022-10-06 00:57:18 +00:00
|
|
|
|
|
|
|
log = logging.getLogger('gajim.p.otr')
|
|
|
|
|
|
|
|
if not ERROR:
|
|
|
|
try:
|
|
|
|
from . import module
|
|
|
|
except Exception as error:
|
|
|
|
log.error(error)
|
|
|
|
ERROR = 'Error: %s' % error
|
2019-06-22 11:54:00 +00:00
|
|
|
|
2019-06-25 14:21:08 +00:00
|
|
|
# ...
|
2019-06-23 01:52:53 +00:00
|
|
|
class OTRPlugin(GajimPlugin):
|
2019-06-24 11:36:33 +00:00
|
|
|
log = logging.getLogger('gajim.p.otr')
|
|
|
|
|
2019-06-25 14:21:08 +00:00
|
|
|
# init plugin #
|
2019-06-22 11:54:00 +00:00
|
|
|
def init(self):
|
2022-10-06 00:57:18 +00:00
|
|
|
self.activatable = (not ERROR)
|
|
|
|
if ERROR:
|
|
|
|
self.available_text = (ERROR)
|
|
|
|
return
|
2019-06-24 11:36:33 +00:00
|
|
|
self.encryption_name = 'OTR'
|
2019-06-23 01:52:53 +00:00
|
|
|
self.description = 'Provides Off-the-Record encryption'
|
2022-10-06 00:57:18 +00:00
|
|
|
self.modules = [module]
|
2019-06-22 11:54:00 +00:00
|
|
|
self.gui_extension_points = {
|
2019-06-23 01:52:53 +00:00
|
|
|
'encrypt' + self.encryption_name: (self._encrypt_message, None),
|
2019-06-25 14:21:08 +00:00
|
|
|
}
|
2019-06-24 11:36:33 +00:00
|
|
|
|
2022-10-06 00:57:18 +00:00
|
|
|
@staticmethod
|
|
|
|
def get_otr(account):
|
|
|
|
return app.connections[account].get_module('OTR')
|
|
|
|
|
2019-06-25 14:21:08 +00:00
|
|
|
# activate encryption #
|
2019-06-22 11:54:00 +00:00
|
|
|
@staticmethod
|
2019-06-23 01:52:53 +00:00
|
|
|
def activate_encryption(ctl):
|
2019-06-22 11:54:00 +00:00
|
|
|
return True
|
2019-06-24 11:36:33 +00:00
|
|
|
|
2019-06-25 14:21:08 +00:00
|
|
|
# encrypt file (just return same file)
|
2019-06-23 01:52:53 +00:00
|
|
|
@staticmethod
|
|
|
|
def encrypt_file(file, account, callback):
|
2019-06-22 11:54:00 +00:00
|
|
|
callback(file)
|
2019-06-23 01:52:53 +00:00
|
|
|
|
2019-06-25 14:21:08 +00:00
|
|
|
# encrypt message #
|
2019-06-24 11:36:33 +00:00
|
|
|
def _encrypt_message(self,con,event,callback):
|
|
|
|
if not event.message or event.type_ != 'chat': return # drop empty and non-chat messages
|
2022-10-06 00:57:18 +00:00
|
|
|
otr = self.get_otr(event.account)
|
|
|
|
otr.otr.encrypt(event,callback)
|