Fix issue with group creation on linked devices.

This commit is contained in:
Greyson Parrelli
2021-06-25 16:35:42 -04:00
committed by GitHub
parent 3d2a634aac
commit a71fe0fd75
4 changed files with 96 additions and 28 deletions

View File

@@ -22,6 +22,9 @@ import org.signal.zkgroup.InvalidInputException;
import org.signal.zkgroup.groups.GroupMasterKey;
import org.thoughtcrime.securesms.crypto.SenderKeyUtil;
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper;
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
import org.thoughtcrime.securesms.groups.v2.processing.GroupsV2StateProcessor;
import org.thoughtcrime.securesms.jobs.RequestGroupV2InfoJob;
import org.whispersystems.signalservice.api.push.DistributionId;
import org.thoughtcrime.securesms.groups.GroupAccessControl;
import org.thoughtcrime.securesms.groups.GroupId;
@@ -441,6 +444,47 @@ private static final String[] GROUP_PROJECTION = {
return groupId;
}
/**
* There was a point in time where we weren't properly responding to group creates on linked devices. This would result in us having a Recipient entry for the
* group, but we'd either be missing the group entry, or that entry would be missing a master key. This method fixes this scenario.
*/
public void fixMissingMasterKey(@NonNull GroupMasterKey groupMasterKey) {
GroupId.V2 groupId = GroupId.v2(groupMasterKey);
if (getGroupV1ByExpectedV2(groupId).isPresent()) {
throw new MissedGroupMigrationInsertException(groupId);
}
SQLiteDatabase db = databaseHelper.getWritableDatabase();
db.beginTransaction();
try {
String query = GROUP_ID + " = ?";
String[] args = SqlUtil.buildArgs(groupId);
ContentValues values = new ContentValues();
values.put(V2_MASTER_KEY, groupMasterKey.serialize());
int updated = db.update(TABLE_NAME, values, query, args);
if (updated < 1) {
Log.w(TAG, "No group entry. Creating restore placeholder for " + groupId);
create(groupMasterKey, DecryptedGroup.newBuilder()
.setRevision(GroupsV2StateProcessor.RESTORE_PLACEHOLDER_REVISION)
.build());
} else {
Log.w(TAG, "Had a group entry, but it was missing a master key. Updated.");
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
Log.w(TAG, "Scheduling request for latest group info for " + groupId);
ApplicationDependencies.getJobManager().add(new RequestGroupV2InfoJob(groupId));
}
/**
* @param groupMasterKey null for V1, must be non-null for V2 (presence dictates group version).
*/