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

Restore rust crypto migration #1013

Merged
merged 4 commits into from
Feb 23, 2024
Merged

Conversation

yostyle
Copy link
Contributor

@yostyle yostyle commented Feb 23, 2024

Type of change

  • Feature
  • Bugfix
  • Technical
  • Other :

Content

Motivation and context

the app crashes during rust crypto migration.

ACRA caught a OpenStore for fr.gouv.tchap.a
org.matrix.rustcomponents.sdk.crypto.CryptoStoreException$OpenStore: Failed to open the store
	at org.matrix.rustcomponents.sdk.crypto.FfiConverterTypeCryptoStoreError.read(matrix_sdk_crypto_ffi.kt:9)
	at org.matrix.rustcomponents.sdk.crypto.FfiConverterTypeCryptoStoreError.read(matrix_sdk_crypto_ffi.kt:1)
	at org.matrix.rustcomponents.sdk.crypto.FfiConverter$DefaultImpls.liftFromRustBuffer(matrix_sdk_crypto_ffi.kt:13)
	at org.matrix.rustcomponents.sdk.crypto.FfiConverterRustBuffer$DefaultImpls.liftFromRustBuffer(matrix_sdk_crypto_ffi.kt:6)
	at org.matrix.rustcomponents.sdk.crypto.FfiConverterTypeCryptoStoreError.liftFromRustBuffer(matrix_sdk_crypto_ffi.kt:2)
	at org.matrix.rustcomponents.sdk.crypto.FfiConverterTypeCryptoStoreError.liftFromRustBuffer(matrix_sdk_crypto_ffi.kt:1)
	at org.matrix.rustcomponents.sdk.crypto.FfiConverterRustBuffer$DefaultImpls.lift(matrix_sdk_crypto_ffi.kt:6)
	at org.matrix.rustcomponents.sdk.crypto.FfiConverterTypeCryptoStoreError.lift(matrix_sdk_crypto_ffi.kt:3)
	at org.matrix.rustcomponents.sdk.crypto.CryptoStoreException$ErrorHandler.lift(matrix_sdk_crypto_ffi.kt:3)
	at org.matrix.rustcomponents.sdk.crypto.CryptoStoreException$ErrorHandler.lift(matrix_sdk_crypto_ffi.kt:1)
	at org.matrix.rustcomponents.sdk.crypto.Matrix_sdk_crypto_ffiKt.checkCallStatus(matrix_sdk_crypto_ffi.kt:75)
	at org.matrix.rustcomponents.sdk.crypto.OlmMachine.<init>(matrix_sdk_crypto_ffi.kt:5)
	at org.matrix.android.sdk.internal.crypto.OlmMachine.<init>(OlmMachine.kt:100)
	at org.matrix.android.sdk.internal.crypto.OlmMachine_Factory.newInstance(OlmMachine_Factory.java:29)
	at org.matrix.android.sdk.internal.crypto.OlmMachine_Factory.get(OlmMachine_Factory.java:2)
	at org.matrix.android.sdk.internal.crypto.OlmMachine_Factory.get(OlmMachine_Factory.java:1)
	at dagger.internal.DoubleCheck.get(DoubleCheck.java:14)
	at dagger.internal.DelegateFactory.get(DelegateFactory.java:5)
	at org.matrix.android.sdk.internal.crypto.DecryptRoomEventUseCase_Factory.get(DecryptRoomEventUseCase_Factory.java:2)
	at org.matrix.android.sdk.internal.crypto.DecryptRoomEventUseCase_Factory.get(DecryptRoomEventUseCase_Factory.java:1)
	at org.matrix.android.sdk.internal.crypto.EventDecryptor_Factory.get(EventDecryptor_Factory.java:2)
	at org.matrix.android.sdk.internal.crypto.EventDecryptor_Factory.get(EventDecryptor_Factory.java:1)
	at org.matrix.android.sdk.internal.session.room.event.DefaultFilterAndStoreEventsTask_Factory.get(DefaultFilterAndStoreEventsTask_Factory.java:2)
	at org.matrix.android.sdk.internal.session.room.event.DefaultFilterAndStoreEventsTask_Factory.get(DefaultFilterAndStoreEventsTask_Factory.java:1)
	at org.matrix.android.sdk.internal.session.room.relation.poll.DefaultFetchPollResponseEventsTask_Factory.get(DefaultFetchPollResponseEventsTask_Factory.java:2)
	at org.matrix.android.sdk.internal.session.room.relation.poll.DefaultFetchPollResponseEventsTask_Factory.get(DefaultFetchPollResponseEventsTask_Factory.java:1)
	at org.matrix.android.sdk.internal.session.room.aggregation.poll.DefaultPollAggregationProcessor_Factory.get(DefaultPollAggregationProcessor_Factory.java:2)
	at org.matrix.android.sdk.internal.session.room.aggregation.poll.DefaultPollAggregationProcessor_Factory.get(DefaultPollAggregationProcessor_Factory.java:1)
	at org.matrix.android.sdk.internal.session.room.EventRelationsAggregationProcessor_Factory.get(EventRelationsAggregationProcessor_Factory.java:2)
	at org.matrix.android.sdk.internal.session.room.EventRelationsAggregationProcessor_Factory.get(EventRelationsAggregationProcessor_Factory.java:1)
	at dagger.internal.SetFactory.get(SetFactory.java:11)
	at dagger.internal.SetFactory.get(SetFactory.java:1)
	at org.matrix.android.sdk.internal.database.EventInsertLiveObserver_Factory.get(EventInsertLiveObserver_Factory.java:2)
	at org.matrix.android.sdk.internal.database.EventInsertLiveObserver_Factory.get(EventInsertLiveObserver_Factory.java:1)
	at dagger.internal.SetFactory.get(SetFactory.java:11)
	at dagger.internal.SetFactory.get(SetFactory.java:1)
	at org.matrix.android.sdk.internal.session.DefaultSession_Factory.get(DefaultSession_Factory.java:2)
	at org.matrix.android.sdk.internal.session.DefaultSession_Factory.get(DefaultSession_Factory.java:1)
	at dagger.internal.DoubleCheck.get(DoubleCheck.java:14)
	at dagger.internal.DelegateFactory.get(DelegateFactory.java:5)
	at org.matrix.android.sdk.internal.session.DaggerSessionComponent$SessionComponentImpl.session(DaggerSessionComponent.java:3)
	at org.matrix.android.sdk.internal.SessionManager.getOrCreateSession(SessionManager.kt:10)
	at org.matrix.android.sdk.internal.SessionManager.getLastSession(SessionManager.kt:9)
	at org.matrix.android.sdk.internal.auth.DefaultAuthenticationService.getLastAuthenticatedSession(DefaultAuthenticationService.kt:3)
	at im.vector.app.core.di.SessionInitializer.tryInitialize(SessionInitializer.kt:109)
	at im.vector.app.core.di.ActiveSessionHolder.getOrInitializeSession(ActiveSessionHolder.kt:23)
	at im.vector.app.features.start.StartAppViewModel.eagerlyInitializeSession(StartAppViewModel.kt:3)
	at im.vector.app.features.start.StartAppViewModel.access$eagerlyInitializeSession(StartAppViewModel.kt:1)
	at im.vector.app.features.start.StartAppViewModel$handleStartApp$1.invokeSuspend(StartAppViewModel.kt:29)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:12)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:124)
	at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:4)
	at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:3)
	at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:1)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:15)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:29)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:1)
	Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@63e5d80, Dispatchers.IO]
