Search in sources :

Example 56 with ProfileKey

use of org.signal.zkgroup.profiles.ProfileKey in project Signal-Android by signalapp.

the class ProfileKeySetTest method new_member_by_self_is_authoritative.

@Test
public void new_member_by_self_is_authoritative() {
    UUID newMember = UUID.randomUUID();
    ProfileKey profileKey = ProfileKeyUtil.createNew();
    ProfileKeySet profileKeySet = new ProfileKeySet();
    profileKeySet.addKeysFromGroupChange(changeBy(newMember).addMember(newMember, profileKey).build());
    assertTrue(profileKeySet.getProfileKeys().isEmpty());
    assertThat(profileKeySet.getAuthoritativeProfileKeys(), is(Collections.singletonMap(ACI.from(newMember), profileKey)));
}
Also used : UUID(java.util.UUID) ProfileKey(org.signal.zkgroup.profiles.ProfileKey) Test(org.junit.Test)

Example 57 with ProfileKey

use of org.signal.zkgroup.profiles.ProfileKey in project Signal-Android by signalapp.

the class ProfileKeySetTest method new_member_by_promote_by_unknown_editor_is_not_authoritative.

@Test
public void new_member_by_promote_by_unknown_editor_is_not_authoritative() {
    UUID newMember = UUID.randomUUID();
    ProfileKey profileKey = ProfileKeyUtil.createNew();
    ProfileKeySet profileKeySet = new ProfileKeySet();
    profileKeySet.addKeysFromGroupChange(changeByUnknown().promote(newMember, profileKey).build());
    assertTrue(profileKeySet.getAuthoritativeProfileKeys().isEmpty());
    assertThat(profileKeySet.getProfileKeys(), is(Collections.singletonMap(ACI.from(newMember), profileKey)));
}
Also used : UUID(java.util.UUID) ProfileKey(org.signal.zkgroup.profiles.ProfileKey) Test(org.junit.Test)

Example 58 with ProfileKey

use of org.signal.zkgroup.profiles.ProfileKey in project Signal-Android by signalapp.

the class ProfileKeySetTest method authoritative_takes_priority_when_seen_first.

@Test
public void authoritative_takes_priority_when_seen_first() {
    UUID editor = UUID.randomUUID();
    UUID member = UUID.randomUUID();
    ProfileKey profileKey1 = ProfileKeyUtil.createNew();
    ProfileKey profileKey2 = ProfileKeyUtil.createNew();
    ProfileKeySet profileKeySet = new ProfileKeySet();
    profileKeySet.addKeysFromGroupChange(changeBy(member).profileKeyUpdate(member, profileKey1).build());
    profileKeySet.addKeysFromGroupChange(changeBy(editor).profileKeyUpdate(member, profileKey2).build());
    assertTrue(profileKeySet.getProfileKeys().isEmpty());
    assertThat(profileKeySet.getAuthoritativeProfileKeys(), is(Collections.singletonMap(ACI.from(member), profileKey1)));
}
Also used : UUID(java.util.UUID) ProfileKey(org.signal.zkgroup.profiles.ProfileKey) Test(org.junit.Test)

Example 59 with ProfileKey

use of org.signal.zkgroup.profiles.ProfileKey in project Signal-Android by signalapp.

the class ProfileKeySetTest method multiple_updates_overwrite.

@Test
public void multiple_updates_overwrite() {
    UUID editor = UUID.randomUUID();
    UUID member = UUID.randomUUID();
    ProfileKey profileKey1 = ProfileKeyUtil.createNew();
    ProfileKey profileKey2 = ProfileKeyUtil.createNew();
    ProfileKeySet profileKeySet = new ProfileKeySet();
    profileKeySet.addKeysFromGroupChange(changeBy(editor).profileKeyUpdate(member, profileKey1).build());
    profileKeySet.addKeysFromGroupChange(changeBy(editor).profileKeyUpdate(member, profileKey2).build());
    assertTrue(profileKeySet.getAuthoritativeProfileKeys().isEmpty());
    assertThat(profileKeySet.getProfileKeys(), is(Collections.singletonMap(ACI.from(member), profileKey2)));
}
Also used : UUID(java.util.UUID) ProfileKey(org.signal.zkgroup.profiles.ProfileKey) Test(org.junit.Test)

