Search in sources :

Example 11 with GroupMasterKey

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

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

use of org.signal.zkgroup.groups.GroupMasterKey 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)

Aggregations

GroupMasterKey (org.signal.zkgroup.groups.GroupMasterKey)13 InvalidInputException (org.signal.zkgroup.InvalidInputException)5 Recipient (org.thoughtcrime.securesms.recipients.Recipient)5 NonNull (androidx.annotation.NonNull)4 GroupDatabase (org.thoughtcrime.securesms.database.GroupDatabase)4 WorkerThread (androidx.annotation.WorkerThread)3 IOException (java.io.IOException)3 GroupSecretParams (org.signal.zkgroup.groups.GroupSecretParams)3 ContentValues (android.content.ContentValues)2 Nullable (androidx.annotation.Nullable)2 ByteString (com.google.protobuf.ByteString)2 HashMap (java.util.HashMap)2 UUID (java.util.UUID)2 Test (org.junit.Test)2 DecryptedGroup (org.signal.storageservice.protos.groups.local.DecryptedGroup)2 DecryptedGroupJoinInfo (org.signal.storageservice.protos.groups.local.DecryptedGroupJoinInfo)2 ClientZkGroupCipher (org.signal.zkgroup.groups.ClientZkGroupCipher)2 UuidCiphertext (org.signal.zkgroup.groups.UuidCiphertext)2 GroupId (org.thoughtcrime.securesms.groups.GroupId)2 SuppressLint (android.annotation.SuppressLint)1