|
|
|
@ -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)
|
|
|
|
|