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) 2008-2012 Kjell Braden <afflux@pentabarf.de>
## Copyright (C) 2019 Pavel R. <pd at narayana dot im> ## 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. # This file is part of Gajim OTR Plugin.
@ -21,6 +22,7 @@ import itertools
import logging import logging
from inspect import signature from inspect import signature
from gajim.common import const, app, helpers, configpaths from gajim.common import const, app, helpers, configpaths
from gajim.common.const import EncryptionData
from nbxmpp.protocol import Message, JID from nbxmpp.protocol import Message, JID
import pathlib import pathlib
@ -91,7 +93,7 @@ class OTR(context.Account):
self.account = account self.account = account
self.stream = app.connections[account] self.stream = app.connections[account]
self.jid = self.stream.get_own_jid() 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() self.loadTrusts()
# get chat control # get chat control
@ -107,12 +109,12 @@ class OTR(context.Account):
# load my private key # load my private key
def loadPrivkey(self): 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 return (my and my.privatekey) and crypt.PK.parsePrivateKey(bytes.fromhex(my.privatekey))[0] or None
# save my privatekey # save my privatekey
def savePrivkey(self): 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 # load known fingerprints
def loadTrusts(self): def loadTrusts(self):
@ -121,7 +123,7 @@ class OTR(context.Account):
# save known fingerprints # save known fingerprints
def saveTrusts(self): def saveTrusts(self):
for peer,fingerprints in self.trusts.items(): 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 # decrypt message
def decrypt(self,stanza,properties): def decrypt(self,stanza,properties):
@ -134,8 +136,8 @@ class OTR(context.Account):
self.log.error("** got exception while decrypting message: %s" % e) self.log.error("** got exception while decrypting message: %s" % e)
channel.printl(OTR.STATUS[e].format(msg=msgtxt,err=e.args[0].error)) channel.printl(OTR.STATUS[e].format(msg=msgtxt,err=e.args[0].error))
else: else:
event.setBody(text and text.decode() or "") stanza.setBody(text and text.decode() or "")
properties.encrypted = OTR.ENCRYPTION_NAME properties.encrypted = EncryptionData({'name': OTR.ENCRYPTION_NAME})
finally: finally:
if channel.mayRetransmit and channel.state and ctl: channel.mayRetransmit = ctl.send_message(channel.lastMessage.decode()) if channel.mayRetransmit and channel.state and ctl: channel.mayRetransmit = ctl.send_message(channel.lastMessage.decode())

Loading…
Cancel
Save