From 6f4ea83fa9a6aa59ed69b9ff614f7a37a7c9a407 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Sat, 11 Jul 2020 13:03:53 +0200 Subject: [PATCH] Create allKnown() fun --- .../src/main/java/im/vector/matrix/rx/RxSession.kt | 4 +--- .../crypto/crosssigning/DefaultCrossSigningService.kt | 5 ++--- .../matrix/android/internal/crypto/store/PrivateKeysInfo.kt | 4 +++- .../features/workers/signout/ServerBackupStatusViewModel.kt | 5 ++--- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/matrix-sdk-android-rx/src/main/java/im/vector/matrix/rx/RxSession.kt b/matrix-sdk-android-rx/src/main/java/im/vector/matrix/rx/RxSession.kt index 98d055bee7..ad2245eef3 100644 --- a/matrix-sdk-android-rx/src/main/java/im/vector/matrix/rx/RxSession.kt +++ b/matrix-sdk-android-rx/src/main/java/im/vector/matrix/rx/RxSession.kt @@ -183,9 +183,7 @@ class RxSession(private val session: Session) { val is4SSetup = session.sharedSecretStorageService.isRecoverySetup() val isCrossSigningEnabled = crossSigningInfo.getOrNull() != null val isCrossSigningTrusted = crossSigningInfo.getOrNull()?.isTrusted() == true - val allPrivateKeysKnown = pInfo.getOrNull() - ?.let { it.master != null && it.selfSigned != null && it.user != null } - .orFalse() + val allPrivateKeysKnown = pInfo.getOrNull()?.allKnown().orFalse() val keysBackupService = session.cryptoService().keysBackupService() val currentBackupVersion = keysBackupService.currentBackupVersion diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/crosssigning/DefaultCrossSigningService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/crosssigning/DefaultCrossSigningService.kt index fdecfe202e..5a7c07fb53 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/crosssigning/DefaultCrossSigningService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/crosssigning/DefaultCrossSigningService.kt @@ -18,6 +18,7 @@ package im.vector.matrix.android.internal.crypto.crosssigning import androidx.lifecycle.LiveData import im.vector.matrix.android.api.MatrixCallback +import im.vector.matrix.android.api.extensions.orFalse import im.vector.matrix.android.api.session.crypto.crosssigning.CrossSigningService import im.vector.matrix.android.api.session.crypto.crosssigning.MXCrossSigningInfo import im.vector.matrix.android.api.util.Optional @@ -509,9 +510,7 @@ internal class DefaultCrossSigningService @Inject constructor( override fun allPrivateKeysKnown(): Boolean { return checkSelfTrust().isVerified() - && cryptoStore.getCrossSigningPrivateKeys()?.selfSigned != null - && cryptoStore.getCrossSigningPrivateKeys()?.user != null - && cryptoStore.getCrossSigningPrivateKeys()?.master != null + && cryptoStore.getCrossSigningPrivateKeys()?.allKnown().orFalse() } override fun trustUser(otherUserId: String, callback: MatrixCallback) { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/store/PrivateKeysInfo.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/store/PrivateKeysInfo.kt index a10b6d2645..d1591e35d8 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/store/PrivateKeysInfo.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/store/PrivateKeysInfo.kt @@ -20,4 +20,6 @@ data class PrivateKeysInfo( val master: String? = null, val selfSigned: String? = null, val user: String? = null -) +) { + fun allKnown() = master != null && selfSigned != null && user != null +} diff --git a/vector/src/main/java/im/vector/riotx/features/workers/signout/ServerBackupStatusViewModel.kt b/vector/src/main/java/im/vector/riotx/features/workers/signout/ServerBackupStatusViewModel.kt index dca98c16b2..bfeb959534 100644 --- a/vector/src/main/java/im/vector/riotx/features/workers/signout/ServerBackupStatusViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/workers/signout/ServerBackupStatusViewModel.kt @@ -26,6 +26,7 @@ import com.airbnb.mvrx.Uninitialized import com.airbnb.mvrx.ViewModelContext import com.squareup.inject.assisted.Assisted import com.squareup.inject.assisted.AssistedInject +import im.vector.matrix.android.api.extensions.orFalse import im.vector.matrix.android.api.session.Session import im.vector.matrix.android.api.session.crypto.crosssigning.MASTER_KEY_SSSS_NAME import im.vector.matrix.android.api.session.crypto.crosssigning.MXCrossSigningInfo @@ -114,9 +115,7 @@ class ServerBackupStatusViewModel @AssistedInject constructor(@Assisted initialS // So recovery is not setup // Check if cross signing is enabled and local secrets known if (crossSigningInfo.getOrNull()?.isTrusted() == true - && pInfo.getOrNull()?.master != null - && pInfo.getOrNull()?.selfSigned != null - && pInfo.getOrNull()?.user != null + && pInfo.getOrNull()?.allKnown().orFalse() ) { // So 4S is not setup and we have local secrets, return@Function4 BannerState.Setup(numberOfKeys = getNumberOfKeysToBackup())