Fix storage service crash when matching a local GV2 group without a master key.

This commit is contained in:
Greyson Parrelli 2021-04-15 12:06:41 -04:00
parent a6eb44ba95
commit 134284723b
2 changed files with 18 additions and 5 deletions

View file

@ -50,7 +50,14 @@ public final class GroupV2RecordProcessor extends DefaultStorageRecordProcessor<
Optional<RecipientId> 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());
}

View file

@ -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");
}