Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable reset all and skip options #7721

Merged
merged 4 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions library/ui-strings/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@
<string name="action_play">Play</string>
<string name="action_dismiss">Dismiss</string>
<string name="action_reset">Reset</string>
<string name="action_proceed_to_reset">Proceed to reset</string>
<string name="action_learn_more">Learn more</string>
<string name="action_next">Next</string>
<string name="action_got_it">Got it</string>
Expand Down Expand Up @@ -2635,8 +2636,10 @@
<string name="bad_passphrase_key_reset_all_action">Forgot or lost all recovery options? Reset everything</string>
<string name="secure_backup_reset_all">Reset everything</string>
<string name="secure_backup_reset_all_no_other_devices">Only do this if you have no other device you can verify this device with.</string>
<string name="secure_backup_reset_all_no_other_devices_long">Resetting your verification keys cannot be undone. After resetting, you won\'t have access to old encrypted messages, and any friends who have previously verified you will see security warnings until you re-verify with them.</string>
<string name="secure_backup_reset_if_you_reset_all">If you reset everything</string>
<string name="secure_backup_reset_no_history">You will restart with no history, no messages, trusted devices or trusted users</string>
<string name="secure_backup_reset_danger_warning">Please only proceed if you\'re sure you\'ve lost all of your other devices and your security key.</string>
<plurals name="secure_backup_reset_devices_you_can_verify">
<item quantity="one">Show the device you can verify with now</item>
<item quantity="other">Show %d devices you can verify with now</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ package org.matrix.android.sdk.internal.session.room.summary

import io.realm.Realm
import io.realm.kotlin.createObject
import kotlinx.coroutines.runBlocking
import org.matrix.android.sdk.api.extensions.orFalse
import org.matrix.android.sdk.api.extensions.tryOrNull
import org.matrix.android.sdk.api.session.events.model.EventType
import org.matrix.android.sdk.api.session.events.model.content.EncryptionEventContent
import org.matrix.android.sdk.api.session.events.model.toModel
Expand All @@ -41,7 +39,6 @@ import org.matrix.android.sdk.api.session.room.send.SendState
import org.matrix.android.sdk.api.session.sync.model.RoomSyncSummary
import org.matrix.android.sdk.api.session.sync.model.RoomSyncUnreadNotifications
import org.matrix.android.sdk.api.session.sync.model.RoomSyncUnreadThreadNotifications
import org.matrix.android.sdk.internal.crypto.EventDecryptor
import org.matrix.android.sdk.internal.database.mapper.ContentMapper
import org.matrix.android.sdk.internal.database.mapper.asDomain
import org.matrix.android.sdk.internal.database.model.CurrentStateEventEntity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ internal class RoomSummaryEventDecryptor @Inject constructor(
}

private val scope: CoroutineScope = CoroutineScope(
cryptoCoroutineScope.coroutineContext
+ SupervisorJob()
+ CoroutineName("RoomSummaryDecryptor")
cryptoCoroutineScope.coroutineContext +
SupervisorJob() +
CoroutineName("RoomSummaryDecryptor")
)

private val channel = Channel<Message>(capacity = 300)
Expand Down Expand Up @@ -116,8 +116,8 @@ internal class RoomSummaryEventDecryptor @Inject constructor(
}
}