ACRA caught a ExtractMigrationDataFailure for fr.gouv.tchap.a
ExtractMigrationDataFailure(cause=org.matrix.rustcomponents.sdk.crypto.MigrationException$Generic: errorMessage=Failed to initialize the store cipher)
	at org.matrix.android.sdk.internal.crypto.store.db.migration.rust.ExtractMigrationDataUseCase.extractData(ExtractMigrationDataUseCase.kt:18)
	at org.matrix.android.sdk.internal.session.MigrateEAtoEROperation.dynamicExecute(MigrateEAtoEROperation.kt:42)
	at org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo022.doMigrate(MigrateCryptoTo022.kt:21)
	at org.matrix.android.sdk.internal.util.database.RealmMigrator.perform(RealmMigrator.kt:49)
	at org.matrix.android.sdk.internal.crypto.store.db.RealmCryptoStoreMigration.doMigrate(RealmCryptoStoreMigration.kt:321)
	at org.matrix.android.sdk.internal.util.database.MatrixRealmMigration.migrate(MatrixRealmMigration.kt:40)
	at io.realm.BaseRealm$6.onMigrationNeeded(BaseRealm.java:9)
	at io.realm.internal.OsSharedRealm.runMigrationCallback(OsSharedRealm.java:16)
	at io.realm.internal.OsSharedRealm.nativeGetSharedRealm(Native Method)
	at io.realm.internal.OsSharedRealm.<init>(OsSharedRealm.java:9)
	at io.realm.internal.OsSharedRealm.getInstance(OsSharedRealm.java:5)
	at io.realm.BaseRealm.<init>(BaseRealm.java:17)
	at io.realm.BaseRealm.<init>(BaseRealm.java:30)
	at io.realm.Realm.<init>(Realm.java:5)
	at io.realm.Realm.createInstance(Realm.java:1)
	at io.realm.RealmCache.createInstance(RealmCache.java:5)
	at io.realm.RealmCache.doCreateRealmOrGetFromCache(RealmCache.java:93)
	at io.realm.RealmCache.createRealmOrGetFromCache(RealmCache.java:2)
	at io.realm.Realm.getInstance(Realm.java:5)
	at org.matrix.android.sdk.internal.crypto.store.db.HelperKt.doRealmTransaction(Helper.kt:20)
	at org.matrix.android.sdk.internal.crypto.store.RustCryptoStore.<init>(RustCryptoStore.kt:60)
	at org.matrix.android.sdk.internal.crypto.store.RustCryptoStore_Factory.newInstance(RustCryptoStore_Factory.java:11)
	at org.matrix.android.sdk.internal.crypto.store.RustCryptoStore_Factory.get(RustCryptoStore_Factory.java:2)
	at org.matrix.android.sdk.internal.crypto.store.RustCryptoStore_Factory.get(RustCryptoStore_Factory.java:1)
	at dagger.internal.DoubleCheck.get(DoubleCheck.java:14)
	at org.matrix.android.sdk.internal.crypto.RustCryptoService_Factory.get(RustCryptoService_Factory.java:2)
	at org.matrix.android.sdk.internal.crypto.RustCryptoService_Factory.get(RustCryptoService_Factory.java:1)
	at dagger.internal.DoubleCheck.get(DoubleCheck.java:14)
	at dagger.internal.DelegateFactory.get(DelegateFactory.java:5)
	at dagger.internal.DoubleCheck.get(DoubleCheck.java:14)
	at org.matrix.android.sdk.internal.session.room.timeline.RoomSummaryEventDecryptor$1.invokeSuspend(RoomSummaryEventDecryptor.kt:46)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:12)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:124)
	at android.os.Handler.handleCallback(Handler.java:938)
	at android.os.Handler.dispatchMessage(Handler.java:99)
	at android.os.Looper.loop(Looper.java:223)
	at android.os.HandlerThread.run(HandlerThread.java:67)
	Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [CoroutineName(RoomSummaryDecryptor), StandaloneCoroutine{Cancelling}@546435f, Handler (android.os.Handler) {1ebd1ac}]
