mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-01-31 11:24:58 +01:00
Cleanup
This commit is contained in:
parent
48de8f4e34
commit
506fa729ea
@ -22,8 +22,10 @@ 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.RendezvousIntent
|
||||
import org.matrix.android.sdk.api.rendezvous.transports.SimpleHttpRendezvousTransport
|
||||
import org.matrix.android.sdk.api.session.Session
|
||||
@ -68,7 +70,7 @@ class Rendezvous(
|
||||
Timber.tag(TAG).d("ourIntent: $ourIntent, theirIntent: $theirIntent, incompatible: $incompatible")
|
||||
|
||||
if (incompatible) {
|
||||
send(Payload(PayloadType.Finish, intent = ourIntent))
|
||||
send(Payload(PayloadType.FINISH, intent = ourIntent))
|
||||
val reason = if (ourIntent == RendezvousIntent.LOGIN_ON_NEW_DEVICE) {
|
||||
RendezvousFailureReason.OtherDeviceNotSignedIn
|
||||
} else {
|
||||
@ -93,14 +95,14 @@ class Rendezvous(
|
||||
Timber.tag(TAG).i("Waiting for protocols")
|
||||
val protocolsResponse = receive()
|
||||
|
||||
if (protocolsResponse?.protocols == null || !protocolsResponse.protocols.contains("login_token")) {
|
||||
send(Payload(PayloadType.Finish, outcome = "unsupported"))
|
||||
if (protocolsResponse?.protocols == null || !protocolsResponse.protocols.contains(Protocol.LOGIN_TOKEN)) {
|
||||
send(Payload(PayloadType.FINISH, outcome = Outcome.UNSUPPORTED))
|
||||
Timber.tag(TAG).i("No supported protocol")
|
||||
cancel(RendezvousFailureReason.Unknown)
|
||||
return null
|
||||
}
|
||||
|
||||
send(Payload(PayloadType.Progress, protocol = "login_token"))
|
||||
send(Payload(PayloadType.PROGRESS, protocol = Protocol.LOGIN_TOKEN))
|
||||
|
||||
return checksum
|
||||
}
|
||||
@ -110,21 +112,23 @@ class Rendezvous(
|
||||
|
||||
val loginToken = receive()
|
||||
|
||||
if (loginToken?.type == PayloadType.Finish) {
|
||||
if (loginToken?.type == PayloadType.FINISH) {
|
||||
when (loginToken.outcome) {
|
||||
"declined" -> {
|
||||
Outcome.DECLINED -> {
|
||||
Timber.tag(TAG).i("Login declined by other device")
|
||||
channel.cancel(RendezvousFailureReason.UserDeclined)
|
||||
return null
|
||||
}
|
||||
"unsupported" -> {
|
||||
Outcome.UNSUPPORTED -> {
|
||||
Timber.tag(TAG).i("Not supported")
|
||||
channel.cancel(RendezvousFailureReason.HomeserverLacksSupport)
|
||||
return null
|
||||
}
|
||||
else -> {
|
||||
channel.cancel(RendezvousFailureReason.Unknown)
|
||||
return null
|
||||
}
|
||||
}
|
||||
channel.cancel(RendezvousFailureReason.Unknown)
|
||||
return null
|
||||
}
|
||||
|
||||
val homeserver = loginToken?.homeserver ?: throw RuntimeException("No homeserver returned")
|
||||
@ -141,7 +145,7 @@ class Rendezvous(
|
||||
val crypto = session.cryptoService()
|
||||
val deviceId = crypto.getMyDevice().deviceId
|
||||
val deviceKey = crypto.getMyDevice().fingerprint()
|
||||
send(Payload(PayloadType.Progress, outcome = "success", deviceId = deviceId, deviceKey = deviceKey))
|
||||
send(Payload(PayloadType.PROGRESS, outcome = Outcome.SUCCESS, deviceId = deviceId, deviceKey = deviceKey))
|
||||
|
||||
// await confirmation of verification
|
||||
|
||||
@ -149,8 +153,9 @@ class Rendezvous(
|
||||
val verifyingDeviceId = verificationResponse?.verifyingDeviceId ?: throw RuntimeException("No verifying device id returned")
|
||||
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})"
|
||||
Timber.tag(TAG).w(
|
||||
"Verifying device $verifyingDeviceId key doesn't match: ${
|
||||
verifyingDeviceFromServer?.fingerprint()} vs ${verificationResponse.verifyingDeviceKey})"
|
||||
)
|
||||
throw RuntimeException("Key from verifying device doesn't match")
|
||||
}
|
||||
|
@ -50,6 +50,7 @@ class ECDHRendezvousChannel(override var transport: RendezvousTransport, theirPu
|
||||
private const val KEY_SPEC = "AES"
|
||||
private val TAG = LoggerTag(ECDHRendezvousChannel::class.java.simpleName, LoggerTag.RENDEZVOUS).value
|
||||
|
||||
// n.b. we are only aver processing byte array that we have generated, so we can make assumptions about the length
|
||||
private fun getDecimalCodeRepresentation(byteArray: ByteArray): String {
|
||||
val b0 = byteArray[0].toUnsignedInt() // need unsigned byte
|
||||
val b1 = byteArray[1].toUnsignedInt() // need unsigned byte
|
||||
|
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
enum class Outcome(val value: String) {
|
||||
@Json(name = "success")
|
||||
SUCCESS("success"),
|
||||
|
||||
@Json(name = "declined")
|
||||
DECLINED("declined"),
|
||||
|
||||
@Json(name = "unsupported")
|
||||
UNSUPPORTED("unsupported")
|
||||
}
|
@ -23,9 +23,9 @@ import com.squareup.moshi.JsonClass
|
||||
internal data class Payload(
|
||||
@Json val type: PayloadType,
|
||||
@Json val intent: RendezvousIntent? = null,
|
||||
@Json val outcome: String? = null,
|
||||
@Json val protocols: List<String>? = null,
|
||||
@Json val protocol: String? = null,
|
||||
@Json val outcome: Outcome? = null,
|
||||
@Json val protocols: List<Protocol>? = null,
|
||||
@Json val protocol: Protocol? = null,
|
||||
@Json val homeserver: String? = null,
|
||||
@Json(name = "login_token") val loginToken: String? = null,
|
||||
@Json(name = "device_id") val deviceId: String? = null,
|
||||
|
@ -20,11 +20,11 @@ import com.squareup.moshi.Json
|
||||
|
||||
internal enum class PayloadType(val value: String) {
|
||||
@Json(name = "m.login.start")
|
||||
Start("m.login.start"),
|
||||
START("m.login.start"),
|
||||
|
||||
@Json(name = "m.login.finish")
|
||||
Finish("m.login.finish"),
|
||||
FINISH("m.login.finish"),
|
||||
|
||||
@Json(name = "m.login.progress")
|
||||
Progress("m.login.progress")
|
||||
PROGRESS("m.login.progress")
|
||||
}
|
||||
|
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
enum class Protocol(val value: String) {
|
||||
@Json(name = "login_token")
|
||||
LOGIN_TOKEN("login_token")
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user