Search in sources :

Example 1 with GroupSecretParams

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

the class AvatarGroupsV2DownloadJob method downloadGroupAvatarBytes.

@Nullable
public static byte[] downloadGroupAvatarBytes(@NonNull Context context, @NonNull GroupMasterKey groupMasterKey, @NonNull String cdnKey) throws IOException {
    if (cdnKey.length() == 0) {
        return null;
    }
    GroupSecretParams groupSecretParams = GroupSecretParams.deriveFromMasterKey(groupMasterKey);
    File attachment = File.createTempFile("avatar", "gv2", context.getCacheDir());
    attachment.deleteOnExit();
    SignalServiceMessageReceiver receiver = ApplicationDependencies.getSignalServiceMessageReceiver();
    byte[] encryptedData;
    try (FileInputStream inputStream = receiver.retrieveGroupsV2ProfileAvatar(cdnKey, attachment, AVATAR_DOWNLOAD_FAIL_SAFE_MAX_SIZE)) {
        encryptedData = new byte[(int) attachment.length()];
        StreamUtil.readFully(inputStream, encryptedData);
        GroupsV2Operations operations = ApplicationDependencies.getGroupsV2Operations();
        GroupsV2Operations.GroupOperations groupOperations = operations.forGroup(groupSecretParams);
        return groupOperations.decryptAvatar(encryptedData);
    } finally {
        if (attachment.exists())
            if (!attachment.delete()) {
                Log.w(TAG, "Unable to delete temp avatar file");
            }
    }
}
Also used : GroupsV2Operations(org.whispersystems.signalservice.api.groupsv2.GroupsV2Operations) GroupSecretParams(org.signal.zkgroup.groups.GroupSecretParams) SignalServiceMessageReceiver(org.whispersystems.signalservice.api.SignalServiceMessageReceiver) File(java.io.File) FileInputStream(java.io.FileInputStream) Nullable(androidx.annotation.Nullable)

Example 2 with GroupSecretParams

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

the class GroupsV2Operations_decrypt_groupJoinInfo_Test method setup.

@Before
public void setup() throws InvalidInputException {
    LibSignalLibraryUtil.assumeLibSignalSupportedOnOS();
    TestZkGroupServer server = new TestZkGroupServer();
    ClientZkOperations clientZkOperations = new ClientZkOperations(server.getServerPublicParams());
    GroupSecretParams groupSecretParams = GroupSecretParams.deriveFromMasterKey(new GroupMasterKey(Util.getSecretBytes(32)));
    groupOperations = new GroupsV2Operations(clientZkOperations).forGroup(groupSecretParams);
}
Also used : GroupSecretParams(org.signal.zkgroup.groups.GroupSecretParams) GroupMasterKey(org.signal.zkgroup.groups.GroupMasterKey) Before(org.junit.Before)

Example 3 with GroupSecretParams

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

the class GroupManagerV2 method migrateGroupOnToServer.

