Skip to content

Commit 4299477

Browse files
committed
Accept and pass any deviceKey payload to rust
1 parent 333d4bc commit 4299477

File tree

5 files changed

+105
-84
lines changed

5 files changed

+105
-84
lines changed

matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/model/CryptoInfoMapper.kt

-13
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,10 @@ package org.matrix.android.sdk.internal.crypto.model
1818
import org.matrix.android.sdk.api.session.crypto.crosssigning.CryptoCrossSigningKey
1919
import org.matrix.android.sdk.api.session.crypto.model.CryptoDeviceInfo
2020
import org.matrix.android.sdk.internal.crypto.model.rest.DeviceKeys
21-
import org.matrix.android.sdk.internal.crypto.model.rest.DeviceKeysWithUnsigned
2221
import org.matrix.android.sdk.internal.crypto.model.rest.RestKeyInfo
2322

2423
internal object CryptoInfoMapper {
2524

26-
fun map(deviceKeysWithUnsigned: DeviceKeysWithUnsigned): CryptoDeviceInfo {
27-
return CryptoDeviceInfo(
28-
deviceId = deviceKeysWithUnsigned.deviceId,
29-
userId = deviceKeysWithUnsigned.userId,
30-
algorithms = deviceKeysWithUnsigned.algorithms,
31-
keys = deviceKeysWithUnsigned.keys,
32-
signatures = deviceKeysWithUnsigned.signatures,
33-
unsigned = deviceKeysWithUnsigned.unsigned,
34-
trustLevel = null
35-
)
36-
}
37-
3825
fun map(cryptoDeviceInfo: CryptoDeviceInfo): DeviceKeys {
3926
return DeviceKeys(
4027
deviceId = cryptoDeviceInfo.deviceId,

matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/model/rest/DeviceKeysWithUnsigned.kt

-68
This file was deleted.

matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/model/rest/KeysQueryResponse.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ internal data class KeysQueryResponse(
3434
* For each device, the information returned will be the same as uploaded via /keys/upload, with the addition of an unsigned property.
3535
*/
3636
@Json(name = "device_keys")
37-
val deviceKeys: Map<String, Map<String, DeviceKeysWithUnsigned>>? = null,
37+
val deviceKeys: Map<String, Map<String, Map<String, Any>>>? = null,
3838

3939
/**
4040
* If any remote homeservers could not be reached, they are recorded here. The names of the

matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/DownloadKeysForUsersTask.kt

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import kotlinx.coroutines.joinAll
2222
import kotlinx.coroutines.sync.Mutex
2323
import kotlinx.coroutines.sync.withLock
2424
import org.matrix.android.sdk.internal.crypto.api.CryptoApi
25-
import org.matrix.android.sdk.internal.crypto.model.rest.DeviceKeysWithUnsigned
2625
import org.matrix.android.sdk.internal.crypto.model.rest.KeysQueryBody
2726
import org.matrix.android.sdk.internal.crypto.model.rest.KeysQueryResponse
2827
import org.matrix.android.sdk.internal.crypto.model.rest.RestKeyInfo
@@ -52,7 +51,7 @@ internal class DefaultDownloadKeysForUsers @Inject constructor(
5251

5352
return if (bestChunkSize.shouldChunk()) {
5453
// Store server results in these mutable maps
55-
val deviceKeys = mutableMapOf<String, Map<String, DeviceKeysWithUnsigned>>()
54+
val deviceKeys = mutableMapOf<String, Map<String, Map<String, Any>>>()
5655
val failures = mutableMapOf<String, Map<String, Any>>()
5756
val masterKeys = mutableMapOf<String, RestKeyInfo?>()
5857
val selfSigningKeys = mutableMapOf<String, RestKeyInfo?>()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
* Copyright 2022 The Matrix.org Foundation C.I.C.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.matrix.android.sdk.internal.crypto
18+
19+
import org.amshove.kluent.internal.assertEquals
20+
import org.junit.Test
21+
import org.matrix.android.sdk.internal.crypto.model.rest.KeysQueryResponse
22+
import org.matrix.android.sdk.internal.di.MoshiProvider
23+
24+
class KeysQueryResponseTest {
25+
26+
private val moshi = MoshiProvider.providesMoshi()
27+
private val keysQueryResponseAdapter = moshi.adapter(KeysQueryResponse::class.java)
28+
29+
private fun aKwysQueryResponseWithDehydrated(): KeysQueryResponse {
30+
val rawResponseWithDehydratedDevice = """
31+
{
32+
"device_keys": {
33+
"@dehydration2:localhost": {
34+
"TDHZGMDVNO": {
35+
"algorithms": [
36+
"m.olm.v1.curve25519-aes-sha2",
37+
"m.megolm.v1.aes-sha2"
38+
],
39+
"device_id": "TDHZGMDVNO",
40+
"keys": {
41+
"curve25519:TDHZGMDVNO": "ClMOrHlQJqaqr4oESYyPURwD4BSQxMlEZZk/AnYxVSk",
42+
"ed25519:TDHZGMDVNO": "5iZ4zfk0URyIH8YOIWnXmJo41Vn34IixGYphkMdDzik"
43+
},
44+
"signatures": {
45+
"@dehydration2:localhost": {
46+
"ed25519:TDHZGMDVNO": "O6VP+ELiCVAJGHaRdReKga0LGMQahjRnp4znZH7iJO6maZV8aSXnpugSoVsSPRvQ4GBkjX+KXAXU+ODZ0J8MDg",
47+
"ed25519:YZ0EmlbDX+t/m/MB5EWkQLw8cEDg7hX4Zy9699h3hd8": "lG3idYliFGOAe4F/7tENIQ6qI0d41VQKY34BHyVvvWKbv63zDDO5kBTwBeXfUSEeRqyxET3SXLXfB1D8E8LUDg"
48+
}
49+
},
50+
"user_id": "@dehydration2:localhost",
51+
"unsigned": {
52+
"device_display_name": "localhost:8080: Chrome on macOS"
53+
}
54+
},
55+
"Y2gISVBZ024gKKAe6Xos44cDbNlO/49YjaOyiqFwjyQ": {
56+
"algorithms": [
57+
"m.olm.v1.curve25519-aes-sha2",
58+
"m.megolm.v1.aes-sha2"
59+
],
60+
"dehydrated": true,
61+
"device_id": "Y2gISVBZ024gKKAe6Xos44cDbNlO/49YjaOyiqFwjyQ",
62+
"keys": {
63+
"curve25519:Y2gISVBZ024gKKAe6Xos44cDbNlO/49YjaOyiqFwjyQ": "Y2gISVBZ024gKKAe6Xos44cDbNlO/49YjaOyiqFwjyQ",
64+
"ed25519:Y2gISVBZ024gKKAe6Xos44cDbNlO/49YjaOyiqFwjyQ": "sVY5Xq13sIdhC4We/p5CH69++GsIWRNUhHijtucBirs"
65+
},
66+
"signatures": {
67+
"@dehydration2:localhost": {
68+
"ed25519:Y2gISVBZ024gKKAe6Xos44cDbNlO/49YjaOyiqFwjyQ": "e2aVrdnD/kor2T0Ok/4SC32MW4WB5JXFSd2wnXV8apxFJBfbdZErANiUbo1Zz/HAasaXM5NBfkr/9gVTdph9BQ",
69+
"ed25519:YZ0EmlbDX+t/m/MB5EWkQLw8cEDg7hX4Zy9699h3hd8": "rVzeE1LbB12XOlckxjRLjt3eq2jVlek6OJ4p08+8g8CMoiJDcw1OVzbJuG/8u6ryarxQF6Yqr4Xu2TqCPBmHDw"
70+
}
71+
},
72+
"user_id": "@dehydration2:localhost",
73+
"unsigned": {
74+
"device_display_name": "Dehydrated device"
75+
}
76+
}
77+
}
78+
}
79+
}
80+
""".trimIndent()
81+
82+
return keysQueryResponseAdapter.fromJson(rawResponseWithDehydratedDevice)!!
83+
}
84+
85+
@Test
86+
fun `Should parse correctly devices with new dehydrated field`() {
87+
val aKeysQueryResponse = aKwysQueryResponseWithDehydrated()
88+
89+
val pojoToJson = keysQueryResponseAdapter.toJson(aKeysQueryResponse)
90+
91+
val rawAdapter = moshi.adapter(Map::class.java)
92+
93+
val rawJson = rawAdapter.fromJson(pojoToJson)!!
94+
95+
val deviceKeys = (rawJson["device_keys"] as Map<*, *>)["@dehydration2:localhost"] as Map<*, *>
96+
97+
assertEquals(deviceKeys.keys.size, 2)
98+
99+
val dehydratedDevice = deviceKeys["Y2gISVBZ024gKKAe6Xos44cDbNlO/49YjaOyiqFwjyQ"] as Map<*, *>
100+
101+
assertEquals(dehydratedDevice["dehydrated"] as? Boolean, true)
102+
}
103+
}

0 commit comments

Comments
 (0)