feat: start verification with the verified device
This commit is contained in:
parent
ffb37e834f
commit
44f862b966
|
|
@ -159,17 +159,21 @@ class KeyVerification {
|
||||||
return methods;
|
return methods;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> sendStart() async {
|
Future<void> sendStart({List<Device>? verifiedDevices}) async {
|
||||||
await send(EventTypes.KeyVerificationRequest, {
|
await send(
|
||||||
'methods': knownVerificationMethods,
|
EventTypes.KeyVerificationRequest,
|
||||||
if (room == null) 'timestamp': DateTime.now().millisecondsSinceEpoch,
|
{
|
||||||
});
|
'methods': knownVerificationMethods,
|
||||||
|
if (room == null) 'timestamp': DateTime.now().millisecondsSinceEpoch,
|
||||||
|
},
|
||||||
|
verifiedDevices: verifiedDevices,
|
||||||
|
);
|
||||||
startedVerification = true;
|
startedVerification = true;
|
||||||
setState(KeyVerificationState.waitingAccept);
|
setState(KeyVerificationState.waitingAccept);
|
||||||
lastActivity = DateTime.now();
|
lastActivity = DateTime.now();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> start() async {
|
Future<void> start({List<Device>? verifiedDevices}) async {
|
||||||
if (room == null) {
|
if (room == null) {
|
||||||
transactionId = client.generateUniqueTransactionId();
|
transactionId = client.generateUniqueTransactionId();
|
||||||
}
|
}
|
||||||
|
|
@ -179,7 +183,9 @@ class KeyVerification {
|
||||||
setState(KeyVerificationState.askSSSS);
|
setState(KeyVerificationState.askSSSS);
|
||||||
_nextAction = 'request';
|
_nextAction = 'request';
|
||||||
} else {
|
} else {
|
||||||
await sendStart();
|
await sendStart(
|
||||||
|
verifiedDevices: verifiedDevices,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -604,7 +610,8 @@ class KeyVerification {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> send(String type, Map<String, dynamic> payload) async {
|
Future<void> send(String type, Map<String, dynamic> payload,
|
||||||
|
{List<Device>? verifiedDevices}) async {
|
||||||
makePayload(payload);
|
makePayload(payload);
|
||||||
Logs().i('[Key Verification] Sending type $type: $payload');
|
Logs().i('[Key Verification] Sending type $type: $payload');
|
||||||
if (room != null) {
|
if (room != null) {
|
||||||
|
|
@ -628,7 +635,19 @@ class KeyVerification {
|
||||||
EventTypes.KeyVerificationRequest,
|
EventTypes.KeyVerificationRequest,
|
||||||
EventTypes.KeyVerificationCancel,
|
EventTypes.KeyVerificationCancel,
|
||||||
}.contains(type)) {
|
}.contains(type)) {
|
||||||
await client.sendToDevicesOfUserIds({userId}, type, payload);
|
if (verifiedDevices == null || verifiedDevices.isEmpty) {
|
||||||
|
await client.sendToDevicesOfUserIds({userId}, type, payload);
|
||||||
|
} else {
|
||||||
|
final deviceKeys = client.userDeviceKeys[userId]?.deviceKeys;
|
||||||
|
deviceKeys?.removeWhere((key, value) =>
|
||||||
|
verifiedDevices.map((e) => e.deviceId).toList().contains(key) ==
|
||||||
|
false);
|
||||||
|
await client.sendToDeviceEncrypted(
|
||||||
|
deviceKeys!.values.toList(),
|
||||||
|
type,
|
||||||
|
payload,
|
||||||
|
);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Logs().e(
|
Logs().e(
|
||||||
'[Key Verification] Tried to broadcast and un-broadcastable type: $type');
|
'[Key Verification] Tried to broadcast and un-broadcastable type: $type');
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,7 @@ class DeviceKeysList {
|
||||||
Future<KeyVerification> startVerification({
|
Future<KeyVerification> startVerification({
|
||||||
bool? newDirectChatEnableEncryption,
|
bool? newDirectChatEnableEncryption,
|
||||||
List<StateEvent>? newDirectChatInitialState,
|
List<StateEvent>? newDirectChatInitialState,
|
||||||
|
List<Device>? verifiedDevice,
|
||||||
}) async {
|
}) async {
|
||||||
final encryption = client.encryption;
|
final encryption = client.encryption;
|
||||||
if (encryption == null) {
|
if (encryption == null) {
|
||||||
|
|
@ -93,10 +94,12 @@ class DeviceKeysList {
|
||||||
// verification request that'll happen automatically once we know the transaction id
|
// verification request that'll happen automatically once we know the transaction id
|
||||||
return request;
|
return request;
|
||||||
} else {
|
} else {
|
||||||
// broadcast self-verification
|
// start verification with verified devices
|
||||||
final request = KeyVerification(
|
final request = KeyVerification(
|
||||||
encryption: encryption, userId: userId, deviceId: '*');
|
encryption: encryption, userId: userId, deviceId: '*');
|
||||||
await request.start();
|
await request.start(
|
||||||
|
verifiedDevices: verifiedDevice,
|
||||||
|
);
|
||||||
encryption.keyVerificationManager.addRequest(request);
|
encryption.keyVerificationManager.addRequest(request);
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue