Make MegolmBackupAuthData.signatures optional for robustness

This commit is contained in:
Benoit Marty 2021-10-19 17:31:51 +02:00
parent 86b7fe67ac
commit 097694f6ef
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 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")
return keysBackupVersionTrust
}
@ -478,7 +478,7 @@ internal class DefaultKeysBackupService @Inject constructor(
cryptoCoroutineScope.launch(coroutineDispatchers.main) {
val updateKeysBackupVersionBody = withContext(coroutineDispatchers.crypto) {
// 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) {
// Add current device signature
@ -497,7 +497,7 @@ internal class DefaultKeysBackupService @Inject constructor(
// Create an updated version of KeysVersionResult
val newMegolmBackupAuthData = authData.copy()
val newSignatures = newMegolmBackupAuthData.signatures.toMutableMap()
val newSignatures = newMegolmBackupAuthData.signatures.orEmpty().toMutableMap()
newSignatures[userId] = myUserSignatures
val newMegolmBackupAuthDataWithNewSignature = newMegolmBackupAuthData.copy(

View File

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