Search in sources :

Example 76 with ProfileKey

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

the class GroupsV2Operations_decrypt_change_Test method can_decrypt_member_direct_join_field3.

@Test
public void can_decrypt_member_direct_join_field3() {
    UUID newMember = UUID.randomUUID();
    ProfileKey profileKey = newProfileKey();
    GroupCandidate groupCandidate = groupCandidate(newMember, profileKey);
    assertDecryption(groupOperations.createGroupJoinDirect(groupCandidate.getProfileKeyCredential().get()).setRevision(10), DecryptedGroupChange.newBuilder().setRevision(10).addNewMembers(DecryptedMember.newBuilder().setRole(Member.Role.DEFAULT).setProfileKey(ByteString.copyFrom(profileKey.serialize())).setJoinedAtRevision(10).setUuid(UuidUtil.toByteString(newMember))));
}
Also used : UUID(java.util.UUID) ProfileKey(org.signal.zkgroup.profiles.ProfileKey) Test(org.junit.Test)

Example 77 with ProfileKey

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

the class ProfileUtil method getProfileKey.

private static ProfileKey getProfileKey(@NonNull Recipient recipient) throws IOException {
    byte[] profileKeyBytes = recipient.getProfileKey();
    if (profileKeyBytes == null) {
        Log.w(TAG, "Profile key unknown for " + recipient.getId());
        throw new IOException("No profile key");
    }
    ProfileKey profileKey;
    try {
        profileKey = new ProfileKey(profileKeyBytes);
    } catch (InvalidInputException e) {
        Log.w(TAG, "Profile key invalid for " + recipient.getId());
        throw new IOException("Invalid profile key");
    }
    return profileKey;
}
Also used : InvalidInputException(org.signal.zkgroup.InvalidInputException) IOException(java.io.IOException) ProfileKey(org.signal.zkgroup.profiles.ProfileKey)

Example 78 with ProfileKey

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

the class TextSecurePreferences method clearLocalCredentials.

private static void clearLocalCredentials(Context context) {
    ProfileKey newProfileKey = ProfileKeyUtil.createNew();
    Recipient self = Recipient.self();
    SignalDatabase.recipients().setProfileKey(self.getId(), newProfileKey);
    ApplicationDependencies.getGroupsV2Authorization().clear();
}
Also used : Recipient(org.thoughtcrime.securesms.recipients.Recipient) ProfileKey(org.signal.zkgroup.profiles.ProfileKey)

Example 79 with ProfileKey

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

the class GroupChangeUtil_resolveConflict_decryptedOnly_Test method field_6__profile_key_changes.

@Test
public void field_6__profile_key_changes() {
    UUID member1 = UUID.randomUUID();
    UUID member2 = UUID.randomUUID();
    UUID member3 = UUID.randomUUID();
    UUID memberNotInGroup = UUID.randomUUID();
    ProfileKey profileKey1 = randomProfileKey();
    ProfileKey profileKey2 = randomProfileKey();
    ProfileKey profileKey3 = randomProfileKey();
    ProfileKey profileKey4 = randomProfileKey();
    ProfileKey profileKey2b = randomProfileKey();
    DecryptedGroup groupState = DecryptedGroup.newBuilder().addMembers(member(member1, profileKey1)).addMembers(member(member2, profileKey2)).addMembers(member(member3, profileKey3)).build();
    DecryptedGroupChange decryptedChange = DecryptedGroupChange.newBuilder().addModifiedProfileKeys(member(member1, profileKey1)).addModifiedProfileKeys(member(member2, profileKey2b)).addModifiedProfileKeys(member(member3, profileKey3)).addModifiedProfileKeys(member(memberNotInGroup, profileKey4)).build();
    DecryptedGroupChange resolvedChanges = GroupChangeUtil.resolveConflict(groupState, decryptedChange).build();
    DecryptedGroupChange expected = DecryptedGroupChange.newBuilder().addModifiedProfileKeys(member(member2, profileKey2b)).build();
    assertEquals(expected, resolvedChanges);
}
Also used : DecryptedGroupChange(org.signal.storageservice.protos.groups.local.DecryptedGroupChange) UUID(java.util.UUID) ProtoTestUtils.randomProfileKey(org.whispersystems.signalservice.api.groupsv2.ProtoTestUtils.randomProfileKey) ProfileKey(org.signal.zkgroup.profiles.ProfileKey) DecryptedGroup(org.signal.storageservice.protos.groups.local.DecryptedGroup) Test(org.junit.Test)

Example 80 with ProfileKey

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

the class ProfileCipherTest method testEncryptDecrypt.

@Test
public void testEncryptDecrypt() throws InvalidCiphertextException, InvalidInputException {
    ProfileKey key = new ProfileKey(Util.getSecretBytes(32));
    ProfileCipher cipher = new ProfileCipher(key);
    byte[] name = cipher.encrypt("Clement\0Duval".getBytes(), 53);
    String plaintext = cipher.decryptString(name);
    assertEquals(plaintext, "Clement\0Duval");
}
Also used : ProfileKey(org.signal.zkgroup.profiles.ProfileKey) 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