diff --git a/app/src/main/kotlin/com/x8bit/bitwarden/data/auth/datasource/disk/AuthDiskSourceImpl.kt b/app/src/main/kotlin/com/x8bit/bitwarden/data/auth/datasource/disk/AuthDiskSourceImpl.kt index 307df5d123..7432fe54ee 100644 --- a/app/src/main/kotlin/com/x8bit/bitwarden/data/auth/datasource/disk/AuthDiskSourceImpl.kt +++ b/app/src/main/kotlin/com/x8bit/bitwarden/data/auth/datasource/disk/AuthDiskSourceImpl.kt @@ -726,7 +726,7 @@ class AuthDiskSourceImpl( val userId = account.profile.userId val accountKeysKey = PROFILE_ACCOUNT_KEYS_KEY.appendIdentifier(userId) val privateKeyKey = MASTER_KEY_ENCRYPTION_PRIVATE_KEY.appendIdentifier(userId) - val accountKeys = getEncryptedString(key = accountKeysKey) + val accountKeys = getLegacyEncryptedString(key = accountKeysKey) ?.let { json.decodeFromStringOrNull(it) } val privateKey = accountKeys ?.publicKeyEncryptionKeyPair @@ -738,7 +738,7 @@ class AuthDiskSourceImpl( accountCryptographicState = accountKeys.toAccountCryptographicState(it), ) // Remove the Account Keys and Private Key - putEncryptedString(key = accountKeysKey, value = null) + clearLegacyEncryptedString(key = accountKeysKey) putString(key = privateKeyKey, value = null) } } diff --git a/app/src/main/kotlin/com/x8bit/bitwarden/data/platform/datasource/disk/legacy/DiskSourceMigrationLoggerImpl.kt b/app/src/main/kotlin/com/x8bit/bitwarden/data/platform/datasource/disk/legacy/DiskSourceMigrationLoggerImpl.kt index 0e9a50e7a7..6fc4ed0d57 100644 --- a/app/src/main/kotlin/com/x8bit/bitwarden/data/platform/datasource/disk/legacy/DiskSourceMigrationLoggerImpl.kt +++ b/app/src/main/kotlin/com/x8bit/bitwarden/data/platform/datasource/disk/legacy/DiskSourceMigrationLoggerImpl.kt @@ -25,16 +25,12 @@ internal class DiskSourceMigrationLoggerImpl( init { flightRecorderManager .isLoggingReadyFlow - .filter { it } - .onEach { - // The older encrypted shared preferences has its own values written to disk, - // so it is normal for there to be 2 values still present. - if (keystoreEncryptedPreferences.all.isNotEmpty() && - encryptedPreferences.all.size <= 2 - ) { - Timber.d("Encrypted data has been migrated to Keystore encryption.") - } + .filter { isLoggingReady -> + isLoggingReady && + keystoreEncryptedPreferences.all.isNotEmpty() && + encryptedPreferences.all.isEmpty() } + .onEach { Timber.d("Encrypted data has been migrated to Keystore encryption.") } .launchIn(unconfinedScope) } } diff --git a/data/src/main/kotlin/com/bitwarden/data/datasource/disk/BaseEncryptedDiskSource.kt b/data/src/main/kotlin/com/bitwarden/data/datasource/disk/BaseEncryptedDiskSource.kt index 8734ff180b..24e2b801cc 100644 --- a/data/src/main/kotlin/com/bitwarden/data/datasource/disk/BaseEncryptedDiskSource.kt +++ b/data/src/main/kotlin/com/bitwarden/data/datasource/disk/BaseEncryptedDiskSource.kt @@ -16,6 +16,14 @@ abstract class BaseEncryptedDiskSource( private val encryptedSharedPreferences: SharedPreferences, private val keystoreEncryptedPreferences: SharedPreferences, ) : BaseDiskSource(sharedPreferences = sharedPreferences) { + protected fun getLegacyEncryptedString( + key: String, + ): String? = encryptedSharedPreferences.getString("$LEGACY_PREFIX$key", null) + + protected fun clearLegacyEncryptedString(key: String) { + encryptedSharedPreferences.edit { remove("$LEGACY_PREFIX$key") } + } + protected fun getEncryptedString( key: String, ): String? = keystoreEncryptedPreferences.getString(key, null)