Caused by: org.matrix.rustcomponents.sdk.crypto.MigrationException$Generic: errorMessage=Failed to initialize the store cipher
	at org.matrix.rustcomponents.sdk.crypto.FfiConverterTypeMigrationError.read(matrix_sdk_crypto_ffi.kt:5)
	at org.matrix.rustcomponents.sdk.crypto.FfiConverterTypeMigrationError.read(matrix_sdk_crypto_ffi.kt:1)
	at org.matrix.rustcomponents.sdk.crypto.FfiConverter$DefaultImpls.liftFromRustBuffer(matrix_sdk_crypto_ffi.kt:13)
	at org.matrix.rustcomponents.sdk.crypto.FfiConverterRustBuffer$DefaultImpls.liftFromRustBuffer(matrix_sdk_crypto_ffi.kt:6)
	at org.matrix.rustcomponents.sdk.crypto.FfiConverterTypeMigrationError.liftFromRustBuffer(matrix_sdk_crypto_ffi.kt:2)
	at org.matrix.rustcomponents.sdk.crypto.FfiConverterTypeMigrationError.liftFromRustBuffer(matrix_sdk_crypto_ffi.kt:1)
	at org.matrix.rustcomponents.sdk.crypto.FfiConverterRustBuffer$DefaultImpls.lift(matrix_sdk_crypto_ffi.kt:6)
	at org.matrix.rustcomponents.sdk.crypto.FfiConverterTypeMigrationError.lift(matrix_sdk_crypto_ffi.kt:3)
	at org.matrix.rustcomponents.sdk.crypto.MigrationException$ErrorHandler.lift(matrix_sdk_crypto_ffi.kt:3)
	at org.matrix.rustcomponents.sdk.crypto.MigrationException$ErrorHandler.lift(matrix_sdk_crypto_ffi.kt:1)
	at org.matrix.rustcomponents.sdk.crypto.Matrix_sdk_crypto_ffiKt.checkCallStatus(matrix_sdk_crypto_ffi.kt:75)
	at org.matrix.rustcomponents.sdk.crypto.Matrix_sdk_crypto_ffiKt.migrate(matrix_sdk_crypto_ffi.kt:63)
	at org.matrix.android.sdk.internal.session.MigrateEAtoEROperation$dynamicExecute$1.invoke(MigrateEAtoEROperation.kt:2)
	at org.matrix.android.sdk.internal.session.MigrateEAtoEROperation$dynamicExecute$1.invoke(MigrateEAtoEROperation.kt:1)
	at org.matrix.android.sdk.internal.crypto.store.db.migration.rust.ExtractMigrationDataUseCase.extract(ExtractMigrationDataUseCase.kt:14)
	at org.matrix.android.sdk.internal.crypto.store.db.migration.rust.ExtractMigrationDataUseCase.extractData(ExtractMigrationDataUseCase.kt:11)
	... 36 more

