diff --git a/lib/src/client.dart b/lib/src/client.dart index 48952d6..bbd7775 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -149,25 +149,10 @@ class Client { bool get fileEncryptionEnabled => true; /// Wheather this session is unknown to others - bool get isUnknownSession { - if (!userDeviceKeys.containsKey(userID)) { - return true; - } - final masterKey = userDeviceKeys[userID].masterKey; - if (masterKey == null) { - return true; - } - if (!masterKey.directVerified) { - return true; - } - if (!userDeviceKeys[userID].deviceKeys.containsKey(deviceID)) { - return true; - } - if (!userDeviceKeys[userID].deviceKeys[deviceID].crossVerified) { - return true; - } - return false; - } + bool get isUnknownSession => + !userDeviceKeys.containsKey(userID) || + !userDeviceKeys[userID].deviceKeys.containsKey(deviceID) || + !userDeviceKeys[userID].deviceKeys[deviceID].signed; /// Warning! This endpoint is for testing only! set rooms(List newList) { diff --git a/lib/src/utils/device_keys_list.dart b/lib/src/utils/device_keys_list.dart index f140298..d96c2db 100644 --- a/lib/src/utils/device_keys_list.dart +++ b/lib/src/utils/device_keys_list.dart @@ -140,6 +140,8 @@ abstract class SignedKey { } } + bool get signed => hasValidSignatureChain(verifiedOnly: false); + String get signingContent { final data = Map.from(content); // some old data might have the custom verified and blocked keys @@ -166,7 +168,7 @@ abstract class SignedKey { return valid; } - bool hasValidSignatureChain({Set visited}) { + bool hasValidSignatureChain({bool verfiedOnly = true, Set visited}) { visited ??= {}; final setKey = '${userId};${identifier}'; if (visited.contains(setKey)) { @@ -225,11 +227,16 @@ abstract class SignedKey { continue; } - if (key.directVerified) { + if ((verifiedOnly && key.directVerified) || + (key is SignedKey && + key.usage.includes('master') && + key.directVerified && + key.userId == client.userID)) { return true; // we verified this key and it is valid...all checks out! } // or else we just recurse into that key and chack if it works out - final haveChain = key.hasValidSignatureChain(visited: visited); + final haveChain = key.hasValidSignatureChain( + verfiedOnly: verfiedOnly, visited: visited); if (haveChain) { return true; }