Search in sources :

Example 1 with UuidCiphertext

use of org.signal.zkgroup.groups.UuidCiphertext in project Signal-Android by WhisperSystems.

the class PendingMemberInvitesViewModel method revokeInviteFor.

void revokeInviteFor(@NonNull GroupMemberEntry.PendingMember pendingMember) {
    UuidCiphertext inviteeCipherText = pendingMember.getInviteeCipherText();
    InviteRevokeConfirmationDialog.showOwnInviteRevokeConfirmationDialog(context, pendingMember.getInvitee(), () -> SimpleTask.run(() -> {
        pendingMember.setBusy(true);
        try {
            return pendingMemberRepository.revokeInvites(Collections.singleton(inviteeCipherText));
        } finally {
            pendingMember.setBusy(false);
        }
    }, result -> {
        if (result) {
            ArrayList<GroupMemberEntry.PendingMember> newList = new ArrayList<>(whoYouInvited.getValue());
            Iterator<GroupMemberEntry.PendingMember> iterator = newList.iterator();
            while (iterator.hasNext()) {
                if (iterator.next().getInviteeCipherText().equals(inviteeCipherText)) {
                    iterator.remove();
                }
            }
            whoYouInvited.setValue(newList);
        } else {
            toastErrorCanceling(1);
        }
    }));
}
Also used : Context(android.content.Context) LiveData(androidx.lifecycle.LiveData) Iterator(java.util.Iterator) ViewModelProvider(androidx.lifecycle.ViewModelProvider) NonNull(androidx.annotation.NonNull) ViewModel(androidx.lifecycle.ViewModel) R(org.thoughtcrime.securesms.R) ArrayList(java.util.ArrayList) List(java.util.List) UuidCiphertext(org.signal.zkgroup.groups.UuidCiphertext) Toast(android.widget.Toast) GroupId(org.thoughtcrime.securesms.groups.GroupId) DefaultValueLiveData(org.thoughtcrime.securesms.util.DefaultValueLiveData) GroupMemberEntry(org.thoughtcrime.securesms.groups.ui.GroupMemberEntry) SimpleTask(org.thoughtcrime.securesms.util.concurrent.SimpleTask) Collections(java.util.Collections) UuidCiphertext(org.signal.zkgroup.groups.UuidCiphertext) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) GroupMemberEntry(org.thoughtcrime.securesms.groups.ui.GroupMemberEntry)

Example 2 with UuidCiphertext

use of org.signal.zkgroup.groups.UuidCiphertext in project Signal-Android by WhisperSystems.

the class GroupManagerV2 method getUuidCipherTexts.

@WorkerThread
@NonNull
Map<UUID, UuidCiphertext> getUuidCipherTexts(@NonNull GroupId.V2 groupId) {
    GroupDatabase.GroupRecord groupRecord = SignalDatabase.groups().requireGroup(groupId);
    GroupDatabase.V2GroupProperties v2GroupProperties = groupRecord.requireV2GroupProperties();
    GroupMasterKey groupMasterKey = v2GroupProperties.getGroupMasterKey();
    ClientZkGroupCipher clientZkGroupCipher = new ClientZkGroupCipher(GroupSecretParams.deriveFromMasterKey(groupMasterKey));
    List<Recipient> recipients = v2GroupProperties.getMemberRecipients(GroupDatabase.MemberSet.FULL_MEMBERS_INCLUDING_SELF);
    Map<UUID, UuidCiphertext> uuidCipherTexts = new HashMap<>();
    for (Recipient recipient : recipients) {
        uuidCipherTexts.put(recipient.requireServiceId().uuid(), clientZkGroupCipher.encryptUuid(recipient.requireServiceId().uuid()));
    }
    return uuidCipherTexts;
}
Also used : HashMap(java.util.HashMap) UuidCiphertext(org.signal.zkgroup.groups.UuidCiphertext) GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) GroupMasterKey(org.signal.zkgroup.groups.GroupMasterKey) Recipient(org.thoughtcrime.securesms.recipients.Recipient) ClientZkGroupCipher(org.signal.zkgroup.groups.ClientZkGroupCipher) UUID(java.util.UUID) WorkerThread(androidx.annotation.WorkerThread) NonNull(androidx.annotation.NonNull)

Example 3 with UuidCiphertext

use of org.signal.zkgroup.groups.UuidCiphertext in project Signal-Android by WhisperSystems.

the class GroupsV2Operations_decrypt_change_Test method can_decrypt_pending_member_removals_field8.

