Merge pull request #4269 from vector-im/feature/bma/required_signature

Make MegolmBackupAuthData.signatures optional for robustness
This commit is contained in:
Benoit Marty 2021-10-19 18:47:35 +02:00 committed by GitHub
commit 89e8e5ca31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 4 deletions

1
changelog.d/4162.bugfix Normal file
View File

@ -0,0 +1 @@
Make MegolmBackupAuthData.signatures optional for robustness

View File

@ -410,7 +410,7 @@ internal class DefaultKeysBackupService @Inject constructor(
val keysBackupVersionTrust = KeysBackupVersionTrust() val keysBackupVersionTrust = KeysBackupVersionTrust()
val authData = keysBackupVersion.getAuthDataAsMegolmBackupAuthData() val authData = keysBackupVersion.getAuthDataAsMegolmBackupAuthData()
if (authData == null || authData.publicKey.isEmpty() || authData.signatures.isEmpty()) { if (authData == null || authData.publicKey.isEmpty() || authData.signatures.isNullOrEmpty()) {
Timber.v("getKeysBackupTrust: Key backup is absent or missing required data") Timber.v("getKeysBackupTrust: Key backup is absent or missing required data")
return keysBackupVersionTrust return keysBackupVersionTrust
} }
@ -478,7 +478,7 @@ internal class DefaultKeysBackupService @Inject constructor(
cryptoCoroutineScope.launch(coroutineDispatchers.main) { cryptoCoroutineScope.launch(coroutineDispatchers.main) {
val updateKeysBackupVersionBody = withContext(coroutineDispatchers.crypto) { val updateKeysBackupVersionBody = withContext(coroutineDispatchers.crypto) {
// Get current signatures, or create an empty set // Get current signatures, or create an empty set
val myUserSignatures = authData.signatures[userId].orEmpty().toMutableMap() val myUserSignatures = authData.signatures?.get(userId).orEmpty().toMutableMap()
if (trust) { if (trust) {
// Add current device signature // Add current device signature
@ -497,7 +497,7 @@ internal class DefaultKeysBackupService @Inject constructor(
// Create an updated version of KeysVersionResult // Create an updated version of KeysVersionResult
val newMegolmBackupAuthData = authData.copy() val newMegolmBackupAuthData = authData.copy()
val newSignatures = newMegolmBackupAuthData.signatures.toMutableMap() val newSignatures = newMegolmBackupAuthData.signatures.orEmpty().toMutableMap()
newSignatures[userId] = myUserSignatures newSignatures[userId] = myUserSignatures
val newMegolmBackupAuthDataWithNewSignature = newMegolmBackupAuthData.copy( val newMegolmBackupAuthDataWithNewSignature = newMegolmBackupAuthData.copy(

View File

@ -51,7 +51,7 @@ data class MegolmBackupAuthData(
* userId -> (deviceSignKeyId -> signature) * userId -> (deviceSignKeyId -> signature)
*/ */
@Json(name = "signatures") @Json(name = "signatures")
val signatures: Map<String, Map<String, String>> val signatures: Map<String, Map<String, String>>? = null
) { ) {
fun toJsonDict(): JsonDict { fun toJsonDict(): JsonDict {