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.
This commit is contained in:
Nicolas Werner 2023-05-03 17:09:35 +02:00
parent c077c9232b
commit 4abefa906b
No known key found for this signature in database
3 changed files with 7 additions and 4 deletions

View File

@ -61,6 +61,7 @@ class CrossSigning {
encryption.ssss.isSecret(EventTypes.CrossSigningMasterKey); encryption.ssss.isSecret(EventTypes.CrossSigningMasterKey);
Future<bool> isCached() async { Future<bool> isCached() async {
await client.accountDataLoading;
if (!enabled) { if (!enabled) {
return false; return false;
} }

View File

@ -603,10 +603,10 @@ class KeyManager {
} }
Future<bool> isCached() async { Future<bool> isCached() async {
await client.accountDataLoading;
if (!enabled) { if (!enabled) {
return false; return false;
} }
await client.accountDataLoading;
await client.userDeviceKeysLoading; await client.userDeviceKeysLoading;
return (await encryption.ssss.getCached(megolmKey)) != null; return (await encryption.ssss.getCached(megolmKey)) != null;
} }

View File

@ -292,14 +292,16 @@ class SSSS {
if (keys == null) { if (keys == null) {
return null; return null;
} }
bool isValid(dbEntry) => bool isValid(SSSSCache dbEntry) =>
keys.contains(dbEntry.keyId) && keys.contains(dbEntry.keyId) &&
dbEntry.ciphertext != null && dbEntry.ciphertext != null &&
client.accountData[type]?.content['encrypted'][dbEntry.keyId] client.accountData[type]?.content['encrypted'][dbEntry.keyId]
['ciphertext'] == ['ciphertext'] ==
dbEntry.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); final ret = await client.database?.getSSSSCache(type);
if (ret == null) { if (ret == null) {