From 134284723bfa5aaa9c171c996e9b37cbfbe7a365 Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Thu, 15 Apr 2021 12:06:41 -0400 Subject: [PATCH] Fix storage service crash when matching a local GV2 group without a master key. --- .../securesms/storage/GroupV2RecordProcessor.java | 9 ++++++++- .../securesms/storage/StorageSyncModels.java | 14 ++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/storage/GroupV2RecordProcessor.java b/app/src/main/java/org/thoughtcrime/securesms/storage/GroupV2RecordProcessor.java index 80ba8e195..935b5c353 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/storage/GroupV2RecordProcessor.java +++ b/app/src/main/java/org/thoughtcrime/securesms/storage/GroupV2RecordProcessor.java @@ -50,7 +50,14 @@ public final class GroupV2RecordProcessor extends DefaultStorageRecordProcessor< Optional recipientId = recipientDatabase.getByGroupId(groupId); return recipientId.transform(recipientDatabase::getRecipientSettingsForSync) - .transform(StorageSyncModels::localToRemoteRecord) + .transform(settings -> { + if (settings.getSyncExtras().getGroupMasterKey() != null) { + return StorageSyncModels.localToRemoteRecord(settings); + } else { + Log.w(TAG, "No local master key. Assuming it matches remote since the groupIds match."); + return StorageSyncModels.localToRemoteRecord(settings, record.getMasterKeyOrThrow()); + } + }) .transform(r -> r.getGroupV2().get()); } diff --git a/app/src/main/java/org/thoughtcrime/securesms/storage/StorageSyncModels.java b/app/src/main/java/org/thoughtcrime/securesms/storage/StorageSyncModels.java index d2ec7e3f0..4507e395a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/storage/StorageSyncModels.java +++ b/app/src/main/java/org/thoughtcrime/securesms/storage/StorageSyncModels.java @@ -33,11 +33,19 @@ public final class StorageSyncModels { return localToRemoteRecord(settings, settings.getStorageId()); } + public static @NonNull SignalStorageRecord localToRemoteRecord(@NonNull RecipientSettings settings, @NonNull GroupMasterKey groupMasterKey) { + if (settings.getStorageId() == null) { + throw new AssertionError("Must have a storage key!"); + } + + return SignalStorageRecord.forGroupV2(localToRemoteGroupV2(settings, settings.getStorageId(), groupMasterKey)); + } + public static @NonNull SignalStorageRecord localToRemoteRecord(@NonNull RecipientSettings settings, @NonNull byte[] rawStorageId) { switch (settings.getGroupType()) { case NONE: return SignalStorageRecord.forContact(localToRemoteContact(settings, rawStorageId)); case SIGNAL_V1: return SignalStorageRecord.forGroupV1(localToRemoteGroupV1(settings, rawStorageId)); - case SIGNAL_V2: return SignalStorageRecord.forGroupV2(localToRemoteGroupV2(settings, rawStorageId)); + case SIGNAL_V2: return SignalStorageRecord.forGroupV2(localToRemoteGroupV2(settings, rawStorageId, settings.getSyncExtras().getGroupMasterKey())); default: throw new AssertionError("Unsupported type!"); } } @@ -119,7 +127,7 @@ public final class StorageSyncModels { .build(); } - private static @NonNull SignalGroupV2Record localToRemoteGroupV2(@NonNull RecipientSettings recipient, byte[] rawStorageId) { + private static @NonNull SignalGroupV2Record localToRemoteGroupV2(@NonNull RecipientSettings recipient, byte[] rawStorageId, @NonNull GroupMasterKey groupMasterKey) { GroupId groupId = recipient.getGroupId(); if (groupId == null) { @@ -130,8 +138,6 @@ public final class StorageSyncModels { throw new AssertionError("Group is not V2"); } - GroupMasterKey groupMasterKey = recipient.getSyncExtras().getGroupMasterKey(); - if (groupMasterKey == null) { throw new AssertionError("Group master key not on recipient record"); }