From b6d73d872be61ff884c00c14b00a900248767761 Mon Sep 17 00:00:00 2001 From: ganfra Date: Tue, 7 Jun 2022 19:57:44 +0200 Subject: [PATCH] Use backup key directly on olmMachine. --- matrix-sdk-android/build.gradle | 2 +- .../org/matrix/android/sdk/internal/crypto/OlmMachine.kt | 3 ++- .../internal/crypto/keysbackup/RustKeyBackupService.kt | 9 +++------ 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/matrix-sdk-android/build.gradle b/matrix-sdk-android/build.gradle index 24d8349c58..dd753f502c 100644 --- a/matrix-sdk-android/build.gradle +++ b/matrix-sdk-android/build.gradle @@ -140,7 +140,7 @@ dependencies { implementation libs.jetbrains.coroutinesCore implementation libs.jetbrains.coroutinesAndroid - implementation 'org.matrix.rustcomponents:crypto-android:0.1.0' + implementation 'org.matrix.rustcomponents:crypto-android:0.2.1-SNAPSHOT' //implementation files('libs/crypto-android-release.aar') // implementation(name: 'crypto-android-release', ext: 'aar') diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/OlmMachine.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/OlmMachine.kt index f45d236d54..806f5e7477 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/OlmMachine.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/OlmMachine.kt @@ -58,6 +58,7 @@ import org.matrix.android.sdk.internal.network.parsing.CheckNumberType import org.matrix.android.sdk.internal.util.time.Clock import timber.log.Timber import uniffi.olm.BackupKeys +import uniffi.olm.BackupRecoveryKey import uniffi.olm.CrossSigningKeyExport import uniffi.olm.CrossSigningStatus import uniffi.olm.CryptoStoreException @@ -840,7 +841,7 @@ internal class OlmMachine( } @Throws(CryptoStoreException::class) - suspend fun saveRecoveryKey(key: String?, version: String?) { + suspend fun saveRecoveryKey(key: BackupRecoveryKey?, version: String?) { withContext(coroutineDispatchers.computation) { inner.saveRecoveryKey(key, version) } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/RustKeyBackupService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/RustKeyBackupService.kt index 54ca9be784..1545e871d8 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/RustKeyBackupService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/RustKeyBackupService.kt @@ -191,9 +191,7 @@ internal class RustKeyBackupService @Inject constructor( override fun saveBackupRecoveryKey(recoveryKey: BackupRecoveryKey?, version: String?) { cryptoCoroutineScope.launch { - val recoveryKeyStr = recoveryKey?.toBase64() - // TODO : change rust API to use BackupRecoveryKey - olmMachine.saveRecoveryKey(recoveryKeyStr, version) + olmMachine.saveRecoveryKey(recoveryKey?.inner, version) } } @@ -729,9 +727,8 @@ internal class RustKeyBackupService @Inject constructor( override suspend fun getKeyBackupRecoveryKeyInfo(): SavedKeyBackupKeyInfo? { val info = olmMachine.getBackupKeys() ?: return null - // TODO change rust ffi to return BackupRecoveryKey instead of base64 string - val backupRecoveryKey = BackupRecoveryKey.fromBase64(info.recoveryKey) - return SavedKeyBackupKeyInfo(backupRecoveryKey, info.backupVersion) + val backupRecoveryKey = BackupRecoveryKey(info.recoveryKey()) + return SavedKeyBackupKeyInfo(backupRecoveryKey, info.backupVersion()) } /**