if (failure.errorType == MXCryptoError.ErrorType.UNKNOWN_INBOUND_SESSION_ID
|| failure.errorType == MXCryptoError.ErrorType.UNKNOWN_MESSAGE_INDEX) {
if (failure.errorType == MXCryptoError.ErrorType.UNKNOWN_INBOUND_SESSION_ID ||
failure.errorType == MXCryptoError.ErrorType.UNKNOWN_MESSAGE_INDEX) {
(event.content["session_id"] as? String)?.let { sessionId ->
unknownSessionsFailure.getOrPut(sessionId) { mutableSetOf() }
.add(event)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package org.matrix.android.sdk.api.session.crypto.keysbackup

import org.matrix.android.sdk.api.session.securestorage.SsssPassphrase

object BackupUtils {
fun recoveryKeyFromBase58(key: String): IBackupRecoveryKey? = BackupRecoveryKey.fromBase58(key)
fun recoveryKeyFromPassphrase(passphrase: String): IBackupRecoveryKey? = BackupRecoveryKey.newFromPassphrase(passphrase)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import org.matrix.android.sdk.api.session.crypto.crosssigning.DeviceTrustLevel
import org.matrix.android.sdk.api.session.crypto.crosssigning.MXCrossSigningInfo
import org.matrix.android.sdk.api.session.crypto.crosssigning.PrivateKeysInfo
import org.matrix.android.sdk.api.session.crypto.crosssigning.UserTrustResult
import org.matrix.android.sdk.api.session.crypto.keysbackup.MegolmBackupAuthData
import org.matrix.android.sdk.api.session.crypto.model.CryptoDeviceInfo
import org.matrix.android.sdk.api.session.crypto.model.ImportRoomKeysResult
import org.matrix.android.sdk.api.session.crypto.model.MXEventDecryptionResult
Expand All @@ -52,7 +51,6 @@ import org.matrix.android.sdk.api.util.JsonDict
import org.matrix.android.sdk.api.util.Optional
import org.matrix.android.sdk.api.util.toOptional
import org.matrix.android.sdk.internal.coroutines.builder.safeInvokeOnClose
import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.CreateKeysBackupVersionBody
import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.DefaultKeysAlgorithmAndData
import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.KeysAlgorithmAndData
import org.matrix.android.sdk.internal.crypto.network.RequestSender
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class SharedSecureStorageActivity :
val requestedSecrets: List<String> = emptyList(),
val resultKeyStoreAlias: String,
val writeSecrets: List<Pair<String, String>> = emptyList(),
val currentStep: SharedSecureStorageViewState.Step = SharedSecureStorageViewState.Step.EnterPassphrase,
) : Parcelable

private val viewModel: SharedSecureStorageViewModel by viewModel()
Expand Down Expand Up @@ -150,7 +151,8 @@ class SharedSecureStorageActivity :
context: Context,
keyId: String? = null,
requestedSecrets: List<String>,
resultKeyStoreAlias: String = DEFAULT_RESULT_KEYSTORE_ALIAS
resultKeyStoreAlias: String = DEFAULT_RESULT_KEYSTORE_ALIAS,
initialStep: SharedSecureStorageViewState.Step = SharedSecureStorageViewState.Step.EnterPassphrase
): Intent {
require(requestedSecrets.isNotEmpty())
return Intent(context, SharedSecureStorageActivity::class.java).also {
Expand All @@ -159,7 +161,8 @@ class SharedSecureStorageActivity :
Args(
keyId = keyId,
requestedSecrets = requestedSecrets,
resultKeyStoreAlias = resultKeyStoreAlias
resultKeyStoreAlias = resultKeyStoreAlias,
currentStep = initialStep
)
)
}
Expand All @@ -169,7 +172,8 @@ class SharedSecureStorageActivity :
context: Context,
keyId: String? = null,
writeSecrets: List<Pair<String, String>>,
resultKeyStoreAlias: String = DEFAULT_RESULT_KEYSTORE_ALIAS
resultKeyStoreAlias: String = DEFAULT_RESULT_KEYSTORE_ALIAS,
initialStep: SharedSecureStorageViewState.Step = SharedSecureStorageViewState.Step.EnterPassphrase
): Intent {
require(writeSecrets.isNotEmpty())
return Intent(context, SharedSecureStorageActivity::class.java).also {
Expand All @@ -178,7 +182,8 @@ class SharedSecureStorageActivity :
Args(
keyId = keyId,
writeSecrets = writeSecrets,
resultKeyStoreAlias = resultKeyStoreAlias
resultKeyStoreAlias = resultKeyStoreAlias,
currentStep = initialStep,
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ data class SharedSecureStorageViewState(
val ready: Boolean = false,
val hasPassphrase: Boolean = true,
val checkingSSSSAction: Async<Unit> = Uninitialized,
val step: Step = Step.EnterPassphrase,
val step: Step = Step.ResetAll,
val activeDeviceCount: Int = 0,
val showResetAllAction: Boolean = false,
val userId: String = "",
Expand All @@ -74,7 +74,8 @@ data class SharedSecureStorageViewState(
} else {
RequestType.ReadSecrets(args.requestedSecrets)
},
resultKeyStoreAlias = args.resultKeyStoreAlias
resultKeyStoreAlias = args.resultKeyStoreAlias,
step = args.currentStep,
)

enum class Step {
Expand Down Expand Up @@ -113,30 +114,35 @@ class SharedSecureStorageViewModel @AssistedInject constructor(
)
}
}
val keyResult = initialState.keyId?.let { session.sharedSecretStorageService().getKey(it) }
?: session.sharedSecretStorageService().getDefaultKey()

if (!keyResult.isSuccess()) {
_viewEvents.post(SharedSecureStorageViewEvent.Dismiss)
} else {
val info = (keyResult as KeyInfoResult.Success).keyInfo
if (info.content.passphrase != null) {
setState {
copy(
hasPassphrase = true,
ready = true,
step = SharedSecureStorageViewState.Step.EnterPassphrase
)
}
if (initialState.step != SharedSecureStorageViewState.Step.ResetAll) {
val keyResult = initialState.keyId?.let { session.sharedSecretStorageService().getKey(it) }
?: session.sharedSecretStorageService().getDefaultKey()

if (!keyResult.isSuccess()) {
_viewEvents.post(SharedSecureStorageViewEvent.Dismiss)
} else {
setState {
copy(
hasPassphrase = false,
ready = true,
step = SharedSecureStorageViewState.Step.EnterKey
)
val info = (keyResult as KeyInfoResult.Success).keyInfo
if (info.content.passphrase != null) {
setState {
copy(
hasPassphrase = true,
ready = true,
step = SharedSecureStorageViewState.Step.EnterPassphrase
)
}
} else {
setState {
copy(
hasPassphrase = false,
ready = true,
step = SharedSecureStorageViewState.Step.EnterKey
)
}
}
}
} else {
setState { copy(ready = true) }
}

session.flow()
Expand Down Expand Up @@ -203,6 +209,7 @@ class SharedSecureStorageViewModel @AssistedInject constructor(
_viewEvents.post(SharedSecureStorageViewEvent.Dismiss)
}
}
/*
SharedSecureStorageViewState.Step.ResetAll -> {
setState {
copy(
Expand All @@ -211,6 +218,7 @@ class SharedSecureStorageViewModel @AssistedInject constructor(
)
}
}
*/
else -> {
_viewEvents.post(SharedSecureStorageViewEvent.Dismiss)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ sealed class VerificationAction : VectorViewModelAction {
data class GotItConclusion(val verified: Boolean) : VerificationAction()
object FailedToGetKeysFrom4S : VerificationAction()
object SkipVerification : VerificationAction()
object ForgotResetAll : VerificationAction()
object VerifyFromPassphrase : VerificationAction()
object ReadyPendingVerification : VerificationAction()
object CancelPendingVerification : VerificationAction()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import im.vector.app.core.platform.VectorViewEvents
sealed class VerificationBottomSheetViewEvents : VectorViewEvents {
object Dismiss : VerificationBottomSheetViewEvents()
object AccessSecretStore : VerificationBottomSheetViewEvents()
object ResetAll : VerificationBottomSheetViewEvents()
object GoToSettings : VerificationBottomSheetViewEvents()
data class ModalError(val errorMessage: CharSequence) : VerificationBottomSheetViewEvents()
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import im.vector.app.core.extensions.toMvRxBundle
import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment
import im.vector.app.databinding.BottomSheetVerificationBinding
import im.vector.app.features.crypto.quads.SharedSecureStorageActivity
import im.vector.app.features.crypto.quads.SharedSecureStorageViewState
import im.vector.app.features.crypto.verification.VerificationAction
import im.vector.app.features.crypto.verification.VerificationBottomSheetViewEvents
import kotlinx.parcelize.Parcelize
Expand Down Expand Up @@ -92,7 +93,18 @@ class SelfVerificationBottomSheet : VectorBaseBottomSheetDialogFragment<BottomSh
requireContext(),
null, // use default key
listOf(MASTER_KEY_SSSS_NAME, USER_SIGNING_KEY_SSSS_NAME, SELF_SIGNING_KEY_SSSS_NAME, KEYBACKUP_SECRET_SSSS_NAME),
SharedSecureStorageActivity.DEFAULT_RESULT_KEYSTORE_ALIAS
SharedSecureStorageActivity.DEFAULT_RESULT_KEYSTORE_ALIAS,
)
)
}
VerificationBottomSheetViewEvents.ResetAll -> {
secretStartForActivityResult.launch(
SharedSecureStorageActivity.newReadIntent(
requireContext(),
null, // use default key
listOf(MASTER_KEY_SSSS_NAME, USER_SIGNING_KEY_SSSS_NAME, SELF_SIGNING_KEY_SSSS_NAME, KEYBACKUP_SECRET_SSSS_NAME),
SharedSecureStorageActivity.DEFAULT_RESULT_KEYSTORE_ALIAS,
SharedSecureStorageViewState.Step.ResetAll
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ class SelfVerificationController @Inject constructor(
}
}
is Success -> {
val invoke = action.invoke()
if (invoke) {
val value = action.invoke()
if (value) {
verifiedSuccessTile()
bottomDone { (host.listener as? InteractionListener)?.onDoneFrom4S() }
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ class SelfVerificationFragment : VectorBaseFragment<BottomSheetVerificationChil
}

override fun onClickSkip() {
TODO("Not yet implemented")
viewModel.handle(VerificationAction.SkipVerification)
}

override fun onClickResetSecurity() {
TODO("Not yet implemented")
viewModel.handle(VerificationAction.ForgotResetAll)
}

override fun onDoneFrom4S() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,17 @@ class SelfVerificationViewModel @AssistedInject constructor(
}
}
}
VerificationAction.SecuredStorageHasBeenReset -> TODO()
VerificationAction.SkipVerification -> TODO()
VerificationAction.SecuredStorageHasBeenReset -> {
if (session.cryptoService().crossSigningService().allPrivateKeysKnown()) {
_viewEvents.post(VerificationBottomSheetViewEvents.Dismiss)
}
}
VerificationAction.SkipVerification -> {
_viewEvents.post(VerificationBottomSheetViewEvents.Dismiss)
}
VerificationAction.ForgotResetAll -> {
_viewEvents.post(VerificationBottomSheetViewEvents.ResetAll)
}
VerificationAction.StartSASVerification -> {
withState { state ->
val request = state.pendingRequest.invoke() ?: return@withState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ class UserVerificationBottomSheet : VectorBaseBottomSheetDialogFragment<BottomSh
.setPositiveButton(R.string.ok, null)
.show()
}
VerificationBottomSheetViewEvents.ResetAll -> {
// no-op for user verification
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,9 @@ class UserVerificationViewModel @AssistedInject constructor(
// Not applicable for user verification
}
VerificationAction.RequestSelfVerification -> TODO()
VerificationAction.ForgotResetAll -> {
// Not applicable for user verification
}
}
}

Expand Down
24 changes: 6 additions & 18 deletions vector/src/main/res/layout/fragment_ssss_reset_all.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:text="@string/secure_backup_reset_all_no_other_devices"
android:text="@string/secure_backup_reset_all_no_other_devices_long"
android:textColor="?vctr_content_primary"
app:layout_constraintBottom_toTopOf="@id/ssss_reset_other_devices"
app:layout_constraintTop_toBottomOf="@id/reset_title" />
Expand All @@ -60,19 +60,6 @@
tools:text="Show 2 devices you can verify with now"
tools:visibility="visible" />

<TextView
android:id="@+id/ssss_reset_text3"
style="@style/Widget.Vector.TextView.Subtitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:text="@string/secure_backup_reset_if_you_reset_all"
android:textColor="?colorError"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/ssss_reset_other_devices" />

<TextView
android:id="@+id/ssss_reset_text4"
style="@style/Widget.Vector.TextView.Body"
Expand All @@ -82,9 +69,10 @@
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:text="@string/secure_backup_reset_no_history"
android:text="@string/secure_backup_reset_danger_warning"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it's for consistency with web?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

android:textColor="?vctr_content_primary"
app:layout_constraintTop_toBottomOf="@id/ssss_reset_text3" />
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/ssss_reset_other_devices" />

<Button
android:id="@+id/ssss_reset_button_cancel"
Expand All @@ -99,7 +87,7 @@
style="@style/Widget.Vector.Button.Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/action_reset"
android:text="@string/action_proceed_to_reset"
tools:ignore="MissingConstraints" />

<androidx.constraintlayout.helper.widget.Flow
Expand All @@ -118,4 +106,4 @@

</androidx.constraintlayout.widget.ConstraintLayout>

</ScrollView>
</ScrollView>