Fix issue with using registration recovery password.

This commit is contained in:
Greyson Parrelli
2024-12-06 15:59:46 -05:00
committed by GitHub
parent 6824f09631
commit 014218782f
10 changed files with 150 additions and 80 deletions

View File

@@ -15,7 +15,6 @@ class StorageServiceValues internal constructor(store: KeyValueStore) : SignalSt
// TODO [linked-device] No need to track this separately -- we'd get the AEP from the primary
private const val SYNC_STORAGE_KEY = "storage.syncStorageKey"
private const val INITIAL_RESTORE_STORAGE_KEY = "storage.initialRestoreStorageKey"
}
public override fun onFirstEverAppLaunch() = Unit
@@ -63,26 +62,8 @@ class StorageServiceValues internal constructor(store: KeyValueStore) : SignalSt
/**
* The [StorageKey] that should be used for our initial storage service data restore.
* The presence of this value indicates that it hasn't been used yet.
* Once there has been *any* write to storage service, this value needs to be cleared.
* Once there has been *any* write to storage service, [SvrValues.masterKeyForInitialDataRestore] needs to be cleared.
*/
@get:Synchronized
@set:Synchronized
var storageKeyForInitialDataRestore: StorageKey?
get() {
return getBlob(INITIAL_RESTORE_STORAGE_KEY, null)?.let { StorageKey(it) }
}
set(value) {
if (value != storageKeyForInitialDataRestore) {
if (value == storageKey) {
Log.w(TAG, "The key already matches the one derived from the AEP! All good, no need to store it.")
store.beginWrite().putBlob(INITIAL_RESTORE_STORAGE_KEY, null).commit()
} else if (value != null) {
Log.w(TAG, "Setting initial restore key!", Throwable())
store.beginWrite().putBlob(INITIAL_RESTORE_STORAGE_KEY, value.serialize()).commit()
} else {
Log.w(TAG, "Clearing initial restore key!", Throwable())
store.beginWrite().putBlob(INITIAL_RESTORE_STORAGE_KEY, null).commit()
}
}
}
val storageKeyForInitialDataRestore: StorageKey?
get() = SignalStore.svr.masterKeyForInitialDataRestore?.deriveStorageServiceKey()
}

View File

@@ -20,6 +20,7 @@ class SvrValues internal constructor(store: KeyValueStore) : SignalStoreValues(s
private const val SVR_LAST_AUTH_REFRESH_TIMESTAMP = "kbs.kbs_auth_tokens.last_refresh_timestamp"
private const val SVR3_AUTH_TOKENS = "kbs.svr3_auth_tokens"
private const val RESTORED_VIA_ACCOUNT_ENTROPY_KEY = "kbs.restore_via_account_entropy_pool"
private const val INITIAL_RESTORE_MASTER_KEY = "kbs.initialRestoreMasterKey"
}
public override fun onFirstEverAppLaunch() = Unit
@@ -83,6 +84,32 @@ class SvrValues internal constructor(store: KeyValueStore) : SignalStoreValues(s
val masterKey: MasterKey
get() = SignalStore.account.accountEntropyPool.deriveMasterKey()
/**
* The [MasterKey] that should be used for our initial syncs with storage service + recovery password.
* The presence of this value indicates that it hasn't been used yet for storage service.
* Once there has been *any* write to storage service, this value needs to be cleared.
*/
@get:Synchronized
@set:Synchronized
var masterKeyForInitialDataRestore: MasterKey?
get() {
return getBlob(INITIAL_RESTORE_MASTER_KEY, null)?.let { MasterKey(it) }
}
set(value) {
if (value != masterKeyForInitialDataRestore) {
if (value == masterKey) {
Log.w(TAG, "The master key already matches the one derived from the AEP! All good, no need to store it.")
store.beginWrite().putBlob(INITIAL_RESTORE_MASTER_KEY, null).commit()
} else if (value != null) {
Log.w(TAG, "Setting initial restore master key!", Throwable())
store.beginWrite().putBlob(INITIAL_RESTORE_MASTER_KEY, value.serialize()).commit()
} else {
Log.w(TAG, "Clearing initial restore master key!", Throwable())
store.beginWrite().putBlob(INITIAL_RESTORE_MASTER_KEY, null).commit()
}
}
}
@get:Synchronized
val pinBackedMasterKey: MasterKey?
/** Returns null if master key is not backed up by a pin. */
@@ -102,7 +129,7 @@ class SvrValues internal constructor(store: KeyValueStore) : SignalStoreValues(s
val recoveryPassword: String?
get() {
return if (hasOptedInWithAccess()) {
masterKey.deriveRegistrationRecoveryPassword()
masterKeyForInitialDataRestore?.deriveRegistrationRecoveryPassword() ?: masterKey.deriveRegistrationRecoveryPassword()
} else {
null
}