1 package org
.asamk
.signal
.manager
;
3 import org
.asamk
.signal
.storage
.groups
.GroupInfo
;
4 import org
.asamk
.signal
.storage
.groups
.GroupInfoV1
;
5 import org
.asamk
.signal
.storage
.groups
.GroupInfoV2
;
6 import org
.signal
.zkgroup
.InvalidInputException
;
7 import org
.signal
.zkgroup
.groups
.GroupMasterKey
;
8 import org
.signal
.zkgroup
.groups
.GroupSecretParams
;
9 import org
.whispersystems
.libsignal
.kdf
.HKDFv3
;
10 import org
.whispersystems
.signalservice
.api
.messages
.SignalServiceDataMessage
;
11 import org
.whispersystems
.signalservice
.api
.messages
.SignalServiceGroup
;
12 import org
.whispersystems
.signalservice
.api
.messages
.SignalServiceGroupV2
;
14 public class GroupUtils
{
16 public static void setGroupContext(
17 final SignalServiceDataMessage
.Builder messageBuilder
, final GroupInfo groupInfo
19 if (groupInfo
instanceof GroupInfoV1
) {
20 SignalServiceGroup group
= SignalServiceGroup
.newBuilder(SignalServiceGroup
.Type
.DELIVER
)
21 .withId(groupInfo
.groupId
)
23 messageBuilder
.asGroupMessage(group
);
25 final GroupInfoV2 groupInfoV2
= (GroupInfoV2
) groupInfo
;
26 SignalServiceGroupV2 group
= SignalServiceGroupV2
.newBuilder(groupInfoV2
.getMasterKey())
27 .withRevision(groupInfoV2
.getGroup() == null ?
0 : groupInfoV2
.getGroup().getRevision())
29 messageBuilder
.asGroupMessage(group
);
33 public static byte[] getGroupId(GroupMasterKey groupMasterKey
) {
34 final GroupSecretParams groupSecretParams
= GroupSecretParams
.deriveFromMasterKey(groupMasterKey
);
35 return groupSecretParams
.getPublicParams().getGroupIdentifier().serialize();
38 public static GroupMasterKey
deriveV2MigrationMasterKey(byte[] groupId
) {
40 return new GroupMasterKey(new HKDFv3().deriveSecrets(groupId
,
41 "GV2 Migration".getBytes(),
42 GroupMasterKey
.SIZE
));
43 } catch (InvalidInputException e
) {
44 throw new AssertionError(e
);