Merge branch 'client-fix-own-device-trust' into 'master'
[Client] Fix trust own device Closes #59 See merge request famedly/famedlysdk!206
This commit is contained in:
commit
67ac01fdc5
|
@ -1394,8 +1394,8 @@ class Client {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Request the missing device key lists.
|
|
||||||
if (outdatedLists.isNotEmpty) {
|
if (outdatedLists.isNotEmpty) {
|
||||||
|
// Request the missing device key lists from the server.
|
||||||
final Map<String, dynamic> response = await this.jsonRequest(
|
final Map<String, dynamic> response = await this.jsonRequest(
|
||||||
type: HTTPType.POST,
|
type: HTTPType.POST,
|
||||||
action: "/client/r0/keys/query",
|
action: "/client/r0/keys/query",
|
||||||
|
@ -1407,17 +1407,23 @@ class Client {
|
||||||
_userDeviceKeys[userId].deviceKeys = {};
|
_userDeviceKeys[userId].deviceKeys = {};
|
||||||
for (final rawDeviceKeyEntry in rawDeviceKeyListEntry.value.entries) {
|
for (final rawDeviceKeyEntry in rawDeviceKeyListEntry.value.entries) {
|
||||||
final String deviceId = rawDeviceKeyEntry.key;
|
final String deviceId = rawDeviceKeyEntry.key;
|
||||||
|
|
||||||
|
// Set the new device key for this device
|
||||||
_userDeviceKeys[userId].deviceKeys[deviceId] =
|
_userDeviceKeys[userId].deviceKeys[deviceId] =
|
||||||
DeviceKeys.fromJson(rawDeviceKeyEntry.value);
|
DeviceKeys.fromJson(rawDeviceKeyEntry.value);
|
||||||
|
|
||||||
|
// Restore verified and blocked flags
|
||||||
if (oldUserDeviceKeys.containsKey(userId) &&
|
if (oldUserDeviceKeys.containsKey(userId) &&
|
||||||
_userDeviceKeys[userId].deviceKeys.containsKey(deviceId)) {
|
_userDeviceKeys[userId].deviceKeys.containsKey(deviceId)) {
|
||||||
_userDeviceKeys[userId].deviceKeys[deviceId].verified =
|
_userDeviceKeys[userId].deviceKeys[deviceId].verified =
|
||||||
_userDeviceKeys[userId].deviceKeys[deviceId].verified;
|
_userDeviceKeys[userId].deviceKeys[deviceId].verified;
|
||||||
_userDeviceKeys[userId].deviceKeys[deviceId].blocked =
|
_userDeviceKeys[userId].deviceKeys[deviceId].blocked =
|
||||||
_userDeviceKeys[userId].deviceKeys[deviceId].blocked;
|
_userDeviceKeys[userId].deviceKeys[deviceId].blocked;
|
||||||
} else if (deviceId == this.deviceID &&
|
}
|
||||||
|
if (deviceId == this.deviceID &&
|
||||||
_userDeviceKeys[userId].deviceKeys[deviceId].ed25519Key ==
|
_userDeviceKeys[userId].deviceKeys[deviceId].ed25519Key ==
|
||||||
this.fingerprintKey) {
|
this.fingerprintKey) {
|
||||||
|
// Always trust the own device
|
||||||
_userDeviceKeys[userId].deviceKeys[deviceId].verified = true;
|
_userDeviceKeys[userId].deviceKeys[deviceId].verified = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,12 +21,14 @@ void test() async {
|
||||||
testClientA.storeAPI = FakeStore(testClientA, Map<String, dynamic>());
|
testClientA.storeAPI = FakeStore(testClientA, Map<String, dynamic>());
|
||||||
await testClientA.checkServer(homeserver);
|
await testClientA.checkServer(homeserver);
|
||||||
await testClientA.login(testUserA, testPasswordA);
|
await testClientA.login(testUserA, testPasswordA);
|
||||||
|
assert(testClientA.encryptionEnabled);
|
||||||
|
|
||||||
print("++++ Login $testUserB ++++");
|
print("++++ Login $testUserB ++++");
|
||||||
Client testClientB = Client("TestClient", debug: false);
|
Client testClientB = Client("TestClient", debug: false);
|
||||||
testClientB.storeAPI = FakeStore(testClientB, Map<String, dynamic>());
|
testClientB.storeAPI = FakeStore(testClientB, Map<String, dynamic>());
|
||||||
await testClientB.checkServer(homeserver);
|
await testClientB.checkServer(homeserver);
|
||||||
await testClientB.login(testUserB, testPasswordA);
|
await testClientB.login(testUserB, testPasswordA);
|
||||||
|
assert(testClientB.encryptionEnabled);
|
||||||
|
|
||||||
print("++++ ($testUserA) Leave all rooms ++++");
|
print("++++ ($testUserA) Leave all rooms ++++");
|
||||||
while (testClientA.rooms.isNotEmpty) {
|
while (testClientA.rooms.isNotEmpty) {
|
||||||
|
@ -55,6 +57,22 @@ void test() async {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
print("++++ Check if own olm device is verified by default ++++");
|
||||||
|
assert(testClientA.userDeviceKeys.containsKey(testUserA));
|
||||||
|
assert(testClientA.userDeviceKeys[testUserA].deviceKeys
|
||||||
|
.containsKey(testClientA.deviceID));
|
||||||
|
assert(testClientA
|
||||||
|
.userDeviceKeys[testUserA].deviceKeys[testClientA.deviceID].verified);
|
||||||
|
assert(!testClientA
|
||||||
|
.userDeviceKeys[testUserA].deviceKeys[testClientA.deviceID].blocked);
|
||||||
|
assert(testClientB.userDeviceKeys.containsKey(testUserB));
|
||||||
|
assert(testClientB.userDeviceKeys[testUserB].deviceKeys
|
||||||
|
.containsKey(testClientB.deviceID));
|
||||||
|
assert(testClientB
|
||||||
|
.userDeviceKeys[testUserB].deviceKeys[testClientB.deviceID].verified);
|
||||||
|
assert(!testClientB
|
||||||
|
.userDeviceKeys[testUserB].deviceKeys[testClientB.deviceID].blocked);
|
||||||
|
|
||||||
print("++++ ($testUserA) Create room and invite $testUserB ++++");
|
print("++++ ($testUserA) Create room and invite $testUserB ++++");
|
||||||
await testClientA.createRoom(invite: [User(testUserB)]);
|
await testClientA.createRoom(invite: [User(testUserB)]);
|
||||||
await Future.delayed(Duration(seconds: 1));
|
await Future.delayed(Duration(seconds: 1));
|
||||||
|
@ -79,6 +97,31 @@ void test() async {
|
||||||
assert(testClientA.userDeviceKeys.containsKey(testUserB));
|
assert(testClientA.userDeviceKeys.containsKey(testUserB));
|
||||||
assert(testClientA.userDeviceKeys[testUserB].deviceKeys
|
assert(testClientA.userDeviceKeys[testUserB].deviceKeys
|
||||||
.containsKey(testClientB.deviceID));
|
.containsKey(testClientB.deviceID));
|
||||||
|
assert(!testClientA
|
||||||
|
.userDeviceKeys[testUserB].deviceKeys[testClientB.deviceID].verified);
|
||||||
|
assert(!testClientA
|
||||||
|
.userDeviceKeys[testUserB].deviceKeys[testClientB.deviceID].blocked);
|
||||||
|
assert(testClientB.userDeviceKeys.containsKey(testUserA));
|
||||||
|
assert(testClientB.userDeviceKeys[testUserA].deviceKeys
|
||||||
|
.containsKey(testClientA.deviceID));
|
||||||
|
assert(!testClientB
|
||||||
|
.userDeviceKeys[testUserA].deviceKeys[testClientA.deviceID].verified);
|
||||||
|
assert(!testClientB
|
||||||
|
.userDeviceKeys[testUserA].deviceKeys[testClientA.deviceID].blocked);
|
||||||
|
await testClientA.userDeviceKeys[testUserB].deviceKeys[testClientB.deviceID]
|
||||||
|
.setVerified(true, testClientA);
|
||||||
|
|
||||||
|
print("++++ Check if own olm device is verified by default ++++");
|
||||||
|
assert(testClientA.userDeviceKeys.containsKey(testUserA));
|
||||||
|
assert(testClientA.userDeviceKeys[testUserA].deviceKeys
|
||||||
|
.containsKey(testClientA.deviceID));
|
||||||
|
assert(testClientA
|
||||||
|
.userDeviceKeys[testUserA].deviceKeys[testClientA.deviceID].verified);
|
||||||
|
assert(testClientB.userDeviceKeys.containsKey(testUserB));
|
||||||
|
assert(testClientB.userDeviceKeys[testUserB].deviceKeys
|
||||||
|
.containsKey(testClientB.deviceID));
|
||||||
|
assert(testClientB
|
||||||
|
.userDeviceKeys[testUserB].deviceKeys[testClientB.deviceID].verified);
|
||||||
|
|
||||||
print("++++ ($testUserA) Send encrypted message: '$testMessage' ++++");
|
print("++++ ($testUserA) Send encrypted message: '$testMessage' ++++");
|
||||||
await room.sendTextEvent(testMessage);
|
await room.sendTextEvent(testMessage);
|
||||||
|
@ -230,4 +273,5 @@ void test() async {
|
||||||
type: HTTPType.POST, action: "/client/r0/logout/all");
|
type: HTTPType.POST, action: "/client/r0/logout/all");
|
||||||
testClientA = null;
|
testClientA = null;
|
||||||
testClientB = null;
|
testClientB = null;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue