Merge branch 'soru/null-device' into 'master'
make sure keys are valid See merge request famedly/famedlysdk!313
This commit is contained in:
commit
998ee66650
|
@ -1655,28 +1655,30 @@ class Client {
|
||||||
// Set the new device key for this device
|
// Set the new device key for this device
|
||||||
|
|
||||||
if (!oldKeys.containsKey(deviceId)) {
|
if (!oldKeys.containsKey(deviceId)) {
|
||||||
_userDeviceKeys[userId].deviceKeys[deviceId] =
|
final entry = DeviceKeys.fromJson(rawDeviceKeyEntry.value);
|
||||||
DeviceKeys.fromJson(rawDeviceKeyEntry.value);
|
if (entry.isValid) {
|
||||||
if (deviceId == deviceID &&
|
_userDeviceKeys[userId].deviceKeys[deviceId] = entry;
|
||||||
_userDeviceKeys[userId].deviceKeys[deviceId].ed25519Key ==
|
if (deviceId == deviceID &&
|
||||||
fingerprintKey) {
|
entry.ed25519Key ==
|
||||||
// Always trust the own device
|
fingerprintKey) {
|
||||||
_userDeviceKeys[userId].deviceKeys[deviceId].verified = true;
|
// Always trust the own device
|
||||||
|
entry.verified = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (database != null) {
|
||||||
|
dbActions.add(() => database.storeUserDeviceKey(
|
||||||
|
id,
|
||||||
|
userId,
|
||||||
|
deviceId,
|
||||||
|
json.encode(
|
||||||
|
_userDeviceKeys[userId].deviceKeys[deviceId].toJson()),
|
||||||
|
_userDeviceKeys[userId].deviceKeys[deviceId].verified,
|
||||||
|
_userDeviceKeys[userId].deviceKeys[deviceId].blocked,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
_userDeviceKeys[userId].deviceKeys[deviceId] = oldKeys[deviceId];
|
_userDeviceKeys[userId].deviceKeys[deviceId] = oldKeys[deviceId];
|
||||||
}
|
}
|
||||||
if (database != null) {
|
|
||||||
dbActions.add(() => database.storeUserDeviceKey(
|
|
||||||
id,
|
|
||||||
userId,
|
|
||||||
deviceId,
|
|
||||||
json.encode(
|
|
||||||
_userDeviceKeys[userId].deviceKeys[deviceId].toJson()),
|
|
||||||
_userDeviceKeys[userId].deviceKeys[deviceId].verified,
|
|
||||||
_userDeviceKeys[userId].deviceKeys[deviceId].blocked,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (database != null) {
|
if (database != null) {
|
||||||
for (final oldDeviceKeyEntry in oldKeys.entries) {
|
for (final oldDeviceKeyEntry in oldKeys.entries) {
|
||||||
|
|
|
@ -15,7 +15,12 @@ class DeviceKeysList {
|
||||||
outdated = dbEntry.outdated;
|
outdated = dbEntry.outdated;
|
||||||
deviceKeys = {};
|
deviceKeys = {};
|
||||||
for (final childEntry in childEntries) {
|
for (final childEntry in childEntries) {
|
||||||
deviceKeys[childEntry.deviceId] = DeviceKeys.fromDb(childEntry);
|
final entry = DeviceKeys.fromDb(childEntry);
|
||||||
|
if (entry.isValid) {
|
||||||
|
deviceKeys[childEntry.deviceId] = entry;
|
||||||
|
} else {
|
||||||
|
outdated = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,6 +67,8 @@ class DeviceKeys {
|
||||||
String get curve25519Key => keys['curve25519:$deviceId'];
|
String get curve25519Key => keys['curve25519:$deviceId'];
|
||||||
String get ed25519Key => keys['ed25519:$deviceId'];
|
String get ed25519Key => keys['ed25519:$deviceId'];
|
||||||
|
|
||||||
|
bool get isValid => userId != null && deviceId != null && curve25519Key != null && ed25519Key != null;
|
||||||
|
|
||||||
Future<void> setVerified(bool newVerified, Client client) {
|
Future<void> setVerified(bool newVerified, Client client) {
|
||||||
verified = newVerified;
|
verified = newVerified;
|
||||||
return client.database?.setVerifiedUserDeviceKey(newVerified, client.id, userId, deviceId);
|
return client.database?.setVerifiedUserDeviceKey(newVerified, client.id, userId, deviceId);
|
||||||
|
|
Loading…
Reference in a new issue