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) {