From 4abefa906bcc629a9cce26c4dcb116d1bc7d3bbf Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Wed, 3 May 2023 17:09:35 +0200 Subject: [PATCH] fix: Always wait for account data to load before returning SSSS status Otherwise it would be possible, that we haven't loaded account data, so we return that cross-signing is disabled and then we load it and return a different result. Might fix the sentry issue for that. --- lib/encryption/cross_signing.dart | 1 + lib/encryption/key_manager.dart | 2 +- lib/encryption/ssss.dart | 8 +++++--- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/encryption/cross_signing.dart b/lib/encryption/cross_signing.dart index e2116343..499b147b 100644 --- a/lib/encryption/cross_signing.dart +++ b/lib/encryption/cross_signing.dart @@ -61,6 +61,7 @@ class CrossSigning { encryption.ssss.isSecret(EventTypes.CrossSigningMasterKey); Future isCached() async { + await client.accountDataLoading; if (!enabled) { return false; } diff --git a/lib/encryption/key_manager.dart b/lib/encryption/key_manager.dart index 16e8468b..354894dd 100644 --- a/lib/encryption/key_manager.dart +++ b/lib/encryption/key_manager.dart @@ -603,10 +603,10 @@ class KeyManager { } Future isCached() async { + await client.accountDataLoading; if (!enabled) { return false; } - await client.accountDataLoading; await client.userDeviceKeysLoading; return (await encryption.ssss.getCached(megolmKey)) != null; } diff --git a/lib/encryption/ssss.dart b/lib/encryption/ssss.dart index 7b4c07e1..93ee4c21 100644 --- a/lib/encryption/ssss.dart +++ b/lib/encryption/ssss.dart @@ -292,14 +292,16 @@ class SSSS { if (keys == null) { return null; } - bool isValid(dbEntry) => + bool isValid(SSSSCache dbEntry) => keys.contains(dbEntry.keyId) && dbEntry.ciphertext != null && client.accountData[type]?.content['encrypted'][dbEntry.keyId] ['ciphertext'] == dbEntry.ciphertext; - if (_cache.containsKey(type) && isValid(_cache[type])) { - return _cache[type]?.content; + + final fromCache = _cache[type]; + if (fromCache != null && isValid(fromCache)) { + return fromCache.content; } final ret = await client.database?.getSSSSCache(type); if (ret == null) {