From a33984acc5b0431d24bc965b99d1bb44ff7073a7 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sat, 27 Jan 2018 20:55:43 +0100 Subject: [PATCH] encrypt muc PM only to actual recipient --- .../crypto/axolotl/AxolotlService.java | 29 +++++++++++++++---- .../ui/ConversationFragment.java | 6 ++-- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java b/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java index 701155e10..1eb4b4a03 100644 --- a/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java +++ b/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java @@ -1234,6 +1234,23 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { return true; } + //this is being used for private muc messages only + private boolean buildHeader(XmppAxolotlMessage axolotlMessage, Jid jid) { + if (jid == null) { + return false; + } + HashSet sessions = new HashSet<>(); + sessions.addAll(this.sessions.getAll(getAddressForJid(jid).getName()).values()); + if (sessions.isEmpty()) { + return false; + } + sessions.addAll(findOwnSessions()); + for(XmppAxolotlSession session : sessions) { + axolotlMessage.addDevice(session); + } + return true; + } + @Nullable public XmppAxolotlMessage encrypt(Message message) { final XmppAxolotlMessage axolotlMessage = new XmppAxolotlMessage(account.getJid().toBareJid(), getOwnDeviceId()); @@ -1249,12 +1266,14 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { Log.w(Config.LOGTAG, getLogprefix(account) + "Failed to encrypt message: " + e.getMessage()); return null; } - //TODO: fix this for MUC PMs - Don't encrypt to all participants - if (!buildHeader(axolotlMessage, message.getConversation())) { - return null; - } - return axolotlMessage; + final boolean success; + if (message.getType() == Message.TYPE_PRIVATE) { + success = buildHeader(axolotlMessage, message.getTrueCounterpart()); + } else { + success = buildHeader(axolotlMessage, message.getConversation()); + } + return success ? axolotlMessage : null; } public void preparePayloadMessage(final Message message, final boolean delay) { diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index 944fdeee3..d7b6ea8a5 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -469,8 +469,10 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa if (conversation.getCorrectingMessage() == null) { message = new Message(conversation, body, conversation.getNextEncryption()); if (conversation.getMode() == Conversation.MODE_MULTI) { - if (conversation.getNextCounterpart() != null) { - message.setCounterpart(conversation.getNextCounterpart()); + final Jid nextCounterpart = conversation.getNextCounterpart(); + if (nextCounterpart != null) { + message.setCounterpart(nextCounterpart); + message.setTrueCounterpart(conversation.getMucOptions().getTrueCounterpart(nextCounterpart)); message.setType(Message.TYPE_PRIVATE); } }