Remove v2 suffix

This commit is contained in:
Benoit Marty 2020-02-19 18:09:33 +01:00
parent f81eb298cb
commit e81439d57b
6 changed files with 48 additions and 48 deletions

View File

@ -29,9 +29,9 @@ import org.junit.runners.MethodSorters
@RunWith(AndroidJUnit4::class)
@FixMethodOrder(MethodSorters.JVM)
class QrCodeV2Test : InstrumentedTest {
class QrCodeTest : InstrumentedTest {
private val qrCode1 = QrCodeDataV2.VerifyingAnotherUser(
private val qrCode1 = QrCodeData.VerifyingAnotherUser(
transactionId = "MaTransaction",
userMasterCrossSigningPublicKey = "ktEwcUP6su1xh+GuE+CYkQ3H6W/DIl+ybHFdaEOrolU",
otherUserMasterCrossSigningPublicKey = "TXluZKTZLvSRWOTPlOqLq534bA+/K4zLFKSu9cGLQaU",
@ -40,7 +40,7 @@ class QrCodeV2Test : InstrumentedTest {
private val value1 = "MATRIX\u0002\u0000\u0000\u000DMaTransaction\u0092Ñ0qCú²íq\u0087á®\u0013à\u0098\u0091\u000DÇéoÃ\"_²lq]hC«¢UMynd¤Ù.ô\u0091XäÏ\u0094ê\u008B«\u009Døl\u000F¿+\u008CË\u0014¤®õÁ\u008BA¥12345678"
private val qrCode2 = QrCodeDataV2.SelfVerifyingMasterKeyTrusted(
private val qrCode2 = QrCodeData.SelfVerifyingMasterKeyTrusted(
transactionId = "MaTransaction",
userMasterCrossSigningPublicKey = "ktEwcUP6su1xh+GuE+CYkQ3H6W/DIl+ybHFdaEOrolU",
otherDeviceKey = "TXluZKTZLvSRWOTPlOqLq534bA+/K4zLFKSu9cGLQaU",
@ -49,7 +49,7 @@ class QrCodeV2Test : InstrumentedTest {
private val value2 = "MATRIX\u0002\u0001\u0000\u000DMaTransaction\u0092Ñ0qCú²íq\u0087á®\u0013à\u0098\u0091\u000DÇéoÃ\"_²lq]hC«¢UMynd¤Ù.ô\u0091XäÏ\u0094ê\u008B«\u009Døl\u000F¿+\u008CË\u0014¤®õÁ\u008BA¥12345678"
private val qrCode3 = QrCodeDataV2.SelfVerifyingMasterKeyNotTrusted(
private val qrCode3 = QrCodeData.SelfVerifyingMasterKeyNotTrusted(
transactionId = "MaTransaction",
deviceKey = "TXluZKTZLvSRWOTPlOqLq534bA+/K4zLFKSu9cGLQaU",
userMasterCrossSigningPublicKey = "ktEwcUP6su1xh+GuE+CYkQ3H6W/DIl+ybHFdaEOrolU",
@ -153,17 +153,17 @@ class QrCodeV2Test : InstrumentedTest {
@Test
fun testSymmetry1() {
qrCode1.toEncodedString().toQrCodeDataV2() shouldEqual qrCode1
qrCode1.toEncodedString().toQrCodeData() shouldEqual qrCode1
}
@Test
fun testSymmetry2() {
qrCode2.toEncodedString().toQrCodeDataV2() shouldEqual qrCode2
qrCode2.toEncodedString().toQrCodeData() shouldEqual qrCode2
}
@Test
fun testSymmetry3() {
qrCode3.toEncodedString().toQrCodeDataV2() shouldEqual qrCode3
qrCode3.toEncodedString().toQrCodeData() shouldEqual qrCode3
}
@Test
@ -221,44 +221,44 @@ class QrCodeV2Test : InstrumentedTest {
// Error cases
@Test
fun testErrorHeader() {
value1.replace("MATRIX", "MOTRIX").toQrCodeDataV2().shouldBeNull()
value1.replace("MATRIX", "MATRI").toQrCodeDataV2().shouldBeNull()
value1.replace("MATRIX", "").toQrCodeDataV2().shouldBeNull()
value1.replace("MATRIX", "MOTRIX").toQrCodeData().shouldBeNull()
value1.replace("MATRIX", "MATRI").toQrCodeData().shouldBeNull()
value1.replace("MATRIX", "").toQrCodeData().shouldBeNull()
}
@Test
fun testErrorVersion() {
value1.replace("MATRIX\u0002", "MATRIX\u0000").toQrCodeDataV2().shouldBeNull()
value1.replace("MATRIX\u0002", "MATRIX\u0001").toQrCodeDataV2().shouldBeNull()
value1.replace("MATRIX\u0002", "MATRIX\u0003").toQrCodeDataV2().shouldBeNull()
value1.replace("MATRIX\u0002", "MATRIX").toQrCodeDataV2().shouldBeNull()
value1.replace("MATRIX\u0002", "MATRIX\u0000").toQrCodeData().shouldBeNull()
value1.replace("MATRIX\u0002", "MATRIX\u0001").toQrCodeData().shouldBeNull()
value1.replace("MATRIX\u0002", "MATRIX\u0003").toQrCodeData().shouldBeNull()
value1.replace("MATRIX\u0002", "MATRIX").toQrCodeData().shouldBeNull()
}
@Test
fun testErrorSecretTooShort() {
value1.replace("12345678", "1234567").toQrCodeDataV2().shouldBeNull()
value1.replace("12345678", "1234567").toQrCodeData().shouldBeNull()
}
@Test
fun testErrorNoTransactionNoKeyNoSecret() {
// But keep transaction length
"MATRIX\u0002\u0000\u0000\u000D".toQrCodeDataV2().shouldBeNull()
"MATRIX\u0002\u0000\u0000\u000D".toQrCodeData().shouldBeNull()
}
@Test
fun testErrorNoKeyNoSecret() {
"MATRIX\u0002\u0000\u0000\u000DMaTransaction".toQrCodeDataV2().shouldBeNull()
"MATRIX\u0002\u0000\u0000\u000DMaTransaction".toQrCodeData().shouldBeNull()
}
@Test
fun testErrorTransactionLengthTooShort() {
// In this case, the secret will be longer, so this is not an error, but it will lead to keys mismatch
value1.replace("\u000DMaTransaction", "\u000CMaTransaction").toQrCodeDataV2().shouldNotBeNull()
value1.replace("\u000DMaTransaction", "\u000CMaTransaction").toQrCodeData().shouldNotBeNull()
}
@Test
fun testErrorTransactionLengthTooBig() {
value1.replace("\u000DMaTransaction", "\u000EMaTransaction").toQrCodeDataV2().shouldBeNull()
value1.replace("\u000DMaTransaction", "\u000EMaTransaction").toQrCodeData().shouldBeNull()
}
private fun compareArray(actual: ByteArray, expected: ByteArray) {

View File

@ -27,7 +27,7 @@ import org.junit.runners.MethodSorters
@RunWith(AndroidJUnit4::class)
@FixMethodOrder(MethodSorters.JVM)
class SharedSecretV2Test : InstrumentedTest {
class SharedSecretTest : InstrumentedTest {
@Test
fun testSharedSecretLengthCase() {

View File

@ -65,7 +65,7 @@ import im.vector.matrix.android.internal.crypto.model.rest.VERIFICATION_METHOD_S
import im.vector.matrix.android.internal.crypto.model.rest.toValue
import im.vector.matrix.android.internal.crypto.store.IMXCryptoStore
import im.vector.matrix.android.internal.crypto.verification.qrcode.DefaultQrCodeVerificationTransaction
import im.vector.matrix.android.internal.crypto.verification.qrcode.QrCodeDataV2
import im.vector.matrix.android.internal.crypto.verification.qrcode.QrCodeData
import im.vector.matrix.android.internal.crypto.verification.qrcode.generateSharedSecretV2
import im.vector.matrix.android.internal.di.DeviceId
import im.vector.matrix.android.internal.di.UserId
@ -788,7 +788,7 @@ internal class DefaultVerificationService @Inject constructor(
))
}
private fun createQrCodeData(requestId: String?, otherUserId: String, otherDeviceId: String?): QrCodeDataV2? {
private fun createQrCodeData(requestId: String?, otherUserId: String, otherDeviceId: String?): QrCodeData? {
requestId ?: run {
Timber.w("## Unknown requestId")
return null
@ -806,7 +806,7 @@ internal class DefaultVerificationService @Inject constructor(
}
}
private fun createQrCodeDataForDistinctUser(requestId: String, otherUserId: String): QrCodeDataV2.VerifyingAnotherUser? {
private fun createQrCodeDataForDistinctUser(requestId: String, otherUserId: String): QrCodeData.VerifyingAnotherUser? {
val myMasterKey = crossSigningService.getMyCrossSigningKeys()
?.masterKey()
?.unpaddedBase64PublicKey
@ -823,7 +823,7 @@ internal class DefaultVerificationService @Inject constructor(
return null
}
return QrCodeDataV2.VerifyingAnotherUser(
return QrCodeData.VerifyingAnotherUser(
transactionId = requestId,
userMasterCrossSigningPublicKey = myMasterKey,
otherUserMasterCrossSigningPublicKey = otherUserMasterKey,
@ -832,7 +832,7 @@ internal class DefaultVerificationService @Inject constructor(
}
// Create a QR code to display on the old device (Osborne2)
private fun createQrCodeDataForVerifiedDevice(requestId: String, otherDeviceId: String?): QrCodeDataV2.SelfVerifyingMasterKeyTrusted? {
private fun createQrCodeDataForVerifiedDevice(requestId: String, otherDeviceId: String?): QrCodeData.SelfVerifyingMasterKeyTrusted? {
val myMasterKey = crossSigningService.getMyCrossSigningKeys()
?.masterKey()
?.unpaddedBase64PublicKey
@ -850,7 +850,7 @@ internal class DefaultVerificationService @Inject constructor(
return null
}
return QrCodeDataV2.SelfVerifyingMasterKeyTrusted(
return QrCodeData.SelfVerifyingMasterKeyTrusted(
transactionId = requestId,
userMasterCrossSigningPublicKey = myMasterKey,
otherDeviceKey = otherDeviceKey,
@ -859,7 +859,7 @@ internal class DefaultVerificationService @Inject constructor(
}
// Create a QR code to display on the new device (Dynabook)
private fun createQrCodeDataForUnVerifiedDevice(requestId: String): QrCodeDataV2.SelfVerifyingMasterKeyNotTrusted? {
private fun createQrCodeDataForUnVerifiedDevice(requestId: String): QrCodeData.SelfVerifyingMasterKeyNotTrusted? {
val myMasterKey = crossSigningService.getMyCrossSigningKeys()
?.masterKey()
?.unpaddedBase64PublicKey
@ -874,7 +874,7 @@ internal class DefaultVerificationService @Inject constructor(
return null
}
return QrCodeDataV2.SelfVerifyingMasterKeyNotTrusted(
return QrCodeData.SelfVerifyingMasterKeyNotTrusted(
transactionId = requestId,
deviceKey = myDeviceKey,
userMasterCrossSigningPublicKey = myMasterKey,

View File

@ -39,7 +39,7 @@ internal class DefaultQrCodeVerificationTransaction(
private val crossSigningService: CrossSigningService,
private val cryptoStore: IMXCryptoStore,
// Not null only if other user is able to scan QR code
private val qrCodeData: QrCodeDataV2?,
private val qrCodeData: QrCodeData?,
val userId: String,
val deviceId: String,
override val isIncoming: Boolean
@ -62,7 +62,7 @@ internal class DefaultQrCodeVerificationTransaction(
}
override fun userHasScannedOtherQrCode(otherQrCodeText: String) {
val otherQrCodeData = otherQrCodeText.toQrCodeDataV2() ?: run {
val otherQrCodeData = otherQrCodeText.toQrCodeData() ?: run {
Timber.d("## Verification QR: Invalid QR Code Data")
cancel(CancelCode.QrCodeInvalid)
return
@ -77,21 +77,21 @@ internal class DefaultQrCodeVerificationTransaction(
// check master key
when (otherQrCodeData) {
is QrCodeDataV2.VerifyingAnotherUser -> {
is QrCodeData.VerifyingAnotherUser -> {
if (otherQrCodeData.otherUserMasterCrossSigningPublicKey != crossSigningService.getUserCrossSigningKeys(userId)?.masterKey()?.unpaddedBase64PublicKey) {
Timber.d("## Verification QR: Invalid other master key ${otherQrCodeData.otherUserMasterCrossSigningPublicKey}")
cancel(CancelCode.MismatchedKeys)
return
} else Unit
}
is QrCodeDataV2.SelfVerifyingMasterKeyTrusted -> {
is QrCodeData.SelfVerifyingMasterKeyTrusted -> {
if (otherQrCodeData.userMasterCrossSigningPublicKey != crossSigningService.getUserCrossSigningKeys(userId)?.masterKey()?.unpaddedBase64PublicKey) {
Timber.d("## Verification QR: Invalid other master key ${otherQrCodeData.userMasterCrossSigningPublicKey}")
cancel(CancelCode.MismatchedKeys)
return
} else Unit
}
is QrCodeDataV2.SelfVerifyingMasterKeyNotTrusted -> {
is QrCodeData.SelfVerifyingMasterKeyNotTrusted -> {
if (otherQrCodeData.userMasterCrossSigningPublicKey != crossSigningService.getUserCrossSigningKeys(userId)?.masterKey()?.unpaddedBase64PublicKey) {
Timber.d("## Verification QR: Invalid other master key ${otherQrCodeData.userMasterCrossSigningPublicKey}")
cancel(CancelCode.MismatchedKeys)
@ -105,7 +105,7 @@ internal class DefaultQrCodeVerificationTransaction(
// Check device key if available
when (otherQrCodeData) {
is QrCodeDataV2.VerifyingAnotherUser -> {
is QrCodeData.VerifyingAnotherUser -> {
if (otherQrCodeData.userMasterCrossSigningPublicKey != crossSigningService.getUserCrossSigningKeys(otherUserId)?.masterKey()?.unpaddedBase64PublicKey) {
Timber.d("## Verification QR: Invalid user master key ${otherQrCodeData.userMasterCrossSigningPublicKey}")
cancel(CancelCode.MismatchedKeys)
@ -115,14 +115,14 @@ internal class DefaultQrCodeVerificationTransaction(
Unit
}
}
is QrCodeDataV2.SelfVerifyingMasterKeyTrusted -> {
is QrCodeData.SelfVerifyingMasterKeyTrusted -> {
if (otherQrCodeData.otherDeviceKey != cryptoStore.getUserDevice(userId, deviceId)?.fingerprint()) {
Timber.d("## Verification QR: Invalid other device key ${otherQrCodeData.otherDeviceKey}")
cancel(CancelCode.MismatchedKeys)
return
} else Unit
}
is QrCodeDataV2.SelfVerifyingMasterKeyNotTrusted -> {
is QrCodeData.SelfVerifyingMasterKeyNotTrusted -> {
if (otherQrCodeData.deviceKey != cryptoStore.getUserDevice(otherUserId, otherDeviceId ?: "")?.fingerprint()) {
Timber.d("## Verification QR: Invalid device key ${otherQrCodeData.deviceKey}")
cancel(CancelCode.MismatchedKeys)

View File

@ -22,7 +22,7 @@ import im.vector.matrix.android.internal.crypto.crosssigning.toBase64NoPadding
// MATRIX
private val prefix = "MATRIX".toByteArray(Charsets.ISO_8859_1)
fun QrCodeDataV2.toEncodedString(): String {
fun QrCodeData.toEncodedString(): String {
var result = ByteArray(0)
// MATRIX
@ -35,9 +35,9 @@ fun QrCodeDataV2.toEncodedString(): String {
// Mode
result += when (this) {
is QrCodeDataV2.VerifyingAnotherUser -> 0
is QrCodeDataV2.SelfVerifyingMasterKeyTrusted -> 1
is QrCodeDataV2.SelfVerifyingMasterKeyNotTrusted -> 2
is QrCodeData.VerifyingAnotherUser -> 0
is QrCodeData.SelfVerifyingMasterKeyTrusted -> 1
is QrCodeData.SelfVerifyingMasterKeyNotTrusted -> 2
}.toByte()
// TransactionId length
@ -66,7 +66,7 @@ fun QrCodeDataV2.toEncodedString(): String {
return result.toString(Charsets.ISO_8859_1)
}
fun String.toQrCodeDataV2(): QrCodeDataV2? {
fun String.toQrCodeData(): QrCodeData? {
val byteArray = toByteArray(Charsets.ISO_8859_1)
// Size should be min 6 + 1 + 1 + 2 + ? + 32 + 32 + ? = 74 + transactionLength + secretLength
@ -115,9 +115,9 @@ fun String.toQrCodeDataV2(): QrCodeDataV2? {
val secret = byteArray.copyOfRange(cursor, byteArray.size).toBase64NoPadding()
return when (mode) {
0 -> QrCodeDataV2.VerifyingAnotherUser(transactionId, key1, key2, secret)
1 -> QrCodeDataV2.SelfVerifyingMasterKeyTrusted(transactionId, key1, key2, secret)
2 -> QrCodeDataV2.SelfVerifyingMasterKeyNotTrusted(transactionId, key1, key2, secret)
0 -> QrCodeData.VerifyingAnotherUser(transactionId, key1, key2, secret)
1 -> QrCodeData.SelfVerifyingMasterKeyTrusted(transactionId, key1, key2, secret)
2 -> QrCodeData.SelfVerifyingMasterKeyNotTrusted(transactionId, key1, key2, secret)
else -> null
}
}

View File

@ -19,7 +19,7 @@ package im.vector.matrix.android.internal.crypto.verification.qrcode
/**
* Ref: https://github.com/uhoreg/matrix-doc/blob/qr_key_verification/proposals/1543-qr_code_key_verification.md#qr-code-format
*/
sealed class QrCodeDataV2(
sealed class QrCodeData(
/**
* the event ID or transaction_id of the associated verification
*/
@ -52,7 +52,7 @@ sealed class QrCodeDataV2(
*/
val otherUserMasterCrossSigningPublicKey: String,
override val sharedSecret: String
) : QrCodeDataV2(
) : QrCodeData(
transactionId,
userMasterCrossSigningPublicKey,
otherUserMasterCrossSigningPublicKey,
@ -73,7 +73,7 @@ sealed class QrCodeDataV2(
*/
val otherDeviceKey: String,
override val sharedSecret: String
) : QrCodeDataV2(
) : QrCodeData(
transactionId,
userMasterCrossSigningPublicKey,
otherDeviceKey,
@ -94,7 +94,7 @@ sealed class QrCodeDataV2(
*/
val userMasterCrossSigningPublicKey: String,
override val sharedSecret: String
) : QrCodeDataV2(
) : QrCodeData(
transactionId,
deviceKey,
userMasterCrossSigningPublicKey,