From 7d9eafe8fb67ac08f75d0fced6123f833be5465c Mon Sep 17 00:00:00 2001 From: Mikunj Date: Thu, 9 Apr 2020 15:30:29 +1000 Subject: [PATCH] Ignore closed group messages from users who are not members. --- .../groups/GroupMessageProcessor.java | 3 +-- .../securesms/jobs/PushDecryptJob.java | 23 ++++++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/org/thoughtcrime/securesms/groups/GroupMessageProcessor.java b/src/org/thoughtcrime/securesms/groups/GroupMessageProcessor.java index 719a7dd7d8..29e591ffb2 100644 --- a/src/org/thoughtcrime/securesms/groups/GroupMessageProcessor.java +++ b/src/org/thoughtcrime/securesms/groups/GroupMessageProcessor.java @@ -137,8 +137,7 @@ public class GroupMessageProcessor { GroupDatabase database = DatabaseFactory.getGroupDatabase(context); String id = GroupUtil.getEncodedId(group); - String masterHexEncodedPublicKey = TextSecurePreferences.getMasterHexEncodedPublicKey(context); - String ourHexEncodedPublicKey = masterHexEncodedPublicKey != null ? masterHexEncodedPublicKey : TextSecurePreferences.getLocalNumber(context); + String ourHexEncodedPublicKey = getMasterHexEncodedPublicKey(context, TextSecurePreferences.getLocalNumber(context)); if (group.getGroupType() == SignalServiceGroup.GroupType.SIGNAL) { // Only update group if admin sent the message diff --git a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java index 29d3a12172..c421e3ba8b 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java @@ -1895,7 +1895,28 @@ public class PushDecryptJob extends BaseJob implements InjectableType { boolean isGroupActive = groupId.isPresent() && groupDatabase.isActive(groupId.get()); boolean isLeaveMessage = message.getGroupInfo().isPresent() && message.getGroupInfo().get().getType() == SignalServiceGroup.Type.QUIT; - return (isContentMessage && !isGroupActive) || (sender.isBlocked() && !isLeaveMessage); + boolean isClosedGroup = conversation.getAddress().isSignalGroup(); + boolean isGroupMember = true; + + // Only allow messages from members of a group + if (isClosedGroup) { + String senderHexEncodedPublicKey = content.getSender(); + + try { + String masterHexEncodedPublicKey = PromiseUtil.timeout(LokiDeviceLinkUtilities.INSTANCE.getMasterHexEncodedPublicKey(content.getSender()), 5000).get(); + if (masterHexEncodedPublicKey != null) { + senderHexEncodedPublicKey = masterHexEncodedPublicKey; + } + } catch (Exception e) { + e.printStackTrace(); + } + + Recipient senderMaster = Recipient.from(context, Address.fromSerialized(senderHexEncodedPublicKey), false); + + isGroupMember = groupId.isPresent() && groupDatabase.getGroupMembers(groupId.get(), true).contains(senderMaster); + } + + return (isContentMessage && !isGroupActive) || (sender.isBlocked() && !isLeaveMessage) || (isContentMessage && !isGroupMember); } else { return sender.isBlocked(); }