This commit is contained in:
Benoit Marty 2019-06-17 18:43:36 +02:00
parent 0b6b95110f
commit 0497d14a08
1 changed files with 18 additions and 6 deletions

View File

@ -223,13 +223,17 @@ internal abstract class SASVerificationTransaction(
cancel(CancelCode.MismatchedKeys) cancel(CancelCode.MismatchedKeys)
return return
} }

val verifiedDevices = ArrayList<String>()

//cannot be empty because it has been validated //cannot be empty because it has been validated
theirMac!!.mac!!.keys.forEach { theirMac!!.mac!!.keys.forEach {
val keyIDNoPrefix = if (it.startsWith("ed25519:")) it.substring("ed25519:".length) else it val keyIDNoPrefix = if (it.startsWith("ed25519:")) it.substring("ed25519:".length) else it
val otherDeviceKey = otherUserKnownDevices?.get(keyIDNoPrefix)?.fingerprint() val otherDeviceKey = otherUserKnownDevices?.get(keyIDNoPrefix)?.fingerprint()
if (otherDeviceKey == null) { if (otherDeviceKey == null) {
cancel(CancelCode.MismatchedKeys) Timber.e("Verification: Could not find device $keyIDNoPrefix to verify")
return //just ignore and continue
return@forEach
} }
val mac = macUsingAgreedMethod(otherDeviceKey, baseInfo + it) val mac = macUsingAgreedMethod(otherDeviceKey, baseInfo + it)
if (mac != theirMac?.mac?.get(it)) { if (mac != theirMac?.mac?.get(it)) {
@ -237,13 +241,21 @@ internal abstract class SASVerificationTransaction(
cancel(CancelCode.MismatchedKeys) cancel(CancelCode.MismatchedKeys)
return return
} }
verifiedDevices.add(keyIDNoPrefix)
} }


setDeviceVerified( // if none of the keys could be verified, then error because the app
otherDeviceId ?: "", // should be informed about that
otherUserId) if (verifiedDevices.isEmpty()) {
Timber.e("Verification: No devices verified")
cancel(CancelCode.MismatchedKeys)
return
}


state = SasVerificationTxState.Verified //TODO what if the otherDevice is not in this list? and should we
verifiedDevices.forEach {
setDeviceVerified(it, otherUserId)
}
} }


private fun setDeviceVerified(deviceId: String, userId: String) { private fun setDeviceVerified(deviceId: String, userId: String) {