mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-26 11:26:01 +03:00
Fix / cross signing info live data not always updated
This commit is contained in:
parent
ea6e8a6789
commit
83e44ac96e
7 changed files with 151 additions and 141 deletions
|
@ -877,10 +877,10 @@ internal class RealmCryptoStore(private val realmConfiguration: RealmConfigurati
|
|||
}
|
||||
|
||||
override fun setMyCrossSigningInfo(info: MXCrossSigningInfo?) {
|
||||
doRealmQueryAndCopy(realmConfiguration) {
|
||||
it.where<CryptoMetadataEntity>().findFirst()
|
||||
}?.userId?.let {
|
||||
setCrossSigningInfo(it, info)
|
||||
doRealmTransaction(realmConfiguration) { realm ->
|
||||
realm.where<CryptoMetadataEntity>().findFirst()?.userId?.let { userId ->
|
||||
addOrUpdateCrossSigningInfo(realm, userId, info)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -998,7 +998,11 @@ internal class RealmCryptoStore(private val realmConfiguration: RealmConfigurati
|
|||
|
||||
override fun setCrossSigningInfo(userId: String, info: MXCrossSigningInfo?) {
|
||||
doRealmTransaction(realmConfiguration) { realm ->
|
||||
addOrUpdateCrossSigningInfo(realm, userId, info)
|
||||
}
|
||||
}
|
||||
|
||||
private fun addOrUpdateCrossSigningInfo(realm: Realm, userId: String, info: MXCrossSigningInfo?): CrossSigningInfoEntity? {
|
||||
var existing = CrossSigningInfoEntity.get(realm, userId)
|
||||
if (info == null) {
|
||||
// Delete known if needed
|
||||
|
@ -1007,14 +1011,15 @@ internal class RealmCryptoStore(private val realmConfiguration: RealmConfigurati
|
|||
} else {
|
||||
// Just override existing, caller should check and untrust id needed
|
||||
existing = CrossSigningInfoEntity.getOrCreate(realm, userId)
|
||||
// existing.crossSigningKeys.forEach { it.deleteFromRealm() }
|
||||
val xkeys = RealmList<KeyInfoEntity>()
|
||||
info.crossSigningKeys.forEach { info ->
|
||||
info.crossSigningKeys.forEach { cryptoCrossSigningKey ->
|
||||
xkeys.add(
|
||||
realm.createObject(KeyInfoEntity::class.java).also { keyInfoEntity ->
|
||||
keyInfoEntity.publicKeyBase64 = info.unpaddedBase64PublicKey
|
||||
keyInfoEntity.usages = info.usages?.let { RealmList(*it.toTypedArray()) }
|
||||
keyInfoEntity.publicKeyBase64 = cryptoCrossSigningKey.unpaddedBase64PublicKey
|
||||
keyInfoEntity.usages = cryptoCrossSigningKey.usages?.let { RealmList(*it.toTypedArray()) }
|
||||
?: RealmList()
|
||||
keyInfoEntity.putSignatures(info.signatures)
|
||||
keyInfoEntity.putSignatures(cryptoCrossSigningKey.signatures)
|
||||
// TODO how to handle better, check if same keys?
|
||||
// reset trust
|
||||
keyInfoEntity.trustLevelEntity = null
|
||||
|
@ -1023,6 +1028,6 @@ internal class RealmCryptoStore(private val realmConfiguration: RealmConfigurati
|
|||
}
|
||||
existing.crossSigningKeys = xkeys
|
||||
}
|
||||
}
|
||||
return existing
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,7 +46,6 @@ import im.vector.matrix.rx.mapOptional
|
|||
import im.vector.matrix.rx.rx
|
||||
import im.vector.matrix.rx.unwrap
|
||||
import im.vector.riotx.R
|
||||
import im.vector.riotx.core.di.HasScreenInjector
|
||||
import im.vector.riotx.core.platform.VectorViewModel
|
||||
import im.vector.riotx.core.resources.StringProvider
|
||||
import im.vector.riotx.core.utils.DataSource
|
||||
|
@ -75,7 +74,6 @@ class RoomMemberProfileViewModel @AssistedInject constructor(@Assisted private v
|
|||
val fragment: RoomMemberProfileFragment = (viewModelContext as FragmentViewModelContext).fragment()
|
||||
return fragment.viewModelFactory.create(state)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private val _viewEvents = PublishDataSource<RoomMemberProfileViewEvents>()
|
||||
|
@ -118,11 +116,8 @@ class RoomMemberProfileViewModel @AssistedInject constructor(@Assisted private v
|
|||
}
|
||||
|
||||
session.rx().liveCrossSigningInfo(initialState.userId)
|
||||
.map {
|
||||
it.getOrNull()
|
||||
}
|
||||
.execute {
|
||||
copy(userMXCrossSigningInfo = it)
|
||||
copy(userMXCrossSigningInfo = it.invoke()?.getOrNull())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -150,7 +145,7 @@ class RoomMemberProfileViewModel @AssistedInject constructor(@Assisted private v
|
|||
private fun prepareVerification(action: RoomMemberProfileAction.VerifyUser) = withState { state ->
|
||||
// Sanity
|
||||
if (state.isRoomEncrypted) {
|
||||
if (!state.isMine && state.userMXCrossSigningInfo.invoke()?.isTrusted() == false) {
|
||||
if (!state.isMine && state.userMXCrossSigningInfo?.isTrusted() == false) {
|
||||
// ok, let's find or create the DM room
|
||||
_actionResultLiveData.postValue(
|
||||
LiveEvent(Success(action.copy(userId = state.userId)))
|
||||
|
|
|
@ -35,7 +35,7 @@ data class RoomMemberProfileViewState(
|
|||
val powerLevelsContent: Async<PowerLevelsContent> = Uninitialized,
|
||||
val userPowerLevelString: Async<String> = Uninitialized,
|
||||
val userMatrixItem: Async<MatrixItem> = Uninitialized,
|
||||
val userMXCrossSigningInfo: Async<MXCrossSigningInfo?> = Uninitialized,
|
||||
val userMXCrossSigningInfo: MXCrossSigningInfo? = null,
|
||||
val allDevicesAreTrusted: Async<Boolean> = Uninitialized
|
||||
) : MvRxState {
|
||||
|
||||
|
|
|
@ -74,11 +74,8 @@ class DeviceListBottomSheetViewModel @AssistedInject constructor(@Assisted priva
|
|||
}
|
||||
|
||||
session.rx().liveCrossSigningInfo(userId)
|
||||
.map {
|
||||
it.getOrNull()
|
||||
}
|
||||
.execute {
|
||||
copy(memberCrossSigningKey = it.invoke())
|
||||
copy(memberCrossSigningKey = it.invoke()?.getOrNull())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -105,6 +105,7 @@ class VectorSettingsSecurityPrivacyFragment @Inject constructor(
|
|||
super.onResume()
|
||||
// My device name may have been updated
|
||||
refreshMyDevice()
|
||||
refreshXSigningStatus()
|
||||
mCryptographyCategory.isVisible = vectorPreferences.developerMode()
|
||||
}
|
||||
|
||||
|
@ -128,6 +129,10 @@ class VectorSettingsSecurityPrivacyFragment @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
refreshXSigningStatus()
|
||||
}
|
||||
|
||||
private fun refreshXSigningStatus() {
|
||||
if (vectorPreferences.developerMode()) {
|
||||
val crossSigningKeys = session.getCrossSigningService().getMyCrossSigningKeys()
|
||||
val xSigningIsEnableInAccount = crossSigningKeys != null
|
||||
|
|
|
@ -16,8 +16,6 @@
|
|||
package im.vector.riotx.features.settings.crosssigning
|
||||
|
||||
import com.airbnb.epoxy.TypedEpoxyController
|
||||
import com.airbnb.mvrx.Loading
|
||||
import com.airbnb.mvrx.Success
|
||||
import im.vector.riotx.R
|
||||
import im.vector.riotx.core.epoxy.loadingItem
|
||||
import im.vector.riotx.core.resources.ColorProvider
|
||||
|
@ -50,6 +48,7 @@ class CrossSigningEpoxyController @Inject constructor(
|
|||
titleIconResourceId(R.drawable.ic_shield_trusted)
|
||||
title(stringProvider.getString(R.string.encryption_information_dg_xsigning_complete))
|
||||
}
|
||||
if (!data.isUploadingKeys) {
|
||||
bottomSheetVerificationActionItem {
|
||||
id("resetkeys")
|
||||
title("Reset keys")
|
||||
|
@ -60,12 +59,14 @@ class CrossSigningEpoxyController @Inject constructor(
|
|||
interactionListener?.onResetCrossSigningKeys()
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (data.xSigningKeysAreTrusted) {
|
||||
genericItem {
|
||||
id("trusted")
|
||||
titleIconResourceId(R.drawable.ic_shield_warning)
|
||||
title(stringProvider.getString(R.string.encryption_information_dg_xsigning_trusted))
|
||||
}
|
||||
if (!data.isUploadingKeys) {
|
||||
bottomSheetVerificationActionItem {
|
||||
id("resetkeys")
|
||||
title("Reset keys")
|
||||
|
@ -92,12 +93,13 @@ class CrossSigningEpoxyController @Inject constructor(
|
|||
interactionListener?.onResetCrossSigningKeys()
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
genericItem {
|
||||
id("not")
|
||||
title(stringProvider.getString(R.string.encryption_information_dg_xsigning_disabled))
|
||||
}
|
||||
|
||||
if (!data.isUploadingKeys) {
|
||||
bottomSheetVerificationActionItem {
|
||||
id("initKeys")
|
||||
title("Initialize keys")
|
||||
|
@ -109,15 +111,15 @@ class CrossSigningEpoxyController @Inject constructor(
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
when (data.crossSigningInfo) {
|
||||
is Loading -> {
|
||||
if (data.isUploadingKeys) {
|
||||
loadingItem {
|
||||
id("loading")
|
||||
}
|
||||
}
|
||||
is Success -> {
|
||||
val crossSigningKeys = data.crossSigningInfo.invoke()
|
||||
} else {
|
||||
|
||||
val crossSigningKeys = data.crossSigningInfo
|
||||
|
||||
crossSigningKeys?.masterKey()?.let {
|
||||
genericItemWithValue {
|
||||
|
@ -170,4 +172,3 @@ class CrossSigningEpoxyController @Inject constructor(
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ import androidx.lifecycle.MutableLiveData
|
|||
import com.airbnb.mvrx.Async
|
||||
import com.airbnb.mvrx.Fail
|
||||
import com.airbnb.mvrx.FragmentViewModelContext
|
||||
import com.airbnb.mvrx.Loading
|
||||
import com.airbnb.mvrx.MvRxState
|
||||
import com.airbnb.mvrx.MvRxViewModelFactory
|
||||
import com.airbnb.mvrx.Success
|
||||
|
@ -44,10 +43,11 @@ import im.vector.riotx.core.resources.StringProvider
|
|||
import im.vector.riotx.core.utils.LiveEvent
|
||||
|
||||
data class CrossSigningSettingsViewState(
|
||||
val crossSigningInfo: Async<MXCrossSigningInfo?> = Uninitialized,
|
||||
val crossSigningInfo: MXCrossSigningInfo? = null,
|
||||
val xSigningIsEnableInAccount: Boolean = false,
|
||||
val xSigningKeysAreTrusted: Boolean = false,
|
||||
val xSigningKeyCanSign: Boolean = true
|
||||
val xSigningKeyCanSign: Boolean = true,
|
||||
val isUploadingKeys: Boolean = false
|
||||
) : MvRxState
|
||||
|
||||
sealed class CrossSigningAction : VectorViewModelAction {
|
||||
|
@ -67,16 +67,13 @@ class CrossSigningSettingsViewModel @AssistedInject constructor(@Assisted privat
|
|||
|
||||
init {
|
||||
session.rx().liveCrossSigningInfo(session.myUserId)
|
||||
.map {
|
||||
it.getOrNull()
|
||||
}
|
||||
.execute {
|
||||
val crossSigningKeys = it.invoke()
|
||||
val crossSigningKeys = it.invoke()?.getOrNull()
|
||||
val xSigningIsEnableInAccount = crossSigningKeys != null
|
||||
val xSigningKeysAreTrusted = session.getCrossSigningService().checkUserTrust(session.myUserId).isVerified()
|
||||
val xSigningKeyCanSign = session.getCrossSigningService().canCrossSign()
|
||||
copy(
|
||||
crossSigningInfo = it,
|
||||
crossSigningInfo = crossSigningKeys,
|
||||
xSigningIsEnableInAccount = xSigningIsEnableInAccount,
|
||||
xSigningKeysAreTrusted = xSigningKeysAreTrusted,
|
||||
xSigningKeyCanSign = xSigningKeyCanSign
|
||||
|
@ -99,9 +96,16 @@ class CrossSigningSettingsViewModel @AssistedInject constructor(@Assisted privat
|
|||
|
||||
private fun initializeCrossSigning(auth: UserPasswordAuth?) {
|
||||
setState {
|
||||
copy(crossSigningInfo = Loading())
|
||||
copy(isUploadingKeys = true)
|
||||
}
|
||||
session.getCrossSigningService().initializeCrossSigning(auth, object : MatrixCallback<Unit> {
|
||||
|
||||
override fun onSuccess(data: Unit) {
|
||||
setState {
|
||||
copy(isUploadingKeys = false)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFailure(failure: Throwable) {
|
||||
if (failure is Failure.OtherServerError
|
||||
&& failure.httpCode == 401
|
||||
|
@ -125,6 +129,9 @@ class CrossSigningSettingsViewModel @AssistedInject constructor(@Assisted privat
|
|||
}
|
||||
}
|
||||
_requestLiveData.postValue(LiveEvent(Fail(Throwable("You cannot do that from mobile"))))
|
||||
setState {
|
||||
copy(isUploadingKeys = false)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue