Don't allow account record updates to delete our profile key.

This commit is contained in:
Greyson Parrelli 2020-06-01 12:55:30 -04:00
parent c4ec0c9897
commit f70e41e7cd
2 changed files with 8 additions and 4 deletions

View File

@ -648,13 +648,18 @@ public class RecipientDatabase extends Database {
public void applyStorageSyncUpdates(@NonNull StorageId storageId, SignalAccountRecord update) {
SQLiteDatabase db = databaseHelper.getWritableDatabase();
ContentValues values = new ContentValues();
ProfileName profileName = ProfileName.fromParts(update.getGivenName().orNull(), update.getFamilyName().orNull());
ContentValues values = new ContentValues();
ProfileName profileName = ProfileName.fromParts(update.getGivenName().orNull(), update.getFamilyName().orNull());
String profileKey = update.getProfileKey().or(Optional.fromNullable(Recipient.self().getProfileKey())).transform(Base64::encodeBytes).orNull();
if (!update.getProfileKey().isPresent()) {
Log.w(TAG, "Got an empty profile key while applying an account record update!");
}
values.put(PROFILE_GIVEN_NAME, profileName.getGivenName());
values.put(PROFILE_FAMILY_NAME, profileName.getFamilyName());
values.put(PROFILE_JOINED_NAME, profileName.toString());
values.put(PROFILE_KEY, update.getProfileKey().transform(Base64::encodeBytes).orNull());
values.put(PROFILE_KEY, profileKey);
values.put(STORAGE_SERVICE_ID, Base64.encodeBytes(update.getId().getRaw()));
values.put(DIRTY, DirtyState.CLEAN.getId());

View File

@ -385,7 +385,6 @@ public final class StorageSyncHelper {
}
public static SignalStorageRecord buildAccountRecord(@NonNull Context context, @NonNull Recipient self) {
SignalAccountRecord account = new SignalAccountRecord.Builder(self.getStorageServiceId())
.setProfileKey(self.getProfileKey())
.setGivenName(self.getProfileName().getGivenName())