@Test
public void can_decrypt_pending_member_removals_field8() throws InvalidInputException {
    UUID oldMember = UUID.randomUUID();
    UuidCiphertext uuidCiphertext = new UuidCiphertext(groupOperations.encryptUuid(oldMember).toByteArray());
    assertDecryption(groupOperations.createRemoveInvitationChange(Collections.singleton(uuidCiphertext)), DecryptedGroupChange.newBuilder().addDeletePendingMembers(DecryptedPendingMemberRemoval.newBuilder().setUuid(UuidUtil.toByteString(oldMember)).setUuidCipherText(ByteString.copyFrom(uuidCiphertext.serialize()))));
}
Also used : UuidCiphertext(org.signal.zkgroup.groups.UuidCiphertext) UUID(java.util.UUID) Test(org.junit.Test)

Example 4 with UuidCiphertext

use of org.signal.zkgroup.groups.UuidCiphertext in project Signal-Android by WhisperSystems.

the class PendingMemberInvitesRepository method getInvitees.

public void getInvitees(@NonNull Consumer<InviteeResult> onInviteesLoaded) {
    executor.execute(() -> {
        GroupDatabase groupDatabase = SignalDatabase.groups();
        GroupDatabase.V2GroupProperties v2GroupProperties = groupDatabase.getGroup(groupId).get().requireV2GroupProperties();
        DecryptedGroup decryptedGroup = v2GroupProperties.getDecryptedGroup();
        List<DecryptedPendingMember> pendingMembersList = decryptedGroup.getPendingMembersList();
        List<SinglePendingMemberInvitedByYou> byMe = new ArrayList<>(pendingMembersList.size());
        List<MultiplePendingMembersInvitedByAnother> byOthers = new ArrayList<>(pendingMembersList.size());
        ByteString self = Recipient.self().requireServiceId().toByteString();
        boolean selfIsAdmin = v2GroupProperties.isAdmin(Recipient.self());
        Stream.of(pendingMembersList).groupBy(DecryptedPendingMember::getAddedByUuid).forEach(g -> {
            ByteString inviterUuid = g.getKey();
            List<DecryptedPendingMember> invitedMembers = g.getValue();
            if (self.equals(inviterUuid)) {
                for (DecryptedPendingMember pendingMember : invitedMembers) {
                    try {
                        Recipient invitee = GroupProtoUtil.pendingMemberToRecipient(context, pendingMember);
                        UuidCiphertext uuidCipherText = new UuidCiphertext(pendingMember.getUuidCipherText().toByteArray());
                        byMe.add(new SinglePendingMemberInvitedByYou(invitee, uuidCipherText));
                    } catch (InvalidInputException e) {
                        Log.w(TAG, e);
                    }
                }
            } else {
                Recipient inviter = GroupProtoUtil.uuidByteStringToRecipient(context, inviterUuid);
                ArrayList<UuidCiphertext> uuidCipherTexts = new ArrayList<>(invitedMembers.size());
                for (DecryptedPendingMember pendingMember : invitedMembers) {
                    try {
                        uuidCipherTexts.add(new UuidCiphertext(pendingMember.getUuidCipherText().toByteArray()));
                    } catch (InvalidInputException e) {
                        Log.w(TAG, e);
                    }
                }
                byOthers.add(new MultiplePendingMembersInvitedByAnother(inviter, uuidCipherTexts));
            }
        });
        onInviteesLoaded.accept(new InviteeResult(byMe, byOthers, selfIsAdmin));
    });
}
Also used : InvalidInputException(org.signal.zkgroup.InvalidInputException) ByteString(com.google.protobuf.ByteString) ArrayList(java.util.ArrayList) Recipient(org.thoughtcrime.securesms.recipients.Recipient) UuidCiphertext(org.signal.zkgroup.groups.UuidCiphertext) GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) DecryptedPendingMember(org.signal.storageservice.protos.groups.local.DecryptedPendingMember) DecryptedGroup(org.signal.storageservice.protos.groups.local.DecryptedGroup)

Aggregations

UuidCiphertext (org.signal.zkgroup.groups.UuidCiphertext)4 NonNull (androidx.annotation.NonNull)2 ArrayList (java.util.ArrayList)2 UUID (java.util.UUID)2 GroupDatabase (org.thoughtcrime.securesms.database.GroupDatabase)2 Recipient (org.thoughtcrime.securesms.recipients.Recipient)2 Context (android.content.Context)1 Toast (android.widget.Toast)1 WorkerThread (androidx.annotation.WorkerThread)1 LiveData (androidx.lifecycle.LiveData)1 ViewModel (androidx.lifecycle.ViewModel)1 ViewModelProvider (androidx.lifecycle.ViewModelProvider)1 ByteString (com.google.protobuf.ByteString)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Test (org.junit.Test)1 DecryptedGroup (org.signal.storageservice.protos.groups.local.DecryptedGroup)1 DecryptedPendingMember (org.signal.storageservice.protos.groups.local.DecryptedPendingMember)1