Remove v2 suffix
This commit is contained in:
parent
f81eb298cb
commit
e81439d57b
|
@ -29,9 +29,9 @@ import org.junit.runners.MethodSorters
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4::class)
|
@RunWith(AndroidJUnit4::class)
|
||||||
@FixMethodOrder(MethodSorters.JVM)
|
@FixMethodOrder(MethodSorters.JVM)
|
||||||
class QrCodeV2Test : InstrumentedTest {
|
class QrCodeTest : InstrumentedTest {
|
||||||
|
|
||||||
private val qrCode1 = QrCodeDataV2.VerifyingAnotherUser(
|
private val qrCode1 = QrCodeData.VerifyingAnotherUser(
|
||||||
transactionId = "MaTransaction",
|
transactionId = "MaTransaction",
|
||||||
userMasterCrossSigningPublicKey = "ktEwcUP6su1xh+GuE+CYkQ3H6W/DIl+ybHFdaEOrolU",
|
userMasterCrossSigningPublicKey = "ktEwcUP6su1xh+GuE+CYkQ3H6W/DIl+ybHFdaEOrolU",
|
||||||
otherUserMasterCrossSigningPublicKey = "TXluZKTZLvSRWOTPlOqLq534bA+/K4zLFKSu9cGLQaU",
|
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 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",
|
transactionId = "MaTransaction",
|
||||||
userMasterCrossSigningPublicKey = "ktEwcUP6su1xh+GuE+CYkQ3H6W/DIl+ybHFdaEOrolU",
|
userMasterCrossSigningPublicKey = "ktEwcUP6su1xh+GuE+CYkQ3H6W/DIl+ybHFdaEOrolU",
|
||||||
otherDeviceKey = "TXluZKTZLvSRWOTPlOqLq534bA+/K4zLFKSu9cGLQaU",
|
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 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",
|
transactionId = "MaTransaction",
|
||||||
deviceKey = "TXluZKTZLvSRWOTPlOqLq534bA+/K4zLFKSu9cGLQaU",
|
deviceKey = "TXluZKTZLvSRWOTPlOqLq534bA+/K4zLFKSu9cGLQaU",
|
||||||
userMasterCrossSigningPublicKey = "ktEwcUP6su1xh+GuE+CYkQ3H6W/DIl+ybHFdaEOrolU",
|
userMasterCrossSigningPublicKey = "ktEwcUP6su1xh+GuE+CYkQ3H6W/DIl+ybHFdaEOrolU",
|
||||||
|
@ -153,17 +153,17 @@ class QrCodeV2Test : InstrumentedTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testSymmetry1() {
|
fun testSymmetry1() {
|
||||||
qrCode1.toEncodedString().toQrCodeDataV2() shouldEqual qrCode1
|
qrCode1.toEncodedString().toQrCodeData() shouldEqual qrCode1
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testSymmetry2() {
|
fun testSymmetry2() {
|
||||||
qrCode2.toEncodedString().toQrCodeDataV2() shouldEqual qrCode2
|
qrCode2.toEncodedString().toQrCodeData() shouldEqual qrCode2
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testSymmetry3() {
|
fun testSymmetry3() {
|
||||||
qrCode3.toEncodedString().toQrCodeDataV2() shouldEqual qrCode3
|
qrCode3.toEncodedString().toQrCodeData() shouldEqual qrCode3
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -221,44 +221,44 @@ class QrCodeV2Test : InstrumentedTest {
|
||||||
// Error cases
|
// Error cases
|
||||||
@Test
|
@Test
|
||||||
fun testErrorHeader() {
|
fun testErrorHeader() {
|
||||||
value1.replace("MATRIX", "MOTRIX").toQrCodeDataV2().shouldBeNull()
|
value1.replace("MATRIX", "MOTRIX").toQrCodeData().shouldBeNull()
|
||||||
value1.replace("MATRIX", "MATRI").toQrCodeDataV2().shouldBeNull()
|
value1.replace("MATRIX", "MATRI").toQrCodeData().shouldBeNull()
|
||||||
value1.replace("MATRIX", "").toQrCodeDataV2().shouldBeNull()
|
value1.replace("MATRIX", "").toQrCodeData().shouldBeNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testErrorVersion() {
|
fun testErrorVersion() {
|
||||||
value1.replace("MATRIX\u0002", "MATRIX\u0000").toQrCodeDataV2().shouldBeNull()
|
value1.replace("MATRIX\u0002", "MATRIX\u0000").toQrCodeData().shouldBeNull()
|
||||||
value1.replace("MATRIX\u0002", "MATRIX\u0001").toQrCodeDataV2().shouldBeNull()
|
value1.replace("MATRIX\u0002", "MATRIX\u0001").toQrCodeData().shouldBeNull()
|
||||||
value1.replace("MATRIX\u0002", "MATRIX\u0003").toQrCodeDataV2().shouldBeNull()
|
value1.replace("MATRIX\u0002", "MATRIX\u0003").toQrCodeData().shouldBeNull()
|
||||||
value1.replace("MATRIX\u0002", "MATRIX").toQrCodeDataV2().shouldBeNull()
|
value1.replace("MATRIX\u0002", "MATRIX").toQrCodeData().shouldBeNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testErrorSecretTooShort() {
|
fun testErrorSecretTooShort() {
|
||||||
value1.replace("12345678", "1234567").toQrCodeDataV2().shouldBeNull()
|
value1.replace("12345678", "1234567").toQrCodeData().shouldBeNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testErrorNoTransactionNoKeyNoSecret() {
|
fun testErrorNoTransactionNoKeyNoSecret() {
|
||||||
// But keep transaction length
|
// But keep transaction length
|
||||||
"MATRIX\u0002\u0000\u0000\u000D".toQrCodeDataV2().shouldBeNull()
|
"MATRIX\u0002\u0000\u0000\u000D".toQrCodeData().shouldBeNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testErrorNoKeyNoSecret() {
|
fun testErrorNoKeyNoSecret() {
|
||||||
"MATRIX\u0002\u0000\u0000\u000DMaTransaction".toQrCodeDataV2().shouldBeNull()
|
"MATRIX\u0002\u0000\u0000\u000DMaTransaction".toQrCodeData().shouldBeNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testErrorTransactionLengthTooShort() {
|
fun testErrorTransactionLengthTooShort() {
|
||||||
// In this case, the secret will be longer, so this is not an error, but it will lead to keys mismatch
|
// 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
|
@Test
|
||||||
fun testErrorTransactionLengthTooBig() {
|
fun testErrorTransactionLengthTooBig() {
|
||||||
value1.replace("\u000DMaTransaction", "\u000EMaTransaction").toQrCodeDataV2().shouldBeNull()
|
value1.replace("\u000DMaTransaction", "\u000EMaTransaction").toQrCodeData().shouldBeNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun compareArray(actual: ByteArray, expected: ByteArray) {
|
private fun compareArray(actual: ByteArray, expected: ByteArray) {
|
|
@ -27,7 +27,7 @@ import org.junit.runners.MethodSorters
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4::class)
|
@RunWith(AndroidJUnit4::class)
|
||||||
@FixMethodOrder(MethodSorters.JVM)
|
@FixMethodOrder(MethodSorters.JVM)
|
||||||
class SharedSecretV2Test : InstrumentedTest {
|
class SharedSecretTest : InstrumentedTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testSharedSecretLengthCase() {
|
fun testSharedSecretLengthCase() {
|
|
@ -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.model.rest.toValue
|
||||||
import im.vector.matrix.android.internal.crypto.store.IMXCryptoStore
|
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.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.crypto.verification.qrcode.generateSharedSecretV2
|
||||||
import im.vector.matrix.android.internal.di.DeviceId
|
import im.vector.matrix.android.internal.di.DeviceId
|
||||||
import im.vector.matrix.android.internal.di.UserId
|
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 {
|
requestId ?: run {
|
||||||
Timber.w("## Unknown requestId")
|
Timber.w("## Unknown requestId")
|
||||||
return null
|
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()
|
val myMasterKey = crossSigningService.getMyCrossSigningKeys()
|
||||||
?.masterKey()
|
?.masterKey()
|
||||||
?.unpaddedBase64PublicKey
|
?.unpaddedBase64PublicKey
|
||||||
|
@ -823,7 +823,7 @@ internal class DefaultVerificationService @Inject constructor(
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
return QrCodeDataV2.VerifyingAnotherUser(
|
return QrCodeData.VerifyingAnotherUser(
|
||||||
transactionId = requestId,
|
transactionId = requestId,
|
||||||
userMasterCrossSigningPublicKey = myMasterKey,
|
userMasterCrossSigningPublicKey = myMasterKey,
|
||||||
otherUserMasterCrossSigningPublicKey = otherUserMasterKey,
|
otherUserMasterCrossSigningPublicKey = otherUserMasterKey,
|
||||||
|
@ -832,7 +832,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(requestId: String, otherDeviceId: String?): QrCodeDataV2.SelfVerifyingMasterKeyTrusted? {
|
private fun createQrCodeDataForVerifiedDevice(requestId: String, otherDeviceId: String?): QrCodeData.SelfVerifyingMasterKeyTrusted? {
|
||||||
val myMasterKey = crossSigningService.getMyCrossSigningKeys()
|
val myMasterKey = crossSigningService.getMyCrossSigningKeys()
|
||||||
?.masterKey()
|
?.masterKey()
|
||||||
?.unpaddedBase64PublicKey
|
?.unpaddedBase64PublicKey
|
||||||
|
@ -850,7 +850,7 @@ internal class DefaultVerificationService @Inject constructor(
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
return QrCodeDataV2.SelfVerifyingMasterKeyTrusted(
|
return QrCodeData.SelfVerifyingMasterKeyTrusted(
|
||||||
transactionId = requestId,
|
transactionId = requestId,
|
||||||
userMasterCrossSigningPublicKey = myMasterKey,
|
userMasterCrossSigningPublicKey = myMasterKey,
|
||||||
otherDeviceKey = otherDeviceKey,
|
otherDeviceKey = otherDeviceKey,
|
||||||
|
@ -859,7 +859,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(requestId: String): QrCodeDataV2.SelfVerifyingMasterKeyNotTrusted? {
|
private fun createQrCodeDataForUnVerifiedDevice(requestId: String): QrCodeData.SelfVerifyingMasterKeyNotTrusted? {
|
||||||
val myMasterKey = crossSigningService.getMyCrossSigningKeys()
|
val myMasterKey = crossSigningService.getMyCrossSigningKeys()
|
||||||
?.masterKey()
|
?.masterKey()
|
||||||
?.unpaddedBase64PublicKey
|
?.unpaddedBase64PublicKey
|
||||||
|
@ -874,7 +874,7 @@ internal class DefaultVerificationService @Inject constructor(
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
return QrCodeDataV2.SelfVerifyingMasterKeyNotTrusted(
|
return QrCodeData.SelfVerifyingMasterKeyNotTrusted(
|
||||||
transactionId = requestId,
|
transactionId = requestId,
|
||||||
deviceKey = myDeviceKey,
|
deviceKey = myDeviceKey,
|
||||||
userMasterCrossSigningPublicKey = myMasterKey,
|
userMasterCrossSigningPublicKey = myMasterKey,
|
||||||
|
|
|
@ -39,7 +39,7 @@ internal class DefaultQrCodeVerificationTransaction(
|
||||||
private val crossSigningService: CrossSigningService,
|
private val crossSigningService: CrossSigningService,
|
||||||
private val cryptoStore: IMXCryptoStore,
|
private val cryptoStore: IMXCryptoStore,
|
||||||
// Not null only if other user is able to scan QR code
|
// Not null only if other user is able to scan QR code
|
||||||
private val qrCodeData: QrCodeDataV2?,
|
private val qrCodeData: QrCodeData?,
|
||||||
val userId: String,
|
val userId: String,
|
||||||
val deviceId: String,
|
val deviceId: String,
|
||||||
override val isIncoming: Boolean
|
override val isIncoming: Boolean
|
||||||
|
@ -62,7 +62,7 @@ internal class DefaultQrCodeVerificationTransaction(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun userHasScannedOtherQrCode(otherQrCodeText: String) {
|
override fun userHasScannedOtherQrCode(otherQrCodeText: String) {
|
||||||
val otherQrCodeData = otherQrCodeText.toQrCodeDataV2() ?: run {
|
val otherQrCodeData = otherQrCodeText.toQrCodeData() ?: run {
|
||||||
Timber.d("## Verification QR: Invalid QR Code Data")
|
Timber.d("## Verification QR: Invalid QR Code Data")
|
||||||
cancel(CancelCode.QrCodeInvalid)
|
cancel(CancelCode.QrCodeInvalid)
|
||||||
return
|
return
|
||||||
|
@ -77,21 +77,21 @@ internal class DefaultQrCodeVerificationTransaction(
|
||||||
|
|
||||||
// check master key
|
// check master key
|
||||||
when (otherQrCodeData) {
|
when (otherQrCodeData) {
|
||||||
is QrCodeDataV2.VerifyingAnotherUser -> {
|
is QrCodeData.VerifyingAnotherUser -> {
|
||||||
if (otherQrCodeData.otherUserMasterCrossSigningPublicKey != crossSigningService.getUserCrossSigningKeys(userId)?.masterKey()?.unpaddedBase64PublicKey) {
|
if (otherQrCodeData.otherUserMasterCrossSigningPublicKey != crossSigningService.getUserCrossSigningKeys(userId)?.masterKey()?.unpaddedBase64PublicKey) {
|
||||||
Timber.d("## Verification QR: Invalid other master key ${otherQrCodeData.otherUserMasterCrossSigningPublicKey}")
|
Timber.d("## Verification QR: Invalid other master key ${otherQrCodeData.otherUserMasterCrossSigningPublicKey}")
|
||||||
cancel(CancelCode.MismatchedKeys)
|
cancel(CancelCode.MismatchedKeys)
|
||||||
return
|
return
|
||||||
} else Unit
|
} else Unit
|
||||||
}
|
}
|
||||||
is QrCodeDataV2.SelfVerifyingMasterKeyTrusted -> {
|
is QrCodeData.SelfVerifyingMasterKeyTrusted -> {
|
||||||
if (otherQrCodeData.userMasterCrossSigningPublicKey != crossSigningService.getUserCrossSigningKeys(userId)?.masterKey()?.unpaddedBase64PublicKey) {
|
if (otherQrCodeData.userMasterCrossSigningPublicKey != crossSigningService.getUserCrossSigningKeys(userId)?.masterKey()?.unpaddedBase64PublicKey) {
|
||||||
Timber.d("## Verification QR: Invalid other master key ${otherQrCodeData.userMasterCrossSigningPublicKey}")
|
Timber.d("## Verification QR: Invalid other master key ${otherQrCodeData.userMasterCrossSigningPublicKey}")
|
||||||
cancel(CancelCode.MismatchedKeys)
|
cancel(CancelCode.MismatchedKeys)
|
||||||
return
|
return
|
||||||
} else Unit
|
} else Unit
|
||||||
}
|
}
|
||||||
is QrCodeDataV2.SelfVerifyingMasterKeyNotTrusted -> {
|
is QrCodeData.SelfVerifyingMasterKeyNotTrusted -> {
|
||||||
if (otherQrCodeData.userMasterCrossSigningPublicKey != crossSigningService.getUserCrossSigningKeys(userId)?.masterKey()?.unpaddedBase64PublicKey) {
|
if (otherQrCodeData.userMasterCrossSigningPublicKey != crossSigningService.getUserCrossSigningKeys(userId)?.masterKey()?.unpaddedBase64PublicKey) {
|
||||||
Timber.d("## Verification QR: Invalid other master key ${otherQrCodeData.userMasterCrossSigningPublicKey}")
|
Timber.d("## Verification QR: Invalid other master key ${otherQrCodeData.userMasterCrossSigningPublicKey}")
|
||||||
cancel(CancelCode.MismatchedKeys)
|
cancel(CancelCode.MismatchedKeys)
|
||||||
|
@ -105,7 +105,7 @@ internal class DefaultQrCodeVerificationTransaction(
|
||||||
|
|
||||||
// Check device key if available
|
// Check device key if available
|
||||||
when (otherQrCodeData) {
|
when (otherQrCodeData) {
|
||||||
is QrCodeDataV2.VerifyingAnotherUser -> {
|
is QrCodeData.VerifyingAnotherUser -> {
|
||||||
if (otherQrCodeData.userMasterCrossSigningPublicKey != crossSigningService.getUserCrossSigningKeys(otherUserId)?.masterKey()?.unpaddedBase64PublicKey) {
|
if (otherQrCodeData.userMasterCrossSigningPublicKey != crossSigningService.getUserCrossSigningKeys(otherUserId)?.masterKey()?.unpaddedBase64PublicKey) {
|
||||||
Timber.d("## Verification QR: Invalid user master key ${otherQrCodeData.userMasterCrossSigningPublicKey}")
|
Timber.d("## Verification QR: Invalid user master key ${otherQrCodeData.userMasterCrossSigningPublicKey}")
|
||||||
cancel(CancelCode.MismatchedKeys)
|
cancel(CancelCode.MismatchedKeys)
|
||||||
|
@ -115,14 +115,14 @@ internal class DefaultQrCodeVerificationTransaction(
|
||||||
Unit
|
Unit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is QrCodeDataV2.SelfVerifyingMasterKeyTrusted -> {
|
is QrCodeData.SelfVerifyingMasterKeyTrusted -> {
|
||||||
if (otherQrCodeData.otherDeviceKey != cryptoStore.getUserDevice(userId, deviceId)?.fingerprint()) {
|
if (otherQrCodeData.otherDeviceKey != cryptoStore.getUserDevice(userId, deviceId)?.fingerprint()) {
|
||||||
Timber.d("## Verification QR: Invalid other device key ${otherQrCodeData.otherDeviceKey}")
|
Timber.d("## Verification QR: Invalid other device key ${otherQrCodeData.otherDeviceKey}")
|
||||||
cancel(CancelCode.MismatchedKeys)
|
cancel(CancelCode.MismatchedKeys)
|
||||||
return
|
return
|
||||||
} else Unit
|
} else Unit
|
||||||
}
|
}
|
||||||
is QrCodeDataV2.SelfVerifyingMasterKeyNotTrusted -> {
|
is QrCodeData.SelfVerifyingMasterKeyNotTrusted -> {
|
||||||
if (otherQrCodeData.deviceKey != cryptoStore.getUserDevice(otherUserId, otherDeviceId ?: "")?.fingerprint()) {
|
if (otherQrCodeData.deviceKey != cryptoStore.getUserDevice(otherUserId, otherDeviceId ?: "")?.fingerprint()) {
|
||||||
Timber.d("## Verification QR: Invalid device key ${otherQrCodeData.deviceKey}")
|
Timber.d("## Verification QR: Invalid device key ${otherQrCodeData.deviceKey}")
|
||||||
cancel(CancelCode.MismatchedKeys)
|
cancel(CancelCode.MismatchedKeys)
|
||||||
|
|
|
@ -22,7 +22,7 @@ import im.vector.matrix.android.internal.crypto.crosssigning.toBase64NoPadding
|
||||||
// MATRIX
|
// MATRIX
|
||||||
private val prefix = "MATRIX".toByteArray(Charsets.ISO_8859_1)
|
private val prefix = "MATRIX".toByteArray(Charsets.ISO_8859_1)
|
||||||
|
|
||||||
fun QrCodeDataV2.toEncodedString(): String {
|
fun QrCodeData.toEncodedString(): String {
|
||||||
var result = ByteArray(0)
|
var result = ByteArray(0)
|
||||||
|
|
||||||
// MATRIX
|
// MATRIX
|
||||||
|
@ -35,9 +35,9 @@ fun QrCodeDataV2.toEncodedString(): String {
|
||||||
|
|
||||||
// Mode
|
// Mode
|
||||||
result += when (this) {
|
result += when (this) {
|
||||||
is QrCodeDataV2.VerifyingAnotherUser -> 0
|
is QrCodeData.VerifyingAnotherUser -> 0
|
||||||
is QrCodeDataV2.SelfVerifyingMasterKeyTrusted -> 1
|
is QrCodeData.SelfVerifyingMasterKeyTrusted -> 1
|
||||||
is QrCodeDataV2.SelfVerifyingMasterKeyNotTrusted -> 2
|
is QrCodeData.SelfVerifyingMasterKeyNotTrusted -> 2
|
||||||
}.toByte()
|
}.toByte()
|
||||||
|
|
||||||
// TransactionId length
|
// TransactionId length
|
||||||
|
@ -66,7 +66,7 @@ fun QrCodeDataV2.toEncodedString(): String {
|
||||||
return result.toString(Charsets.ISO_8859_1)
|
return result.toString(Charsets.ISO_8859_1)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun String.toQrCodeDataV2(): QrCodeDataV2? {
|
fun String.toQrCodeData(): QrCodeData? {
|
||||||
val byteArray = toByteArray(Charsets.ISO_8859_1)
|
val byteArray = toByteArray(Charsets.ISO_8859_1)
|
||||||
|
|
||||||
// Size should be min 6 + 1 + 1 + 2 + ? + 32 + 32 + ? = 74 + transactionLength + secretLength
|
// 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()
|
val secret = byteArray.copyOfRange(cursor, byteArray.size).toBase64NoPadding()
|
||||||
|
|
||||||
return when (mode) {
|
return when (mode) {
|
||||||
0 -> QrCodeDataV2.VerifyingAnotherUser(transactionId, key1, key2, secret)
|
0 -> QrCodeData.VerifyingAnotherUser(transactionId, key1, key2, secret)
|
||||||
1 -> QrCodeDataV2.SelfVerifyingMasterKeyTrusted(transactionId, key1, key2, secret)
|
1 -> QrCodeData.SelfVerifyingMasterKeyTrusted(transactionId, key1, key2, secret)
|
||||||
2 -> QrCodeDataV2.SelfVerifyingMasterKeyNotTrusted(transactionId, key1, key2, secret)
|
2 -> QrCodeData.SelfVerifyingMasterKeyNotTrusted(transactionId, key1, key2, secret)
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -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
|
* 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
|
* the event ID or transaction_id of the associated verification
|
||||||
*/
|
*/
|
||||||
|
@ -52,7 +52,7 @@ sealed class QrCodeDataV2(
|
||||||
*/
|
*/
|
||||||
val otherUserMasterCrossSigningPublicKey: String,
|
val otherUserMasterCrossSigningPublicKey: String,
|
||||||
override val sharedSecret: String
|
override val sharedSecret: String
|
||||||
) : QrCodeDataV2(
|
) : QrCodeData(
|
||||||
transactionId,
|
transactionId,
|
||||||
userMasterCrossSigningPublicKey,
|
userMasterCrossSigningPublicKey,
|
||||||
otherUserMasterCrossSigningPublicKey,
|
otherUserMasterCrossSigningPublicKey,
|
||||||
|
@ -73,7 +73,7 @@ sealed class QrCodeDataV2(
|
||||||
*/
|
*/
|
||||||
val otherDeviceKey: String,
|
val otherDeviceKey: String,
|
||||||
override val sharedSecret: String
|
override val sharedSecret: String
|
||||||
) : QrCodeDataV2(
|
) : QrCodeData(
|
||||||
transactionId,
|
transactionId,
|
||||||
userMasterCrossSigningPublicKey,
|
userMasterCrossSigningPublicKey,
|
||||||
otherDeviceKey,
|
otherDeviceKey,
|
||||||
|
@ -94,7 +94,7 @@ sealed class QrCodeDataV2(
|
||||||
*/
|
*/
|
||||||
val userMasterCrossSigningPublicKey: String,
|
val userMasterCrossSigningPublicKey: String,
|
||||||
override val sharedSecret: String
|
override val sharedSecret: String
|
||||||
) : QrCodeDataV2(
|
) : QrCodeData(
|
||||||
transactionId,
|
transactionId,
|
||||||
deviceKey,
|
deviceKey,
|
||||||
userMasterCrossSigningPublicKey,
|
userMasterCrossSigningPublicKey,
|
Loading…
Reference in New Issue