diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/session/contentscanner/ScanEncryptorUtilsTest.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/session/contentscanner/ScanEncryptorUtilsTest.kt index 93b6797388..ba04e4607e 100644 --- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/session/contentscanner/ScanEncryptorUtilsTest.kt +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/session/contentscanner/ScanEncryptorUtilsTest.kt @@ -16,7 +16,6 @@ package org.matrix.android.sdk.internal.session.contentscanner -import okio.ByteString.Companion.decodeBase64 import org.amshove.kluent.shouldBe import org.amshove.kluent.shouldBeEqualTo import org.amshove.kluent.shouldNotBe @@ -24,11 +23,7 @@ import org.junit.Test import org.matrix.android.sdk.api.session.crypto.attachments.ElementToDecrypt import org.matrix.android.sdk.api.session.crypto.model.EncryptedFileInfo import org.matrix.android.sdk.api.session.crypto.model.EncryptedFileKey -import org.matrix.android.sdk.internal.crypto.tools.withOlmDecryption -import org.matrix.android.sdk.internal.di.MoshiProvider import org.matrix.android.sdk.internal.session.contentscanner.model.DownloadBody -import org.matrix.android.sdk.internal.session.contentscanner.model.EncryptedBody -import org.matrix.olm.OlmPkMessage class ScanEncryptorUtilsTest { private val anMxcUrl = "mxc://matrix.org/123456" @@ -67,7 +62,6 @@ class ScanEncryptorUtilsTest { @Test fun whenServerKeyIsProvidedTheContentIsEncrypted() { - System.loadLibrary("olm") val result = ScanEncryptorUtils.getDownloadBodyAndEncryptIfNeeded( publicServerKey = aPublicKey, mxcUrl = anMxcUrl, @@ -78,6 +72,8 @@ class ScanEncryptorUtilsTest { result.encryptedBody shouldNotBe null } + // Note: PkDecryption is not exposed in the FFI layer, so we cannot use this test. + /* @Test fun checkThatTheCodeIsAbleToDecryptContent() { System.loadLibrary("olm") @@ -121,4 +117,5 @@ class ScanEncryptorUtilsTest { .fromJson(result) parseResult shouldBeEqualTo clearInfo } + */ } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tools/Tools.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tools/Tools.kt deleted file mode 100644 index 3a0bf7fed5..0000000000 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tools/Tools.kt +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2020 The Matrix.org Foundation C.I.C. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.matrix.android.sdk.internal.crypto.tools - -// TODO BMA -data object OlmPkEncryption - -internal fun withOlmEncryption(block: (OlmPkEncryption) -> T): T { - val olmPkEncryption = OlmPkEncryption - return block(olmPkEncryption) -} diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/contentscanner/ScanEncryptorUtils.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/contentscanner/ScanEncryptorUtils.kt index 6375049b98..f02a11628a 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/contentscanner/ScanEncryptorUtils.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/contentscanner/ScanEncryptorUtils.kt @@ -19,10 +19,10 @@ package org.matrix.android.sdk.internal.session.contentscanner import org.matrix.android.sdk.api.session.crypto.attachments.ElementToDecrypt import org.matrix.android.sdk.api.session.crypto.model.EncryptedFileInfo import org.matrix.android.sdk.api.session.crypto.model.EncryptedFileKey -import org.matrix.android.sdk.internal.crypto.tools.withOlmEncryption import org.matrix.android.sdk.internal.session.contentscanner.model.DownloadBody import org.matrix.android.sdk.internal.session.contentscanner.model.EncryptedBody import org.matrix.android.sdk.internal.session.contentscanner.model.toCanonicalJson +import org.matrix.rustcomponents.sdk.crypto.PkEncryption internal object ScanEncryptorUtils { @@ -43,22 +43,15 @@ internal object ScanEncryptorUtils { v = "v2" ) return if (publicServerKey != null) { - // We should encrypt - withOlmEncryption { //olm -> - // TODO BMA - error("Not supported anymore") - /* - olm.setRecipientKey(publicServerKey) - val olmResult = olm.encrypt(DownloadBody(encryptedInfo).toCanonicalJson()) - DownloadBody( - encryptedBody = EncryptedBody( - cipherText = olmResult.mCipherText, - ephemeral = olmResult.mEphemeralKey, - mac = olmResult.mMac - ) - ) - */ - } + val pkEncryption = PkEncryption.fromBase64(key = publicServerKey) + val pkMessage = pkEncryption.encrypt(DownloadBody(encryptedInfo).toCanonicalJson()) + DownloadBody( + encryptedBody = EncryptedBody( + cipherText = pkMessage.ciphertext, + ephemeral = pkMessage.ephemeralKey, + mac = pkMessage.mac + ) + ) } else { DownloadBody(encryptedInfo) }