From cbf418c401145747b8d685314ba4ef369c535d76 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 22 Jan 2020 18:22:01 +0100 Subject: [PATCH] Update after MSC change --- .../crypto/verification/qrcode/Extensions.kt | 25 +++++------- .../crypto/verification/qrcode/QrCodeData.kt | 14 ++++--- .../crypto/verification/qrcode/QrCodeTest.kt | 38 ++++++++----------- 3 files changed, 34 insertions(+), 43 deletions(-) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/qrcode/Extensions.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/qrcode/Extensions.kt index a2fc5e688c..1f139343ef 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/qrcode/Extensions.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/qrcode/Extensions.kt @@ -26,8 +26,7 @@ import im.vector.matrix.android.api.permalinks.PermalinkFactory * request= * &action=verify * &key_=... - * &verification_algorithms= - * &verification_key= + * &secret= * &other_user_key= * */ @@ -35,18 +34,17 @@ fun QrCodeData.toUrl(): String { return buildString { append(PermalinkFactory.createPermalink(userId)) append("?request=") - append(PermalinkFactory.escape(requestId)) - append("&action=verify") + append(PermalinkFactory.escape(requestEventId)) + append("&action=") + append(action) for ((keyId, key) in keys) { append("&key_$keyId=") append(PermalinkFactory.escape(key)) } - append("&verification_algorithms=") - append(PermalinkFactory.escape(verificationAlgorithms)) - append("&verification_key=") - append(PermalinkFactory.escape(verificationKey)) + append("&secret=") + append(PermalinkFactory.escape(sharedSecret)) append("&other_user_key=") append(PermalinkFactory.escape(otherUserKey)) } @@ -85,15 +83,12 @@ fun String.toQrCodeData(): QrCodeData? { (it.substringBefore("=") to it.substringAfter("=")) }.toMap() - if (keyValues["action"] != "verify") { - return null - } + val action = keyValues["action"] ?: return null val requestId = keyValues["request"] ?.let { PermalinkFactory.unescape(it) } ?.takeIf { MatrixPatterns.isEventId(it) } ?: return null - val verificationAlgorithms = keyValues["verification_algorithms"] ?: return null - val verificationKey = keyValues["verification_key"] ?: return null + val sharedSecret = keyValues["secret"] ?: return null val otherUserKey = keyValues["other_user_key"] ?: return null val keys = keyValues.keys @@ -106,9 +101,9 @@ fun String.toQrCodeData(): QrCodeData? { return QrCodeData( userId, requestId, + action, keys, - verificationAlgorithms, - verificationKey, + sharedSecret, otherUserKey ) } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/qrcode/QrCodeData.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/qrcode/QrCodeData.kt index 9b97deb7ea..8b400413b0 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/qrcode/QrCodeData.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/qrcode/QrCodeData.kt @@ -22,15 +22,19 @@ package im.vector.matrix.android.internal.crypto.verification.qrcode data class QrCodeData( val userId: String, // the event ID of the associated verification request event. - val requestId: String, + val requestEventId: String, + // The action + val action: String, // key_: each key that the user wants verified will have an entry of this form, where the value is the key in unpadded base64. // The QR code should contain at least the user's master cross-signing key. val keys: Map, - // algorithm - val verificationAlgorithms: String, // random single-use shared secret in unpadded base64. It must be at least 256-bits long (43 characters when base64-encoded). - val verificationKey: String, + val sharedSecret: String, // the other user's master cross-signing key, in unpadded base64. In other words, if Alice is displaying the QR code, // this would be the copy of Bob's master cross-signing key that Alice has. val otherUserKey: String -) +) { + companion object { + const val ACTION_VERIFY = "verify" + } +} diff --git a/matrix-sdk-android/src/test/java/im/vector/matrix/android/internal/crypto/verification/qrcode/QrCodeTest.kt b/matrix-sdk-android/src/test/java/im/vector/matrix/android/internal/crypto/verification/qrcode/QrCodeTest.kt index 022dd76fb4..5eec2f3b62 100644 --- a/matrix-sdk-android/src/test/java/im/vector/matrix/android/internal/crypto/verification/qrcode/QrCodeTest.kt +++ b/matrix-sdk-android/src/test/java/im/vector/matrix/android/internal/crypto/verification/qrcode/QrCodeTest.kt @@ -28,17 +28,17 @@ class QrCodeTest { private val basicQrCodeData = QrCodeData( userId = "@benoit:matrix.org", - requestId = "\$azertyazerty", + requestEventId = "\$azertyazerty", + action = QrCodeData.ACTION_VERIFY, keys = mapOf( "1" to "abcdef", "2" to "ghijql" ), - verificationAlgorithms = "verificationAlgorithm", - verificationKey = "verificationKey", + sharedSecret = "sharedSecret", otherUserKey = "otherUserKey" ) - private val basicUrl = "https://matrix.to/#/@benoit:matrix.org?request=\$azertyazerty&action=verify&key_1=abcdef&key_2=ghijql&verification_algorithms=verificationAlgorithm&verification_key=verificationKey&other_user_key=otherUserKey" + private val basicUrl = "https://matrix.to/#/@benoit:matrix.org?request=\$azertyazerty&action=verify&key_1=abcdef&key_2=ghijql&secret=sharedSecret&other_user_key=otherUserKey" @Test fun testNominalCase() { @@ -51,11 +51,10 @@ class QrCodeTest { decodedData.shouldNotBeNull() decodedData.userId shouldBeEqualTo "@benoit:matrix.org" - decodedData.requestId shouldBeEqualTo "\$azertyazerty" + decodedData.requestEventId shouldBeEqualTo "\$azertyazerty" decodedData.keys["1"]?.shouldBeEqualTo("abcdef") decodedData.keys["2"]?.shouldBeEqualTo("ghijql") - decodedData.verificationAlgorithms shouldBeEqualTo "verificationAlgorithm" - decodedData.verificationKey shouldBeEqualTo "verificationKey" + decodedData.sharedSecret shouldBeEqualTo "sharedSecret" decodedData.otherUserKey shouldBeEqualTo "otherUserKey" } @@ -64,7 +63,7 @@ class QrCodeTest { val url = basicQrCodeData .copy( userId = "@benoit/foo:matrix.org", - requestId = "\$azertyazerty/bar" + requestEventId = "\$azertyazerty/bar" ) .toUrl() @@ -77,11 +76,10 @@ class QrCodeTest { decodedData.shouldNotBeNull() decodedData.userId shouldBeEqualTo "@benoit/foo:matrix.org" - decodedData.requestId shouldBeEqualTo "\$azertyazerty/bar" + decodedData.requestEventId shouldBeEqualTo "\$azertyazerty/bar" decodedData.keys["1"]?.shouldBeEqualTo("abcdef") decodedData.keys["2"]?.shouldBeEqualTo("ghijql") - decodedData.verificationAlgorithms shouldBeEqualTo "verificationAlgorithm" - decodedData.verificationKey shouldBeEqualTo "verificationKey" + decodedData.sharedSecret shouldBeEqualTo "sharedSecret" decodedData.otherUserKey shouldBeEqualTo "otherUserKey" } @@ -93,14 +91,15 @@ class QrCodeTest { } @Test - fun testBadActionCase() { + fun testOtherActionCase() { basicUrl.replace("&action=verify", "&action=confirm") .toQrCodeData() - .shouldBeNull() + ?.action + ?.shouldBeEqualTo("confirm") } @Test - fun testBadRequestId() { + fun testBadRequestEventId() { basicUrl.replace("\$azertyazerty", "@azertyazerty") .toQrCodeData() .shouldBeNull() @@ -121,15 +120,8 @@ class QrCodeTest { } @Test - fun testMissingVerificationAlgorithm() { - basicUrl.replace("&verification_algorithms=verificationAlgorithm", "") - .toQrCodeData() - .shouldBeNull() - } - - @Test - fun testMissingVerificationKey() { - basicUrl.replace("&verification_key=verificationKey", "") + fun testMissingSecret() { + basicUrl.replace("&secret=sharedSecret", "") .toQrCodeData() .shouldBeNull() }