Map active flags from core user keys to mail domain user keys

We need to have the active flag on user keys to make sure
the client doesn't use the inactive user keys.
The flags is already kept by the core model, we need to formard to the mail domain
user keys.

MAILAND-2725
This commit is contained in:
M. Thiercelin 2022-02-22 18:44:05 +01:00 committed by Marin Thiercelin
parent 1b6c0f5064
commit d0f98baad2
5 changed files with 15 additions and 11 deletions

View File

@ -140,7 +140,8 @@ class AddressCryptoAndroidTest {
UserId(USER_ID_VALUE),
0u,
PgpField.PrivateKey(NotBlankString(ACTIVER_USER_KEY.trimIndent())),
null
null,
active = true,
)
)
}
@ -183,13 +184,15 @@ class AddressCryptoAndroidTest {
UserId(USER_ID_VALUE),
0u,
PgpField.PrivateKey(NotBlankString(INACTIVE_USER_KEY.trimIndent())),
null
null,
active = true,
),
UserKey(
UserId(USER_ID_VALUE),
0u,
PgpField.PrivateKey(NotBlankString(ACTIVER_USER_KEY.trimIndent())),
null
null,
active = true,
),
)
val key = AddressKey(

View File

@ -21,13 +21,9 @@ package ch.protonmail.android.feature.user
import ch.protonmail.android.api.models.Keys
import ch.protonmail.android.api.models.address.Address
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.filterIsInstance
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.runBlocking
import me.proton.core.crypto.common.keystore.KeyStoreCrypto
import me.proton.core.crypto.common.keystore.decrypt
import me.proton.core.domain.arch.DataResult
import me.proton.core.domain.entity.UserId
import me.proton.core.key.domain.extension.primary
import me.proton.core.network.domain.ApiException
@ -65,7 +61,7 @@ fun UserManager.getLegacyKeysBlocking(userId: UserId): List<Keys> = getUserBlock
null,
null,
key.activation,
1
key.privateKey.isActive.toInt()
)
}

View File

@ -61,7 +61,8 @@ class UserKeyBridgeMapper @Inject constructor() : BridgeMapper<OldKey, UserKey>
id = UserId(id),
version = 4.toUInt(), // TODO not implemented on old Keys
privateKey = PgpField.PrivateKey(NotBlankString(privateKey)),
token = getToken(token)
token = getToken(token),
active = active == 1
)
private fun getToken(token: String?) = token?.takeIfNotBlank()?.let { PgpField.Message(NotBlankString(it)) }

View File

@ -34,7 +34,8 @@ data class UserKey(
val id: UserId,
val version: UInt,
val privateKey: PgpField.PrivateKey,
val token: PgpField.Message?
val token: PgpField.Message?,
val active: Boolean,
)
/**

View File

@ -54,6 +54,7 @@ internal class UserTest {
User(addresses = Addresses(emptyMap()), plans = listOf(Mail.Paid))
}
}
// endregion
// region keys
@ -69,6 +70,7 @@ internal class UserTest {
User(addresses = notEmptyAddresses, keys = UserKeys.Empty)
}
}
// endregion
// region plans
@ -143,7 +145,8 @@ internal class UserTest {
UserId("key"),
4.toUInt(),
PgpField.PrivateKey(NotBlankString("key")),
PgpField.Message(NotBlankString("token"))
PgpField.Message(NotBlankString("token")),
active = true
)
private val notEmptyKeys = UserKeys(dummyKey, listOf(dummyKey))