@WorkerThread
void migrateGroupOnToServer(@NonNull GroupId.V1 groupIdV1, @NonNull Collection<Recipient> members) throws IOException, MembershipNotSuitableForV2Exception, GroupAlreadyExistsException, GroupChangeFailedException {
    GroupMasterKey groupMasterKey = groupIdV1.deriveV2MigrationMasterKey();
    GroupSecretParams groupSecretParams = GroupSecretParams.deriveFromMasterKey(groupMasterKey);
    GroupDatabase.GroupRecord groupRecord = groupDatabase.requireGroup(groupIdV1);
    String name = Util.emptyIfNull(groupRecord.getTitle());
    byte[] avatar = groupRecord.hasAvatar() ? AvatarHelper.getAvatarBytes(context, groupRecord.getRecipientId()) : null;
    int messageTimer = Recipient.resolved(groupRecord.getRecipientId()).getExpiresInSeconds();
    Set<RecipientId> memberIds = Stream.of(members).map(Recipient::getId).filterNot(m -> m.equals(Recipient.self().getId())).collect(Collectors.toSet());
    createGroupOnServer(groupSecretParams, name, avatar, memberIds, Member.Role.ADMINISTRATOR, messageTimer);
}
Also used : SignalStore(org.thoughtcrime.securesms.keyvalue.SignalStore) Arrays(java.util.Arrays) MessageSender(org.thoughtcrime.securesms.sms.MessageSender) NonNull(androidx.annotation.NonNull) GroupChangeUtil(org.whispersystems.signalservice.api.groupsv2.GroupChangeUtil) RequestGroupV2InfoJob(org.thoughtcrime.securesms.jobs.RequestGroupV2InfoJob) ProfileKey(org.signal.zkgroup.profiles.ProfileKey) GroupMasterKey(org.signal.zkgroup.groups.GroupMasterKey) PushGroupSilentUpdateSendJob(org.thoughtcrime.securesms.jobs.PushGroupSilentUpdateSendJob) Member(org.signal.storageservice.protos.groups.Member) DecryptedGroupJoinInfo(org.signal.storageservice.protos.groups.local.DecryptedGroupJoinInfo) ProfileUploadJob(org.thoughtcrime.securesms.jobs.ProfileUploadJob) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) ByteArrayInputStream(java.io.ByteArrayInputStream) Locale(java.util.Locale) Map(java.util.Map) DecryptedGroupChange(org.signal.storageservice.protos.groups.local.DecryptedGroupChange) GroupExistsException(org.whispersystems.signalservice.internal.push.exceptions.GroupExistsException) Recipient(org.thoughtcrime.securesms.recipients.Recipient) GroupsV2StateProcessor(org.thoughtcrime.securesms.groups.v2.processing.GroupsV2StateProcessor) OutgoingGroupUpdateMessage(org.thoughtcrime.securesms.mms.OutgoingGroupUpdateMessage) InvalidGroupStateException(org.whispersystems.signalservice.api.groupsv2.InvalidGroupStateException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) NotInGroupException(org.whispersystems.signalservice.internal.push.exceptions.NotInGroupException) GroupCandidateHelper(org.thoughtcrime.securesms.groups.v2.GroupCandidateHelper) GroupCandidate(org.whispersystems.signalservice.api.groupsv2.GroupCandidate) GroupExternalCredential(org.signal.storageservice.protos.groups.GroupExternalCredential) ACI(org.whispersystems.signalservice.api.push.ACI) DecryptedGroupUtil(org.whispersystems.signalservice.api.groupsv2.DecryptedGroupUtil) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) Collection(java.util.Collection) ProfileKeyUtil(org.thoughtcrime.securesms.crypto.ProfileKeyUtil) Set(java.util.Set) DecryptedPendingMember(org.signal.storageservice.protos.groups.local.DecryptedPendingMember) GroupLinkPassword(org.thoughtcrime.securesms.groups.v2.GroupLinkPassword) GroupsV2Operations(org.whispersystems.signalservice.api.groupsv2.GroupsV2Operations) UUID(java.util.UUID) GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase) InvalidInputException(org.signal.zkgroup.InvalidInputException) ByteString(com.google.protobuf.ByteString) Objects(java.util.Objects) Log(org.signal.core.util.logging.Log) DecryptedGroup(org.signal.storageservice.protos.groups.local.DecryptedGroup) List(java.util.List) Nullable(androidx.annotation.Nullable) Context(android.content.Context) SignalDatabase(org.thoughtcrime.securesms.database.SignalDatabase) Stream(com.annimon.stream.Stream) Util(org.thoughtcrime.securesms.util.Util) WorkerThread(androidx.annotation.WorkerThread) VerificationFailedException(org.signal.zkgroup.VerificationFailedException) HashMap(java.util.HashMap) AccessControl(org.signal.storageservice.protos.groups.AccessControl) GroupInviteLinkUrl(org.thoughtcrime.securesms.groups.v2.GroupInviteLinkUrl) GroupPatchNotAcceptedException(org.whispersystems.signalservice.internal.push.exceptions.GroupPatchNotAcceptedException) HashSet(java.util.HashSet) AuthorizationFailedException(org.whispersystems.signalservice.api.push.exceptions.AuthorizationFailedException) ClientZkGroupCipher(org.signal.zkgroup.groups.ClientZkGroupCipher) NotAbleToApplyGroupV2ChangeException(org.whispersystems.signalservice.api.groupsv2.NotAbleToApplyGroupV2ChangeException) DecryptedRequestingMember(org.signal.storageservice.protos.groups.local.DecryptedRequestingMember) DecryptedMember(org.signal.storageservice.protos.groups.local.DecryptedMember) DecryptedGroupV2Context(org.thoughtcrime.securesms.database.model.databaseprotos.DecryptedGroupV2Context) ConflictException(org.whispersystems.signalservice.api.push.exceptions.ConflictException) GroupChangeReconstruct(org.whispersystems.signalservice.api.groupsv2.GroupChangeReconstruct) Collectors(com.annimon.stream.Collectors) ProfileKeyCredential(org.signal.zkgroup.profiles.ProfileKeyCredential) GroupSecretParams(org.signal.zkgroup.groups.GroupSecretParams) AvatarHelper(org.thoughtcrime.securesms.profiles.AvatarHelper) MmsException(org.thoughtcrime.securesms.mms.MmsException) UuidUtil(org.whispersystems.signalservice.api.util.UuidUtil) IOException(java.io.IOException) GroupsV2Api(org.whispersystems.signalservice.api.groupsv2.GroupsV2Api) Optional(org.whispersystems.libsignal.util.guava.Optional) GroupLinkNotActiveException(org.whispersystems.signalservice.api.groupsv2.GroupLinkNotActiveException) UuidCiphertext(org.signal.zkgroup.groups.UuidCiphertext) Closeable(java.io.Closeable) GroupChange(org.signal.storageservice.protos.groups.GroupChange) Collections(java.util.Collections) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) GroupSecretParams(org.signal.zkgroup.groups.GroupSecretParams) GroupMasterKey(org.signal.zkgroup.groups.GroupMasterKey) GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) Recipient(org.thoughtcrime.securesms.recipients.Recipient) ByteString(com.google.protobuf.ByteString) WorkerThread(androidx.annotation.WorkerThread)

