Support the GroupsV2 "end group" (terminate) feature (#2098)

* Show and enforce the terminated state of a group

A group admin can permanently terminate a group. Afterwards the group is
read-only for everyone, not even an admin can send messages or start calls;
members keep access to the existing history. Other clients silently drop
messages sent to a terminated group.

Read the DecryptedGroup.terminated flag through GroupInfo.isTerminated() and:

- surface it in listGroups (json and plain text) and as the DBus IsTerminated
  group property
- refuse to send to a terminated group locally (messages, reactions, typing and
  group stories) rather than send one that other clients ignore
- drop incoming messages addressed to a terminated group

* Add terminateGroup command to terminate a group for everyone

Let a group admin permanently terminate a GroupV2 group via the
TerminateGroupAction (Groups.proto field 28, change epoch 7) the pinned library
already exposes as GroupsV2Operations.createTerminateGroup().

- GroupV2Helper.terminateGroup builds and commits the change
- GroupHelper.terminateGroup resolves/refreshes the group (v2 only), sends the
  update to members and syncs storage, with the same conflict-retry as
  updateGroup
- exposed through Manager.terminateGroup, the terminateGroup CLI/JSON-RPC command
  and the DBus Group.terminateGroup method

---------

Co-authored-by: FailSpy <FailSpy@users.noreply.github.com>
This commit is contained in:
Javair RatliffandFailSpy authored and GitHub committed 2026-08-08 17:16:49 +02:00
1 parent 85580d1ff6
commit 13819c8f09
19 files changed
+291 -9

No files matched your search

@@ -184,6 +184,10 @@ public interface Manager extends Closeable {
void deleteGroup(GroupId groupId) throws IOException;
SendGroupMessageResults terminateGroup(
GroupId groupId
) throws IOException, GroupNotFoundException, NotAGroupMemberException;
Pair<GroupId, SendGroupMessageResults> createGroup(
String name,
Set<RecipientIdentifier.Single> members,
@@ -22,7 +22,8 @@ public record Group(
GroupPermission permissionEditDetails,
GroupPermission permissionSendMessage,
boolean isMember,
boolean isAdmin
boolean isAdmin,
boolean isTerminated
) {
public static Group from(
@@ -59,6 +60,7 @@ public record Group(
groupInfo.getPermissionEditDetails(),
groupInfo.getPermissionSendMessage(),
groupInfo.isMember(selfRecipientId),
groupInfo.isAdmin(selfRecipientId));
groupInfo.isAdmin(selfRecipientId),
groupInfo.isTerminated());
}
}
@@ -363,6 +363,28 @@ public class GroupHelper {
return results;
}
public SendGroupMessageResults terminateGroup(final GroupId groupId) throws IOException, GroupNotFoundException, NotAGroupMemberException {
final var group = getGroupForUpdating(groupId);
if (!(group instanceof GroupInfoV2)) {
throw new IOException("Terminating a group is only supported for Signal group v2 groups.");
}
SendGroupMessageResults results;
try {
results = terminateGroupV2((GroupInfoV2) group);
} catch (ConflictException e) {
// Detected conflicting update, refreshing group and trying again
results = terminateGroupV2((GroupInfoV2) getGroup(groupId, true));
}
context.getJobExecutor().enqueueJob(new SyncStorageJob());
return results;
}
private SendGroupMessageResults terminateGroupV2(final GroupInfoV2 group) throws IOException {
final var groupGroupChangePair = context.getGroupV2Helper().terminateGroup(group);
return sendUpdateGroupV2Message(group, groupGroupChangePair.first(), groupGroupChangePair.second());
}
public void updateGroupProfileKey(GroupIdV2 groupId) throws GroupNotFoundException, NotAGroupMemberException, IOException {
var group = getGroupForUpdating(groupId);
@@ -543,6 +543,14 @@ class GroupV2Helper {
return commitChange(groupInfoV2, change);
}
Pair<DecryptedGroup, GroupChangeResponse> terminateGroup(
GroupInfoV2 groupInfoV2
) throws IOException {
final GroupsV2Operations.GroupOperations groupOperations = getGroupOperations(groupInfoV2);
final var change = groupOperations.createTerminateGroup();
return commitChange(groupInfoV2, change);
}
Pair<DecryptedGroup, GroupChangeResponse> setMemberLabels(
GroupInfoV2 groupInfoV2,
String labelEmoji,
@@ -837,6 +837,15 @@ public final class IncomingMessageHandler {
return true;
}
if (group.isTerminated()) {
return message == null
|| message.getBody().isPresent()
|| message.getAttachments().isPresent()
|| message.getQuote().isPresent()
|| message.getPreviews().isPresent()
|| message.getMentions().isPresent()
|| message.getSticker().isPresent();
}
if (group.isAnnouncementGroup() && !group.isAdmin(recipientId)) {
return message == null
|| message.getBody().isPresent()
@@ -567,7 +567,7 @@ public class SendHelper {
return results;
}
private GroupInfo getGroupForSending(GroupId groupId) throws GroupNotFoundException, NotAGroupMemberException {
private GroupInfo getGroupForSending(GroupId groupId) throws GroupNotFoundException, NotAGroupMemberException, GroupSendingNotAllowedException {
var g = context.getGroupHelper().getGroup(groupId);
if (g == null) {
throw new GroupNotFoundException(groupId);
@@ -575,6 +575,10 @@ public class SendHelper {
if (!g.isMember(account.getSelfRecipientId())) {
throw new NotAGroupMemberException(groupId, g.getTitle());
}
if (g.isTerminated()) {
// Other clients drop messages sent to a terminated group.
throw new GroupSendingNotAllowedException(groupId, g.getTitle());
}
if (!g.isProfileSharingEnabled()) {
g.setProfileSharingEnabled(true);
account.getGroupStore().updateGroup(g);
@@ -610,6 +610,11 @@ public class ManagerImpl implements Manager {
context.getGroupHelper().deleteGroup(groupId);
}
@Override
public SendGroupMessageResults terminateGroup(GroupId groupId) throws IOException, GroupNotFoundException, NotAGroupMemberException {
return context.getGroupHelper().terminateGroup(groupId);
}
@Override
public Pair<GroupId, SendGroupMessageResults> createGroup(
String name,
@@ -912,6 +917,10 @@ public class ManagerImpl implements Manager {
if (!(groupInfo instanceof GroupInfoV2 groupInfoV2)) {
throw new IOException("Stories are only supported for V2 groups");
}
if (groupInfoV2.isTerminated()) {
// Other clients drop messages sent to a terminated group.
throw new IOException("Cannot send a story to a group that has been terminated");
}
final var uploadedAttachment = context.getAttachmentHelper().uploadAttachment(attachment);
final var groupContext = SignalServiceGroupV2.newBuilder(groupInfoV2.getMasterKey())
@@ -66,6 +66,8 @@ public sealed abstract class GroupInfo permits GroupInfoV1, GroupInfoV2 {
public abstract boolean isAnnouncementGroup();
public abstract boolean isTerminated();
public abstract GroupPermission getPermissionAddMember();
public abstract GroupPermission getPermissionEditDetails();
@@ -113,6 +113,11 @@ public final class GroupInfoV1 extends GroupInfo {
return false;
}
@Override
public boolean isTerminated() {
return false;
}
@Override
public GroupPermission getPermissionAddMember() {
return GroupPermission.EVERY_MEMBER;
@@ -211,6 +211,11 @@ public final class GroupInfoV2 extends GroupInfo {
return this.group != null && this.group.isAnnouncementGroup == EnabledState.ENABLED;
}
@Override
public boolean isTerminated() {
return this.group != null && Boolean.TRUE.equals(this.group.terminated);
}
@Override
public GroupPermission getPermissionAddMember() {
final var accessControl = getAccessControl();
@@ -0,0 +1,104 @@
package org.asamk.signal.manager.storage.groups;
import org.asamk.signal.manager.api.Group;
import org.asamk.signal.manager.api.GroupId;
import org.asamk.signal.manager.api.GroupIdV2;
import org.asamk.signal.manager.groups.GroupUtils;
import org.asamk.signal.manager.storage.recipients.RecipientAddress;
import org.asamk.signal.manager.storage.recipients.RecipientId;
import org.asamk.signal.manager.storage.recipients.RecipientResolver;
import org.asamk.signal.manager.storage.recipients.TestRecipientId;
import org.junit.jupiter.api.Test;
import org.signal.core.models.ServiceId;
import org.signal.libsignal.zkgroup.InvalidInputException;
import org.signal.libsignal.zkgroup.groups.GroupMasterKey;
import org.signal.storageservice.storage.protos.groups.local.DecryptedGroup;
import org.whispersystems.signalservice.api.push.DistributionId;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
class GroupInfoTerminatedTest {
private static final RecipientResolver UNUSED_RESOLVER = new RecipientResolver() {
@Override
public RecipientId resolveRecipient(final RecipientAddress address) {
throw new UnsupportedOperationException();
}
@Override
public RecipientId resolveRecipient(final long recipientId) {
throw new UnsupportedOperationException();
}
@Override
public RecipientId resolveRecipient(final String identifier) {
throw new UnsupportedOperationException();
}
@Override
public RecipientId resolveRecipient(final ServiceId serviceId) {
throw new UnsupportedOperationException();
}
};
private static GroupMasterKey masterKey() {
final var bytes = new byte[32];
for (int i = 0; i < bytes.length; i++) {
bytes[i] = (byte) (i + 1);
}
try {
return new GroupMasterKey(bytes);
} catch (InvalidInputException e) {
throw new AssertionError(e);
}
}
private static GroupInfoV2 groupV2(final DecryptedGroup group) {
final var masterKey = masterKey();
return new GroupInfoV2(GroupUtils.getGroupIdV2(masterKey),
masterKey,
group,
DistributionId.create(),
false,
false,
false,
null,
UNUSED_RESOLVER);
}
@Test
void v1GroupsAreNeverTerminated() {
final var group = new GroupInfoV1(GroupId.v1(new byte[16]));
assertFalse(group.isTerminated());
}
@Test
void v2ReadsTerminatedFlagFromDecryptedGroup() {
assertTrue(groupV2(new DecryptedGroup.Builder().terminated(true).build()).isTerminated());
assertFalse(groupV2(new DecryptedGroup.Builder().terminated(false).build()).isTerminated());
assertFalse(groupV2(new DecryptedGroup.Builder().build()).isTerminated());
}
@Test
void v2IsNotTerminatedWhenGroupStateMissing() {
final var masterKey = masterKey();
final var group = new GroupInfoV2(GroupUtils.getGroupIdV2(masterKey), masterKey, UNUSED_RESOLVER);
assertFalse(group.isTerminated());
}
@Test
void groupApiRecordCarriesTerminatedFromModel() {
final RecipientId self = TestRecipientId.createTestId(1);
final var terminated = Group.from(groupV2(new DecryptedGroup.Builder().terminated(true).build()),
recipientId -> null,
self);
assertTrue(terminated.isTerminated());
final var live = Group.from(groupV2(new DecryptedGroup.Builder().terminated(false).build()),
recipientId -> null,
self);
assertFalse(live.isTerminated());
}
}