Gajim 1.3 compatibility fixes [WIP]

dev
Bohdan Horbeshko 2 years ago
parent f47352751d
commit 247602d0f7

@ -1,5 +1,6 @@
## Copyright (C) 2008-2012 Kjell Braden <afflux@pentabarf.de>
## Copyright (C) 2019 Pavel R. <pd at narayana dot im>
## Copyright (C) 2022 Bohdan Horbeshko <bodqhrohro@gmail.com>
#
# This file is part of Gajim OTR Plugin.
@ -21,6 +22,7 @@ import itertools
import logging
from inspect import signature
from gajim.common import const, app, helpers, configpaths
from gajim.common.const import EncryptionData
from nbxmpp.protocol import Message, JID
import pathlib
@ -91,7 +93,7 @@ class OTR(context.Account):
self.account = account
self.stream = app.connections[account]
self.jid = self.stream.get_own_jid()
self.keystore = Keystore(os.path.join(configpaths.get('MY_DATA'), 'otr_' + self.jid.getStripped() + '.db'))
self.keystore = Keystore(os.path.join(configpaths.get('MY_DATA'), 'otr_' + self.jid.bare + '.db'))
self.loadTrusts()
# get chat control
@ -107,12 +109,12 @@ class OTR(context.Account):
# load my private key
def loadPrivkey(self):
my = self.keystore.load(jid=self.jid)
my = self.keystore.load(jid=str(self.jid))
return (my and my.privatekey) and crypt.PK.parsePrivateKey(bytes.fromhex(my.privatekey))[0] or None
# save my privatekey
def savePrivkey(self):
self.keystore.save(jid=self.jid,privatekey=self.getPrivkey().serializePrivateKey().hex())
self.keystore.save(jid=str(self.jid),privatekey=self.getPrivkey().serializePrivateKey().hex())
# load known fingerprints
def loadTrusts(self):
@ -121,7 +123,7 @@ class OTR(context.Account):
# save known fingerprints
def saveTrusts(self):
for peer,fingerprints in self.trusts.items():
for fingerprint,trust in fingerprints.items(): self.keystore.save(jid=peer,fingerprint=fingerprint,trust=trust)
for fingerprint,trust in fingerprints.items(): self.keystore.save(jid=str(peer),fingerprint=fingerprint,trust=trust)
# decrypt message
def decrypt(self,stanza,properties):
@ -134,8 +136,8 @@ 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:
event.setBody(text and text.decode() or "")
properties.encrypted = OTR.ENCRYPTION_NAME
stanza.setBody(text and text.decode() or "")
properties.encrypted = EncryptionData({'name': OTR.ENCRYPTION_NAME})
finally:
if channel.mayRetransmit and channel.state and ctl: channel.mayRetransmit = ctl.send_message(channel.lastMessage.decode())

Loading…
Cancel
Save