mirror of
https://github.com/bitwarden/android.git
synced 2026-06-01 10:16:47 -05:00
Remove the in-memory deviceKey (#1270)
This commit is contained in:
committed by
Álison Fernandes
parent
20f7811b6a
commit
921240d173
@@ -119,15 +119,8 @@ interface AuthDiskSource {
|
||||
|
||||
/**
|
||||
* Stores the device key for the given [userId].
|
||||
*
|
||||
* When [inMemoryOnly] is `true`, the value will only be available via a call to [getDeviceKey]
|
||||
* during the current app session.
|
||||
*/
|
||||
fun storeDeviceKey(
|
||||
userId: String,
|
||||
deviceKey: String?,
|
||||
inMemoryOnly: Boolean = false,
|
||||
)
|
||||
fun storeDeviceKey(userId: String, deviceKey: String?)
|
||||
|
||||
/**
|
||||
* Gets the stored [PendingAuthRequestJson] for the given [userId].
|
||||
|
||||
@@ -56,7 +56,6 @@ class AuthDiskSourceImpl(
|
||||
),
|
||||
AuthDiskSource {
|
||||
|
||||
private val inMemoryDeviceKeys = mutableMapOf<String, String?>()
|
||||
private val inMemoryPinProtectedUserKeys = mutableMapOf<String, String?>()
|
||||
private val mutableOrganizationsFlowMap =
|
||||
mutableMapOf<String, MutableSharedFlow<List<SyncResponseJson.Profile.Organization>?>>()
|
||||
@@ -200,15 +199,12 @@ class AuthDiskSourceImpl(
|
||||
|
||||
override fun getDeviceKey(
|
||||
userId: String,
|
||||
): String? = inMemoryDeviceKeys[userId] ?: getEncryptedString(key = "${DEVICE_KEY_KEY}_$userId")
|
||||
): String? = getEncryptedString(key = "${DEVICE_KEY_KEY}_$userId")
|
||||
|
||||
override fun storeDeviceKey(
|
||||
userId: String,
|
||||
deviceKey: String?,
|
||||
inMemoryOnly: Boolean,
|
||||
) {
|
||||
inMemoryDeviceKeys[userId] = deviceKey
|
||||
if (inMemoryOnly) return
|
||||
putEncryptedString(key = "${DEVICE_KEY_KEY}_$userId", value = deviceKey)
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.bitwarden.crypto.TrustDeviceResponse
|
||||
import com.x8bit.bitwarden.data.auth.datasource.disk.AuthDiskSource
|
||||
import com.x8bit.bitwarden.data.auth.datasource.network.service.DevicesService
|
||||
import com.x8bit.bitwarden.data.auth.manager.util.toUserStateJson
|
||||
import com.x8bit.bitwarden.data.platform.util.asSuccess
|
||||
import com.x8bit.bitwarden.data.platform.util.flatMap
|
||||
import com.x8bit.bitwarden.data.vault.datasource.sdk.VaultSdkSource
|
||||
|
||||
@@ -17,19 +18,7 @@ class TrustedDeviceManagerImpl(
|
||||
) : TrustedDeviceManager {
|
||||
override suspend fun trustThisDeviceIfNecessary(userId: String): Result<Boolean> =
|
||||
if (!authDiskSource.shouldTrustDevice) {
|
||||
// Even though we are not trusting the device, we still store the device key in
|
||||
// memory. This allows the user to be "trusted" for this session but on timeout
|
||||
// or reboot, the "trust" will be gone.
|
||||
vaultSdkSource
|
||||
.getTrustDevice(userId = userId)
|
||||
.onSuccess { trustedDevice ->
|
||||
authDiskSource.storeDeviceKey(
|
||||
userId = userId,
|
||||
deviceKey = trustedDevice.deviceKey,
|
||||
inMemoryOnly = true,
|
||||
)
|
||||
}
|
||||
.map { false }
|
||||
false.asSuccess()
|
||||
} else {
|
||||
vaultSdkSource
|
||||
.getTrustDevice(userId = userId)
|
||||
|
||||
Reference in New Issue
Block a user