Search in sources :

Example 11 with InvalidInputException

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

the class SignalServiceContent method createGroupV2Info.

private static SignalServiceGroupV2 createGroupV2Info(SignalServiceProtos.DataMessage content) throws InvalidMessageStructureException {
    if (!content.hasGroupV2())
        return null;
    SignalServiceProtos.GroupContextV2 groupV2 = content.getGroupV2();
    if (!groupV2.hasMasterKey()) {
        throw new InvalidMessageStructureException("No GV2 master key on message");
    }
    if (!groupV2.hasRevision()) {
        throw new InvalidMessageStructureException("No GV2 revision on message");
    }
    SignalServiceGroupV2.Builder builder;
    try {
        builder = SignalServiceGroupV2.newBuilder(new GroupMasterKey(groupV2.getMasterKey().toByteArray())).withRevision(groupV2.getRevision());
    } catch (InvalidInputException e) {
        throw new InvalidMessageStructureException("Invalid GV2 input!");
    }
    if (groupV2.hasGroupChange() && !groupV2.getGroupChange().isEmpty()) {
        builder.withSignedGroupChange(groupV2.getGroupChange().toByteArray());
    }
    return builder.build();
}
Also used : InvalidInputException(org.signal.zkgroup.InvalidInputException) SignalServiceProtos(org.whispersystems.signalservice.internal.push.SignalServiceProtos) InvalidMessageStructureException(org.whispersystems.signalservice.api.InvalidMessageStructureException) GroupMasterKey(org.signal.zkgroup.groups.GroupMasterKey)

Example 12 with InvalidInputException

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

the class SignalServiceGroupV2 method fromProtobuf.

/**
 * Creates a context model populated from a protobuf group V2 context.
 */
public static SignalServiceGroupV2 fromProtobuf(SignalServiceProtos.GroupContextV2 groupContextV2) {
    GroupMasterKey masterKey;
    try {
        masterKey = new GroupMasterKey(groupContextV2.getMasterKey().toByteArray());
    } catch (InvalidInputException e) {
        throw new AssertionError(e);
    }
    Builder builder = newBuilder(masterKey);
    if (groupContextV2.hasGroupChange() && !groupContextV2.getGroupChange().isEmpty()) {
        builder.withSignedGroupChange(groupContextV2.getGroupChange().toByteArray());
    }
    return builder.withRevision(groupContextV2.getRevision()).build();
}
Also used : InvalidInputException(org.signal.zkgroup.InvalidInputException) GroupMasterKey(org.signal.zkgroup.groups.GroupMasterKey)

Example 13 with InvalidInputException

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

the class GroupInviteLinkUrl method fromUri.

/**
 * @return null iff not a group url.
 * @throws InvalidGroupLinkException If group url, but cannot be parsed.
 */
@Nullable
public static GroupInviteLinkUrl fromUri(@NonNull String urlString) throws InvalidGroupLinkException, UnknownGroupLinkVersionException {
    URI uri = getGroupUrl(urlString);
    if (uri == null) {
        return null;
    }
    try {
        if (!"/".equals(uri.getPath()) && uri.getPath().length() > 0) {
            throw new InvalidGroupLinkException("No path was expected in uri");
        }
        String encoding = uri.getFragment();
        if (encoding == null || encoding.length() == 0) {
            throw new InvalidGroupLinkException("No reference was in the uri");
        }
        byte[] bytes = Base64UrlSafe.decodePaddingAgnostic(encoding);
        GroupInviteLink groupInviteLink = GroupInviteLink.parseFrom(bytes);
        // noinspection SwitchStatementWithTooFewBranches
        switch(groupInviteLink.getContentsCase()) {
            case V1CONTENTS:
                {
                    GroupInviteLink.GroupInviteLinkContentsV1 groupInviteLinkContentsV1 = groupInviteLink.getV1Contents();
                    GroupMasterKey groupMasterKey = new GroupMasterKey(groupInviteLinkContentsV1.getGroupMasterKey().toByteArray());
                    GroupLinkPassword password = GroupLinkPassword.fromBytes(groupInviteLinkContentsV1.getInviteLinkPassword().toByteArray());
                    return new GroupInviteLinkUrl(groupMasterKey, password);
                }
            default:
                throw new UnknownGroupLinkVersionException("Url contains no known group link content");
        }
    } catch (InvalidInputException | IOException e) {
        throw new InvalidGroupLinkException(e);
    }
}
Also used : InvalidInputException(org.signal.zkgroup.InvalidInputException) GroupInviteLink(org.signal.storageservice.protos.groups.GroupInviteLink) GroupMasterKey(org.signal.zkgroup.groups.GroupMasterKey) ByteString(com.google.protobuf.ByteString) IOException(java.io.IOException) URI(java.net.URI) Nullable(androidx.annotation.Nullable)

Example 14 with InvalidInputException

use of org.signal.zkgroup.InvalidInputException 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

InvalidInputException (org.signal.zkgroup.InvalidInputException)14 IOException (java.io.IOException)5 GroupMasterKey (org.signal.zkgroup.groups.GroupMasterKey)4 ProfileKey (org.signal.zkgroup.profiles.ProfileKey)3 Recipient (org.thoughtcrime.securesms.recipients.Recipient)3 NonNull (androidx.annotation.NonNull)2 Nullable (androidx.annotation.Nullable)2 ByteString (com.google.protobuf.ByteString)2 SecureRandom (java.security.SecureRandom)2 HashMap (java.util.HashMap)2 UUID (java.util.UUID)2 VerificationFailedException (org.signal.zkgroup.VerificationFailedException)2 GroupDatabase (org.thoughtcrime.securesms.database.GroupDatabase)2 SignalServiceProtos (org.whispersystems.signalservice.internal.push.SignalServiceProtos)2 Application (android.app.Application)1 ContentValues (android.content.ContentValues)1 Context (android.content.Context)1 Intent (android.content.Intent)1 Build (android.os.Build)1 ResultReceiver (android.os.ResultReceiver)1