Remove deviceId from /keys/upload/{deviceId} as not spec-compliant (#1502)

FTR: 1b6a74fd93
This commit is contained in:
Benoit Marty 2020-06-19 23:23:36 +02:00
parent 19ed5a2d3d
commit 1fb2569a39
5 changed files with 7 additions and 28 deletions

View File

@ -32,6 +32,7 @@ Other changes:
- Fix self-assignment of callback in `DefaultRoomPushRuleService#setRoomNotificationState` (#1520) - Fix self-assignment of callback in `DefaultRoomPushRuleService#setRoomNotificationState` (#1520)
- Random housekeeping clean-ups indicated by Lint (#1520, #1541) - Random housekeeping clean-ups indicated by Lint (#1520, #1541)
- Keys Backup API now use the unstable prefix (#1503) - 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) Changes in RiotX 0.22.0 (2020-06-15)
=================================================== ===================================================

View File

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

View File

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

View File

@ -60,21 +60,11 @@ internal interface CryptoApi {
* Upload device and/or one-time keys. * 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 * 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") @POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "keys/upload")
fun uploadKeys(@Body body: KeysUploadBody): Call<KeysUploadResponse> 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. * Download device keys.
* Doc: https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-keys-query * Doc: https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-keys-query

View File

@ -23,7 +23,6 @@ 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.crypto.model.rest.RestDeviceInfo
import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import im.vector.matrix.android.internal.util.convertToUTF8
import org.greenrobot.eventbus.EventBus import org.greenrobot.eventbus.EventBus
import timber.log.Timber import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
@ -33,9 +32,8 @@ internal interface UploadKeysTask : Task<UploadKeysTask.Params, KeysUploadRespon
// the device keys to send. // the device keys to send.
val deviceKeys: RestDeviceInfo?, val deviceKeys: RestDeviceInfo?,
// the one-time keys to send. // the one-time keys to send.
val oneTimeKeys: JsonDict?, 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)
} }
internal class DefaultUploadKeysTask @Inject constructor( internal class DefaultUploadKeysTask @Inject constructor(
@ -44,8 +42,6 @@ internal class DefaultUploadKeysTask @Inject constructor(
) : UploadKeysTask { ) : UploadKeysTask {
override suspend fun execute(params: UploadKeysTask.Params): KeysUploadResponse { override suspend fun execute(params: UploadKeysTask.Params): KeysUploadResponse {
val encodedDeviceId = convertToUTF8(params.deviceId)
val body = KeysUploadBody( val body = KeysUploadBody(
deviceKeys = params.deviceKeys, deviceKeys = params.deviceKeys,
oneTimeKeys = params.oneTimeKeys oneTimeKeys = params.oneTimeKeys
@ -54,11 +50,7 @@ internal class DefaultUploadKeysTask @Inject constructor(
Timber.i("## Uploading device keys -> $body") Timber.i("## Uploading device keys -> $body")
return executeRequest(eventBus) { return executeRequest(eventBus) {
apiCall = if (encodedDeviceId.isBlank()) { apiCall = cryptoApi.uploadKeys(body)
cryptoApi.uploadKeys(body)
} else {
cryptoApi.uploadKeys(encodedDeviceId, body)
}
} }
} }
} }