Example 4 with GroupSecretParams

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

the class GroupManagerV2 method getGroupExternalCredential.

@WorkerThread
@NonNull
GroupExternalCredential getGroupExternalCredential(@NonNull GroupId.V2 groupId) throws IOException, VerificationFailedException {
    GroupMasterKey groupMasterKey = SignalDatabase.groups().requireGroup(groupId).requireV2GroupProperties().getGroupMasterKey();
    GroupSecretParams groupSecretParams = GroupSecretParams.deriveFromMasterKey(groupMasterKey);
    return groupsV2Api.getGroupExternalCredential(authorization.getAuthorizationForToday(selfAci, groupSecretParams));
}
Also used : GroupSecretParams(org.signal.zkgroup.groups.GroupSecretParams) GroupMasterKey(org.signal.zkgroup.groups.GroupMasterKey) WorkerThread(androidx.annotation.WorkerThread) NonNull(androidx.annotation.NonNull)

Aggregations

GroupSecretParams (org.signal.zkgroup.groups.GroupSecretParams)4 GroupMasterKey (org.signal.zkgroup.groups.GroupMasterKey)3 NonNull (androidx.annotation.NonNull)2 Nullable (androidx.annotation.Nullable)2 WorkerThread (androidx.annotation.WorkerThread)2 Context (android.content.Context)1 Collectors (com.annimon.stream.Collectors)1 Stream (com.annimon.stream.Stream)1 ByteString (com.google.protobuf.ByteString)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Closeable (java.io.Closeable)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1