Migrate local group to v2 if another member has migrated it

This commit is contained in:
AsamK 2020-12-12 11:14:36 +01:00
parent f6061f95de
commit c10910e466
7 changed files with 101 additions and 34 deletions

View file

@ -3,6 +3,10 @@ package org.asamk.signal.manager;
import org.asamk.signal.storage.groups.GroupInfo;
import org.asamk.signal.storage.groups.GroupInfoV1;
import org.asamk.signal.storage.groups.GroupInfoV2;
import org.signal.zkgroup.InvalidInputException;
import org.signal.zkgroup.groups.GroupMasterKey;
import org.signal.zkgroup.groups.GroupSecretParams;
import org.whispersystems.libsignal.kdf.HKDFv3;
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
import org.whispersystems.signalservice.api.messages.SignalServiceGroup;
import org.whispersystems.signalservice.api.messages.SignalServiceGroupV2;
@ -25,4 +29,19 @@ public class GroupUtils {
messageBuilder.asGroupMessage(group);
}
}
public static byte[] getGroupId(GroupMasterKey groupMasterKey) {
final GroupSecretParams groupSecretParams = GroupSecretParams.deriveFromMasterKey(groupMasterKey);
return groupSecretParams.getPublicParams().getGroupIdentifier().serialize();
}
public static GroupMasterKey deriveV2MigrationMasterKey(byte[] groupId) {
try {
return new GroupMasterKey(new HKDFv3().deriveSecrets(groupId,
"GV2 Migration".getBytes(),
GroupMasterKey.SIZE));
} catch (InvalidInputException e) {
throw new AssertionError(e);
}
}
}