Be more careful with unknown IDs during storage sync.

This commit is contained in:
Greyson Parrelli
2021-05-27 16:12:07 -04:00
committed by Cody Henthorne
parent 1c40f2d167
commit 1322f5bc08
4 changed files with 30 additions and 12 deletions

View File

@@ -4,6 +4,7 @@ import com.google.protobuf.ByteString;
import org.signal.zkgroup.groups.GroupMasterKey;
import org.whispersystems.libsignal.InvalidKeyException;
import org.whispersystems.libsignal.logging.Log;
import org.whispersystems.signalservice.internal.storage.protos.ManifestRecord;
import org.whispersystems.signalservice.internal.storage.protos.StorageItem;
import org.whispersystems.signalservice.internal.storage.protos.StorageManifest;
@@ -15,6 +16,8 @@ import java.util.List;
public final class SignalStorageModels {
private static final String TAG = SignalStorageModels.class.getSimpleName();
public static SignalStorageManifest remoteToLocalStorageManifest(StorageManifest manifest, StorageKey storageKey) throws IOException, InvalidKeyException {
byte[] rawRecord = SignalStorageCipher.decrypt(storageKey.deriveManifestKey(manifest.getVersion()), manifest.getValue().toByteArray());
ManifestRecord manifestRecord = ManifestRecord.parseFrom(rawRecord);
@@ -42,6 +45,9 @@ public final class SignalStorageModels {
} else if (record.hasAccount() && type == ManifestRecord.Identifier.Type.ACCOUNT_VALUE) {
return SignalStorageRecord.forAccount(id, new SignalAccountRecord(id, record.getAccount()));
} else {
if (StorageId.isKnownType(type)) {
Log.w(TAG, "StorageId is of known type (" + type + "), but the data is bad! Falling back to unknown.");
}
return SignalStorageRecord.forUnknown(StorageId.forType(key, type));
}
}

View File

@@ -53,13 +53,25 @@ public class StorageId {
public static boolean isKnownType(int val) {
for (ManifestRecord.Identifier.Type type : ManifestRecord.Identifier.Type.values()) {
if (type.getNumber() == val) {
if (type != ManifestRecord.Identifier.Type.UNRECOGNIZED && type.getNumber() == val) {
return true;
}
}
return false;
}
public static int largestKnownType() {
int max = 0;
for (ManifestRecord.Identifier.Type type : ManifestRecord.Identifier.Type.values()) {
if (type != ManifestRecord.Identifier.Type.UNRECOGNIZED) {
max = Math.max(type.getNumber(), max);
}
}
return max;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;