Setup backupV2 infrastructure and testing.

Co-authored-by: Clark Chen <clark@signal.org>
This commit is contained in:
Greyson Parrelli
2023-09-13 15:15:33 -04:00
committed by Cody Henthorne
parent feb74d90f6
commit b540b5813e
47 changed files with 3782 additions and 274 deletions

View File

@@ -263,6 +263,30 @@ internal class AccountValues internal constructor(store: KeyValueStore) : Signal
}
}
fun restorePniIdentityKeyFromBackup(publicKey: ByteArray, privateKey: ByteArray) {
synchronized(this) {
Log.i(TAG, "Setting a new PNI identity key pair.")
store
.beginWrite()
.putBlob(KEY_PNI_IDENTITY_PUBLIC_KEY, publicKey)
.putBlob(KEY_PNI_IDENTITY_PRIVATE_KEY, privateKey)
.commit()
}
}
fun restoreAciIdentityKeyFromBackup(publicKey: ByteArray, privateKey: ByteArray) {
synchronized(this) {
Log.i(TAG, "Setting a new ACI identity key pair.")
store
.beginWrite()
.putBlob(KEY_ACI_IDENTITY_PUBLIC_KEY, publicKey)
.putBlob(KEY_ACI_IDENTITY_PRIVATE_KEY, privateKey)
.commit()
}
}
/** Only to be used when restoring an identity public key from an old backup */
fun restoreLegacyIdentityPublicKeyFromBackup(base64: String) {
Log.w(TAG, "Restoring legacy identity public key from backup.")
@@ -347,6 +371,18 @@ internal class AccountValues internal constructor(store: KeyValueStore) : Signal
}
}
/**
* Function for testing backup/restore
*/
@Deprecated("debug only")
fun clearRegistrationButKeepCredentials() {
putBoolean(KEY_IS_REGISTERED, false)
ApplicationDependencies.getIncomingMessageObserver().notifyRegistrationChanged()
Recipient.self().live().refresh()
}
val deviceName: String?
get() = getString(KEY_DEVICE_NAME, null)

View File

@@ -32,6 +32,10 @@ internal class ReleaseChannelValues(store: KeyValueStore) : SignalStoreValues(st
putString(KEY_RELEASE_CHANNEL_RECIPIENT_ID, id.serialize())
}
fun clearReleaseChannelRecipientId() {
putString(KEY_RELEASE_CHANNEL_RECIPIENT_ID, "")
}
var nextScheduledCheck by longValue(KEY_NEXT_SCHEDULED_CHECK, 0)
var previousManifestMd5 by blobValue(KEY_PREVIOUS_MANIFEST_MD5, ByteArray(0))
var highestVersionNoteReceived by integerValue(KEY_HIGHEST_VERSION_NOTE_RECEIVED, 0)

View File

@@ -301,4 +301,9 @@ public final class SignalStore {
public static void inject(@NonNull KeyValueStore store) {
instance = new SignalStore(store);
}
public static void clearAllDataForBackupRestore() {
releaseChannelValues().clearReleaseChannelRecipientId();
account().clearRegistrationButKeepCredentials();
}
}