From 5ac70dac2b293076b631a1addbef5a85c65da901 Mon Sep 17 00:00:00 2001 From: Valere Date: Mon, 27 May 2024 09:48:20 +0200 Subject: [PATCH] Bump rust sdk crypto to 0.4.1 --- matrix-sdk-android/build.gradle | 2 +- .../matrix/android/sdk/internal/crypto/Device.kt | 2 +- .../android/sdk/internal/crypto/OlmMachine.kt | 10 ++++++++-- .../crypto/keysbackup/RustKeyBackupService.kt | 2 +- .../store/db/migration/rust/RealmToMigrate.kt | 16 ++++++++++------ 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/matrix-sdk-android/build.gradle b/matrix-sdk-android/build.gradle index af9e7cdf1f..678aab3d1f 100644 --- a/matrix-sdk-android/build.gradle +++ b/matrix-sdk-android/build.gradle @@ -215,7 +215,7 @@ dependencies { implementation libs.google.phonenumber - implementation("org.matrix.rustcomponents:crypto-android:0.3.16") + implementation("org.matrix.rustcomponents:crypto-android:0.4.1") // api project(":library:rustCrypto") testImplementation libs.tests.junit diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/Device.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/Device.kt index d2865f0f65..e50b22d5e0 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/Device.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/Device.kt @@ -31,8 +31,8 @@ import org.matrix.android.sdk.internal.crypto.verification.SasVerification import org.matrix.android.sdk.internal.crypto.verification.VerificationRequest import org.matrix.android.sdk.internal.crypto.verification.prepareMethods import org.matrix.rustcomponents.sdk.crypto.CryptoStoreException -import org.matrix.rustcomponents.sdk.crypto.LocalTrust import org.matrix.rustcomponents.sdk.crypto.SignatureException +import uniffi.matrix_sdk_crypto.LocalTrust import org.matrix.rustcomponents.sdk.crypto.Device as InnerDevice /** Class representing a device that supports E2EE in the Matrix world 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 4fe59fb1dd..b8d9711358 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 @@ -75,7 +75,6 @@ import org.matrix.rustcomponents.sdk.crypto.DeviceLists import org.matrix.rustcomponents.sdk.crypto.EncryptionSettings import org.matrix.rustcomponents.sdk.crypto.KeyRequestPair import org.matrix.rustcomponents.sdk.crypto.KeysImportResult -import org.matrix.rustcomponents.sdk.crypto.LocalTrust import org.matrix.rustcomponents.sdk.crypto.Logger import org.matrix.rustcomponents.sdk.crypto.MegolmV1BackupKey import org.matrix.rustcomponents.sdk.crypto.Request @@ -86,6 +85,7 @@ import org.matrix.rustcomponents.sdk.crypto.ShieldState import org.matrix.rustcomponents.sdk.crypto.SignatureVerification import org.matrix.rustcomponents.sdk.crypto.setLogger import timber.log.Timber +import uniffi.matrix_sdk_crypto.LocalTrust import java.io.File import java.nio.charset.Charset import javax.inject.Inject @@ -828,8 +828,14 @@ internal class OlmMachine @Inject constructor( val requests = withContext(coroutineDispatchers.io) { inner.bootstrapCrossSigning() } + (requests.uploadKeysRequest)?.let { + when (it) { + is Request.KeysUpload -> requestSender.uploadKeys(it) + else -> {} + } + } requestSender.uploadCrossSigningKeys(requests.uploadSigningKeysRequest, uiaInterceptor) - requestSender.sendSignatureUpload(requests.signatureRequest) + requestSender.sendSignatureUpload(requests.uploadSignatureRequest) } /** 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 4796180cdc..37d1bd4b89 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 @@ -68,9 +68,9 @@ import org.matrix.android.sdk.internal.util.JsonCanonicalizer import org.matrix.olm.OlmException import org.matrix.rustcomponents.sdk.crypto.Request import org.matrix.rustcomponents.sdk.crypto.RequestType -import org.matrix.rustcomponents.sdk.crypto.SignatureState import org.matrix.rustcomponents.sdk.crypto.SignatureVerification import timber.log.Timber +import uniffi.matrix_sdk_crypto.SignatureState import java.security.InvalidParameterException import javax.inject.Inject import kotlin.random.Random diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/migration/rust/RealmToMigrate.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/migration/rust/RealmToMigrate.kt index d99403fe19..7f9e7e212a 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/migration/rust/RealmToMigrate.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/migration/rust/RealmToMigrate.kt @@ -100,7 +100,7 @@ fun RealmToMigrate.getPickledAccount(pickleKey: ByteArray): MigrationData { ) MigrationData( account = pickledAccount, - pickleKey = pickleKey.map { it.toUByte() }, + pickleKey = pickleKey, crossSigning = CrossSigningKeyExport( masterKey = masterKey, selfSigningKey = selfSignedKey, @@ -153,7 +153,7 @@ fun RealmToMigrate.getPickledAccount(pickleKey: ByteArray): MigrationData { migrationData = MigrationData( account = pickledAccount, - pickleKey = pickleKey.map { it.toUByte() }, + pickleKey = pickleKey, crossSigning = CrossSigningKeyExport( masterKey = masterKey, selfSigningKey = selfSignedKey, @@ -222,8 +222,10 @@ fun RealmToMigrate.pickledOlmSessions(pickleKey: ByteArray, chunkSize: Int, onCh pickle = pickle, senderKey = deviceKey, createdUsingFallbackKey = false, - creationTime = lastReceivedMessageTs.toString(), - lastUseTime = lastReceivedMessageTs.toString() + // / Unix timestamp (in seconds) when the session was created. + creationTime = (lastReceivedMessageTs / 1000).toULong(), + // / Unix timestamp (in seconds) when the session was last used. + lastUseTime = (lastReceivedMessageTs / 1000).toULong(), ) // should we check the tracking status? pickledSessions.add(pickledSession) @@ -323,8 +325,10 @@ private fun OlmSessionEntity.toPickledSession(pickleKey: ByteArray): PickledSess pickle = pickledOlmSession, senderKey = deviceKey, createdUsingFallbackKey = false, - creationTime = lastReceivedMessageTs.toString(), - lastUseTime = lastReceivedMessageTs.toString() + // Rust expect in seconds + creationTime = (lastReceivedMessageTs / 1000).toULong(), + // Rust expect in seconds + lastUseTime = (lastReceivedMessageTs / 1000).toULong(), ) }