Screenshots / GIFs

Tests

  • Step 1
  • Step 2
  • Step ...

Tested devices

  • Physical
  • Emulator
  • OS version(s):

Checklist

@yostyle yostyle self-assigned this Feb 23, 2024
@yostyle yostyle added bug Something isn't working P1 android labels Feb 23, 2024
@yostyle yostyle changed the title Restore rust crypto migation Restore rust crypto migration Feb 23, 2024
@tchap-danger-bot
Copy link

Warnings
⚠️

Please add a changelog. See instructions here

⚠️ Please add a reviewer to your PR.

Generated by 🚫 dangerJS against b8790eb

@tchap-danger-bot
Copy link

Warnings
⚠️ Please add a reviewer to your PR.

Generated by 🚫 dangerJS against 81705e9

@yostyle yostyle force-pushed the yostyle/restore_crypto_migration branch from 81705e9 to 1a6deb8 Compare February 23, 2024 15:49
@tchap-danger-bot
Copy link

Warnings
⚠️ Please add a reviewer to your PR.

Generated by 🚫 dangerJS against 1a6deb8

@yostyle yostyle force-pushed the yostyle/restore_crypto_migration branch from 1a6deb8 to 8bb8b86 Compare February 23, 2024 16:01
@tchap-danger-bot
Copy link

Warnings
⚠️ Please add a reviewer to your PR.

Generated by 🚫 dangerJS against 8bb8b86

@yostyle yostyle merged commit 8200e68 into develop Feb 23, 2024
15 of 16 checks passed
@yostyle yostyle deleted the yostyle/restore_crypto_migration branch February 23, 2024 16:44
scope.launch {
Timber.v("Intercepting key request, try backup")
/**
* It's a bit hacky, check how this can be better integrated with rust?
Copy link
Member

Choose a reason for hiding this comment

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

@yostyle is this a hack from us or from element android?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

from element

@@ -227,7 +227,6 @@ class VectorPreferences @Inject constructor(
private const val DID_ASK_TO_ENABLE_SESSION_PUSH = "DID_ASK_TO_ENABLE_SESSION_PUSH"

const val TCHAP_SETTINGS_HIDE_FROM_USERS_DIRECTORY_PREFERENCE_KEY = "TCHAP_SETTINGS_HIDE_FROM_USERS_DIRECTORY_PREFERENCE_KEY"
const val TCHAP_SETTINGS_CHRISTMAS_PREFERENCE_KEY = "TCHAP_SETTINGS_CHRISTMAS_PREFERENCE_KEY"
Copy link
Member

Choose a reason for hiding this comment

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

should not be part of this PR, it messes with commit history and overall understanding

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android bug Something isn't working P1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants