From 517a4bc4e67fcc4c682fdd837948d29698eb50f7 Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Thu, 30 Jul 2026 12:33:46 -0400 Subject: [PATCH] Don't remove self profile key during restore. --- .../v2/database/RecipientTableArchiveExtensions.kt | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/backup/v2/database/RecipientTableArchiveExtensions.kt b/app/src/main/java/org/thoughtcrime/securesms/backup/v2/database/RecipientTableArchiveExtensions.kt index 04e1e69d9e..3796a94c6c 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/backup/v2/database/RecipientTableArchiveExtensions.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/backup/v2/database/RecipientTableArchiveExtensions.kt @@ -13,9 +13,9 @@ import org.signal.core.util.logging.Log import org.signal.core.util.nullIfBlank import org.signal.core.util.select import org.signal.core.util.update -import org.signal.libsignal.zkgroup.InvalidInputException import org.thoughtcrime.securesms.backup.v2.exporters.ContactArchiveExporter import org.thoughtcrime.securesms.backup.v2.exporters.GroupArchiveExporter +import org.thoughtcrime.securesms.crypto.ProfileKeyUtil import org.thoughtcrime.securesms.database.GroupTable import org.thoughtcrime.securesms.database.IdentityTable import org.thoughtcrime.securesms.database.RecipientTable @@ -131,10 +131,12 @@ fun RecipientTable.restoreSelfFromBackup(accountData: AccountData, selfId: Recip put(RecipientTable.UNREGISTERED_TIMESTAMP, 0) put(RecipientTable.EXTRAS, RecipientExtras().encode()) - try { - put(RecipientTable.PROFILE_KEY, Base64.encodeWithPadding(accountData.profileKey.toByteArray()).nullIfBlank()) - } catch (e: InvalidInputException) { - Log.w(TAG, "Missing profile key during restore") + val profileKey = ProfileKeyUtil.profileKeyOrNull(accountData.profileKey.toByteArray()) + if (profileKey != null) { + put(RecipientTable.PROFILE_KEY, Base64.encodeWithPadding(profileKey.serialize())) + } else { + // Don't clear the key we already have. A null profile key for self is fatal in a bunch of places (profile uploads, outgoing messages, etc). + Log.w(TAG, "Missing profile key during restore! Keeping the existing one.") } put(RecipientTable.USERNAME, accountData.username)