Example 60 with ProfileKey

use of org.signal.zkgroup.profiles.ProfileKey in project Signal-Android by signalapp.

the class DecryptedGroupUtil_apply_Test method apply_modify_member_profile_keys.

@Test
public void apply_modify_member_profile_keys() throws NotAbleToApplyGroupV2ChangeException {
    ProfileKey profileKey1 = randomProfileKey();
    ProfileKey profileKey2a = randomProfileKey();
    ProfileKey profileKey2b = randomProfileKey();
    DecryptedMember member1 = member(UUID.randomUUID(), profileKey1);
    DecryptedMember member2a = member(UUID.randomUUID(), profileKey2a);
    DecryptedMember member2b = withProfileKey(member2a, profileKey2b);
    DecryptedGroup newGroup = DecryptedGroupUtil.apply(DecryptedGroup.newBuilder().setRevision(13).addMembers(member1).addMembers(member2a).build(), DecryptedGroupChange.newBuilder().setRevision(14).addModifiedProfileKeys(member2b).build());
    assertEquals(DecryptedGroup.newBuilder().setRevision(14).addMembers(member1).addMembers(member2b).build(), newGroup);
}
Also used : ProtoTestUtils.withProfileKey(org.whispersystems.signalservice.api.groupsv2.ProtoTestUtils.withProfileKey) ProfileKey(org.signal.zkgroup.profiles.ProfileKey) ProtoTestUtils.randomProfileKey(org.whispersystems.signalservice.api.groupsv2.ProtoTestUtils.randomProfileKey) ProtoTestUtils.newProfileKey(org.whispersystems.signalservice.api.groupsv2.ProtoTestUtils.newProfileKey) DecryptedGroup(org.signal.storageservice.protos.groups.local.DecryptedGroup) DecryptedMember(org.signal.storageservice.protos.groups.local.DecryptedMember) Test(org.junit.Test)

Aggregations

ProfileKey (org.signal.zkgroup.profiles.ProfileKey)150 Test (org.junit.Test)102 UUID (java.util.UUID)90 DecryptedGroup (org.signal.storageservice.protos.groups.local.DecryptedGroup)50 ProtoTestUtils.randomProfileKey (org.whispersystems.signalservice.api.groupsv2.ProtoTestUtils.randomProfileKey)50 DecryptedGroupChange (org.signal.storageservice.protos.groups.local.DecryptedGroupChange)34 ProtoTestUtils.newProfileKey (org.whispersystems.signalservice.api.groupsv2.ProtoTestUtils.newProfileKey)28 ProtoTestUtils.withProfileKey (org.whispersystems.signalservice.api.groupsv2.ProtoTestUtils.withProfileKey)28 IOException (java.io.IOException)24 GroupChange (org.signal.storageservice.protos.groups.GroupChange)14 DecryptedMember (org.signal.storageservice.protos.groups.local.DecryptedMember)14 InvalidCiphertextException (org.whispersystems.signalservice.api.crypto.InvalidCiphertextException)12 InvalidInputException (org.signal.zkgroup.InvalidInputException)8 ProfileKeyCredential (org.signal.zkgroup.profiles.ProfileKeyCredential)8 Recipient (org.thoughtcrime.securesms.recipients.Recipient)8 InvalidKeyException (org.whispersystems.libsignal.InvalidKeyException)8 NonNull (androidx.annotation.NonNull)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 RecipientDatabase (org.thoughtcrime.securesms.database.RecipientDatabase)6 IdentityKey (org.whispersystems.libsignal.IdentityKey)6