[Client] Fix trust own device

This commit is contained in:
Christian Pauly 2020-02-19 10:24:54 +01:00
parent f1bd1ec398
commit 48da43bcc6
2 changed files with 52 additions and 2 deletions

View file

@ -1394,8 +1394,8 @@ class Client {
}
}
// Request the missing device key lists.
if (outdatedLists.isNotEmpty) {
// Request the missing device key lists from the server.
final Map<String, dynamic> response = await this.jsonRequest(
type: HTTPType.POST,
action: "/client/r0/keys/query",
@ -1407,17 +1407,23 @@ class Client {
_userDeviceKeys[userId].deviceKeys = {};
for (final rawDeviceKeyEntry in rawDeviceKeyListEntry.value.entries) {
final String deviceId = rawDeviceKeyEntry.key;
// Set the new device key for this device
_userDeviceKeys[userId].deviceKeys[deviceId] =
DeviceKeys.fromJson(rawDeviceKeyEntry.value);
// Restore verified and blocked flags
if (oldUserDeviceKeys.containsKey(userId) &&
_userDeviceKeys[userId].deviceKeys.containsKey(deviceId)) {
_userDeviceKeys[userId].deviceKeys[deviceId].verified =
_userDeviceKeys[userId].deviceKeys[deviceId].verified;
_userDeviceKeys[userId].deviceKeys[deviceId].blocked =
_userDeviceKeys[userId].deviceKeys[deviceId].blocked;
} else if (deviceId == this.deviceID &&
}
if (deviceId == this.deviceID &&
_userDeviceKeys[userId].deviceKeys[deviceId].ed25519Key ==
this.fingerprintKey) {
// Always trust the own device
_userDeviceKeys[userId].deviceKeys[deviceId].verified = true;
}
}

View file

@ -21,12 +21,14 @@ void test() async {
testClientA.storeAPI = FakeStore(testClientA, Map<String, dynamic>());
await testClientA.checkServer(homeserver);
await testClientA.login(testUserA, testPasswordA);
assert(testClientA.encryptionEnabled);
print("++++ Login $testUserB ++++");
Client testClientB = Client("TestClient", debug: false);
testClientB.storeAPI = FakeStore(testClientB, Map<String, dynamic>());
await testClientB.checkServer(homeserver);
await testClientB.login(testUserB, testPasswordA);
assert(testClientB.encryptionEnabled);
print("++++ ($testUserA) Leave all rooms ++++");
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 ++++");
await testClientA.createRoom(invite: [User(testUserB)]);
await Future.delayed(Duration(seconds: 1));
@ -79,6 +97,31 @@ void test() async {
assert(testClientA.userDeviceKeys.containsKey(testUserB));
assert(testClientA.userDeviceKeys[testUserB].deviceKeys
.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' ++++");
await room.sendTextEvent(testMessage);
@ -230,4 +273,5 @@ void test() async {
type: HTTPType.POST, action: "/client/r0/logout/all");
testClientA = null;
testClientB = null;
return;
}