mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-03-24 14:58:59 +03:00
QRCode: requestId is not supposed to be an eventId
This commit is contained in:
parent
8e5c7239cf
commit
80f4f95f81
5 changed files with 63 additions and 28 deletions
matrix-sdk-android/src
main/java/im/vector/matrix/android/internal/crypto/verification
test/java/im/vector/matrix/android/internal/crypto/verification/qrcode
|
@ -786,25 +786,25 @@ internal class DefaultVerificationService @Inject constructor(
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createQrCodeData(requestEventId: String?, otherUserId: String, otherDeviceId: String?): QrCodeData? {
|
private fun createQrCodeData(requestId: String?, otherUserId: String, otherDeviceId: String?): QrCodeData? {
|
||||||
requestEventId ?: run {
|
requestId ?: run {
|
||||||
Timber.w("## Unknown requestEventId")
|
Timber.w("## Unknown requestId")
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
return when {
|
return when {
|
||||||
userId != otherUserId ->
|
userId != otherUserId ->
|
||||||
createQrCodeDataForDistinctUser(requestEventId, otherUserId, otherDeviceId)
|
createQrCodeDataForDistinctUser(requestId, otherUserId, otherDeviceId)
|
||||||
crossSigningService.isCrossSigningVerified() ->
|
crossSigningService.isCrossSigningVerified() ->
|
||||||
// This is a self verification and I am the old device (Osborne2)
|
// This is a self verification and I am the old device (Osborne2)
|
||||||
createQrCodeDataForVerifiedDevice(requestEventId, otherDeviceId)
|
createQrCodeDataForVerifiedDevice(requestId, otherDeviceId)
|
||||||
else ->
|
else ->
|
||||||
// This is a self verification and I am the new device (Dynabook)
|
// This is a self verification and I am the new device (Dynabook)
|
||||||
createQrCodeDataForUnVerifiedDevice(requestEventId, otherDeviceId)
|
createQrCodeDataForUnVerifiedDevice(requestId, otherDeviceId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createQrCodeDataForDistinctUser(requestEventId: String, otherUserId: String, otherDeviceId: String?): QrCodeData? {
|
private fun createQrCodeDataForDistinctUser(requestId: String, otherUserId: String, otherDeviceId: String?): QrCodeData? {
|
||||||
val myMasterKey = crossSigningService.getMyCrossSigningKeys()
|
val myMasterKey = crossSigningService.getMyCrossSigningKeys()
|
||||||
?.masterKey()
|
?.masterKey()
|
||||||
?.unpaddedBase64PublicKey
|
?.unpaddedBase64PublicKey
|
||||||
|
@ -840,7 +840,7 @@ internal class DefaultVerificationService @Inject constructor(
|
||||||
|
|
||||||
return QrCodeData(
|
return QrCodeData(
|
||||||
userId = userId,
|
userId = userId,
|
||||||
requestEventId = requestEventId,
|
requestId = requestId,
|
||||||
action = QrCodeData.ACTION_VERIFY,
|
action = QrCodeData.ACTION_VERIFY,
|
||||||
keys = hashMapOf(
|
keys = hashMapOf(
|
||||||
myMasterKey to myMasterKey,
|
myMasterKey to myMasterKey,
|
||||||
|
@ -853,7 +853,7 @@ internal class DefaultVerificationService @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a QR code to display on the old device (Osborne2)
|
// Create a QR code to display on the old device (Osborne2)
|
||||||
private fun createQrCodeDataForVerifiedDevice(requestEventId: String, otherDeviceId: String?): QrCodeData? {
|
private fun createQrCodeDataForVerifiedDevice(requestId: String, otherDeviceId: String?): QrCodeData? {
|
||||||
val myMasterKey = crossSigningService.getMyCrossSigningKeys()
|
val myMasterKey = crossSigningService.getMyCrossSigningKeys()
|
||||||
?.masterKey()
|
?.masterKey()
|
||||||
?.unpaddedBase64PublicKey
|
?.unpaddedBase64PublicKey
|
||||||
|
@ -885,7 +885,7 @@ internal class DefaultVerificationService @Inject constructor(
|
||||||
|
|
||||||
return QrCodeData(
|
return QrCodeData(
|
||||||
userId = userId,
|
userId = userId,
|
||||||
requestEventId = requestEventId,
|
requestId = requestId,
|
||||||
action = QrCodeData.ACTION_VERIFY,
|
action = QrCodeData.ACTION_VERIFY,
|
||||||
keys = hashMapOf(
|
keys = hashMapOf(
|
||||||
myMasterKey to myMasterKey,
|
myMasterKey to myMasterKey,
|
||||||
|
@ -898,7 +898,7 @@ internal class DefaultVerificationService @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a QR code to display on the new device (Dynabook)
|
// Create a QR code to display on the new device (Dynabook)
|
||||||
private fun createQrCodeDataForUnVerifiedDevice(requestEventId: String, otherDeviceId: String?): QrCodeData? {
|
private fun createQrCodeDataForUnVerifiedDevice(requestId: String, otherDeviceId: String?): QrCodeData? {
|
||||||
val myMasterKey = crossSigningService.getMyCrossSigningKeys()
|
val myMasterKey = crossSigningService.getMyCrossSigningKeys()
|
||||||
?.masterKey()
|
?.masterKey()
|
||||||
?.unpaddedBase64PublicKey
|
?.unpaddedBase64PublicKey
|
||||||
|
@ -926,7 +926,7 @@ internal class DefaultVerificationService @Inject constructor(
|
||||||
|
|
||||||
return QrCodeData(
|
return QrCodeData(
|
||||||
userId = userId,
|
userId = userId,
|
||||||
requestEventId = requestEventId,
|
requestId = requestId,
|
||||||
action = QrCodeData.ACTION_VERIFY,
|
action = QrCodeData.ACTION_VERIFY,
|
||||||
keys = hashMapOf(
|
keys = hashMapOf(
|
||||||
// Note: no master key here
|
// Note: no master key here
|
||||||
|
|
|
@ -81,8 +81,8 @@ internal class DefaultQrCodeVerificationTransaction(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (otherQrCodeData.requestEventId != transactionId) {
|
if (otherQrCodeData.requestId != transactionId) {
|
||||||
Timber.d("## Verification QR: Invalid transaction actual ${otherQrCodeData.requestEventId} expected:$transactionId")
|
Timber.d("## Verification QR: Invalid transaction actual ${otherQrCodeData.requestId} expected:$transactionId")
|
||||||
cancel(CancelCode.QrCodeInvalid)
|
cancel(CancelCode.QrCodeInvalid)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ fun QrCodeData.toUrl(): String {
|
||||||
return buildString {
|
return buildString {
|
||||||
append(PermalinkFactory.createPermalink(userId))
|
append(PermalinkFactory.createPermalink(userId))
|
||||||
append("?request=")
|
append("?request=")
|
||||||
append(URLEncoder.encode(requestEventId, ENCODING))
|
append(URLEncoder.encode(requestId, ENCODING))
|
||||||
append("&action=")
|
append("&action=")
|
||||||
append(URLEncoder.encode(action, ENCODING))
|
append(URLEncoder.encode(action, ENCODING))
|
||||||
|
|
||||||
|
@ -105,10 +105,10 @@ fun String.toQrCodeData(): QrCodeData? {
|
||||||
(it.substringBefore("=") to it.substringAfter("=").let { value -> URLDecoder.decode(value, ENCODING) })
|
(it.substringBefore("=") to it.substringAfter("=").let { value -> URLDecoder.decode(value, ENCODING) })
|
||||||
}.toMap()
|
}.toMap()
|
||||||
|
|
||||||
val action = keyValues["action"] ?: return null
|
val action = keyValues["action"]?.takeIf { it.isNotBlank() } ?: return null
|
||||||
|
|
||||||
val requestEventId = keyValues["request"]?.takeIf { MatrixPatterns.isEventId(it) } ?: return null
|
val requestEventId = keyValues["request"]?.takeIf { it.isNotBlank() } ?: return null
|
||||||
val sharedSecret = keyValues["secret"] ?: return null
|
val sharedSecret = keyValues["secret"]?.takeIf { it.isNotBlank() } ?: return null
|
||||||
val otherUserKey = keyValues["other_user_key"]
|
val otherUserKey = keyValues["other_user_key"]
|
||||||
val otherDeviceKey = keyValues["other_device_key"]
|
val otherDeviceKey = keyValues["other_device_key"]
|
||||||
|
|
||||||
|
|
|
@ -21,8 +21,8 @@ package im.vector.matrix.android.internal.crypto.verification.qrcode
|
||||||
*/
|
*/
|
||||||
data class QrCodeData(
|
data class QrCodeData(
|
||||||
val userId: String,
|
val userId: String,
|
||||||
// the event ID of the associated verification request event.
|
// Request Id. Can be an arbitrary value. In DM, it will be the event ID of the associated verification request event.
|
||||||
val requestEventId: String,
|
val requestId: String,
|
||||||
// The action
|
// The action
|
||||||
val action: String,
|
val action: String,
|
||||||
// key_<key_id>: each key that the user wants verified will have an entry of this form, where the value is the key in unpadded base64.
|
// key_<key_id>: each key that the user wants verified will have an entry of this form, where the value is the key in unpadded base64.
|
||||||
|
|
|
@ -30,7 +30,7 @@ class QrCodeTest {
|
||||||
|
|
||||||
private val basicQrCodeData = QrCodeData(
|
private val basicQrCodeData = QrCodeData(
|
||||||
userId = "@benoit:matrix.org",
|
userId = "@benoit:matrix.org",
|
||||||
requestEventId = "\$azertyazerty",
|
requestId = "\$azertyazerty",
|
||||||
action = QrCodeData.ACTION_VERIFY,
|
action = QrCodeData.ACTION_VERIFY,
|
||||||
keys = mapOf(
|
keys = mapOf(
|
||||||
"1" to "abcdef",
|
"1" to "abcdef",
|
||||||
|
@ -61,7 +61,7 @@ class QrCodeTest {
|
||||||
decodedData.shouldNotBeNull()
|
decodedData.shouldNotBeNull()
|
||||||
|
|
||||||
decodedData.userId shouldBeEqualTo "@benoit:matrix.org"
|
decodedData.userId shouldBeEqualTo "@benoit:matrix.org"
|
||||||
decodedData.requestEventId shouldBeEqualTo "\$azertyazerty"
|
decodedData.requestId shouldBeEqualTo "\$azertyazerty"
|
||||||
decodedData.keys["1"]?.shouldBeEqualTo("abcdef")
|
decodedData.keys["1"]?.shouldBeEqualTo("abcdef")
|
||||||
decodedData.keys["2"]?.shouldBeEqualTo("ghijql")
|
decodedData.keys["2"]?.shouldBeEqualTo("ghijql")
|
||||||
decodedData.sharedSecret shouldBeEqualTo "sharedSecret"
|
decodedData.sharedSecret shouldBeEqualTo "sharedSecret"
|
||||||
|
@ -74,7 +74,7 @@ class QrCodeTest {
|
||||||
val url = basicQrCodeData
|
val url = basicQrCodeData
|
||||||
.copy(
|
.copy(
|
||||||
userId = "@benoit/foo:matrix.org",
|
userId = "@benoit/foo:matrix.org",
|
||||||
requestEventId = "\$azertyazerty/bar"
|
requestId = "\$azertyazerty/bar"
|
||||||
)
|
)
|
||||||
.toUrl()
|
.toUrl()
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ class QrCodeTest {
|
||||||
decodedData.shouldNotBeNull()
|
decodedData.shouldNotBeNull()
|
||||||
|
|
||||||
decodedData.userId shouldBeEqualTo "@benoit/foo:matrix.org"
|
decodedData.userId shouldBeEqualTo "@benoit/foo:matrix.org"
|
||||||
decodedData.requestEventId shouldBeEqualTo "\$azertyazerty/bar"
|
decodedData.requestId shouldBeEqualTo "\$azertyazerty/bar"
|
||||||
decodedData.keys["1"]?.shouldBeEqualTo("abcdef")
|
decodedData.keys["1"]?.shouldBeEqualTo("abcdef")
|
||||||
decodedData.keys["2"]?.shouldBeEqualTo("ghijql")
|
decodedData.keys["2"]?.shouldBeEqualTo("ghijql")
|
||||||
decodedData.sharedSecret shouldBeEqualTo "sharedSecret"
|
decodedData.sharedSecret shouldBeEqualTo "sharedSecret"
|
||||||
|
@ -111,7 +111,7 @@ class QrCodeTest {
|
||||||
decodedData.shouldNotBeNull()
|
decodedData.shouldNotBeNull()
|
||||||
|
|
||||||
decodedData.userId shouldBeEqualTo "@benoit:matrix.org"
|
decodedData.userId shouldBeEqualTo "@benoit:matrix.org"
|
||||||
decodedData.requestEventId shouldBeEqualTo "\$azertyazerty"
|
decodedData.requestId shouldBeEqualTo "\$azertyazerty"
|
||||||
decodedData.keys["1"]?.shouldBeEqualTo("abcdef")
|
decodedData.keys["1"]?.shouldBeEqualTo("abcdef")
|
||||||
decodedData.keys["2"]?.shouldBeEqualTo("ghijql")
|
decodedData.keys["2"]?.shouldBeEqualTo("ghijql")
|
||||||
decodedData.sharedSecret shouldBeEqualTo "sharedSecret"
|
decodedData.sharedSecret shouldBeEqualTo "sharedSecret"
|
||||||
|
@ -135,7 +135,7 @@ class QrCodeTest {
|
||||||
decodedData.shouldNotBeNull()
|
decodedData.shouldNotBeNull()
|
||||||
|
|
||||||
decodedData.userId shouldBeEqualTo "@benoit:matrix.org"
|
decodedData.userId shouldBeEqualTo "@benoit:matrix.org"
|
||||||
decodedData.requestEventId shouldBeEqualTo "\$azertyazerty"
|
decodedData.requestId shouldBeEqualTo "\$azertyazerty"
|
||||||
decodedData.keys["1"]?.shouldBeEqualTo("abcdef")
|
decodedData.keys["1"]?.shouldBeEqualTo("abcdef")
|
||||||
decodedData.keys["2"]?.shouldBeEqualTo("ghijql")
|
decodedData.keys["2"]?.shouldBeEqualTo("ghijql")
|
||||||
decodedData.sharedSecret shouldBeEqualTo "sharedSecret"
|
decodedData.sharedSecret shouldBeEqualTo "sharedSecret"
|
||||||
|
@ -173,6 +173,13 @@ class QrCodeTest {
|
||||||
.shouldBeNull()
|
.shouldBeNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testEmptyActionCase() {
|
||||||
|
basicUrl.replace("&action=verify", "&action=")
|
||||||
|
.toQrCodeData()
|
||||||
|
.shouldBeNull()
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testOtherActionCase() {
|
fun testOtherActionCase() {
|
||||||
basicUrl.replace("&action=verify", "&action=confirm")
|
basicUrl.replace("&action=verify", "&action=confirm")
|
||||||
|
@ -182,8 +189,15 @@ class QrCodeTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testBadRequestEventId() {
|
fun testMissingRequestId() {
|
||||||
basicUrl.replace("%24azertyazerty", "%32azertyazerty")
|
basicUrl.replace("request=%24azertyazerty", "")
|
||||||
|
.toQrCodeData()
|
||||||
|
.shouldBeNull()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testEmptyRequestId() {
|
||||||
|
basicUrl.replace("request=%24azertyazerty", "request=")
|
||||||
.toQrCodeData()
|
.toQrCodeData()
|
||||||
.shouldBeNull()
|
.shouldBeNull()
|
||||||
}
|
}
|
||||||
|
@ -208,4 +222,25 @@ class QrCodeTest {
|
||||||
.toQrCodeData()
|
.toQrCodeData()
|
||||||
.shouldBeNull()
|
.shouldBeNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testEmptySecret() {
|
||||||
|
basicUrl.replace("&secret=sharedSecret", "&secret=")
|
||||||
|
.toQrCodeData()
|
||||||
|
.shouldBeNull()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testSelfSigning() {
|
||||||
|
// request is not an eventId in this case
|
||||||
|
val url = "https://matrix.to/#/@benoit0815:matrix.org" +
|
||||||
|
"?request=local.4dff40e1-7bf1-4e80-81ed-c6090d43bf20" +
|
||||||
|
"&action=verify" +
|
||||||
|
"&key_utbSRFcFjFDYf0KcNv3FoBHFSbvUPXtCYutuOg6WQ%2Bs=utbSRFcFjFDYf0KcNv3FoBHFSbvUPXtCYutuOg6WQ%2Bs" +
|
||||||
|
"&key_YSOXZVBXIZ=F0XWqgUePgwm5HMYG3yhBNneHmscrAxxlooLHjy8YQc" +
|
||||||
|
"&secret=LYVcEQmfdorbJ3vbQnq7nbNZc%2BGmDxUen1rByV9hRM4" +
|
||||||
|
"&other_device_key=eGoUqZqAroCYpjp7FLGIkTEzYHBFED4uUAfJ267gqQQ"
|
||||||
|
|
||||||
|
url.toQrCodeData()!!.requestId shouldBeEqualTo "local.4dff40e1-7bf1-4e80-81ed-c6090d43bf20"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue