diff --git a/CHANGES.md b/CHANGES.md
index 587f2d61c2..9d2f39a441 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -1,3 +1,15 @@
+Changes in Element v1.6.22 (2024-09-23)
+=======================================
+
+Important: this version removes the dependency of the deprecated libolm library.
+Application installations that have not been updated to the first version with the migration (1.6.3 release at 2023-06-27) will not be able to migrate the account.
+More details in ([#8901](https://github.com/element-hq/element-android/issues/8901))
+
+Other changes
+-------------
+ - Remove legacy QR code login. ([#8889](https://github.com/element-hq/element-android/issues/8889))
+
+
Changes in Element v1.6.20 (2024-07-25)
=======================================
@@ -13,7 +25,7 @@ Bugfixes 🐛
----------
- Fix redacted events not grouped correctly when hidden events are inserted between. ([#8840](https://github.com/element-hq/element-android/issues/8840))
- Element-Android session doesn't encrypt for a dehydrated device ([#8842](https://github.com/element-hq/element-android/issues/8842))
- - Intercept only links from `element.io` well known hosts. The previous behaviour broke OIDC login in Element X. ([#8894](https://github.com/element-hq/element-android/issues/8894))
+ - Intercept only links from `element.io` well known hosts. The previous behaviour broke OIDC login in Element X. ([#8849](https://github.com/element-hq/element-android/issues/8849))
Other changes
-------------
diff --git a/build.gradle b/build.gradle
index 5fd7606f3e..cbb72b9266 100644
--- a/build.gradle
+++ b/build.gradle
@@ -88,9 +88,9 @@ allprojects {
}
// Jitsi repo
maven {
- url "https://github.com/element-hq/jitsi_libre_maven/raw/main/android-sdk-8.1.1"
+ url "https://github.com/element-hq/jitsi_libre_maven/raw/main/mobile-sdk-10.2.0"
// Note: to test Jitsi release you can use a local file like this:
- // url "file:///Users/bmarty/workspaces/jitsi_libre_maven/android-sdk-8.1.1"
+ // url "file:///Users/bmarty/workspaces/jitsi_libre_maven/mobile-sdk-10.2.0"
content {
groups.jitsi.regex.each { includeGroupByRegex it }
groups.jitsi.group.each { includeGroup it }
diff --git a/dependencies_groups.gradle b/dependencies_groups.gradle
index 5c976d8c32..478999d331 100644
--- a/dependencies_groups.gradle
+++ b/dependencies_groups.gradle
@@ -73,6 +73,7 @@ ext.groups = [
'com.facebook.flipper',
'com.facebook.fresco',
'com.facebook.infer.annotation',
+ 'com.facebook.react',
'com.facebook.soloader',
'com.facebook.stetho',
'com.facebook.yoga',
diff --git a/docs/jitsi.md b/docs/jitsi.md
index b413d93dfc..d962b1e8a3 100644
--- a/docs/jitsi.md
+++ b/docs/jitsi.md
@@ -28,18 +28,18 @@ The generated maven repository is then host in the project https://github.com/el
#### Jitsi version
-Update the script `./tools/jitsi/build_jisti_libs.sh` with the tag of the project `https://github.com/jitsi/jitsi-meet`.
+Update the script `./tools/jitsi/build_jitsi_libs.sh` with the tag of the project `https://github.com/jitsi/jitsi-meet`.
Latest tag can be found from this page: https://github.com/jitsi/jitsi-meet-release-notes/blob/master/CHANGELOG-MOBILE-SDKS.md
-Currently we are building the version with the tag `android-sdk-8.1.1`.
+Currently we are building the version with the tag `mobile-sdk-10.2.0`.
#### Run the build script
At the root of the Element Android, run the following script:
```shell script
-./tools/jitsi/build_jisti_libs.sh
+./tools/jitsi/build_jitsi_libs.sh
```
It will build the Jitsi Meet Android library and put every generated files in the folder `/tmp/jitsi`
@@ -49,7 +49,7 @@ It will build the Jitsi Meet Android library and put every generated files in th
- Update the file `./build.gradle` to use the previously created local Maven repository. Currently we have this line:
```groovy
-url "https://github.com/element-hq/jitsi_libre_maven/raw/main/android-sdk-8.1.1"
+url "https://github.com/element-hq/jitsi_libre_maven/raw/main/mobile-sdk-10.2.0"
```
You can uncomment and update the line starting with `// url "file://...` and comment the line starting with `url`, to test the library using the locally generated Maven repository.
@@ -57,13 +57,7 @@ You can uncomment and update the line starting with `// url "file://...` and com
- Update the dependency of the Jitsi Meet library in the file `./vector/build.gradle`. Currently we have this line:
```groovy
-api('org.jitsi.react:jitsi-meet-sdk:8.1.1')
-```
-
-- Update the dependency of the WebRTC library in the file `./vector/build.gradle`. Currently we have this line:
-
-```groovy
-implementation('com.facebook.react:react-native-webrtc:111.0.0-jitsi-13672566@aar')
+api('org.jitsi.react:jitsi-meet-sdk:10.2.0')
```
- Perform a gradle sync and build the project
@@ -88,7 +82,7 @@ If all the tests are passed, you can export the generated Jitsi library to our M
- Update the file `./build.gradle` to use the previously created Maven repository. Currently we have this line:
```groovy
-url "https://github.com/element-hq/jitsi_libre_maven/raw/main/android-sdk-8.1.1"
+url "https://github.com/element-hq/jitsi_libre_maven/raw/main/mobile-sdk-10.2.0"
```
- Build the project and perform the sanity tests again.
diff --git a/fastlane/metadata/android/en-US/changelogs/40106220.txt b/fastlane/metadata/android/en-US/changelogs/40106220.txt
new file mode 100644
index 0000000000..7a30d8a05a
--- /dev/null
+++ b/fastlane/metadata/android/en-US/changelogs/40106220.txt
@@ -0,0 +1,2 @@
+Main changes in this version: crypto sdk upgrade.
+Full changelog: https://github.com/element-hq/element-android/releases
diff --git a/library/ui-strings/src/main/res/values-fa/strings.xml b/library/ui-strings/src/main/res/values-fa/strings.xml
index e28afadaa8..4be2e46ce7 100644
--- a/library/ui-strings/src/main/res/values-fa/strings.xml
+++ b/library/ui-strings/src/main/res/values-fa/strings.xml
@@ -2966,4 +2966,4 @@
\n%s
آغاز گپ به هر حالدعوت به هر حال
-
+
\ No newline at end of file
diff --git a/library/ui-strings/src/main/res/values-zh-rCN/strings.xml b/library/ui-strings/src/main/res/values-zh-rCN/strings.xml
index 970bee794c..30fba77195 100644
--- a/library/ui-strings/src/main/res/values-zh-rCN/strings.xml
+++ b/library/ui-strings/src/main/res/values-zh-rCN/strings.xml
@@ -2865,4 +2865,4 @@
显示投票切换引用切换有序列表
-
+
\ No newline at end of file
diff --git a/library/ui-strings/src/main/res/values/strings.xml b/library/ui-strings/src/main/res/values/strings.xml
index 2a98069c2e..30e6ef673e 100644
--- a/library/ui-strings/src/main/res/values/strings.xml
+++ b/library/ui-strings/src/main/res/values/strings.xml
@@ -1175,9 +1175,9 @@
Room addresses
- See and managed addresses of this room, and its visibility in the room directory.
+ See and manage addresses of this room, and its visibility in the room directory.Space addresses
- See and managed addresses of this space.
+ See and manage addresses of this space.Published AddressesPublished addresses can be used by anyone on any server to join your room. To publish an address, it needs to be set as a local address first.
@@ -2228,7 +2228,8 @@
If you don’t know your password, go back to reset it.This is not a valid user identifier. Expected format: \'@user:homeserver.org\'Unable to find a valid homeserver. Please check your identifier
- Scan QR code
+
+ Scan QR codeSeen by
@@ -3475,9 +3476,10 @@
Session nameCustom session names can help you recognize your devices more easily.Please be aware that session names are also visible to people you communicate with.
- Sign in with QR Code
- You can use this device to sign in a mobile or web device with a QR code. There are two ways to do this:
-
+
+ Sign in with QR Code
+
+ You can use this device to sign in a mobile or web device with a QR code. There are two ways to do this:Inactive sessionsInactive sessions are sessions you have not used in some time, but they continue to receive encryption keys.\n\nRemoving inactive sessions improves security and performance, and makes it easier for you to identify if a new session is suspicious.Unverified sessions
@@ -3515,45 +3517,82 @@
Tap top right to see the option to feedback.Try it out
- 1
- 2
- 3
+
+ 1
+
+ 2
+
+ 3
- Scan QR code
- Use the camera on this device to scan the QR code shown on your other device:
- Sign in with QR code
- Use your signed in device to scan the QR code below:
- Scan the QR code below with your device that’s signed out.
- Secure connection established
- Check your signed in device, the code below should be displayed. Confirm that the code below matches with that device:
- Unsuccessful connection
- Linking with this device is not supported.
- The linking wasn’t completed in the required time.
- The request was denied on the other device.
- The request failed.
- A security issue was encountered setting up secure messaging. One of the following may be compromised: Your homeserver; Your internet connection(s); Your device(s);
- The other device is already signed in.
- The other device must be signed in.
- That QR code is invalid.
- The sign in was cancelled on the other device.
- The homeserver doesn\'t support sign in with QR code.
- Open the app on your other device
- Go to Settings -> Security & Privacy
- Select \'Show QR code\'
- Start at the sign in screen
- Select \'Sign in with QR code\'
- Start at the sign in screen
- Select \'Scan QR code\'
- Show QR code in this device
- Signing in a mobile device?
- Scan QR code
- Connecting to device
- Signing you in
- No match?
- Try again
- Confirm
- Please ensure that you know the origin of this code. By linking devices, you will provide someone with full access to your account.
+
+ Scan QR code
+
+ Use the camera on this device to scan the QR code shown on your other device:
+
+ Sign in with QR code
+
+ Use your signed in device to scan the QR code below:
+
+ Scan the QR code below with your device that’s signed out.
+
+ Secure connection established
+
+ Check your signed in device, the code below should be displayed. Confirm that the code below matches with that device:
+
+ Unsuccessful connection
+
+ Linking with this device is not supported.
+
+ The linking wasn’t completed in the required time.
+
+ The request was denied on the other device.
+
+ The request failed.
+
+ A security issue was encountered setting up secure messaging. One of the following may be compromised: Your homeserver; Your internet connection(s); Your device(s);
+
+ The other device is already signed in.
+
+ The other device must be signed in.
+
+ That QR code is invalid.
+
+ The sign in was cancelled on the other device.
+
+ The homeserver doesn\'t support sign in with QR code.
+
+ Open the app on your other device
+
+ Go to Settings -> Security & Privacy
+
+ Select \'Show QR code\'
+
+ Start at the sign in screen
+
+ Select \'Sign in with QR code\'
+
+ Start at the sign in screen
+
+ Select \'Scan QR code\'
+
+ Show QR code in this device
+
+ Signing in a mobile device?
+
+ Scan QR code
+
+ Connecting to device
+
+ Signing you in
+
+ No match?
+
+ Try again
+
+ Confirm
+
+ Please ensure that you know the origin of this code. By linking devices, you will provide someone with full access to your account.Apply bold format
diff --git a/library/ui-styles/src/main/res/values/stylable_qr_code_instructions_view.xml b/library/ui-styles/src/main/res/values/stylable_qr_code_instructions_view.xml
deleted file mode 100644
index c9a4bb9d05..0000000000
--- a/library/ui-styles/src/main/res/values/stylable_qr_code_instructions_view.xml
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
diff --git a/library/ui-styles/src/main/res/values/stylable_qr_code_login_header_view.xml b/library/ui-styles/src/main/res/values/stylable_qr_code_login_header_view.xml
deleted file mode 100644
index 99f56084d9..0000000000
--- a/library/ui-styles/src/main/res/values/stylable_qr_code_login_header_view.xml
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
diff --git a/matrix-sdk-android/build.gradle b/matrix-sdk-android/build.gradle
index 78f4a6d179..02f1e371fe 100644
--- a/matrix-sdk-android/build.gradle
+++ b/matrix-sdk-android/build.gradle
@@ -62,7 +62,7 @@ android {
// that the app's state is completely cleared between tests.
testInstrumentationRunnerArguments clearPackageData: 'true'
- buildConfigField "String", "SDK_VERSION", "\"1.6.20\""
+ buildConfigField "String", "SDK_VERSION", "\"1.6.22\""
buildConfigField "String", "GIT_SDK_REVISION", "\"${gitRevision()}\""
buildConfigField "String", "GIT_SDK_REVISION_UNIX_DATE", "\"${gitRevisionUnixDate()}\""
@@ -205,9 +205,6 @@ dependencies {
// Work
implementation libs.androidx.work
- // olm lib is now hosted in MavenCentral
- implementation 'org.matrix.android:olm-sdk:3.2.12'
-
// DI
implementation libs.dagger.dagger
kapt libs.dagger.daggerCompiler
@@ -224,7 +221,7 @@ dependencies {
implementation libs.google.phonenumber
- implementation("org.matrix.rustcomponents:crypto-android:0.4.1")
+ implementation("org.matrix.rustcomponents:crypto-android:0.4.3")
// api project(":library:rustCrypto")
testImplementation libs.tests.junit
@@ -236,6 +233,7 @@ dependencies {
testImplementation 'net.lachlanmckee:timber-junit-rule:1.0.1'
// Transitively required for mocking realm as monarchy doesn't expose Rx
testImplementation libs.rx.rxKotlin
+ testImplementation libs.tests.robolectric
kaptAndroidTest libs.dagger.daggerCompiler
androidTestImplementation libs.androidx.testCore
diff --git a/matrix-sdk-android/src/androidTest/assets/crypto_store_20.realm b/matrix-sdk-android/src/androidTest/assets/crypto_store_20.realm
deleted file mode 100644
index cfdd2e6da6..0000000000
--- a/matrix-sdk-android/src/androidTest/assets/crypto_store_20.realm
+++ /dev/null
@@ -1,3 +0,0 @@
-version https://git-lfs.github.com/spec/v1
-oid sha256:a7acd69f37612bab0a1ab7f456656712d7ba19dbb679f81b97b58ef44e239f42
-size 8523776
diff --git a/matrix-sdk-android/src/androidTest/assets/crypto_store_migration_16.realm b/matrix-sdk-android/src/androidTest/assets/crypto_store_migration_16.realm
deleted file mode 100644
index 4995bfc4a1..0000000000
--- a/matrix-sdk-android/src/androidTest/assets/crypto_store_migration_16.realm
+++ /dev/null
@@ -1,3 +0,0 @@
-version https://git-lfs.github.com/spec/v1
-oid sha256:59b4957aa2f9cdc17b14ec8546e144537fac9dee050c6eb173f56fa8602c2736
-size 2097152
diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/api/rendezvous/RendezvousTest.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/api/rendezvous/RendezvousTest.kt
deleted file mode 100644
index 5b5aad4c51..0000000000
--- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/api/rendezvous/RendezvousTest.kt
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright 2023 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.api.rendezvous
-
-import org.amshove.kluent.invoking
-import org.amshove.kluent.shouldBeEqualTo
-import org.amshove.kluent.shouldBeInstanceOf
-import org.amshove.kluent.shouldThrow
-import org.amshove.kluent.with
-import org.junit.Test
-import org.matrix.android.sdk.InstrumentedTest
-import org.matrix.android.sdk.api.rendezvous.channels.ECDHRendezvousChannel
-import org.matrix.android.sdk.api.rendezvous.model.RendezvousError
-import org.matrix.android.sdk.common.CommonTestHelper
-
-class RendezvousTest : InstrumentedTest {
-
- @Test
- fun shouldSuccessfullyBuildChannels() = CommonTestHelper.runCryptoTest(context()) { _, _ ->
- val cases = listOf(
- // v1:
- "{\"rendezvous\":{\"algorithm\":\"org.matrix.msc3903.rendezvous.v1.curve25519-aes-sha256\"," +
- "\"key\":\"aeSGwYTV1IUhikUyCapzC6p2xG5NpJ4Lwj2UgUMlcTk\",\"transport\":" +
- "{\"type\":\"org.matrix.msc3886.http.v1\",\"uri\":\"https://rendezvous.lab.element.dev/bcab62cd-3e34-48b4-bc39-90895da8f6fe\"}}," +
- "\"intent\":\"login.reciprocate\"}",
- // v2:
- "{\"rendezvous\":{\"algorithm\":\"org.matrix.msc3903.rendezvous.v2.curve25519-aes-sha256\"," +
- "\"key\":\"aeSGwYTV1IUhikUyCapzC6p2xG5NpJ4Lwj2UgUMlcTk\",\"transport\":" +
- "{\"type\":\"org.matrix.msc3886.http.v1\",\"uri\":\"https://rendezvous.lab.element.dev/bcab62cd-3e34-48b4-bc39-90895da8f6fe\"}}," +
- "\"intent\":\"login.reciprocate\"}",
- )
-
- cases.forEach { input ->
- Rendezvous.buildChannelFromCode(input).channel shouldBeInstanceOf ECDHRendezvousChannel::class
- }
- }
-
- @Test
- fun shouldFailToBuildChannelAsUnsupportedAlgorithm() {
- invoking {
- Rendezvous.buildChannelFromCode(
- "{\"rendezvous\":{\"algorithm\":\"bad algo\"," +
- "\"key\":\"aeSGwYTV1IUhikUyCapzC6p2xG5NpJ4Lwj2UgUMlcTk\",\"transport\":" +
- "{\"type\":\"org.matrix.msc3886.http.v1\",\"uri\":\"https://rendezvous.lab.element.dev/bcab62cd-3e34-48b4-bc39-90895da8f6fe\"}}," +
- "\"intent\":\"login.reciprocate\"}"
- )
- } shouldThrow RendezvousError::class with {
- this.reason shouldBeEqualTo RendezvousFailureReason.UnsupportedAlgorithm
- }
- }
-
- @Test
- fun shouldFailToBuildChannelAsUnsupportedTransport() {
- invoking {
- Rendezvous.buildChannelFromCode(
- "{\"rendezvous\":{\"algorithm\":\"org.matrix.msc3903.rendezvous.v1.curve25519-aes-sha256\"," +
- "\"key\":\"aeSGwYTV1IUhikUyCapzC6p2xG5NpJ4Lwj2UgUMlcTk\",\"transport\":" +
- "{\"type\":\"bad transport\",\"uri\":\"https://rendezvous.lab.element.dev/bcab62cd-3e34-48b4-bc39-90895da8f6fe\"}}," +
- "\"intent\":\"login.reciprocate\"}"
- )
- } shouldThrow RendezvousError::class with {
- this.reason shouldBeEqualTo RendezvousFailureReason.UnsupportedTransport
- }
- }
-
- @Test
- fun shouldFailToBuildChannelWithInvalidIntent() {
- invoking {
- Rendezvous.buildChannelFromCode(
- "{\"rendezvous\":{\"algorithm\":\"org.matrix.msc3903.rendezvous.v1.curve25519-aes-sha256\"," +
- "\"key\":\"aeSGwYTV1IUhikUyCapzC6p2xG5NpJ4Lwj2UgUMlcTk\",\"transport\":" +
- "{\"type\":\"org.matrix.msc3886.http.v1\",\"uri\":\"https://rendezvous.lab.element.dev/bcab62cd-3e34-48b4-bc39-90895da8f6fe\"}}," +
- "\"intent\":\"foo\"}"
- )
- } shouldThrow RendezvousError::class with {
- this.reason shouldBeEqualTo RendezvousFailureReason.InvalidCode
- }
- }
-
- @Test
- fun shouldFailToBuildChannelAsInvalidCode() {
- val cases = listOf(
- "{}",
- "rubbish",
- ""
- )
-
- cases.forEach { input ->
- invoking {
- Rendezvous.buildChannelFromCode(input)
- } shouldThrow RendezvousError::class with {
- this.reason shouldBeEqualTo RendezvousFailureReason.InvalidCode
- }
- }
- }
-}
diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/TestMatrix.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/TestMatrix.kt
index 60201b34c7..f042e0734f 100644
--- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/TestMatrix.kt
+++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/TestMatrix.kt
@@ -36,7 +36,6 @@ import org.matrix.android.sdk.internal.network.ApiInterceptor
import org.matrix.android.sdk.internal.network.UserAgentHolder
import org.matrix.android.sdk.internal.util.BackgroundDetectionObserver
import org.matrix.android.sdk.internal.worker.MatrixWorkerFactory
-import org.matrix.olm.OlmManager
import java.util.concurrent.Executors
import javax.inject.Inject
@@ -49,7 +48,6 @@ internal class TestMatrix(context: Context, matrixConfiguration: MatrixConfigura
@Inject internal lateinit var rawService: RawService
@Inject internal lateinit var userAgentHolder: UserAgentHolder
@Inject internal lateinit var backgroundDetectionObserver: BackgroundDetectionObserver
- @Inject internal lateinit var olmManager: OlmManager
@Inject internal lateinit var sessionManager: SessionManager
@Inject internal lateinit var homeServerHistoryService: HomeServerHistoryService
@Inject internal lateinit var apiInterceptor: ApiInterceptor
diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/keysbackup/KeysBackupPasswordTest.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/keysbackup/KeysBackupPasswordTest.kt
index 9bf08f6fc0..8d63f06d3e 100644
--- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/keysbackup/KeysBackupPasswordTest.kt
+++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/keysbackup/KeysBackupPasswordTest.kt
@@ -20,7 +20,6 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Assert.assertArrayEquals
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
-import org.junit.Before
import org.junit.FixMethodOrder
import org.junit.Ignore
import org.junit.Test
@@ -29,19 +28,12 @@ import org.junit.runners.MethodSorters
import org.matrix.android.sdk.InstrumentedTest
import org.matrix.android.sdk.api.listeners.ProgressListener
import org.matrix.android.sdk.common.assertByteArrayNotEqual
-import org.matrix.olm.OlmManager
-import org.matrix.olm.OlmPkDecryption
@Ignore("Ignored in order to speed up test run time")
@RunWith(AndroidJUnit4::class)
@FixMethodOrder(MethodSorters.JVM)
class KeysBackupPasswordTest : InstrumentedTest {
- @Before
- fun ensureLibLoaded() {
- OlmManager()
- }
-
/**
* Check KeysBackupPassword utilities
*/
@@ -51,7 +43,7 @@ class KeysBackupPasswordTest : InstrumentedTest {
assertEquals(32, generatePrivateKeyResult.salt.length)
assertEquals(500_000, generatePrivateKeyResult.iterations)
- assertEquals(OlmPkDecryption.privateKeyLength(), generatePrivateKeyResult.privateKey.size)
+ assertEquals(EXPECTED_PRIVATE_KEY_LENGTH, generatePrivateKeyResult.privateKey.size)
// Reverse operation
val retrievedPrivateKey = retrievePrivateKeyWithPassword(
@@ -60,7 +52,7 @@ class KeysBackupPasswordTest : InstrumentedTest {
generatePrivateKeyResult.iterations
)
- assertEquals(OlmPkDecryption.privateKeyLength(), retrievedPrivateKey.size)
+ assertEquals(EXPECTED_PRIVATE_KEY_LENGTH, retrievedPrivateKey.size)
assertArrayEquals(generatePrivateKeyResult.privateKey, retrievedPrivateKey)
}
@@ -101,7 +93,7 @@ class KeysBackupPasswordTest : InstrumentedTest {
assertEquals(32, generatePrivateKeyResult.salt.length)
assertEquals(500_000, generatePrivateKeyResult.iterations)
- assertEquals(OlmPkDecryption.privateKeyLength(), generatePrivateKeyResult.privateKey.size)
+ assertEquals(EXPECTED_PRIVATE_KEY_LENGTH, generatePrivateKeyResult.privateKey.size)
// Reverse operation, with bad password
val retrievedPrivateKey = retrievePrivateKeyWithPassword(
@@ -110,7 +102,7 @@ class KeysBackupPasswordTest : InstrumentedTest {
generatePrivateKeyResult.iterations
)
- assertEquals(OlmPkDecryption.privateKeyLength(), retrievedPrivateKey.size)
+ assertEquals(EXPECTED_PRIVATE_KEY_LENGTH, retrievedPrivateKey.size)
assertByteArrayNotEqual(generatePrivateKeyResult.privateKey, retrievedPrivateKey)
}
@@ -123,7 +115,7 @@ class KeysBackupPasswordTest : InstrumentedTest {
assertEquals(32, generatePrivateKeyResult.salt.length)
assertEquals(500_000, generatePrivateKeyResult.iterations)
- assertEquals(OlmPkDecryption.privateKeyLength(), generatePrivateKeyResult.privateKey.size)
+ assertEquals(EXPECTED_PRIVATE_KEY_LENGTH, generatePrivateKeyResult.privateKey.size)
// Reverse operation, with bad iteration
val retrievedPrivateKey = retrievePrivateKeyWithPassword(
@@ -132,7 +124,7 @@ class KeysBackupPasswordTest : InstrumentedTest {
500_001
)
- assertEquals(OlmPkDecryption.privateKeyLength(), retrievedPrivateKey.size)
+ assertEquals(EXPECTED_PRIVATE_KEY_LENGTH, retrievedPrivateKey.size)
assertByteArrayNotEqual(generatePrivateKeyResult.privateKey, retrievedPrivateKey)
}
@@ -145,7 +137,7 @@ class KeysBackupPasswordTest : InstrumentedTest {
assertEquals(32, generatePrivateKeyResult.salt.length)
assertEquals(500_000, generatePrivateKeyResult.iterations)
- assertEquals(OlmPkDecryption.privateKeyLength(), generatePrivateKeyResult.privateKey.size)
+ assertEquals(EXPECTED_PRIVATE_KEY_LENGTH, generatePrivateKeyResult.privateKey.size)
// Reverse operation, with bad iteration
val retrievedPrivateKey = retrievePrivateKeyWithPassword(
@@ -154,7 +146,7 @@ class KeysBackupPasswordTest : InstrumentedTest {
generatePrivateKeyResult.iterations
)
- assertEquals(OlmPkDecryption.privateKeyLength(), retrievedPrivateKey.size)
+ assertEquals(EXPECTED_PRIVATE_KEY_LENGTH, retrievedPrivateKey.size)
assertByteArrayNotEqual(generatePrivateKeyResult.privateKey, retrievedPrivateKey)
}
@@ -169,7 +161,7 @@ class KeysBackupPasswordTest : InstrumentedTest {
val retrievedPrivateKey = retrievePrivateKeyWithPassword(password, salt, iteration)
- assertEquals(OlmPkDecryption.privateKeyLength(), retrievedPrivateKey.size)
+ assertEquals(EXPECTED_PRIVATE_KEY_LENGTH, retrievedPrivateKey.size)
// Data from RiotWeb
val privateKeyBytes = byteArrayOf(
@@ -187,5 +179,7 @@ class KeysBackupPasswordTest : InstrumentedTest {
private const val BAD_PASSWORD = "passw0rd"
private const val BAD_SALT = "AA0lxhQ9aYgGfMsclVWPIAublg8h9Nlu"
+
+ private const val EXPECTED_PRIVATE_KEY_LENGTH = 32
}
}
diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/store/migration/DynamicElementAndroidToElementRMigrationTest.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/store/migration/DynamicElementAndroidToElementRMigrationTest.kt
deleted file mode 100644
index 52a75d0653..0000000000
--- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/store/migration/DynamicElementAndroidToElementRMigrationTest.kt
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * Copyright 2022 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.store.migration
-
-import android.content.Context
-import androidx.test.ext.junit.runners.AndroidJUnit4
-import androidx.test.platform.app.InstrumentationRegistry
-import io.mockk.spyk
-import io.realm.Realm
-import io.realm.kotlin.where
-import org.amshove.kluent.internal.assertEquals
-import org.junit.After
-import org.junit.Assert.assertNotNull
-import org.junit.Assert.assertTrue
-import org.junit.Before
-import org.junit.Ignore
-import org.junit.Rule
-import org.junit.Test
-import org.junit.runner.RunWith
-import org.matrix.android.sdk.TestBuildVersionSdkIntProvider
-import org.matrix.android.sdk.api.securestorage.SecretStoringUtils
-import org.matrix.android.sdk.internal.crypto.RustEncryptionConfiguration
-import org.matrix.android.sdk.internal.crypto.store.db.RealmCryptoStoreMigration
-import org.matrix.android.sdk.internal.crypto.store.db.RealmCryptoStoreModule
-import org.matrix.android.sdk.internal.crypto.store.db.RustMigrationInfoProvider
-import org.matrix.android.sdk.internal.crypto.store.db.model.CryptoMetadataEntity
-import org.matrix.android.sdk.internal.crypto.store.db.model.OlmSessionEntity
-import org.matrix.android.sdk.internal.database.RealmKeysUtils
-import org.matrix.android.sdk.internal.database.TestRealmConfigurationFactory
-import org.matrix.android.sdk.internal.util.time.Clock
-import org.matrix.android.sdk.test.shared.createTimberTestRule
-import org.matrix.olm.OlmAccount
-import org.matrix.olm.OlmManager
-import org.matrix.rustcomponents.sdk.crypto.OlmMachine
-import java.io.File
-import java.security.KeyStore
-
-@RunWith(AndroidJUnit4::class)
-class DynamicElementAndroidToElementRMigrationTest {
-
- @get:Rule val configurationFactory = TestRealmConfigurationFactory()
-
- @Rule
- fun timberTestRule() = createTimberTestRule()
-
- var context: Context = InstrumentationRegistry.getInstrumentation().context
- var realm: Realm? = null
-
- @Before
- fun setUp() {
- // Ensure Olm is initialized
- OlmManager()
- }
-
- @After
- fun tearDown() {
- realm?.close()
- }
-
- private val keyStore = spyk(KeyStore.getInstance("AndroidKeyStore")).also { it.load(null) }
-
- private val rustEncryptionConfiguration = RustEncryptionConfiguration(
- "foo",
- RealmKeysUtils(
- context,
- SecretStoringUtils(context, keyStore, TestBuildVersionSdkIntProvider(), false)
- )
- )
-
- private val fakeClock = object : Clock {
- override fun epochMillis() = 0L
- }
-
- @Test
- fun given_a_valid_crypto_store_realm_file_then_migration_should_be_successful() {
- testMigrate(false)
- }
-
- @Test
- @Ignore("We don't migrate group sessions for now, and it's making this test suite unstable")
- fun given_a_valid_crypto_store_realm_file_no_lazy_then_migration_should_be_successful() {
- testMigrate(true)
- }
-
- private fun testMigrate(migrateGroupSessions: Boolean) {
- val targetFile = File(configurationFactory.root, "rust-sdk")
-
- val realmName = "crypto_store_migration_16.realm"
- val infoProvider = RustMigrationInfoProvider(
- targetFile,
- rustEncryptionConfiguration
- ).apply {
- migrateMegolmGroupSessions = migrateGroupSessions
- }
- val migration = RealmCryptoStoreMigration(fakeClock, infoProvider)
-
- val realmConfiguration = configurationFactory.createConfiguration(
- realmName,
- null,
- RealmCryptoStoreModule(),
- migration.schemaVersion,
- migration
- )
- configurationFactory.copyRealmFromAssets(context, realmName, realmName)
-
- realm = Realm.getInstance(realmConfiguration)
- val metaData = realm!!.where().findFirst()!!
- val userId = metaData.userId!!
- val deviceId = metaData.deviceId!!
- val olmAccount = metaData.getOlmAccount()!!
-
- val machine = OlmMachine(userId, deviceId, targetFile.path, rustEncryptionConfiguration.getDatabasePassphrase())
-
- assertEquals(olmAccount.identityKeys()[OlmAccount.JSON_KEY_FINGER_PRINT_KEY], machine.identityKeys()["ed25519"])
- assertNotNull(machine.getBackupKeys())
- val crossSigningStatus = machine.crossSigningStatus()
- assertTrue(crossSigningStatus.hasMaster)
- assertTrue(crossSigningStatus.hasSelfSigning)
- assertTrue(crossSigningStatus.hasUserSigning)
-
- if (migrateGroupSessions) {
- assertTrue("Some outbound sessions should be migrated", machine.roomKeyCounts().total.toInt() > 0)
- assertTrue("There are some backed-up sessions", machine.roomKeyCounts().backedUp.toInt() > 0)
- } else {
- assertTrue(machine.roomKeyCounts().total.toInt() == 0)
- assertTrue(machine.roomKeyCounts().backedUp.toInt() == 0)
- }
-
- // legacy olm sessions should have been deleted
- val remainingOlmSessions = realm!!.where().findAll().size
- assertEquals("legacy olm sessions should have been removed from store", 0, remainingOlmSessions)
- }
-}
diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/database/CryptoSanityMigrationTest.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/database/CryptoSanityMigrationTest.kt
deleted file mode 100644
index 828c0f51d4..0000000000
--- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/database/CryptoSanityMigrationTest.kt
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Copyright 2023 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.database
-
-import android.content.Context
-import androidx.test.platform.app.InstrumentationRegistry
-import io.mockk.spyk
-import io.realm.Realm
-import org.junit.After
-import org.junit.Before
-import org.junit.Rule
-import org.junit.Test
-import org.matrix.android.sdk.TestBuildVersionSdkIntProvider
-import org.matrix.android.sdk.api.securestorage.SecretStoringUtils
-import org.matrix.android.sdk.internal.crypto.RustEncryptionConfiguration
-import org.matrix.android.sdk.internal.crypto.store.db.RealmCryptoStoreMigration
-import org.matrix.android.sdk.internal.crypto.store.db.RealmCryptoStoreModule
-import org.matrix.android.sdk.internal.crypto.store.db.RustMigrationInfoProvider
-import org.matrix.android.sdk.internal.util.time.Clock
-import org.matrix.olm.OlmManager
-import java.io.File
-import java.security.KeyStore
-
-class CryptoSanityMigrationTest {
- @get:Rule val configurationFactory = TestRealmConfigurationFactory()
-
- lateinit var context: Context
- var realm: Realm? = null
-
- @Before
- fun setUp() {
- // Ensure Olm is initialized
- OlmManager()
- context = InstrumentationRegistry.getInstrumentation().context
- }
-
- @After
- fun tearDown() {
- realm?.close()
- }
-
- private val keyStore = spyk(KeyStore.getInstance("AndroidKeyStore")).also { it.load(null) }
-
- @Test
- fun cryptoDatabaseShouldMigrateGracefully() {
- val realmName = "crypto_store_20.realm"
-
- val rustMigrationInfo = RustMigrationInfoProvider(
- File(configurationFactory.root, "test_rust"),
- RustEncryptionConfiguration(
- "foo",
- RealmKeysUtils(
- context,
- SecretStoringUtils(context, keyStore, TestBuildVersionSdkIntProvider(), false)
- )
- ),
- )
- val migration = RealmCryptoStoreMigration(
- object : Clock {
- override fun epochMillis(): Long {
- return 0L
- }
- },
- rustMigrationInfo
- )
-
- val realmConfiguration = configurationFactory.createConfiguration(
- realmName,
- "7b9a21a8a311e85d75b069a343c23fc952fc3fec5e0c83ecfa13f24b787479c487c3ed587db3dd1f5805d52041fc0ac246516e94b27ffa699ff928622e621aca",
- RealmCryptoStoreModule(),
- migration.schemaVersion,
- migration
- )
- configurationFactory.copyRealmFromAssets(context, realmName, realmName)
-
- realm = Realm.getInstance(realmConfiguration)
- }
-}
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
new file mode 100644
index 0000000000..ba04e4607e
--- /dev/null
+++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/session/contentscanner/ScanEncryptorUtilsTest.kt
@@ -0,0 +1,121 @@
+/*
+ * Copyright (c) 2024 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.session.contentscanner
+
+import org.amshove.kluent.shouldBe
+import org.amshove.kluent.shouldBeEqualTo
+import org.amshove.kluent.shouldNotBe
+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.session.contentscanner.model.DownloadBody
+
+class ScanEncryptorUtilsTest {
+ private val anMxcUrl = "mxc://matrix.org/123456"
+ private val anElementToDecrypt = ElementToDecrypt(
+ k = "key",
+ iv = "iv",
+ sha256 = "sha256"
+ )
+ private val aPublicKey = "6n3l15JqsNhpM1OwRIoDCL/3c1B5idcwvy07Y5qFRyw="
+ private val aPrivateKey = "CLYwNaeA9d0KHE0DniO1bxGgmNsPJ/pyanF4b4tcK1M="
+
+ @Test
+ fun whenNoServerKeyIsProvidedTheContentIsNotEncrypted() {
+ val result = ScanEncryptorUtils.getDownloadBodyAndEncryptIfNeeded(
+ publicServerKey = null,
+ mxcUrl = anMxcUrl,
+ elementToDecrypt = anElementToDecrypt
+ )
+ result shouldBeEqualTo DownloadBody(
+ file = EncryptedFileInfo(
+ url = anMxcUrl,
+ iv = anElementToDecrypt.iv,
+ hashes = mapOf("sha256" to anElementToDecrypt.sha256),
+ key = EncryptedFileKey(
+ k = anElementToDecrypt.k,
+ alg = "A256CTR",
+ keyOps = listOf("encrypt", "decrypt"),
+ kty = "oct",
+ ext = true
+ ),
+ v = "v2"
+ ),
+ encryptedBody = null
+ )
+ }
+
+ @Test
+ fun whenServerKeyIsProvidedTheContentIsEncrypted() {
+ val result = ScanEncryptorUtils.getDownloadBodyAndEncryptIfNeeded(
+ publicServerKey = aPublicKey,
+ mxcUrl = anMxcUrl,
+ elementToDecrypt = anElementToDecrypt
+ )
+ result.file shouldBe null
+ // Note: we cannot check the members of EncryptedBody because they change on each call.
+ 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")
+ val clearInfo = ScanEncryptorUtils.getDownloadBodyAndEncryptIfNeeded(
+ publicServerKey = null,
+ mxcUrl = anMxcUrl,
+ elementToDecrypt = anElementToDecrypt
+ )
+ // Uncomment to get a new encrypted body
+ // val encryptedBody = ScanEncryptorUtils.getDownloadBodyAndEncryptIfNeeded(
+ // publicServerKey = aPublicKey,
+ // mxcUrl = anMxcUrl,
+ // elementToDecrypt = anElementToDecrypt
+ // ).encryptedBody!!
+ // println("libolmEncryptedBody: $encryptedBody")
+ val libolmEncryptedBody = EncryptedBody(
+ cipherText = "GTnDhm6xe5fPe/QCr6fyGcZXheFhZlPG" +
+ "nJZiCK8Xwq6qTg71vSUGWtLdt3uaTmK7" +
+ "F7fB3PBKchHu2VVv6MMgo8fpUQ7KBbmu" +
+ "NWTrNmf3QdhXuRwUwz/q4GxsbGR2zjSX" +
+ "/UoE5S4ymVtOVhvSfXQfssN56wVIzC6S" +
+ "dy57y6b1IXPihlCUdvb8LMkMvViHYeNf" +
+ "beFrAfMlsyr1+jdZEXZF5Q7iruhsH2iu" +
+ "k7+Ayl9rdILCD5tjE9pezwe1V6uc/Agb",
+ mac = "Wk77HRg50oM",
+ ephemeral = "rMTK6/CGASinfX4USFS5qmD3r4meffxKc/jCSFIBczw"
+ )
+ // Try to decrypt the body
+ val result = withOlmDecryption { olmPkDecryption ->
+ olmPkDecryption.setPrivateKey(aPrivateKey.decodeBase64()!!.toByteArray())
+ olmPkDecryption.decrypt(
+ OlmPkMessage().apply {
+ mCipherText = libolmEncryptedBody.cipherText
+ mMac = libolmEncryptedBody.mac
+ mEphemeralKey = libolmEncryptedBody.ephemeral
+ }
+ )
+ }
+ val parseResult = MoshiProvider.providesMoshi()
+ .adapter(DownloadBody::class.java)
+ .fromJson(result)
+ parseResult shouldBeEqualTo clearInfo
+ }
+ */
+}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/Matrix.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/Matrix.kt
index b9780b8021..5f87425cfc 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/Matrix.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/Matrix.kt
@@ -39,7 +39,6 @@ import org.matrix.android.sdk.internal.network.ApiInterceptor
import org.matrix.android.sdk.internal.network.UserAgentHolder
import org.matrix.android.sdk.internal.util.BackgroundDetectionObserver
import org.matrix.android.sdk.internal.worker.MatrixWorkerFactory
-import org.matrix.olm.OlmManager
import java.util.concurrent.Executors
import javax.inject.Inject
@@ -59,7 +58,6 @@ class Matrix(context: Context, matrixConfiguration: MatrixConfiguration) {
@Inject internal lateinit var debugService: DebugService
@Inject internal lateinit var userAgentHolder: UserAgentHolder
@Inject internal lateinit var backgroundDetectionObserver: BackgroundDetectionObserver
- @Inject internal lateinit var olmManager: OlmManager
@Inject internal lateinit var sessionManager: SessionManager
@Inject internal lateinit var homeServerHistoryService: HomeServerHistoryService
@Inject internal lateinit var apiInterceptor: ApiInterceptor
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/crypto/CryptoConstants.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/crypto/CryptoConstants.kt
index aced0ca3a2..5b6bd0c3e1 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/crypto/CryptoConstants.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/crypto/CryptoConstants.kt
@@ -31,11 +31,6 @@ const val MXCRYPTO_ALGORITHM_MEGOLM = "m.megolm.v1.aes-sha2"
*/
const val MXCRYPTO_ALGORITHM_MEGOLM_BACKUP = "m.megolm_backup.v1.curve25519-aes-sha2"
-/**
- * Secured Shared Storage algorithm constant.
- */
-const val SSSS_ALGORITHM_CURVE25519_AES_SHA2 = "m.secret_storage.v1.curve25519-aes-sha2"
-
/* Secrets are encrypted using AES-CTR-256 and MACed using HMAC-SHA-256. **/
const val SSSS_ALGORITHM_AES_HMAC_SHA2 = "m.secret_storage.v1.aes-hmac-sha2"
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/Rendezvous.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/Rendezvous.kt
deleted file mode 100644
index 5bceecf643..0000000000
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/Rendezvous.kt
+++ /dev/null
@@ -1,254 +0,0 @@
-/*
- * Copyright 2022 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.api.rendezvous
-
-import android.net.Uri
-import org.matrix.android.sdk.api.auth.AuthenticationService
-import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig
-import org.matrix.android.sdk.api.logger.LoggerTag
-import org.matrix.android.sdk.api.rendezvous.channels.ECDHRendezvousChannel
-import org.matrix.android.sdk.api.rendezvous.model.ECDHRendezvousCode
-import org.matrix.android.sdk.api.rendezvous.model.Outcome
-import org.matrix.android.sdk.api.rendezvous.model.Payload
-import org.matrix.android.sdk.api.rendezvous.model.PayloadType
-import org.matrix.android.sdk.api.rendezvous.model.Protocol
-import org.matrix.android.sdk.api.rendezvous.model.RendezvousCode
-import org.matrix.android.sdk.api.rendezvous.model.RendezvousError
-import org.matrix.android.sdk.api.rendezvous.model.RendezvousIntent
-import org.matrix.android.sdk.api.rendezvous.model.RendezvousTransportType
-import org.matrix.android.sdk.api.rendezvous.model.SecureRendezvousChannelAlgorithm
-import org.matrix.android.sdk.api.rendezvous.transports.SimpleHttpRendezvousTransport
-import org.matrix.android.sdk.api.session.Session
-import org.matrix.android.sdk.api.session.crypto.crosssigning.DeviceTrustLevel
-import org.matrix.android.sdk.api.util.MatrixJsonParser
-import timber.log.Timber
-
-// n.b MSC3886/MSC3903/MSC3906 that this is based on are now closed.
-// However, we want to keep this implementation around for some time.
-// TODO define an end-of-life date for this implementation.
-
-/**
- * Implementation of MSC3906 to sign in + E2EE set up using a QR code.
- */
-class Rendezvous(
- val channel: RendezvousChannel,
- val theirIntent: RendezvousIntent,
-) {
- companion object {
- private val TAG = LoggerTag(Rendezvous::class.java.simpleName, LoggerTag.RENDEZVOUS).value
-
- @Throws(RendezvousError::class)
- fun buildChannelFromCode(code: String): Rendezvous {
- // we first check that the code is valid JSON and has right high-level structure
- val genericParsed = try {
- // we rely on moshi validating the code and throwing exception if invalid JSON or algorithm doesn't match
- MatrixJsonParser.getMoshi().adapter(RendezvousCode::class.java).fromJson(code)
- } catch (a: Throwable) {
- throw RendezvousError("Malformed code", RendezvousFailureReason.InvalidCode)
- } ?: throw RendezvousError("Code is null", RendezvousFailureReason.InvalidCode)
-
- // then we check that algorithm is supported
- if (!SecureRendezvousChannelAlgorithm.values().map { it.value }.contains(genericParsed.rendezvous.algorithm)) {
- throw RendezvousError("Unsupported algorithm", RendezvousFailureReason.UnsupportedAlgorithm)
- }
-
- // and, that the transport is supported
- if (!RendezvousTransportType.values().map { it.value }.contains(genericParsed.rendezvous.transport.type)) {
- throw RendezvousError("Unsupported transport", RendezvousFailureReason.UnsupportedTransport)
- }
-
- // now that we know the overall structure looks sensible, we rely on moshi validating the code and
- // throwing exception if other parts are invalid
- val supportedParsed = try {
- MatrixJsonParser.getMoshi().adapter(ECDHRendezvousCode::class.java).fromJson(code)
- } catch (a: Throwable) {
- throw RendezvousError("Malformed ECDH rendezvous code", RendezvousFailureReason.InvalidCode)
- } ?: throw RendezvousError("ECDH rendezvous code is null", RendezvousFailureReason.InvalidCode)
-
- val transport = SimpleHttpRendezvousTransport(supportedParsed.rendezvous.transport.uri)
-
- return Rendezvous(
- ECDHRendezvousChannel(transport, supportedParsed.rendezvous.algorithm, supportedParsed.rendezvous.key),
- supportedParsed.intent
- )
- }
- }
-
- private val adapter = MatrixJsonParser.getMoshi().adapter(Payload::class.java)
-
- // not yet implemented: RendezvousIntent.RECIPROCATE_LOGIN_ON_EXISTING_DEVICE
- val ourIntent: RendezvousIntent = RendezvousIntent.LOGIN_ON_NEW_DEVICE
-
- @Throws(RendezvousError::class)
- private suspend fun checkCompatibility() {
- val incompatible = theirIntent == ourIntent
-
- Timber.tag(TAG).d("ourIntent: $ourIntent, theirIntent: $theirIntent, incompatible: $incompatible")
-
- if (incompatible) {
- // inform the other side
- send(Payload(PayloadType.FINISH, intent = ourIntent))
- if (ourIntent == RendezvousIntent.LOGIN_ON_NEW_DEVICE) {
- throw RendezvousError("The other device isn't signed in", RendezvousFailureReason.OtherDeviceNotSignedIn)
- } else {
- throw RendezvousError("The other device is already signed in", RendezvousFailureReason.OtherDeviceAlreadySignedIn)
- }
- }
- }
-
- @Throws(RendezvousError::class)
- suspend fun startAfterScanningCode(): String {
- val checksum = channel.connect()
-
- Timber.tag(TAG).i("Connected to secure channel with checksum: $checksum")
-
- checkCompatibility()
-
- // get protocols
- Timber.tag(TAG).i("Waiting for protocols")
- val protocolsResponse = receive()
-
- if (protocolsResponse?.protocols == null || !protocolsResponse.protocols.contains(Protocol.LOGIN_TOKEN)) {
- send(Payload(PayloadType.FINISH, outcome = Outcome.UNSUPPORTED))
- throw RendezvousError("Unsupported protocols", RendezvousFailureReason.UnsupportedHomeserver)
- }
-
- send(Payload(PayloadType.PROGRESS, protocol = Protocol.LOGIN_TOKEN))
-
- return checksum
- }
-
- @Throws(RendezvousError::class)
- suspend fun waitForLoginOnNewDevice(authenticationService: AuthenticationService): Session {
- Timber.tag(TAG).i("Waiting for login_token")
-
- val loginToken = receive()
-
- if (loginToken?.type == PayloadType.FINISH) {
- when (loginToken.outcome) {
- Outcome.DECLINED -> {
- throw RendezvousError("Login declined by other device", RendezvousFailureReason.UserDeclined)
- }
- Outcome.UNSUPPORTED -> {
- throw RendezvousError("Homeserver lacks support", RendezvousFailureReason.UnsupportedHomeserver)
- }
- else -> {
- throw RendezvousError("Unknown error", RendezvousFailureReason.Unknown)
- }
- }
- }
-
- val homeserver = loginToken?.homeserver ?: throw RendezvousError("No homeserver returned", RendezvousFailureReason.ProtocolError)
- val token = loginToken.loginToken ?: throw RendezvousError("No login token returned", RendezvousFailureReason.ProtocolError)
-
- Timber.tag(TAG).i("Got login_token now attempting to sign in with $homeserver")
-
- val hsConfig = HomeServerConnectionConfig(homeServerUri = Uri.parse(homeserver))
- return authenticationService.loginUsingQrLoginToken(hsConfig, token)
- }
-
- @Throws(RendezvousError::class)
- suspend fun completeVerificationOnNewDevice(session: Session) {
- val userId = session.myUserId
- val crypto = session.cryptoService()
- val deviceId = crypto.getMyCryptoDevice().deviceId
- val deviceKey = crypto.getMyCryptoDevice().fingerprint()
- send(Payload(PayloadType.PROGRESS, outcome = Outcome.SUCCESS, deviceId = deviceId, deviceKey = deviceKey))
-
- try {
- // explicitly download keys for ourself rather than racing with initial sync which might not complete in time
- crypto.downloadKeysIfNeeded(listOf(userId), false)
- } catch (e: Throwable) {
- // log as warning and continue as initial sync might still complete
- Timber.tag(TAG).w(e, "Failed to download keys for self")
- }
-
- // await confirmation of verification
- val verificationResponse = receive()
- if (verificationResponse?.outcome == Outcome.VERIFIED) {
- val verifyingDeviceId = verificationResponse.verifyingDeviceId
- ?: throw RendezvousError("No verifying device id returned", RendezvousFailureReason.ProtocolError)
- val verifyingDeviceFromServer = crypto.getCryptoDeviceInfo(userId, verifyingDeviceId)
- if (verifyingDeviceFromServer?.fingerprint() != verificationResponse.verifyingDeviceKey) {
- Timber.tag(TAG).w(
- "Verifying device $verifyingDeviceId key doesn't match: ${
- verifyingDeviceFromServer?.fingerprint()
- } vs ${verificationResponse.verifyingDeviceKey})"
- )
- // inform the other side
- send(Payload(PayloadType.FINISH, outcome = Outcome.E2EE_SECURITY_ERROR))
- throw RendezvousError("Key from verifying device doesn't match", RendezvousFailureReason.E2EESecurityIssue)
- }
-
- verificationResponse.masterKey?.let { masterKeyFromVerifyingDevice ->
- // verifying device provided us with a master key, so use it to check integrity
-
- // see what the homeserver told us
- val localMasterKey = crypto.crossSigningService().getMyCrossSigningKeys()?.masterKey()
-
- // n.b. if no local master key this is a problem, as well as it not matching
- if (localMasterKey?.unpaddedBase64PublicKey != masterKeyFromVerifyingDevice) {
- Timber.tag(TAG).w("Master key from verifying device doesn't match: $masterKeyFromVerifyingDevice vs $localMasterKey")
- // inform the other side
- send(Payload(PayloadType.FINISH, outcome = Outcome.E2EE_SECURITY_ERROR))
- throw RendezvousError("Master key from verifying device doesn't match", RendezvousFailureReason.E2EESecurityIssue)
- }
-
- // set other device as verified
- Timber.tag(TAG).i("Setting device $verifyingDeviceId as verified")
- crypto.setDeviceVerification(DeviceTrustLevel(locallyVerified = true, crossSigningVerified = false), userId, verifyingDeviceId)
-
- Timber.tag(TAG).i("Setting master key as trusted")
- crypto.crossSigningService().markMyMasterKeyAsTrusted()
- } ?: run {
- // set other device as verified anyway
- Timber.tag(TAG).i("Setting device $verifyingDeviceId as verified")
- crypto.setDeviceVerification(DeviceTrustLevel(locallyVerified = true, crossSigningVerified = false), userId, verifyingDeviceId)
-
- Timber.tag(TAG).i("No master key given by verifying device")
- }
-
- // request secrets from other sessions.
- Timber.tag(TAG).i("Requesting secrets from other sessions")
-
- session.sharedSecretStorageService().requestMissingSecrets()
- } else {
- Timber.tag(TAG).i("Not doing verification")
- }
- }
-
- @Throws(RendezvousError::class)
- private suspend fun receive(): Payload? {
- val data = channel.receive() ?: return null
- val payload = try {
- adapter.fromJson(data.toString(Charsets.UTF_8))
- } catch (e: Exception) {
- Timber.tag(TAG).w(e, "Failed to parse payload")
- throw RendezvousError("Invalid payload received", RendezvousFailureReason.Unknown)
- }
-
- return payload
- }
-
- private suspend fun send(payload: Payload) {
- channel.send(adapter.toJson(payload).toByteArray(Charsets.UTF_8))
- }
-
- suspend fun close() {
- channel.close()
- }
-}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/RendezvousChannel.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/RendezvousChannel.kt
deleted file mode 100644
index 0956a5b0a0..0000000000
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/RendezvousChannel.kt
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright 2022 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.api.rendezvous
-
-import org.matrix.android.sdk.api.rendezvous.model.RendezvousError
-
-/**
- * Representation of a rendezvous channel such as that described by MSC3903.
- */
-interface RendezvousChannel {
- val transport: RendezvousTransport
-
- /**
- * @returns the checksum/confirmation digits to be shown to the user
- */
- @Throws(RendezvousError::class)
- suspend fun connect(): String
-
- /**
- * Send a payload via the channel.
- * @param data payload to send
- */
- @Throws(RendezvousError::class)
- suspend fun send(data: ByteArray)
-
- /**
- * Receive a payload from the channel.
- * @returns the received payload
- */
- @Throws(RendezvousError::class)
- suspend fun receive(): ByteArray?
-
- /**
- * Closes the channel and cleans up.
- */
- suspend fun close()
-}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/RendezvousFailureReason.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/RendezvousFailureReason.kt
deleted file mode 100644
index 18e625d825..0000000000
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/RendezvousFailureReason.kt
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright 2022 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.api.rendezvous
-
-enum class RendezvousFailureReason(val canRetry: Boolean = true) {
- UserDeclined,
- OtherDeviceNotSignedIn,
- OtherDeviceAlreadySignedIn,
- Unknown,
- Expired,
- UserCancelled,
- InvalidCode,
- UnsupportedAlgorithm(false),
- UnsupportedTransport(false),
- UnsupportedHomeserver(false),
- ProtocolError,
- E2EESecurityIssue(false)
-}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/RendezvousTransport.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/RendezvousTransport.kt
deleted file mode 100644
index 81632e951a..0000000000
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/RendezvousTransport.kt
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright 2022 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.api.rendezvous
-
-import okhttp3.MediaType
-import org.matrix.android.sdk.api.rendezvous.model.RendezvousError
-import org.matrix.android.sdk.api.rendezvous.model.RendezvousTransportDetails
-
-interface RendezvousTransport {
- var ready: Boolean
-
- @Throws(RendezvousError::class)
- suspend fun details(): RendezvousTransportDetails
-
- @Throws(RendezvousError::class)
- suspend fun send(contentType: MediaType, data: ByteArray)
-
- @Throws(RendezvousError::class)
- suspend fun receive(): ByteArray?
-
- suspend fun close()
-}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/channels/ECDHRendezvousChannel.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/channels/ECDHRendezvousChannel.kt
deleted file mode 100644
index bcde4a2a7f..0000000000
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/channels/ECDHRendezvousChannel.kt
+++ /dev/null
@@ -1,199 +0,0 @@
-/*
- * Copyright 2022 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.api.rendezvous.channels
-
-import android.util.Base64
-import com.squareup.moshi.JsonClass
-import kotlinx.coroutines.sync.Mutex
-import kotlinx.coroutines.sync.withLock
-import okhttp3.MediaType.Companion.toMediaType
-import org.matrix.android.sdk.api.logger.LoggerTag
-import org.matrix.android.sdk.api.rendezvous.RendezvousChannel
-import org.matrix.android.sdk.api.rendezvous.RendezvousFailureReason
-import org.matrix.android.sdk.api.rendezvous.RendezvousTransport
-import org.matrix.android.sdk.api.rendezvous.model.RendezvousError
-import org.matrix.android.sdk.api.rendezvous.model.SecureRendezvousChannelAlgorithm
-import org.matrix.android.sdk.api.util.MatrixJsonParser
-import org.matrix.android.sdk.internal.crypto.verification.getDecimalCodeRepresentation
-import org.matrix.olm.OlmSAS
-import timber.log.Timber
-import java.security.SecureRandom
-import java.util.LinkedList
-import javax.crypto.Cipher
-import javax.crypto.spec.IvParameterSpec
-import javax.crypto.spec.SecretKeySpec
-
-/**
- * Implements X25519 ECDH key agreement and AES-256-GCM encryption channel as per MSC3903:
- * https://github.com/matrix-org/matrix-spec-proposals/pull/3903
- */
-class ECDHRendezvousChannel(
- override var transport: RendezvousTransport,
- private val algorithm: SecureRendezvousChannelAlgorithm,
- theirPublicKeyBase64: String?,
-) : RendezvousChannel {
- companion object {
- private const val ALGORITHM_SPEC = "AES/GCM/NoPadding"
- private const val KEY_SPEC = "AES"
- private val TAG = LoggerTag(ECDHRendezvousChannel::class.java.simpleName, LoggerTag.RENDEZVOUS).value
- }
-
- @JsonClass(generateAdapter = true)
- internal data class ECDHPayload(
- val algorithm: SecureRendezvousChannelAlgorithm? = null,
- val key: String? = null,
- val ciphertext: String? = null,
- val iv: String? = null,
- )
-
- private val olmSASMutex = Mutex()
- private var olmSAS: OlmSAS?
- private val ourPublicKey: ByteArray
- private val ecdhAdapter = MatrixJsonParser.getMoshi().adapter(ECDHPayload::class.java)
- private var theirPublicKey: ByteArray? = null
- private var aesKey: ByteArray? = null
-
- init {
- theirPublicKeyBase64?.let {
- theirPublicKey = decodeBase64(it)
- }
- olmSAS = OlmSAS()
- ourPublicKey = decodeBase64(olmSAS!!.publicKey)
- }
-
- fun encodeBase64(input: ByteArray?): String? {
- if (algorithm == SecureRendezvousChannelAlgorithm.ECDH_V2) {
- return Base64.encodeToString(input, Base64.NO_WRAP or Base64.NO_PADDING)
- }
- return Base64.encodeToString(input, Base64.NO_WRAP)
- }
-
- fun decodeBase64(input: String?): ByteArray {
- // for decoding we aren't concerned about padding
- return Base64.decode(input, Base64.NO_WRAP)
- }
-
- @Throws(RendezvousError::class)
- override suspend fun connect(): String {
- val sas = olmSAS ?: throw RendezvousError("Channel closed", RendezvousFailureReason.Unknown)
- val isInitiator = theirPublicKey == null
-
- if (isInitiator) {
- Timber.tag(TAG).i("Waiting for other device to send their public key")
- val res = this.receiveAsPayload() ?: throw RendezvousError("No reply from other device", RendezvousFailureReason.ProtocolError)
-
- if (res.key == null) {
- throw RendezvousError(
- "Unsupported algorithm: ${res.algorithm}",
- RendezvousFailureReason.UnsupportedAlgorithm,
- )
- }
- theirPublicKey = decodeBase64(res.key)
- } else {
- // send our public key unencrypted
- Timber.tag(TAG).i("Sending public key")
- send(
- ECDHPayload(
- algorithm = algorithm,
- key = encodeBase64(ourPublicKey)
- )
- )
- }
-
- olmSASMutex.withLock {
- sas.setTheirPublicKey(encodeBase64(theirPublicKey))
- sas.setTheirPublicKey(encodeBase64(theirPublicKey))
-
- val initiatorKey = encodeBase64(if (isInitiator) ourPublicKey else theirPublicKey)
- val recipientKey = encodeBase64(if (isInitiator) theirPublicKey else ourPublicKey)
- val aesInfo = "${algorithm.value}|$initiatorKey|$recipientKey"
-
- aesKey = sas.generateShortCode(aesInfo, 32)
-
- val rawChecksum = sas.generateShortCode(aesInfo, 5)
- return rawChecksum.getDecimalCodeRepresentation(separator = "-")
- }
- }
-
- private suspend fun send(payload: ECDHPayload) {
- transport.send("application/json".toMediaType(), ecdhAdapter.toJson(payload).toByteArray(Charsets.UTF_8))
- }
-
- override suspend fun send(data: ByteArray) {
- if (aesKey == null) {
- throw IllegalStateException("Shared secret not established")
- }
- send(encrypt(data))
- }
-
- private suspend fun receiveAsPayload(): ECDHPayload? {
- transport.receive()?.toString(Charsets.UTF_8)?.let {
- return ecdhAdapter.fromJson(it)
- } ?: return null
- }
-
- override suspend fun receive(): ByteArray? {
- if (aesKey == null) {
- throw IllegalStateException("Shared secret not established")
- }
- val payload = receiveAsPayload() ?: return null
- return decrypt(payload)
- }
-
- override suspend fun close() {
- val sas = olmSAS ?: throw IllegalStateException("Channel already closed")
- olmSASMutex.withLock {
- // this does a double release check already so we don't re-check ourselves
- sas.releaseSas()
- olmSAS = null
- }
- transport.close()
- }
-
- private fun encrypt(plainText: ByteArray): ECDHPayload {
- val iv = ByteArray(16)
- SecureRandom().nextBytes(iv)
-
- val cipherText = LinkedList()
-
- val encryptCipher = Cipher.getInstance(ALGORITHM_SPEC)
- val secretKeySpec = SecretKeySpec(aesKey, KEY_SPEC)
- val ivParameterSpec = IvParameterSpec(iv)
- encryptCipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, ivParameterSpec)
- cipherText.addAll(encryptCipher.update(plainText).toList())
- cipherText.addAll(encryptCipher.doFinal().toList())
-
- return ECDHPayload(
- ciphertext = encodeBase64(cipherText.toByteArray()),
- iv = encodeBase64(iv)
- )
- }
-
- private fun decrypt(payload: ECDHPayload): ByteArray {
- val iv = decodeBase64(payload.iv)
- val encryptCipher = Cipher.getInstance(ALGORITHM_SPEC)
- val secretKeySpec = SecretKeySpec(aesKey, KEY_SPEC)
- val ivParameterSpec = IvParameterSpec(iv)
- encryptCipher.init(Cipher.DECRYPT_MODE, secretKeySpec, ivParameterSpec)
-
- val plainText = LinkedList()
- plainText.addAll(encryptCipher.update(decodeBase64(payload.ciphertext)).toList())
- plainText.addAll(encryptCipher.doFinal().toList())
-
- return plainText.toByteArray()
- }
-}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/model/ECDHRendezvous.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/model/ECDHRendezvous.kt
deleted file mode 100644
index 55bac6397e..0000000000
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/model/ECDHRendezvous.kt
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright 2022 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.api.rendezvous.model
-
-import com.squareup.moshi.JsonClass
-
-@JsonClass(generateAdapter = true)
-data class ECDHRendezvous(
- val transport: SimpleHttpRendezvousTransportDetails,
- val algorithm: SecureRendezvousChannelAlgorithm,
- val key: String
-)
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/model/ECDHRendezvousCode.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/model/ECDHRendezvousCode.kt
deleted file mode 100644
index 575b5d4bfd..0000000000
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/model/ECDHRendezvousCode.kt
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright 2022 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.api.rendezvous.model
-
-import com.squareup.moshi.JsonClass
-
-@JsonClass(generateAdapter = true)
-data class ECDHRendezvousCode(
- val intent: RendezvousIntent,
- val rendezvous: ECDHRendezvous
-)
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/model/Outcome.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/model/Outcome.kt
deleted file mode 100644
index 0ebd1f88b3..0000000000
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/model/Outcome.kt
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright 2022 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.api.rendezvous.model
-
-import com.squareup.moshi.Json
-import com.squareup.moshi.JsonClass
-
-@JsonClass(generateAdapter = false)
-enum class Outcome(val value: String) {
- @Json(name = "success")
- SUCCESS("success"),
-
- @Json(name = "declined")
- DECLINED("declined"),
-
- @Json(name = "unsupported")
- UNSUPPORTED("unsupported"),
-
- @Json(name = "verified")
- VERIFIED("verified"),
-
- @Json(name = "e2ee_security_error")
- E2EE_SECURITY_ERROR("e2ee_security_error")
-}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/model/Payload.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/model/Payload.kt
deleted file mode 100644
index 04631ce959..0000000000
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/model/Payload.kt
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright 2022 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.api.rendezvous.model
-
-import com.squareup.moshi.Json
-import com.squareup.moshi.JsonClass
-
-@JsonClass(generateAdapter = true)
-internal data class Payload(
- val type: PayloadType,
- val intent: RendezvousIntent? = null,
- val outcome: Outcome? = null,
- val protocols: List? = null,
- val protocol: Protocol? = null,
- val homeserver: String? = null,
- @Json(name = "login_token") val loginToken: String? = null,
- @Json(name = "device_id") val deviceId: String? = null,
- @Json(name = "device_key") val deviceKey: String? = null,
- @Json(name = "verifying_device_id") val verifyingDeviceId: String? = null,
- @Json(name = "verifying_device_key") val verifyingDeviceKey: String? = null,
- @Json(name = "master_key") val masterKey: String? = null
-)
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/model/PayloadType.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/model/PayloadType.kt
deleted file mode 100644
index 33beb1f525..0000000000
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/model/PayloadType.kt
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright 2022 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.api.rendezvous.model
-
-import com.squareup.moshi.Json
-import com.squareup.moshi.JsonClass
-
-@JsonClass(generateAdapter = false)
-internal enum class PayloadType(val value: String) {
- @Json(name = "m.login.start")
- START("m.login.start"),
-
- @Json(name = "m.login.finish")
- FINISH("m.login.finish"),
-
- @Json(name = "m.login.progress")
- PROGRESS("m.login.progress")
-}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/model/Protocol.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/model/Protocol.kt
deleted file mode 100644
index 6fce2fa11c..0000000000
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/model/Protocol.kt
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright 2022 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.api.rendezvous.model
-
-import com.squareup.moshi.Json
-import com.squareup.moshi.JsonClass
-
-@JsonClass(generateAdapter = false)
-enum class Protocol(val value: String) {
- @Json(name = "org.matrix.msc3906.login_token")
- LOGIN_TOKEN("org.matrix.msc3906.login_token")
-}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/model/Rendezvous.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/model/Rendezvous.kt
deleted file mode 100644
index f424f8cab0..0000000000
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/model/Rendezvous.kt
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright 2023 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.api.rendezvous.model
-
-import com.squareup.moshi.JsonClass
-
-@JsonClass(generateAdapter = true)
-open class Rendezvous(
- val transport: RendezvousTransportDetails,
- val algorithm: String,
-)
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/model/RendezvousCode.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/model/RendezvousCode.kt
deleted file mode 100644
index ffa8bf6661..0000000000
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/model/RendezvousCode.kt
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright 2023 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.api.rendezvous.model
-
-import com.squareup.moshi.JsonClass
-
-@JsonClass(generateAdapter = true)
-open class RendezvousCode(
- open val intent: RendezvousIntent,
- open val rendezvous: Rendezvous
-)
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/model/RendezvousError.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/model/RendezvousError.kt
deleted file mode 100644
index c52b11a322..0000000000
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/model/RendezvousError.kt
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Copyright 2022 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.api.rendezvous.model
-
-import org.matrix.android.sdk.api.rendezvous.RendezvousFailureReason
-
-class RendezvousError(val description: String, val reason: RendezvousFailureReason) : Exception(description)
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/model/RendezvousIntent.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/model/RendezvousIntent.kt
deleted file mode 100644
index 65037e1252..0000000000
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/model/RendezvousIntent.kt
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright 2022 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.api.rendezvous.model
-
-import com.squareup.moshi.Json
-import com.squareup.moshi.JsonClass
-
-@JsonClass(generateAdapter = false)
-enum class RendezvousIntent {
- @Json(name = "login.start") LOGIN_ON_NEW_DEVICE,
- @Json(name = "login.reciprocate") RECIPROCATE_LOGIN_ON_EXISTING_DEVICE
-}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/model/RendezvousTransportDetails.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/model/RendezvousTransportDetails.kt
deleted file mode 100644
index 34d96ac64a..0000000000
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/model/RendezvousTransportDetails.kt
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Copyright 2022 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.api.rendezvous.model
-
-import com.squareup.moshi.JsonClass
-
-@JsonClass(generateAdapter = true)
-open class RendezvousTransportDetails(
- val type: String
-)
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/model/RendezvousTransportType.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/model/RendezvousTransportType.kt
deleted file mode 100644
index 6fca7efa71..0000000000
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/model/RendezvousTransportType.kt
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright 2022 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.api.rendezvous.model
-
-import com.squareup.moshi.Json
-import com.squareup.moshi.JsonClass
-
-@JsonClass(generateAdapter = false)
-enum class RendezvousTransportType(val value: String) {
- @Json(name = "org.matrix.msc3886.http.v1")
- MSC3886_SIMPLE_HTTP_V1("org.matrix.msc3886.http.v1")
-}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/model/SecureRendezvousChannelAlgorithm.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/model/SecureRendezvousChannelAlgorithm.kt
deleted file mode 100644
index 123e41a5d7..0000000000
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/model/SecureRendezvousChannelAlgorithm.kt
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright 2022 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.api.rendezvous.model
-
-import com.squareup.moshi.Json
-import com.squareup.moshi.JsonClass
-
-@JsonClass(generateAdapter = false)
-enum class SecureRendezvousChannelAlgorithm(val value: String) {
- @Json(name = "org.matrix.msc3903.rendezvous.v1.curve25519-aes-sha256")
- ECDH_V1("org.matrix.msc3903.rendezvous.v1.curve25519-aes-sha256"),
- @Json(name = "org.matrix.msc3903.rendezvous.v2.curve25519-aes-sha256")
- ECDH_V2("org.matrix.msc3903.rendezvous.v2.curve25519-aes-sha256")
-}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/model/SimpleHttpRendezvousTransportDetails.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/model/SimpleHttpRendezvousTransportDetails.kt
deleted file mode 100644
index d2342bb9d5..0000000000
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/model/SimpleHttpRendezvousTransportDetails.kt
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Copyright 2022 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.api.rendezvous.model
-
-import com.squareup.moshi.JsonClass
-
-@JsonClass(generateAdapter = true)
-data class SimpleHttpRendezvousTransportDetails(
- val uri: String
-) : RendezvousTransportDetails(type = RendezvousTransportType.MSC3886_SIMPLE_HTTP_V1.name)
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/transports/SimpleHttpRendezvousTransport.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/transports/SimpleHttpRendezvousTransport.kt
deleted file mode 100644
index 620b599e3d..0000000000
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/rendezvous/transports/SimpleHttpRendezvousTransport.kt
+++ /dev/null
@@ -1,173 +0,0 @@
-/*
- * Copyright 2022 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.api.rendezvous.transports
-
-import kotlinx.coroutines.delay
-import okhttp3.MediaType
-import okhttp3.Request
-import okhttp3.RequestBody.Companion.toRequestBody
-import org.matrix.android.sdk.api.logger.LoggerTag
-import org.matrix.android.sdk.api.rendezvous.RendezvousFailureReason
-import org.matrix.android.sdk.api.rendezvous.RendezvousTransport
-import org.matrix.android.sdk.api.rendezvous.model.RendezvousError
-import org.matrix.android.sdk.api.rendezvous.model.RendezvousTransportDetails
-import org.matrix.android.sdk.api.rendezvous.model.SimpleHttpRendezvousTransportDetails
-import timber.log.Timber
-import java.text.SimpleDateFormat
-import java.util.Date
-import java.util.Locale
-
-/**
- * Implementation of the Simple HTTP transport MSC3886: https://github.com/matrix-org/matrix-spec-proposals/pull/3886
- */
-class SimpleHttpRendezvousTransport(rendezvousUri: String?) : RendezvousTransport {
- companion object {
- private val TAG = LoggerTag(SimpleHttpRendezvousTransport::class.java.simpleName, LoggerTag.RENDEZVOUS).value
- }
-
- override var ready = false
- private var cancelled = false
- private var uri: String?
- private var etag: String? = null
- private var expiresAt: Date? = null
-
- init {
- uri = rendezvousUri
- }
-
- override suspend fun details(): RendezvousTransportDetails {
- val uri = uri ?: throw IllegalStateException("Rendezvous not set up")
-
- return SimpleHttpRendezvousTransportDetails(uri)
- }
-
- @Throws(RendezvousError::class)
- override suspend fun send(contentType: MediaType, data: ByteArray) {
- if (cancelled) {
- throw IllegalStateException("Rendezvous cancelled")
- }
-
- val method = if (uri != null) "PUT" else "POST"
- val uri = this.uri ?: throw RuntimeException("No rendezvous URI")
-
- val httpClient = okhttp3.OkHttpClient.Builder().build()
-
- val request = Request.Builder()
- .url(uri)
- .method(method, data.toRequestBody())
- .header("content-type", contentType.toString())
-
- etag?.let {
- request.header("if-match", it)
- }
-
- val response = httpClient.newCall(request.build()).execute()
-
- if (response.code == 404) {
- throw get404Error()
- }
- etag = response.header("etag")
-
- Timber.tag(TAG).i("Sent data to $uri new etag $etag")
-
- if (method == "POST") {
- val location = response.header("location") ?: throw RuntimeException("No rendezvous URI found in response")
-
- response.header("expires")?.let {
- val format = SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US)
- expiresAt = format.parse(it)
- }
-
- // resolve location header which could be relative or absolute
- this.uri = response.request.url.toUri().resolve(location).toString()
- ready = true
- }
- }
-
- @Throws(RendezvousError::class)
- override suspend fun receive(): ByteArray? {
- if (cancelled) {
- throw IllegalStateException("Rendezvous cancelled")
- }
- val uri = uri ?: throw IllegalStateException("Rendezvous not set up")
- val httpClient = okhttp3.OkHttpClient.Builder().build()
- while (true) {
- Timber.tag(TAG).i("Polling: $uri after etag $etag")
- val request = Request.Builder()
- .url(uri)
- .get()
-
- etag?.let {
- request.header("if-none-match", it)
- }
-
- val response = httpClient.newCall(request.build()).execute()
-
- try {
- // expired
- if (response.code == 404) {
- throw get404Error()
- }
-
- // rely on server expiring the channel rather than checking ourselves
-
- if (response.header("content-type") != "application/json") {
- response.header("etag")?.let {
- etag = it
- }
- } else if (response.code == 200) {
- response.header("etag")?.let {
- etag = it
- }
- return response.body?.bytes()
- }
-
- // sleep for a second before polling again
- // we rely on the server expiring the channel rather than checking it ourselves
- delay(1000)
- } finally {
- response.close()
- }
- }
- }
-
- private fun get404Error(): RendezvousError {
- if (expiresAt != null && Date() > expiresAt) {
- return RendezvousError("Expired", RendezvousFailureReason.Expired)
- }
-
- return RendezvousError("Received unexpected 404", RendezvousFailureReason.Unknown)
- }
-
- override suspend fun close() {
- cancelled = true
- ready = false
-
- uri?.let {
- try {
- val httpClient = okhttp3.OkHttpClient.Builder().build()
- val request = Request.Builder()
- .url(it)
- .delete()
- .build()
- httpClient.newCall(request).execute()
- } catch (e: Throwable) {
- Timber.tag(TAG).w(e, "Failed to delete channel")
- }
- }
- }
-}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/crypto/MXCryptoError.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/crypto/MXCryptoError.kt
index 94ee7ba403..220a75bd3f 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/crypto/MXCryptoError.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/crypto/MXCryptoError.kt
@@ -18,7 +18,6 @@ package org.matrix.android.sdk.api.session.crypto
import org.matrix.android.sdk.api.session.crypto.model.CryptoDeviceInfo
import org.matrix.android.sdk.api.session.crypto.model.MXUsersDevicesMap
-import org.matrix.olm.OlmException
/**
* Represents a crypto error response.
@@ -34,8 +33,6 @@ sealed class MXCryptoError : Throwable() {
val detailedErrorDescription: String? = null
) : MXCryptoError()
- data class OlmError(val olmException: OlmException) : MXCryptoError()
-
data class UnknownDevice(val deviceList: MXUsersDevicesMap) : MXCryptoError()
enum class ErrorType {
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 b8d9711358..c45f85671e 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
@@ -53,7 +53,6 @@ import org.matrix.android.sdk.api.util.toOptional
import org.matrix.android.sdk.internal.coroutines.builder.safeInvokeOnClose
import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.DefaultKeysAlgorithmAndData
import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.KeysAlgorithmAndData
-import org.matrix.android.sdk.internal.crypto.model.MXInboundMegolmSessionWrapper
import org.matrix.android.sdk.internal.crypto.network.RequestSender
import org.matrix.android.sdk.internal.crypto.verification.SasVerification
import org.matrix.android.sdk.internal.crypto.verification.VerificationRequest
@@ -318,22 +317,6 @@ internal class OlmMachine @Inject constructor(
inner.receiveVerificationEvent(serializedEvent, roomId)
}
- /**
- * Used for lazy migration of inboundGroupSession from EA to ER.
- */
- suspend fun importRoomKey(inbound: MXInboundMegolmSessionWrapper): Result {
- Timber.v("Migration:: Tentative lazy migration")
- return withContext(coroutineDispatchers.io) {
- val export = inbound.exportKeys()
- ?: return@withContext Result.failure(Exception("Failed to export key"))
- val result = importDecryptedKeys(listOf(export), null).also {
- Timber.v("Migration:: Tentative lazy migration result: ${it.totalNumberOfKeys}")
- }
- if (result.totalNumberOfKeys == 1) return@withContext Result.success(Unit)
- return@withContext Result.failure(Exception("Import failed"))
- }
- }
-
/**
* Mark the given list of users to be tracked, triggering a key query request for them.
*
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/PrepareToEncryptUseCase.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/PrepareToEncryptUseCase.kt
index e4c0469c74..72242d876c 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/PrepareToEncryptUseCase.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/PrepareToEncryptUseCase.kt
@@ -121,7 +121,8 @@ internal class PrepareToEncryptUseCase @Inject constructor(
HistoryVisibility.INVITED
} else {
HistoryVisibility.JOINED
- }
+ },
+ errorOnVerifiedUserProblem = false,
)
measureTimeMillis {
keyShareLock.withLock {
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/RustCryptoService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/RustCryptoService.kt
index a6e4efd875..c998f104f4 100755
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/RustCryptoService.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/RustCryptoService.kt
@@ -504,15 +504,8 @@ internal class RustCryptoService @Inject constructor(
val content = event.content?.toModel() ?: throw mxCryptoError
val roomId = event.roomId
val sessionId = content.sessionId
- val senderKey = content.senderKey
if (roomId != null && sessionId != null) {
- // try to perform a lazy migration from legacy store
- val legacy = tryOrNull("Failed to access legacy crypto store") {
- cryptoStore.getInboundGroupSession(sessionId, senderKey.orEmpty())
- }
- if (legacy == null || olmMachine.importRoomKey(legacy).isFailure) {
- perSessionBackupQueryRateLimiter.tryFromBackupIfPossible(sessionId, roomId)
- }
+ perSessionBackupQueryRateLimiter.tryFromBackupIfPossible(sessionId, roomId)
}
}
throw mxCryptoError
@@ -851,9 +844,9 @@ internal class RustCryptoService @Inject constructor(
override fun removeSessionListener(listener: NewSessionListener) {
megolmSessionImportManager.removeListener(listener)
}
-/* ==========================================================================================
- * DEBUG INFO
- * ========================================================================================== */
+ /* ==========================================================================================
+ * DEBUG INFO
+ * ========================================================================================== */
override fun toString(): String {
return "DefaultCryptoService of $myUserId ($deviceId)"
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 37d1bd4b89..6750808454 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
@@ -65,7 +65,6 @@ import org.matrix.android.sdk.internal.crypto.network.RequestSender
import org.matrix.android.sdk.internal.di.MoshiProvider
import org.matrix.android.sdk.internal.session.SessionScope
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.SignatureVerification
@@ -840,8 +839,8 @@ internal class RustKeyBackupService @Inject constructor(
try {
olmMachine.enableBackupV1(retrievedMegolmBackupAuthData.publicKey, keysVersionResult.version)
keysBackupVersion = keysVersionResult
- } catch (e: OlmException) {
- Timber.e(e, "OlmException")
+ } catch (e: Exception) {
+ Timber.e(e, "Exception")
keysBackupStateManager.state = KeysBackupState.Disabled
return
}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/model/MXInboundMegolmSessionWrapper.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/model/MXInboundMegolmSessionWrapper.kt
deleted file mode 100644
index 2c6a0a967a..0000000000
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/model/MXInboundMegolmSessionWrapper.kt
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Copyright 2022 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.model
-
-import org.matrix.android.sdk.api.crypto.MXCRYPTO_ALGORITHM_MEGOLM
-import org.matrix.android.sdk.api.extensions.tryOrNull
-import org.matrix.android.sdk.internal.crypto.MegolmSessionData
-import org.matrix.olm.OlmInboundGroupSession
-import timber.log.Timber
-
-data class MXInboundMegolmSessionWrapper(
- // olm object
- val session: OlmInboundGroupSession,
- // data about the session
- val sessionData: InboundGroupSessionData
-) {
- // shortcut
- val roomId = sessionData.roomId
- val senderKey = sessionData.senderKey
- val safeSessionId = tryOrNull("Fail to get megolm session Id") { session.sessionIdentifier() }
-
- /**
- * Export the inbound group session keys.
- * @param index the index to export. If null, the first known index will be used
- * @return the inbound group session as MegolmSessionData if the operation succeeds
- */
- internal fun exportKeys(index: Long? = null): MegolmSessionData? {
- return try {
- val keysClaimed = sessionData.keysClaimed ?: return null
- val wantedIndex = index ?: session.firstKnownIndex
-
- MegolmSessionData(
- senderClaimedEd25519Key = sessionData.keysClaimed?.get("ed25519"),
- forwardingCurve25519KeyChain = sessionData.forwardingCurve25519KeyChain?.toList().orEmpty(),
- sessionKey = session.export(wantedIndex),
- senderClaimedKeys = keysClaimed,
- roomId = sessionData.roomId,
- sessionId = session.sessionIdentifier(),
- senderKey = senderKey,
- algorithm = MXCRYPTO_ALGORITHM_MEGOLM,
- sharedHistory = sessionData.sharedHistory
- )
- } catch (e: Exception) {
- Timber.e(e, "## Failed to export megolm : sessionID ${tryOrNull { session.sessionIdentifier() }} failed")
- null
- }
- }
-
- companion object {
-
- /**
- * @exportFormat true if the megolm keys are in export format
- * (ie, they lack an ed25519 signature)
- */
- @Throws
- internal fun newFromMegolmData(megolmSessionData: MegolmSessionData, exportFormat: Boolean): MXInboundMegolmSessionWrapper {
- val exportedKey = megolmSessionData.sessionKey ?: throw IllegalArgumentException("key data not found")
- val inboundSession = if (exportFormat) {
- OlmInboundGroupSession.importSession(exportedKey)
- } else {
- OlmInboundGroupSession(exportedKey)
- }
- .also {
- if (it.sessionIdentifier() != megolmSessionData.sessionId) {
- it.releaseSession()
- throw IllegalStateException("Mismatched group session Id")
- }
- }
- val data = InboundGroupSessionData(
- roomId = megolmSessionData.roomId,
- senderKey = megolmSessionData.senderKey,
- keysClaimed = megolmSessionData.senderClaimedKeys,
- forwardingCurve25519KeyChain = megolmSessionData.forwardingCurve25519KeyChain,
- sharedHistory = megolmSessionData.sharedHistory,
- trusted = false
- )
-
- return MXInboundMegolmSessionWrapper(
- inboundSession,
- data
- )
- }
- }
-}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/model/MXKey.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/model/MXKey.kt
deleted file mode 100755
index 6b747d19f2..0000000000
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/model/MXKey.kt
+++ /dev/null
@@ -1,132 +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.model
-
-import org.matrix.android.sdk.api.util.JsonDict
-import timber.log.Timber
-
-internal data class MXKey(
- /**
- * The type of the key (in the example: "signed_curve25519").
- */
- val type: String,
-
- /**
- * The id of the key (in the example: "AAAAFw").
- */
- private val keyId: String,
-
- /**
- * The key (in the example: "IjwIcskng7YjYcn0tS8TUOT2OHHtBSfMpcfIczCgXj4").
- */
- val value: String,
-
- /**
- * signature user Id to [deviceid][signature].
- */
- private val signatures: Map>,
-
- /**
- * We have to store the original json because it can contain other fields
- * that we don't support yet but they would be needed to check signatures.
- */
- private val rawMap: JsonDict
-) {
-
- /**
- * @return the signed data map
- */
- fun signalableJSONDictionary(): Map {
- return rawMap.filter {
- it.key != "signatures" && it.key != "unsigned"
- }
- }
-
- /**
- * Returns a signature for an user Id and a signkey.
- *
- * @param userId the user id
- * @param signkey the sign key
- * @return the signature
- */
- fun signatureForUserId(userId: String, signkey: String): String? {
- // sanity checks
- if (userId.isNotBlank() && signkey.isNotBlank()) {
- return signatures[userId]?.get(signkey)
- }
-
- return null
- }
-
- companion object {
- /**
- * Key types.
- */
- const val KEY_CURVE_25519_TYPE = "curve25519"
- const val KEY_SIGNED_CURVE_25519_TYPE = "signed_curve25519"
- // const val KEY_ED_25519_TYPE = "ed25519"
-
- /**
- * Convert a map to a MXKey.
- *
- * @param map the map to convert
- *
- * Json Example:
- *
- *
- *
- * into several val members
- */
- fun from(map: Map?): MXKey? {
- if (map?.isNotEmpty() == true) {
- val firstKey = map.keys.first()
-
- val components = firstKey.split(":").dropLastWhile { it.isEmpty() }
-
- if (components.size == 2) {
- val params = map[firstKey]
- if (params != null) {
- if (params["key"] is String) {
- @Suppress("UNCHECKED_CAST")
- return MXKey(
- type = components[0],
- keyId = components[1],
- value = params["key"] as String,
- signatures = params["signatures"] as Map>,
- rawMap = params
- )
- }
- }
- }
- }
-
- // Error case
- Timber.e("## Unable to parse map")
- return null
- }
- }
-}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/model/MXOlmSessionResult.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/model/MXOlmSessionResult.kt
deleted file mode 100755
index 666ab2d678..0000000000
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/model/MXOlmSessionResult.kt
+++ /dev/null
@@ -1,32 +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.model
-
-import org.matrix.android.sdk.api.session.crypto.model.CryptoDeviceInfo
-import java.io.Serializable
-
-internal data class MXOlmSessionResult(
- /**
- * the device.
- */
- val deviceInfo: CryptoDeviceInfo,
- /**
- * Base64 olm session id.
- * null if no session could be established.
- */
- var sessionId: String?
-) : Serializable
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/model/MXUsersDevicesMap.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/model/MXUsersDevicesMap.kt
deleted file mode 100755
index 58aff14a3d..0000000000
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/model/MXUsersDevicesMap.kt
+++ /dev/null
@@ -1,27 +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.model
-
-import org.matrix.android.sdk.api.session.crypto.model.MXUsersDevicesMap
-
-internal fun MXUsersDevicesMap.toDebugString() =
- map.entries.joinToString { "${it.key} [${it.value.keys.joinToString { it }}]" }
-
-internal fun MXUsersDevicesMap.toDebugCount() =
- map.entries.fold(0) { acc, new ->
- acc + new.value.keys.size
- }
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/model/OlmInboundGroupSessionWrapper.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/model/OlmInboundGroupSessionWrapper.kt
deleted file mode 100755
index ecb2946680..0000000000
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/model/OlmInboundGroupSessionWrapper.kt
+++ /dev/null
@@ -1,151 +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.model
-
-import org.matrix.android.sdk.api.crypto.MXCRYPTO_ALGORITHM_MEGOLM
-import org.matrix.android.sdk.internal.crypto.MegolmSessionData
-import org.matrix.olm.OlmInboundGroupSession
-import timber.log.Timber
-import java.io.Serializable
-
-/**
- * This class adds more context to a OlmInboundGroupSession object.
- * This allows additional checks. The class implements Serializable so that the context can be stored.
- */
-internal class OlmInboundGroupSessionWrapper : Serializable {
-
- // The associated olm inbound group session.
- var olmInboundGroupSession: OlmInboundGroupSession? = null
-
- // The room in which this session is used.
- var roomId: String? = null
-
- // The base64-encoded curve25519 key of the sender.
- var senderKey: String? = null
-
- // Other keys the sender claims.
- var keysClaimed: Map? = null
-
- // Devices which forwarded this session to us (normally empty).
- var forwardingCurve25519KeyChain: List? = ArrayList()
-
- /**
- * @return the first known message index
- */
- val firstKnownIndex: Long?
- get() {
- if (null != olmInboundGroupSession) {
- try {
- return olmInboundGroupSession!!.firstKnownIndex
- } catch (e: Exception) {
- Timber.e(e, "## getFirstKnownIndex() : getFirstKnownIndex failed")
- }
- }
-
- return null
- }
-
- /**
- * Constructor.
- *
- * @param sessionKey the session key
- * @param isImported true if it is an imported session key
- */
- constructor(sessionKey: String, isImported: Boolean) {
- try {
- if (!isImported) {
- olmInboundGroupSession = OlmInboundGroupSession(sessionKey)
- } else {
- olmInboundGroupSession = OlmInboundGroupSession.importSession(sessionKey)
- }
- } catch (e: Exception) {
- Timber.e(e, "Cannot create")
- }
- }
-
- /**
- * Create a new instance from the provided keys map.
- *
- * @param megolmSessionData the megolm session data
- * @throws Exception if the data are invalid
- */
- @Throws(Exception::class)
- constructor(megolmSessionData: MegolmSessionData) {
- try {
- olmInboundGroupSession = OlmInboundGroupSession.importSession(megolmSessionData.sessionKey!!)
-
- if (olmInboundGroupSession!!.sessionIdentifier() != megolmSessionData.sessionId) {
- throw Exception("Mismatched group session Id")
- }
-
- senderKey = megolmSessionData.senderKey
- keysClaimed = megolmSessionData.senderClaimedKeys
- roomId = megolmSessionData.roomId
- } catch (e: Exception) {
- throw Exception(e.message)
- }
- }
-
- /**
- * Export the inbound group session keys.
- *
- * @return the inbound group session as MegolmSessionData if the operation succeeds
- */
- fun exportKeys(): MegolmSessionData? {
- return try {
- if (null == forwardingCurve25519KeyChain) {
- forwardingCurve25519KeyChain = ArrayList()
- }
-
- if (keysClaimed == null) {
- return null
- }
-
- MegolmSessionData(
- senderClaimedEd25519Key = keysClaimed?.get("ed25519"),
- forwardingCurve25519KeyChain = ArrayList(forwardingCurve25519KeyChain!!),
- senderKey = senderKey,
- senderClaimedKeys = keysClaimed,
- roomId = roomId,
- sessionId = olmInboundGroupSession!!.sessionIdentifier(),
- sessionKey = olmInboundGroupSession!!.export(olmInboundGroupSession!!.firstKnownIndex),
- algorithm = MXCRYPTO_ALGORITHM_MEGOLM
- )
- } catch (e: Exception) {
- Timber.e(e, "## export() : senderKey $senderKey failed")
- null
- }
- }
-
- /**
- * Export the session for a message index.
- *
- * @param messageIndex the message index
- * @return the exported data
- */
- fun exportSession(messageIndex: Long): String? {
- if (null != olmInboundGroupSession) {
- try {
- return olmInboundGroupSession!!.export(messageIndex)
- } catch (e: Exception) {
- Timber.e(e, "## exportSession() : export failed")
- }
- }
-
- return null
- }
-}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/model/OlmInboundGroupSessionWrapper2.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/model/OlmInboundGroupSessionWrapper2.kt
deleted file mode 100755
index 600fcb1003..0000000000
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/model/OlmInboundGroupSessionWrapper2.kt
+++ /dev/null
@@ -1,158 +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.model
-
-import org.matrix.android.sdk.api.crypto.MXCRYPTO_ALGORITHM_MEGOLM
-import org.matrix.android.sdk.internal.crypto.MegolmSessionData
-import org.matrix.olm.OlmInboundGroupSession
-import timber.log.Timber
-import java.io.Serializable
-
-/**
- * This class adds more context to a OlmInboundGroupSession object.
- * This allows additional checks. The class implements Serializable so that the context can be stored.
- */
-// Note used anymore, just for database migration
-// Deprecated("Use MXInboundMegolmSessionWrapper")
-internal class OlmInboundGroupSessionWrapper2 : Serializable {
-
- // The associated olm inbound group session.
- var olmInboundGroupSession: OlmInboundGroupSession? = null
-
- // The room in which this session is used.
- var roomId: String? = null
-
- // The base64-encoded curve25519 key of the sender.
- var senderKey: String? = null
-
- // Other keys the sender claims.
- var keysClaimed: Map? = null
-
- // Devices which forwarded this session to us (normally empty).
- var forwardingCurve25519KeyChain: List? = ArrayList()
-
- /**
- * @return the first known message index
- */
- val firstKnownIndex: Long?
- get() {
- return try {
- olmInboundGroupSession?.firstKnownIndex
- } catch (e: Exception) {
- Timber.e(e, "## getFirstKnownIndex() : getFirstKnownIndex failed")
- null
- }
- }
-
- /**
- * Constructor.
- *
- * @param sessionKey the session key
- * @param isImported true if it is an imported session key
- */
- constructor(sessionKey: String, isImported: Boolean) {
- try {
- if (!isImported) {
- olmInboundGroupSession = OlmInboundGroupSession(sessionKey)
- } else {
- olmInboundGroupSession = OlmInboundGroupSession.importSession(sessionKey)
- }
- } catch (e: Exception) {
- Timber.e(e, "Cannot create")
- }
- }
-
- constructor() {
- // empty
- }
-
- /**
- * Create a new instance from the provided keys map.
- *
- * @param megolmSessionData the megolm session data
- * @throws Exception if the data are invalid
- */
- @Throws(Exception::class)
- constructor(megolmSessionData: MegolmSessionData) {
- try {
- val safeSessionKey = megolmSessionData.sessionKey ?: throw Exception("invalid data")
- olmInboundGroupSession = OlmInboundGroupSession.importSession(safeSessionKey)
- .also {
- if (it.sessionIdentifier() != megolmSessionData.sessionId) {
- throw Exception("Mismatched group session Id")
- }
- }
-
- senderKey = megolmSessionData.senderKey
- keysClaimed = megolmSessionData.senderClaimedKeys
- roomId = megolmSessionData.roomId
- } catch (e: Exception) {
- throw Exception(e.message)
- }
- }
-
- /**
- * Export the inbound group session keys.
- * @param index the index to export. If null, the first known index will be used
- *
- * @return the inbound group session as MegolmSessionData if the operation succeeds
- */
- fun exportKeys(index: Long? = null): MegolmSessionData? {
- return try {
- if (null == forwardingCurve25519KeyChain) {
- forwardingCurve25519KeyChain = ArrayList()
- }
-
- if (keysClaimed == null) {
- return null
- }
-
- val safeOlmInboundGroupSession = olmInboundGroupSession ?: return null
-
- val wantedIndex = index ?: safeOlmInboundGroupSession.firstKnownIndex
-
- MegolmSessionData(
- senderClaimedEd25519Key = keysClaimed?.get("ed25519"),
- forwardingCurve25519KeyChain = forwardingCurve25519KeyChain?.toList().orEmpty(),
- senderKey = senderKey,
- senderClaimedKeys = keysClaimed,
- roomId = roomId,
- sessionId = safeOlmInboundGroupSession.sessionIdentifier(),
- sessionKey = safeOlmInboundGroupSession.export(wantedIndex),
- algorithm = MXCRYPTO_ALGORITHM_MEGOLM
- )
- } catch (e: Exception) {
- Timber.e(e, "## export() : senderKey $senderKey failed")
- null
- }
- }
-
- /**
- * Export the session for a message index.
- *
- * @param messageIndex the message index
- * @return the exported data
- */
- fun exportSession(messageIndex: Long): String? {
- return try {
- return olmInboundGroupSession?.export(messageIndex)
- } catch (e: Exception) {
- Timber.e(e, "## exportSession() : export failed")
- null
- }
- }
-}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/model/OlmSessionWrapper.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/model/OlmSessionWrapper.kt
deleted file mode 100644
index a1e58ead0c..0000000000
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/model/OlmSessionWrapper.kt
+++ /dev/null
@@ -1,40 +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.model
-
-import kotlinx.coroutines.sync.Mutex
-import org.matrix.olm.OlmSession
-
-/**
- * Encapsulate a OlmSession and a last received message Timestamp.
- */
-internal data class OlmSessionWrapper(
- // The associated olm session.
- val olmSession: OlmSession,
- // Timestamp at which the session last received a message.
- var lastReceivedMessageTs: Long = 0,
-
- val mutex: Mutex = Mutex()
-) {
-
- /**
- * Notify that a message has been received on this olm session so that it updates `lastReceivedMessageTs`.
- */
- fun onMessageReceived(currentTimeMillis: Long) {
- lastReceivedMessageTs = currentTimeMillis
- }
-}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/model/OutboundGroupSessionWrapper.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/model/OutboundGroupSessionWrapper.kt
deleted file mode 100644
index 5a6d1f4bc1..0000000000
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/model/OutboundGroupSessionWrapper.kt
+++ /dev/null
@@ -1,28 +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.model
-
-import org.matrix.olm.OlmOutboundGroupSession
-
-internal data class OutboundGroupSessionWrapper(
- val outboundGroupSession: OlmOutboundGroupSession,
- val creationTime: Long,
- /**
- * As per MSC 3061, declares if this key could be shared when inviting a new user to the room.
- */
- val sharedHistory: Boolean = false
-)
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/secrets/DefaultSharedSecretStorageService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/secrets/DefaultSharedSecretStorageService.kt
index 05b9e14b82..f443e5b7f6 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/secrets/DefaultSharedSecretStorageService.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/secrets/DefaultSharedSecretStorageService.kt
@@ -20,7 +20,6 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.withContext
import org.matrix.android.sdk.api.MatrixCoroutineDispatchers
import org.matrix.android.sdk.api.crypto.SSSS_ALGORITHM_AES_HMAC_SHA2
-import org.matrix.android.sdk.api.crypto.SSSS_ALGORITHM_CURVE25519_AES_SHA2
import org.matrix.android.sdk.api.extensions.orFalse
import org.matrix.android.sdk.api.listeners.ProgressListener
import org.matrix.android.sdk.api.session.accountdata.SessionAccountDataService
@@ -44,9 +43,7 @@ import org.matrix.android.sdk.api.util.toBase64NoPadding
import org.matrix.android.sdk.internal.crypto.SecretShareManager
import org.matrix.android.sdk.internal.crypto.keysbackup.generatePrivateKeyWithPassword
import org.matrix.android.sdk.internal.crypto.tools.HkdfSha256
-import org.matrix.android.sdk.internal.crypto.tools.withOlmDecryption
import org.matrix.android.sdk.internal.di.UserId
-import org.matrix.olm.OlmPkMessage
import java.security.SecureRandom
import javax.crypto.Cipher
import javax.crypto.Mac
@@ -321,22 +318,7 @@ internal class DefaultSharedSecretStorageService @Inject constructor(
?: throw SharedSecretStorageError.ParsingError
val algorithm = key.keyInfo.content
- if (SSSS_ALGORITHM_CURVE25519_AES_SHA2 == algorithm.algorithm) {
- val keySpec = secretKey as? RawBytesKeySpec ?: throw SharedSecretStorageError.BadKeyFormat
- return withContext(cryptoCoroutineScope.coroutineContext + coroutineDispatchers.computation) {
- // decrypt from recovery key
- withOlmDecryption { olmPkDecryption ->
- olmPkDecryption.setPrivateKey(keySpec.privateKey)
- olmPkDecryption.decrypt(OlmPkMessage()
- .apply {
- mCipherText = secretContent.ciphertext
- mEphemeralKey = secretContent.ephemeral
- mMac = secretContent.mac
- }
- )
- }
- }
- } else if (SSSS_ALGORITHM_AES_HMAC_SHA2 == algorithm.algorithm) {
+ if (SSSS_ALGORITHM_AES_HMAC_SHA2 == algorithm.algorithm) {
val keySpec = secretKey as? RawBytesKeySpec ?: throw SharedSecretStorageError.BadKeyFormat
return withContext(cryptoCoroutineScope.coroutineContext + coroutineDispatchers.computation) {
decryptAesHmacSha2(keySpec, name, secretContent)
@@ -366,8 +348,7 @@ internal class DefaultSharedSecretStorageService @Inject constructor(
val keyInfo = (keyInfoResult as? KeyInfoResult.Success)?.keyInfo
?: return IntegrityResult.Error(SharedSecretStorageError.UnknownKey(keyId ?: ""))
- if (keyInfo.content.algorithm != SSSS_ALGORITHM_AES_HMAC_SHA2 &&
- keyInfo.content.algorithm != SSSS_ALGORITHM_CURVE25519_AES_SHA2) {
+ if (keyInfo.content.algorithm != SSSS_ALGORITHM_AES_HMAC_SHA2) {
// Unsupported algorithm
return IntegrityResult.Error(
SharedSecretStorageError.UnsupportedAlgorithm(keyInfo.content.algorithm ?: "")
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/IMXCommonCryptoStore.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/IMXCommonCryptoStore.kt
index 68b002c087..ca389c9b00 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/IMXCommonCryptoStore.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/IMXCommonCryptoStore.kt
@@ -23,7 +23,6 @@ import org.matrix.android.sdk.api.session.crypto.model.CryptoRoomInfo
import org.matrix.android.sdk.api.session.crypto.model.DeviceInfo
import org.matrix.android.sdk.api.session.events.model.content.EncryptionEventContent
import org.matrix.android.sdk.api.util.Optional
-import org.matrix.android.sdk.internal.crypto.model.MXInboundMegolmSessionWrapper
import org.matrix.android.sdk.internal.crypto.store.db.CryptoStoreAggregator
/**
@@ -143,14 +142,4 @@ interface IMXCommonCryptoStore {
* @return the device or null if not found
*/
fun deviceWithIdentityKey(userId: String, identityKey: String): CryptoDeviceInfo?
-
- /**
- * Retrieve an inbound group session.
- * Used in rust for lazy migration
- *
- * @param sessionId the session identifier.
- * @param senderKey the base64-encoded curve25519 key of the sender.
- * @return an inbound group session.
- */
- fun getInboundGroupSession(sessionId: String, senderKey: String): MXInboundMegolmSessionWrapper?
}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/RustCryptoStore.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/RustCryptoStore.kt
index 6854449861..93d4963c91 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/RustCryptoStore.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/RustCryptoStore.kt
@@ -35,32 +35,23 @@ import org.matrix.android.sdk.api.session.events.model.content.EncryptionEventCo
import org.matrix.android.sdk.api.util.Optional
import org.matrix.android.sdk.api.util.toOptional
import org.matrix.android.sdk.internal.crypto.OlmMachine
-import org.matrix.android.sdk.internal.crypto.model.MXInboundMegolmSessionWrapper
import org.matrix.android.sdk.internal.crypto.store.db.CryptoStoreAggregator
import org.matrix.android.sdk.internal.crypto.store.db.doRealmTransaction
import org.matrix.android.sdk.internal.crypto.store.db.doRealmTransactionAsync
import org.matrix.android.sdk.internal.crypto.store.db.doWithRealm
import org.matrix.android.sdk.internal.crypto.store.db.mapper.CryptoRoomInfoMapper
import org.matrix.android.sdk.internal.crypto.store.db.mapper.MyDeviceLastSeenInfoEntityMapper
-import org.matrix.android.sdk.internal.crypto.store.db.model.AuditTrailEntity
-import org.matrix.android.sdk.internal.crypto.store.db.model.AuditTrailEntityFields
import org.matrix.android.sdk.internal.crypto.store.db.model.CryptoMetadataEntity
import org.matrix.android.sdk.internal.crypto.store.db.model.CryptoRoomEntity
import org.matrix.android.sdk.internal.crypto.store.db.model.CryptoRoomEntityFields
import org.matrix.android.sdk.internal.crypto.store.db.model.MyDeviceLastSeenInfoEntity
import org.matrix.android.sdk.internal.crypto.store.db.model.MyDeviceLastSeenInfoEntityFields
-import org.matrix.android.sdk.internal.crypto.store.db.model.OlmInboundGroupSessionEntity
-import org.matrix.android.sdk.internal.crypto.store.db.model.OlmInboundGroupSessionEntityFields
-import org.matrix.android.sdk.internal.crypto.store.db.model.OutgoingKeyRequestEntity
-import org.matrix.android.sdk.internal.crypto.store.db.model.OutgoingKeyRequestEntityFields
-import org.matrix.android.sdk.internal.crypto.store.db.model.createPrimaryKey
import org.matrix.android.sdk.internal.crypto.store.db.query.getById
import org.matrix.android.sdk.internal.crypto.store.db.query.getOrCreate
import org.matrix.android.sdk.internal.di.CryptoDatabase
import org.matrix.android.sdk.internal.di.DeviceId
import org.matrix.android.sdk.internal.di.UserId
import org.matrix.android.sdk.internal.session.SessionScope
-import org.matrix.android.sdk.internal.util.time.Clock
import timber.log.Timber
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
@@ -75,7 +66,6 @@ private val loggerTag = LoggerTag("RealmCryptoStore", LoggerTag.CRYPTO)
@SessionScope
internal class RustCryptoStore @Inject constructor(
@CryptoDatabase private val realmConfiguration: RealmConfiguration,
- private val clock: Clock,
@UserId private val userId: String,
@DeviceId private val deviceId: String,
private val myDeviceLastSeenInfoEntityMapper: MyDeviceLastSeenInfoEntityMapper,
@@ -134,20 +124,6 @@ internal class RustCryptoStore @Inject constructor(
}
}
- /**
- * Needed for lazy migration of sessions from the legacy store.
- */
- override fun getInboundGroupSession(sessionId: String, senderKey: String): MXInboundMegolmSessionWrapper? {
- val key = OlmInboundGroupSessionEntity.createPrimaryKey(sessionId, senderKey)
-
- return doWithRealm(realmConfiguration) { realm ->
- realm.where()
- .equalTo(OlmInboundGroupSessionEntityFields.PRIMARY_KEY, key)
- .findFirst()
- ?.toModel()
- }
- }
-
// ================================================
// Things that should be migrated to another store than realm
// ================================================
@@ -163,30 +139,7 @@ internal class RustCryptoStore @Inject constructor(
// nop
}
- override fun tidyUpDataBase() {
- // These entities are not used in rust actually, but as they are not yet cleaned up, this will do it with time
- val prevWeekTs = clock.epochMillis() - 7 * 24 * 60 * 60 * 1_000
- doRealmTransaction("tidyUpDataBase", realmConfiguration) { realm ->
-
- // Clean the old ones?
- realm.where()
- .lessThan(OutgoingKeyRequestEntityFields.CREATION_TIME_STAMP, prevWeekTs)
- .findAll()
- .also { Timber.i("## Crypto Clean up ${it.size} OutgoingKeyRequestEntity") }
- .deleteAllFromRealm()
-
- // Only keep one month history
-
- val prevMonthTs = clock.epochMillis() - 4 * 7 * 24 * 60 * 60 * 1_000L
- realm.where()
- .lessThan(AuditTrailEntityFields.AGE_LOCAL_TS, prevMonthTs)
- .findAll()
- .also { Timber.i("## Crypto Clean up ${it.size} AuditTrailEntity") }
- .deleteAllFromRealm()
-
- // Can we do something for WithHeldSessionEntity?
- }
- }
+ override fun tidyUpDataBase() = Unit
override fun close() {
val tasks = monarchyWriteAsyncExecutor.shutdownNow()
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/UserDataToStore.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/UserDataToStore.kt
deleted file mode 100644
index 914ce4704e..0000000000
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/UserDataToStore.kt
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright (c) 2023 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.store
-
-import org.matrix.android.sdk.api.session.crypto.crosssigning.UserIdentity
-import org.matrix.android.sdk.api.session.crypto.model.CryptoDeviceInfo
-
-internal data class UserDataToStore(
- /**
- * Map of userId -> (Map of deviceId -> [CryptoDeviceInfo]).
- */
- val userDevices: MutableMap> = mutableMapOf(),
- /**
- * Map of userId -> [UserIdentity].
- */
- val userIdentities: MutableMap = mutableMapOf(),
-)
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/Helper.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/Helper.kt
index 6412df205f..fb10ecc999 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/Helper.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/Helper.kt
@@ -16,15 +16,9 @@
package org.matrix.android.sdk.internal.crypto.store.db
-import android.util.Base64
import io.realm.Realm
import io.realm.RealmConfiguration
-import io.realm.RealmObject
import timber.log.Timber
-import java.io.ByteArrayOutputStream
-import java.io.ObjectOutputStream
-import java.util.zip.GZIPInputStream
-import java.util.zip.GZIPOutputStream
import kotlin.system.measureTimeMillis
/**
@@ -36,24 +30,6 @@ internal fun doWithRealm(realmConfiguration: RealmConfiguration, action: (Re
}
}
-/**
- * Get realm, do the query, copy from realm, close realm, and return the copied result.
- */
-internal fun doRealmQueryAndCopy(realmConfiguration: RealmConfiguration, action: (Realm) -> T?): T? {
- return Realm.getInstance(realmConfiguration).use { realm ->
- action.invoke(realm)?.let { realm.copyFromRealm(it) }
- }
-}
-
-/**
- * Get realm, do the list query, copy from realm, close realm, and return the copied result.
- */
-internal fun doRealmQueryAndCopyList(realmConfiguration: RealmConfiguration, action: (Realm) -> Iterable): Iterable {
- return Realm.getInstance(realmConfiguration).use { realm ->
- action.invoke(realm).let { realm.copyFromRealm(it) }
- }
-}
-
/**
* Get realm instance, invoke the action in a transaction and close realm.
*/
@@ -70,38 +46,3 @@ internal fun doRealmTransactionAsync(realmConfiguration: RealmConfiguration, act
realm.executeTransactionAsync { action.invoke(it) }
}
}
-
-/**
- * Serialize any Serializable object, zip it and convert to Base64 String.
- */
-internal fun serializeForRealm(o: Any?): String? {
- if (o == null) {
- return null
- }
-
- val baos = ByteArrayOutputStream()
- val gzis = GZIPOutputStream(baos)
- val out = ObjectOutputStream(gzis)
- out.use {
- it.writeObject(o)
- }
- return Base64.encodeToString(baos.toByteArray(), Base64.DEFAULT)
-}
-
-/**
- * Do the opposite of serializeForRealm.
- */
-@Suppress("UNCHECKED_CAST")
-internal fun deserializeFromRealm(string: String?): T? {
- if (string == null) {
- return null
- }
- val decodedB64 = Base64.decode(string.toByteArray(), Base64.DEFAULT)
-
- val bais = decodedB64.inputStream()
- val gzis = GZIPInputStream(bais)
- val ois = SafeObjectInputStream(gzis)
- return ois.use {
- it.readObject() as T
- }
-}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStoreMigration.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStoreMigration.kt
index 1b0143f4fa..bbb14aaca0 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStoreMigration.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStoreMigration.kt
@@ -17,31 +17,8 @@
package org.matrix.android.sdk.internal.crypto.store.db
import io.realm.DynamicRealm
-import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo001Legacy
-import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo002Legacy
-import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo003RiotX
-import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo004
-import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo005
-import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo006
-import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo007
-import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo008
-import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo009
-import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo010
-import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo011
-import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo012
-import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo013
-import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo014
-import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo015
-import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo016
-import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo017
-import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo018
-import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo019
-import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo020
-import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo021
-import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo022
-import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo023
+import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo024
import org.matrix.android.sdk.internal.util.database.MatrixRealmMigration
-import org.matrix.android.sdk.internal.util.time.Clock
import javax.inject.Inject
/**
@@ -49,13 +26,11 @@ import javax.inject.Inject
* 0, 1, 2: legacy Riot-Android;
* 3: migrate to RiotX schema;
* 4, 5, 6, 7, 8, 9: migrations from RiotX (which was previously 1, 2, 3, 4, 5, 6).
+ * 24: Delete nearly all the crypto DB
*/
-internal class RealmCryptoStoreMigration @Inject constructor(
- private val clock: Clock,
- private val rustMigrationInfoProvider: RustMigrationInfoProvider,
-) : MatrixRealmMigration(
+internal class RealmCryptoStoreMigration @Inject constructor() : MatrixRealmMigration(
dbName = "Crypto",
- schemaVersion = 23L,
+ schemaVersion = 24L,
) {
/**
* Forces all RealmCryptoStoreMigration instances to be equal.
@@ -65,33 +40,6 @@ internal class RealmCryptoStoreMigration @Inject constructor(
override fun hashCode() = 5000
override fun doMigrate(realm: DynamicRealm, oldVersion: Long) {
- if (oldVersion < 1) MigrateCryptoTo001Legacy(realm).perform()
- if (oldVersion < 2) MigrateCryptoTo002Legacy(realm).perform()
- if (oldVersion < 3) MigrateCryptoTo003RiotX(realm).perform()
- if (oldVersion < 4) MigrateCryptoTo004(realm).perform()
- if (oldVersion < 5) MigrateCryptoTo005(realm).perform()
- if (oldVersion < 6) MigrateCryptoTo006(realm).perform()
- if (oldVersion < 7) MigrateCryptoTo007(realm).perform()
- if (oldVersion < 8) MigrateCryptoTo008(realm, clock).perform()
- if (oldVersion < 9) MigrateCryptoTo009(realm).perform()
- if (oldVersion < 10) MigrateCryptoTo010(realm).perform()
- if (oldVersion < 11) MigrateCryptoTo011(realm).perform()
- if (oldVersion < 12) MigrateCryptoTo012(realm).perform()
- if (oldVersion < 13) MigrateCryptoTo013(realm).perform()
- if (oldVersion < 14) MigrateCryptoTo014(realm).perform()
- if (oldVersion < 15) MigrateCryptoTo015(realm).perform()
- if (oldVersion < 16) MigrateCryptoTo016(realm).perform()
- if (oldVersion < 17) MigrateCryptoTo017(realm).perform()
- if (oldVersion < 18) MigrateCryptoTo018(realm).perform()
- if (oldVersion < 19) MigrateCryptoTo019(realm).perform()
- if (oldVersion < 20) MigrateCryptoTo020(realm).perform()
- if (oldVersion < 21) MigrateCryptoTo021(realm).perform()
- if (oldVersion < 22) MigrateCryptoTo022(
- realm,
- rustMigrationInfoProvider.rustDirectory,
- rustMigrationInfoProvider.rustEncryptionConfiguration,
- rustMigrationInfoProvider.migrateMegolmGroupSessions
- ).perform()
- if (oldVersion < 23) MigrateCryptoTo023(realm).perform()
+ if (oldVersion < 24) MigrateCryptoTo024(realm).perform()
}
}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStoreModule.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStoreModule.kt
index 6696cf8281..8b94baacde 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStoreModule.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStoreModule.kt
@@ -17,23 +17,9 @@
package org.matrix.android.sdk.internal.crypto.store.db
import io.realm.annotations.RealmModule
-import org.matrix.android.sdk.internal.crypto.store.db.model.AuditTrailEntity
-import org.matrix.android.sdk.internal.crypto.store.db.model.CrossSigningInfoEntity
import org.matrix.android.sdk.internal.crypto.store.db.model.CryptoMetadataEntity
import org.matrix.android.sdk.internal.crypto.store.db.model.CryptoRoomEntity
-import org.matrix.android.sdk.internal.crypto.store.db.model.DeviceInfoEntity
-import org.matrix.android.sdk.internal.crypto.store.db.model.KeyInfoEntity
-import org.matrix.android.sdk.internal.crypto.store.db.model.KeyRequestReplyEntity
-import org.matrix.android.sdk.internal.crypto.store.db.model.KeysBackupDataEntity
import org.matrix.android.sdk.internal.crypto.store.db.model.MyDeviceLastSeenInfoEntity
-import org.matrix.android.sdk.internal.crypto.store.db.model.OlmInboundGroupSessionEntity
-import org.matrix.android.sdk.internal.crypto.store.db.model.OlmSessionEntity
-import org.matrix.android.sdk.internal.crypto.store.db.model.OutboundGroupSessionInfoEntity
-import org.matrix.android.sdk.internal.crypto.store.db.model.OutgoingKeyRequestEntity
-import org.matrix.android.sdk.internal.crypto.store.db.model.SharedSessionEntity
-import org.matrix.android.sdk.internal.crypto.store.db.model.TrustLevelEntity
-import org.matrix.android.sdk.internal.crypto.store.db.model.UserEntity
-import org.matrix.android.sdk.internal.crypto.store.db.model.WithHeldSessionEntity
/**
* Realm module for Crypto store classes.
@@ -43,21 +29,7 @@ import org.matrix.android.sdk.internal.crypto.store.db.model.WithHeldSessionEnti
classes = [
CryptoMetadataEntity::class,
CryptoRoomEntity::class,
- DeviceInfoEntity::class,
- KeysBackupDataEntity::class,
- OlmInboundGroupSessionEntity::class,
- OlmSessionEntity::class,
- UserEntity::class,
- KeyInfoEntity::class,
- CrossSigningInfoEntity::class,
- TrustLevelEntity::class,
- AuditTrailEntity::class,
- OutgoingKeyRequestEntity::class,
- KeyRequestReplyEntity::class,
MyDeviceLastSeenInfoEntity::class,
- WithHeldSessionEntity::class,
- SharedSessionEntity::class,
- OutboundGroupSessionInfoEntity::class
]
)
internal class RealmCryptoStoreModule
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RustMigrationInfoProvider.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RustMigrationInfoProvider.kt
deleted file mode 100644
index 667990468c..0000000000
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RustMigrationInfoProvider.kt
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright 2023 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.store.db
-
-import org.matrix.android.sdk.internal.crypto.RustEncryptionConfiguration
-import org.matrix.android.sdk.internal.di.SessionRustFilesDirectory
-import java.io.File
-import javax.inject.Inject
-
-internal class RustMigrationInfoProvider @Inject constructor(
- @SessionRustFilesDirectory
- val rustDirectory: File,
- val rustEncryptionConfiguration: RustEncryptionConfiguration
-) {
-
- var migrateMegolmGroupSessions: Boolean = false
-}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/SafeObjectInputStream.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/SafeObjectInputStream.kt
deleted file mode 100644
index 5897869a97..0000000000
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/SafeObjectInputStream.kt
+++ /dev/null
@@ -1,44 +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.store.db
-
-import java.io.IOException
-import java.io.InputStream
-import java.io.ObjectInputStream
-import java.io.ObjectStreamClass
-
-/**
- * Package has been renamed from `im.vector.matrix.android` to `org.matrix.android.sdk`
- * so ensure deserialization of previously stored objects still works
- *
- * Ref: https://stackoverflow.com/questions/3884492/how-can-i-change-package-for-a-bunch-of-java-serializable-classes
- */
-internal class SafeObjectInputStream(inputStream: InputStream) : ObjectInputStream(inputStream) {
-
- init {
- enableResolveObject(true)
- }
-
- @Throws(IOException::class, ClassNotFoundException::class)
- override fun readClassDescriptor(): ObjectStreamClass {
- val read = super.readClassDescriptor()
- if (read.name.startsWith("im.vector.matrix.android.")) {
- return ObjectStreamClass.lookup(Class.forName(read.name.replace("im.vector.matrix.android.", "org.matrix.android.sdk.")))
- }
- return read
- }
-}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/mapper/CrossSigningKeysMapper.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/mapper/CrossSigningKeysMapper.kt
deleted file mode 100644
index 8b7bf9c26b..0000000000
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/mapper/CrossSigningKeysMapper.kt
+++ /dev/null
@@ -1,87 +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.store.db.mapper
-
-import com.squareup.moshi.Moshi
-import com.squareup.moshi.Types
-import io.realm.RealmList
-import org.matrix.android.sdk.api.session.crypto.crosssigning.CryptoCrossSigningKey
-import org.matrix.android.sdk.api.session.crypto.crosssigning.DeviceTrustLevel
-import org.matrix.android.sdk.internal.crypto.store.db.model.KeyInfoEntity
-import timber.log.Timber
-import javax.inject.Inject
-
-internal class CrossSigningKeysMapper @Inject constructor(moshi: Moshi) {
-
- private val signaturesAdapter = moshi.adapter