Derive GV2 master key and group id from GV1.

This commit is contained in:
Alan Evans
2020-10-13 10:15:37 -03:00
committed by Greyson Parrelli
parent 9effa47dd8
commit babe1833bb
2 changed files with 69 additions and 4 deletions

View File

@@ -3,11 +3,13 @@ package org.thoughtcrime.securesms.groups;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.signal.zkgroup.InvalidInputException;
import org.signal.zkgroup.groups.GroupIdentifier;
import org.signal.zkgroup.groups.GroupMasterKey;
import org.signal.zkgroup.groups.GroupSecretParams;
import org.thoughtcrime.securesms.util.Hex;
import org.thoughtcrime.securesms.util.Util;
import org.whispersystems.libsignal.kdf.HKDFv3;
import java.io.IOException;
import java.security.SecureRandom;
@@ -258,13 +260,25 @@ public abstract class GroupId {
@Override
public boolean isV1() {
return true;
}
return true;
}
@Override
public boolean isV2() {
return false;
}
return false;
}
public GroupMasterKey deriveV2MigrationMasterKey() {
try {
return new GroupMasterKey(new HKDFv3().deriveSecrets(getDecodedId(), "GV2 Migration".getBytes(), GroupMasterKey.SIZE));
} catch (InvalidInputException e) {
throw new AssertionError(e);
}
}
public GroupId.V2 deriveV2MigrationGroupId() {
return v2(deriveV2MigrationMasterKey());
}
}
public static final class V2 extends GroupId.Push {