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)
- 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

@ -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.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
@ -33,9 +32,8 @@ internal interface UploadKeysTask : Task<UploadKeysTask.Params, KeysUploadRespon
// the device keys to send.
val deviceKeys: RestDeviceInfo?,
// 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)
}
}
}