Commit 011ed972 authored by Philipp Hörist's avatar Philipp Hörist

Check encryption before sending message

Check if encryption is activated for a JID before sending the message
parent 3512e2f9
......@@ -1016,7 +1016,6 @@ class ChatControlBase(ChatCommandProcessor, CommandTools, EventHelper):
attention=attention,
correct_id=correct_id,
automatic_message=False,
encryption=self.encryption,
xhtml=xhtml)
con.send_message(message_)
......
......@@ -58,6 +58,7 @@ from gajim.common import modules
from gajim.common import i18n
from gajim.common.i18n import _
from gajim.common.nec import NetworkEvent
from gajim.common.helpers import get_encryption_method
from gajim.common.connection_handlers import ConnectionHandlers
from gajim.common.connection_handlers_events import OurShowEvent
from gajim.common.connection_handlers_events import InformationEvent
......@@ -1332,13 +1333,15 @@ class Connection(CommonConnection, ConnectionHandlers):
stanza = self.get_module('Message').build_message_stanza(message)
message.stanza = stanza
if message.require_encryption:
method = get_encryption_method(message.account, message.jid)
if method is not None:
# TODO: Make extension point return encrypted message
extension = 'encrypt'
if message.is_groupchat:
extension = 'gc_encrypt'
app.plugin_manager.extension_point(extension + message.encryption,
app.plugin_manager.extension_point(extension + method,
self,
message,
self._send_message)
......@@ -1362,10 +1365,6 @@ class Connection(CommonConnection, ConnectionHandlers):
log.warning('Trying to send message while offline')
return
if message.require_encryption:
raise ValueError('Encryption for multi recipient '
'messages not supported')
for jid in jids:
message = message.copy()
message.jid = jid
......
......@@ -27,6 +27,7 @@
from typing import Any # pylint: disable=unused-import
from typing import Dict # pylint: disable=unused-import
from typing import Optional
import sys
import re
......@@ -1748,6 +1749,7 @@ def load_file_async(path, callback, user_data=None):
_on_load_finished,
(callback, user_data))
def _on_load_finished(file, result, user_data):
callback, user_data = user_data
try:
......@@ -1756,3 +1758,9 @@ def _on_load_finished(file, result, user_data):
callback(None, error, user_data)
else:
callback(contents, None, user_data)
def get_encryption_method(account: str, jid: str) -> Optional[str]:
config_key = '%s-%s' % (account, jid)
state = app.config.get_per('encryption', config_key, 'encryption')
return state or None
......@@ -244,8 +244,7 @@ class HTTPUpload(BaseModule):
jid=transfer.contact.jid,
message=uri,
type_=type_,
oob_url=uri,
encryption=transfer.encryption)
oob_url=uri)
self._con.send_message(message)
......
......@@ -17,6 +17,7 @@ from collections import namedtuple
from nbxmpp.protocol import JID
from gajim.common import app
from gajim.common.const import MUCJoinedState
from gajim.common.const import KindConstant
......@@ -68,7 +69,6 @@ class OutgoingMessage:
attention=None,
correct_id=None,
automatic_message=False,
encryption=None,
oob_url=None,
xhtml=None):
......@@ -105,7 +105,6 @@ class OutgoingMessage:
self.attention = attention
self.correct_id = correct_id
self.automatic_message = automatic_message
self.encryption = encryption
self.oob_url = oob_url
......@@ -156,10 +155,6 @@ class OutgoingMessage:
def is_encrypted(self):
return bool(self.additional_data.get_value('encrypted', 'name', False))
@property
def require_encryption(self):
return bool(self.encryption)
@property
def msg_iq(self):
# Backwards compatibility for plugins
......
......@@ -1591,8 +1591,7 @@ class GroupchatControl(ChatControlBase):
type_='groupchat',
label=label,
chatstate=chatstate,
correct_id=correct_id,
encryption=self.encryption)
correct_id=correct_id)
message_.additional_data.set_value('gajim', 'xhtml', xhtml)
con.send_message(message_)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment