From d6b7575c4c2d7c04b0aa086225097847e041f670 Mon Sep 17 00:00:00 2001 From: Bohdan Horbeshko Date: Wed, 20 Sep 2023 16:19:34 +0300 Subject: [PATCH] =?UTF-8?q?pip=20pycryptodome=20compatibility,=20Gajim=20?= =?UTF-8?q?=E2=89=A41.8,=20eliminate=20carbons?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- otr.py | 13 +++++++++++-- plugin-manifest.json | 4 ++-- plugin.py | 20 ++++++++++++-------- potr/compatcrypto/pycrypto.py | 26 ++++++++++++++++++-------- 4 files changed, 43 insertions(+), 20 deletions(-) diff --git a/otr.py b/otr.py index f6a6002..c57c2d4 100644 --- a/otr.py +++ b/otr.py @@ -24,6 +24,7 @@ from gajim.common import const, app, helpers, configpaths from gajim.common.const import EncryptionData from gajim.common.structs import OutgoingMessage from nbxmpp.protocol import Message, JID +from nbxmpp.simplexml import Node import pathlib import sys @@ -52,7 +53,7 @@ class OTRChannel(context.Context): # print some text to chat window def printl(self,line): control = app.window.get_control() - control and control.add_message("OTR: "+line,kind='status',tim=0.0) + control and control.add_info_message("OTR: "+line) @staticmethod def getPolicy(policy): return OTR.DEFAULT_POLICY.get(policy) @@ -138,7 +139,8 @@ class OTR(context.Account): # decrypt message def decrypt(self,stanza,properties): - peer = stanza.getFrom().new_as_bare() + sFrom = stanza.getFrom() + peer = sFrom.new_as_bare() msgtxt = stanza.getBody() channel, ctl = self.getContext(peer), self.getControl(peer) try: @@ -147,6 +149,7 @@ class OTR(context.Account): self.log.error("** got exception while decrypting message: %s" % e) channel.printl(OTR.STATUS[e].format(msg=msgtxt,err=e.args[0].error)) else: + channel.resource = sFrom.resource stanza.setBody(text and text.decode() or "") properties.encrypted = EncryptionData({'name': OTR.ENCRYPTION_NAME}) finally: @@ -156,6 +159,10 @@ class OTR(context.Account): def encrypt(self,event,callback): peer = event.msg_iq.getTo().new_as_bare() channel, ctl = self.getContext(peer), self.getControl(peer) + if not hasattr(channel, 'resource'): + channel.resource = "" + if channel.resource: + peer = peer.new_with(resource=channel.resource) if event.xhtml: return ctl.client.send_message(self.makeOutgoingMessage(event.message, ctl, peer)) # skip xhtml messages try: encrypted = channel.sendMessage(context.FRAGMENT_SEND_ALL_BUT_LAST,event.message.encode(),appdata=event.msg_iq.getThread()) or b'' @@ -167,4 +174,6 @@ class OTR(context.Account): event.msg_iq.setBody(encrypted.decode()) # encrypted data goes here event.message = message # message that will be displayed in our chat goes here event.encrypted, event.additional_data["encrypted"] = OTR.ENCRYPTION_NAME, {"name":OTR.ENCRYPTION_NAME} # some mandatory encryption flags + if channel.resource: + event.stanza.addChild('no-copy', namespace='urn:xmpp:hints') # don't send carbons callback(event) diff --git a/plugin-manifest.json b/plugin-manifest.json index 55570b0..abb39ae 100644 --- a/plugin-manifest.json +++ b/plugin-manifest.json @@ -14,8 +14,8 @@ "win32" ], "requirements": [ - "gajim>=1.5,<1.6" + "gajim>=1.5,<1.9" ], "short_name": "otrplugin", - "version": "0.4" + "version": "0.5" } diff --git a/plugin.py b/plugin.py index c329338..141c998 100644 --- a/plugin.py +++ b/plugin.py @@ -29,8 +29,10 @@ log = logging.getLogger('gajim.p.otr') try: from Cryptodome import * except ImportError as e: - log.error(e) - ERROR = 'Cryptodome is missing' + try: from Crypto import * + except ImportError as e: + log.error(e) + ERROR = 'Cryptodome is missing' if not ERROR: try: @@ -54,7 +56,7 @@ class OTRPlugin(GajimPlugin): self.modules = [module] self.gui_extension_points = { 'encrypt' + self.encryption_name: (self._encrypt_message, None), - 'message_actions_box': (self._message_actions_box_activate, self._message_actions_box_deactivate), + # 'message_actions_box': (self._message_actions_box_activate, self._message_actions_box_deactivate), } self._menuitem = None @@ -67,13 +69,15 @@ class OTRPlugin(GajimPlugin): return grid._ui.encryption_menu_button.get_menu_model() def activate(self): - if app.window is not None: - grid = self._get_grid() - self._actions_hack_activate(grid) + pass + # if app.window is not None: + # grid = self._get_grid() + # self._actions_hack_activate(grid) def deactivate(self): - grid = self._get_grid() - self._actions_hack_deactivate(grid) + pass + # grid = self._get_grid() + # self._actions_hack_deactivate(grid) @staticmethod def get_otr(account): diff --git a/potr/compatcrypto/pycrypto.py b/potr/compatcrypto/pycrypto.py index bb003b8..47f7a6c 100644 --- a/potr/compatcrypto/pycrypto.py +++ b/potr/compatcrypto/pycrypto.py @@ -17,14 +17,24 @@ # along with this library. If not, see . -from Cryptodome import Cipher -from Cryptodome.Hash import HMAC as _HMAC -from Cryptodome.Hash import SHA256 as _SHA256 -from Cryptodome.Hash import SHA as _SHA1 -from Cryptodome.PublicKey import DSA -from Cryptodome.Random import random -from Cryptodome.Signature import DSS -from Cryptodome.Util import Counter +try: + from Cryptodome import Cipher + from Cryptodome.Hash import HMAC as _HMAC + from Cryptodome.Hash import SHA256 as _SHA256 + from Cryptodome.Hash import SHA as _SHA1 + from Cryptodome.PublicKey import DSA + from Cryptodome.Random import random + from Cryptodome.Signature import DSS + from Cryptodome.Util import Counter +except ImportError as e: + from Crypto import Cipher + from Crypto.Hash import HMAC as _HMAC + from Crypto.Hash import SHA256 as _SHA256 + from Crypto.Hash import SHA as _SHA1 + from Crypto.PublicKey import DSA + from Crypto.Random import random + from Crypto.Signature import DSS + from Crypto.Util import Counter from numbers import Number