Merge pull request #1510 from vector-im/feature/keys_backup_unstable

Fixes issue from timokoesters and do some cleanup
This commit is contained in:
Benoit Marty 2020-06-26 15:55:40 +02:00 committed by GitHub
commit fb0d262336
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 198 additions and 174 deletions

View File

@ -1,9 +1,6 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<option name="RIGHT_MARGIN" value="160" />
<AndroidXmlCodeStyleSettings>
<option name="ARRANGEMENT_SETTINGS_MIGRATED_TO_191" value="true" />
</AndroidXmlCodeStyleSettings>
<JetCodeStyleSettings>
<option name="PACKAGES_TO_USE_STAR_IMPORTS">
<value>

View File

@ -31,6 +31,8 @@ Other changes:
- Fix minor typo in contribution guide (#1512)
- Fix self-assignment of callback in `DefaultRoomPushRuleService#setRoomNotificationState` (#1520)
- Random housekeeping clean-ups indicated by Lint (#1520, #1541)
- Keys Backup API now use the unstable prefix (#1503)
- Remove deviceId from /keys/upload/{deviceId} as not spec-compliant (#1502)
Changes in RiotX 0.22.0 (2020-06-15)
===================================================

View File

@ -933,9 +933,7 @@ internal class DefaultCryptoService @Inject constructor(
signatures = objectSigner.signObject(canonicalJson)
)
// For now, we set the device id explicitly, as we may not be using the
// same one as used in login.
val uploadDeviceKeysParams = UploadKeysTask.Params(rest, null, getMyDevice().deviceId)
val uploadDeviceKeysParams = UploadKeysTask.Params(rest, null)
return uploadKeysTask.execute(uploadDeviceKeysParams)
}

View File

@ -16,7 +16,6 @@
package im.vector.matrix.android.internal.crypto
import im.vector.matrix.android.api.auth.data.Credentials
import im.vector.matrix.android.internal.crypto.model.MXKey
import im.vector.matrix.android.internal.crypto.model.rest.KeysUploadResponse
import im.vector.matrix.android.internal.crypto.tasks.UploadKeysTask
@ -30,7 +29,6 @@ import kotlin.math.min
@SessionScope
internal class OneTimeKeysUploader @Inject constructor(
private val credentials: Credentials,
private val olmDevice: MXOlmDevice,
private val objectSigner: ObjectSigner,
private val uploadKeysTask: UploadKeysTask
@ -153,7 +151,7 @@ internal class OneTimeKeysUploader @Inject constructor(
// For now, we set the device id explicitly, as we may not be using the
// same one as used in login.
val uploadParams = UploadKeysTask.Params(null, oneTimeJson, credentials.deviceId!!)
val uploadParams = UploadKeysTask.Params(null, oneTimeJson)
return uploadKeysTask.execute(uploadParams)
}

View File

@ -60,21 +60,11 @@ internal interface CryptoApi {
* Upload device and/or one-time keys.
* Doc: https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-keys-upload
*
* @param params the params.
* @param body the keys to be sent.
*/
@POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "keys/upload")
fun uploadKeys(@Body body: KeysUploadBody): Call<KeysUploadResponse>
/**
* Upload device and/or one-time keys.
* Doc: not documented
*
* @param deviceId the deviceId
* @param params the params.
*/
@POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "keys/upload/{deviceId}")
fun uploadKeys(@Path("deviceId") deviceId: String, @Body body: KeysUploadBody): Call<KeysUploadResponse>
/**
* Download device keys.
* Doc: https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-keys-query

View File

@ -47,14 +47,14 @@ internal interface RoomKeysApi {
* Create a new keys backup version.
* @param createKeysBackupVersionBody the body
*/
@POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "room_keys/version")
@POST(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/version")
fun createKeysBackupVersion(@Body createKeysBackupVersionBody: CreateKeysBackupVersionBody): Call<KeysVersion>
/**
* Get the key backup last version
* If not supported by the server, an error is returned: {"errcode":"M_NOT_FOUND","error":"No backup found"}
*/
@GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "room_keys/version")
@GET(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/version")
fun getKeysBackupLastVersion(): Call<KeysVersionResult>
/**
@ -63,7 +63,7 @@ internal interface RoomKeysApi {
*
* @param version version
*/
@GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "room_keys/version/{version}")
@GET(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/version/{version}")
fun getKeysBackupVersion(@Path("version") version: String): Call<KeysVersionResult>
/**
@ -71,7 +71,7 @@ internal interface RoomKeysApi {
* @param version version
* @param updateKeysBackupVersionBody the body
*/
@PUT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "room_keys/version/{version}")
@PUT(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/version/{version}")
fun updateKeysBackupVersion(@Path("version") version: String,
@Body keysBackupVersionBody: UpdateKeysBackupVersionBody): Call<Unit>
@ -93,7 +93,7 @@ internal interface RoomKeysApi {
* @param version the version of the backup
* @param keyBackupData the data to send
*/
@PUT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "room_keys/keys/{roomId}/{sessionId}")
@PUT(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/keys/{roomId}/{sessionId}")
fun storeRoomSessionData(@Path("roomId") roomId: String,
@Path("sessionId") sessionId: String,
@Query("version") version: String,
@ -106,7 +106,7 @@ internal interface RoomKeysApi {
* @param version the version of the backup
* @param roomKeysBackupData the data to send
*/
@PUT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "room_keys/keys/{roomId}")
@PUT(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/keys/{roomId}")
fun storeRoomSessionsData(@Path("roomId") roomId: String,
@Query("version") version: String,
@Body roomKeysBackupData: RoomKeysBackupData): Call<BackupKeysResult>
@ -117,7 +117,7 @@ internal interface RoomKeysApi {
* @param version the version of the backup
* @param keysBackupData the data to send
*/
@PUT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "room_keys/keys")
@PUT(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/keys")
fun storeSessionsData(@Query("version") version: String,
@Body keysBackupData: KeysBackupData): Call<BackupKeysResult>
@ -132,7 +132,7 @@ internal interface RoomKeysApi {
* @param sessionId the session id
* @param version the version of the backup, or empty String to retrieve the last version
*/
@GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "room_keys/keys/{roomId}/{sessionId}")
@GET(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/keys/{roomId}/{sessionId}")
fun getRoomSessionData(@Path("roomId") roomId: String,
@Path("sessionId") sessionId: String,
@Query("version") version: String): Call<KeyBackupData>
@ -143,7 +143,7 @@ internal interface RoomKeysApi {
* @param roomId the room id
* @param version the version of the backup, or empty String to retrieve the last version
*/
@GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "room_keys/keys/{roomId}")
@GET(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/keys/{roomId}")
fun getRoomSessionsData(@Path("roomId") roomId: String,
@Query("version") version: String): Call<RoomKeysBackupData>
@ -152,7 +152,7 @@ internal interface RoomKeysApi {
*
* @param version the version of the backup, or empty String to retrieve the last version
*/
@GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "room_keys/keys")
@GET(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/keys")
fun getSessionsData(@Query("version") version: String): Call<KeysBackupData>
/* ==========================================================================================
@ -162,7 +162,7 @@ internal interface RoomKeysApi {
/**
* Deletes keys from the backup.
*/
@DELETE(NetworkConstants.URI_API_PREFIX_PATH_R0 + "room_keys/keys/{roomId}/{sessionId}")
@DELETE(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/keys/{roomId}/{sessionId}")
fun deleteRoomSessionData(@Path("roomId") roomId: String,
@Path("sessionId") sessionId: String,
@Query("version") version: String): Call<Unit>
@ -170,14 +170,14 @@ internal interface RoomKeysApi {
/**
* Deletes keys from the backup.
*/
@DELETE(NetworkConstants.URI_API_PREFIX_PATH_R0 + "room_keys/keys/{roomId}")
@DELETE(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/keys/{roomId}")
fun deleteRoomSessionsData(@Path("roomId") roomId: String,
@Query("version") version: String): Call<Unit>
/**
* Deletes keys from the backup.
*/
@DELETE(NetworkConstants.URI_API_PREFIX_PATH_R0 + "room_keys/keys")
@DELETE(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/keys")
fun deleteSessionsData(@Query("version") version: String): Call<Unit>
/* ==========================================================================================
@ -187,6 +187,6 @@ internal interface RoomKeysApi {
/**
* Deletes a backup.
*/
@DELETE(NetworkConstants.URI_API_PREFIX_PATH_R0 + "room_keys/version/{version}")
@DELETE(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "room_keys/version/{version}")
fun deleteBackup(@Path("version") version: String): Call<Unit>
}

View File

@ -15,9 +15,9 @@
*/
package im.vector.matrix.android.internal.crypto.model
import im.vector.matrix.android.api.util.JsonDict
import im.vector.matrix.android.internal.crypto.crosssigning.DeviceTrustLevel
import im.vector.matrix.android.internal.crypto.model.rest.RestDeviceInfo
import im.vector.matrix.android.internal.crypto.model.rest.DeviceKeys
import im.vector.matrix.android.internal.crypto.model.rest.UnsignedDeviceInfo
import im.vector.matrix.android.internal.crypto.store.db.model.CryptoMapper
import im.vector.matrix.android.internal.crypto.store.db.model.DeviceInfoEntity
@ -27,7 +27,7 @@ data class CryptoDeviceInfo(
var algorithms: List<String>? = null,
override val keys: Map<String, String>? = null,
override val signatures: Map<String, Map<String, String>>? = null,
val unsigned: JsonDict? = null,
val unsigned: UnsignedDeviceInfo? = null,
var trustLevel: DeviceTrustLevel? = null,
var isBlocked: Boolean = false,
val firstTimeSeenLocalTs: Long? = null
@ -61,7 +61,7 @@ data class CryptoDeviceInfo(
* @return the display name
*/
fun displayName(): String? {
return unsigned?.get("device_display_name") as? String
return unsigned?.deviceDisplayName
}
override fun signalableJSONDictionary(): Map<String, Any> {
@ -74,7 +74,7 @@ data class CryptoDeviceInfo(
}
}
internal fun CryptoDeviceInfo.toRest(): RestDeviceInfo {
internal fun CryptoDeviceInfo.toRest(): DeviceKeys {
return CryptoInfoMapper.map(this)
}

View File

@ -15,30 +15,30 @@
*/
package im.vector.matrix.android.internal.crypto.model
import im.vector.matrix.android.internal.crypto.model.rest.RestDeviceInfo
import im.vector.matrix.android.internal.crypto.model.rest.DeviceKeys
import im.vector.matrix.android.internal.crypto.model.rest.DeviceKeysWithUnsigned
import im.vector.matrix.android.internal.crypto.model.rest.RestKeyInfo
internal object CryptoInfoMapper {
fun map(restDeviceInfo: RestDeviceInfo): CryptoDeviceInfo {
fun map(deviceKeysWithUnsigned: DeviceKeysWithUnsigned): CryptoDeviceInfo {
return CryptoDeviceInfo(
deviceId = restDeviceInfo.deviceId,
userId = restDeviceInfo.userId,
algorithms = restDeviceInfo.algorithms,
keys = restDeviceInfo.keys,
signatures = restDeviceInfo.signatures,
unsigned = restDeviceInfo.unsigned,
deviceId = deviceKeysWithUnsigned.deviceId,
userId = deviceKeysWithUnsigned.userId,
algorithms = deviceKeysWithUnsigned.algorithms,
keys = deviceKeysWithUnsigned.keys,
signatures = deviceKeysWithUnsigned.signatures,
unsigned = deviceKeysWithUnsigned.unsigned,
trustLevel = null
)
}
fun map(cryptoDeviceInfo: CryptoDeviceInfo): RestDeviceInfo {
return RestDeviceInfo(
fun map(cryptoDeviceInfo: CryptoDeviceInfo): DeviceKeys {
return DeviceKeys(
deviceId = cryptoDeviceInfo.deviceId,
algorithms = cryptoDeviceInfo.algorithms,
keys = cryptoDeviceInfo.keys,
signatures = cryptoDeviceInfo.signatures,
unsigned = cryptoDeviceInfo.unsigned,
userId = cryptoDeviceInfo.userId
)
}

View File

@ -21,21 +21,35 @@ import com.squareup.moshi.JsonClass
@JsonClass(generateAdapter = true)
data class DeviceKeys(
/**
* Required. The ID of the user the device belongs to. Must match the user ID used when logging in.
*/
@Json(name = "user_id")
val userId: String?,
val userId: String,
/**
* Required. The ID of the device these keys belong to. Must match the device ID used when logging in.
*/
@Json(name = "device_id")
val deviceId: String?,
val deviceId: String,
/**
* Required. The encryption algorithms supported by this device.
*/
@Json(name = "algorithms")
val algorithms: List<String>?,
/**
* Required. Public identity keys. The names of the properties should be in the format <algorithm>:<device_id>.
* The keys themselves should be encoded as specified by the key algorithm.
*/
@Json(name = "keys")
val keys: Map<String, String>?,
/**
* Required. Signatures for the device key object. A map from user ID, to a map from <algorithm>:<device_id> to the signature.
* The signature is calculated using the process described at https://matrix.org/docs/spec/appendices.html#signing-json.
*/
@Json(name = "signatures")
val signatures: Map<String, Map<String, String>>?,
@Json(name = "usage")
val usage: List<String>? = null
val signatures: Map<String, Map<String, String>>?
)

View File

@ -0,0 +1,61 @@
/*
* Copyright (c) 2020 New Vector Ltd
*
* 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 im.vector.matrix.android.internal.crypto.model.rest
import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
@JsonClass(generateAdapter = true)
data class DeviceKeysWithUnsigned(
/**
* Required. The ID of the user the device belongs to. Must match the user ID used when logging in.
*/
@Json(name = "user_id")
val userId: String,
/**
* Required. The ID of the device these keys belong to. Must match the device ID used when logging in.
*/
@Json(name = "device_id")
val deviceId: String,
/**
* Required. The encryption algorithms supported by this device.
*/
@Json(name = "algorithms")
val algorithms: List<String>?,
/**
* Required. Public identity keys. The names of the properties should be in the format <algorithm>:<device_id>.
* The keys themselves should be encoded as specified by the key algorithm.
*/
@Json(name = "keys")
val keys: Map<String, String>?,
/**
* Required. Signatures for the device key object. A map from user ID, to a map from <algorithm>:<device_id> to the signature.
* The signature is calculated using the process described at https://matrix.org/docs/spec/appendices.html#signing-json.
*/
@Json(name = "signatures")
val signatures: Map<String, Map<String, String>>?,
/**
* Additional data added to the device key information by intermediate servers, and not covered by the signatures.
*/
@Json(name = "unsigned")
val unsigned: UnsignedDeviceInfo? = null
)

View File

@ -28,18 +28,20 @@ import com.squareup.moshi.JsonClass
* The user_signing_keys property will only be included when a user requests their own keys.
*/
@JsonClass(generateAdapter = true)
internal data class KeysQueryResponse(
internal data class KeysQueryResponse(
/**
* The device keys per devices per users.
* Map from userId to map from deviceId to MXDeviceInfo
* TODO Use MXUsersDevicesMap?
* Information on the queried devices. A map from user ID, to a map from device ID to device information.
* For each device, the information returned will be the same as uploaded via /keys/upload, with the addition of an unsigned property.
*/
@Json(name = "device_keys")
val deviceKeys: Map<String, Map<String, RestDeviceInfo>>? = null,
val deviceKeys: Map<String, Map<String, DeviceKeysWithUnsigned>>? = null,
/**
* The failures sorted by homeservers. TODO Bad comment ?
* TODO Use MXUsersDevicesMap?
* If any remote homeservers could not be reached, they are recorded here. The names of the
* properties are the names of the unreachable servers.
*
* If the homeserver could be reached, but the user or device was unknown, no failure is recorded.
* Instead, the corresponding user or device is missing from the device_keys result.
*/
val failures: Map<String, Map<String, Any>>? = null,

View File

@ -20,11 +20,25 @@ import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
import im.vector.matrix.android.api.util.JsonDict
/**
* Ref: https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-keys-upload
*/
@JsonClass(generateAdapter = true)
internal data class KeysUploadBody(
/**
* Identity keys for the device.
*
* May be absent if no new identity keys are required.
*/
@Json(name = "device_keys")
val deviceKeys: RestDeviceInfo? = null,
val deviceKeys: DeviceKeys? = null,
/**
* One-time public keys for "pre-key" messages. The names of the properties should be in the
* format <algorithm>:<key_id>. The format of the key is determined by the key algorithm.
*
* May be absent if no new one-time keys are required.
*/
@Json(name = "one_time_keys")
val oneTimeKeys: JsonDict? = null
)

View File

@ -24,7 +24,8 @@ import com.squareup.moshi.JsonClass
@JsonClass(generateAdapter = true)
internal data class KeysUploadResponse(
/**
* The count per algorithm as returned by the home server: a map (algorithm to count).
* Required. For each key algorithm, the number of unclaimed one-time keys
* of that type currently held on the server for this device.
*/
@Json(name = "one_time_key_counts")
val oneTimeKeyCounts: Map<String, Int>? = null

View File

@ -1,60 +0,0 @@
/*
* Copyright 2020 New Vector Ltd
*
* 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 im.vector.matrix.android.internal.crypto.model.rest
import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
import im.vector.matrix.android.api.util.JsonDict
@JsonClass(generateAdapter = true)
internal data class RestDeviceInfo(
/**
* The id of this device.
*/
@Json(name = "device_id")
val deviceId: String,
/**
* the user id
*/
@Json(name = "user_id")
val userId: String,
/**
* The list of algorithms supported by this device.
*/
@Json(name = "algorithms")
val algorithms: List<String>? = null,
/**
* A map from "<key type>:<deviceId>" to "<base64-encoded key>".
*/
@Json(name = "keys")
val keys: Map<String, String>? = null,
/**
* The signature of this MXDeviceInfo.
* A map from "<userId>" to a map from "<key type>:<deviceId>" to "<signature>"
*/
@Json(name = "signatures")
val signatures: Map<String, Map<String, String>>? = null,
/*
* Additional data from the home server.
*/
@Json(name = "unsigned")
val unsigned: JsonDict? = null
)

View File

@ -27,6 +27,7 @@ internal data class RestKeyInfo(
*/
@Json(name = "user_id")
val userId: String,
/**
* Allowed uses for the key.
* Must contain "master" for master keys, "self_signing" for self-signing keys, and "user_signing" for user-signing keys.

View File

@ -0,0 +1,29 @@
/*
* Copyright (c) 2020 New Vector Ltd
*
* 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 im.vector.matrix.android.internal.crypto.model.rest
import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
@JsonClass(generateAdapter = true)
data class UnsignedDeviceInfo(
/**
* The display name which the user set on the device.
*/
@Json(name = "device_display_name")
val deviceDisplayName: String? = null
)

View File

@ -20,6 +20,7 @@ import com.squareup.moshi.Types
import im.vector.matrix.android.api.util.JsonDict
import im.vector.matrix.android.internal.crypto.crosssigning.DeviceTrustLevel
import im.vector.matrix.android.internal.crypto.model.CryptoDeviceInfo
import im.vector.matrix.android.internal.crypto.model.rest.UnsignedDeviceInfo
import im.vector.matrix.android.internal.di.SerializeNulls
import timber.log.Timber
@ -57,7 +58,8 @@ object CryptoMapper {
locallyVerified = it.locallyVerified
)
},
unsignedMapJson = mapMigrationAdapter.toJson(deviceInfo.unsigned)
// We store the device name if present now
unsignedMapJson = deviceInfo.unsigned?.deviceDisplayName
)
}
@ -69,14 +71,7 @@ object CryptoMapper {
trustLevel = deviceInfoEntity.trustLevelEntity?.let {
DeviceTrustLevel(it.crossSignedVerified ?: false, it.locallyVerified)
},
unsigned = deviceInfoEntity.unsignedMapJson?.let {
try {
mapMigrationAdapter.fromJson(it)
} catch (failure: Throwable) {
Timber.e(failure)
null
}
},
unsigned = deviceInfoEntity.unsignedMapJson?.let { UnsignedDeviceInfo(deviceDisplayName = it) },
signatures = deviceInfoEntity.signatureMapJson?.let {
try {
mapOfStringMigrationAdapter.fromJson(it)

View File

@ -23,35 +23,25 @@ import io.realm.annotations.PrimaryKey
internal fun DeviceInfoEntity.Companion.createPrimaryKey(userId: String, deviceId: String) = "$userId|$deviceId"
// deviceInfoData contains serialized data
internal open class DeviceInfoEntity(@PrimaryKey var primaryKey: String = "",
var deviceId: String? = null,
var identityKey: String? = null,
// var deviceInfoData: String? = null,
var userId: String? = null,
var isBlocked: Boolean? = null,
var algorithmListJson: String? = null,
var keysMapJson: String? = null,
var signatureMapJson: String? = null,
var unsignedMapJson: String? = null,
var trustLevelEntity: TrustLevelEntity? = null,
/**
* We use that to make distinction between old devices (there before mine)
* and new ones. Used for example to detect new unverified login
*/
var firstTimeSeenLocalTs: Long? = null
internal open class DeviceInfoEntity(
@PrimaryKey var primaryKey: String = "",
var deviceId: String? = null,
var identityKey: String? = null,
var userId: String? = null,
var isBlocked: Boolean? = null,
var algorithmListJson: String? = null,
var keysMapJson: String? = null,
var signatureMapJson: String? = null,
// Will contain the device name from unsigned data if present
var unsignedMapJson: String? = null,
var trustLevelEntity: TrustLevelEntity? = null,
/**
* We use that to make distinction between old devices (there before mine)
* and new ones. Used for example to detect new unverified login
*/
var firstTimeSeenLocalTs: Long? = null
) : RealmObject() {
// // Deserialize data
// fun getDeviceInfo(): MXDeviceInfo? {
// return deserializeFromRealm(deviceInfoData)
// }
//
// // Serialize data
// fun putDeviceInfo(deviceInfo: MXDeviceInfo?) {
// deviceInfoData = serializeForRealm(deviceInfo)
// }
@LinkingObjects("devices")
val users: RealmResults<UserEntity>? = null

View File

@ -18,12 +18,11 @@ package im.vector.matrix.android.internal.crypto.tasks
import im.vector.matrix.android.api.util.JsonDict
import im.vector.matrix.android.internal.crypto.api.CryptoApi
import im.vector.matrix.android.internal.crypto.model.rest.DeviceKeys
import im.vector.matrix.android.internal.crypto.model.rest.KeysUploadBody
import im.vector.matrix.android.internal.crypto.model.rest.KeysUploadResponse
import im.vector.matrix.android.internal.crypto.model.rest.RestDeviceInfo
import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.task.Task
import im.vector.matrix.android.internal.util.convertToUTF8
import org.greenrobot.eventbus.EventBus
import timber.log.Timber
import javax.inject.Inject
@ -31,11 +30,10 @@ import javax.inject.Inject
internal interface UploadKeysTask : Task<UploadKeysTask.Params, KeysUploadResponse> {
data class Params(
// the device keys to send.
val deviceKeys: RestDeviceInfo?,
val deviceKeys: DeviceKeys?,
// the one-time keys to send.
val oneTimeKeys: JsonDict?,
// the explicit device_id to use for upload (default is to use the same as that used during auth).
val deviceId: String)
val oneTimeKeys: JsonDict?
)
}
internal class DefaultUploadKeysTask @Inject constructor(
@ -44,8 +42,6 @@ internal class DefaultUploadKeysTask @Inject constructor(
) : UploadKeysTask {
override suspend fun execute(params: UploadKeysTask.Params): KeysUploadResponse {
val encodedDeviceId = convertToUTF8(params.deviceId)
val body = KeysUploadBody(
deviceKeys = params.deviceKeys,
oneTimeKeys = params.oneTimeKeys
@ -54,11 +50,7 @@ internal class DefaultUploadKeysTask @Inject constructor(
Timber.i("## Uploading device keys -> $body")
return executeRequest(eventBus) {
apiCall = if (encodedDeviceId.isBlank()) {
cryptoApi.uploadKeys(body)
} else {
cryptoApi.uploadKeys(encodedDeviceId, body)
}
apiCall = cryptoApi.uploadKeys(body)
}
}
}