feat: Implement getting fingerprints
This commit is contained in:
parent
af33ed51d1
commit
f1ec8d1793
@ -1,4 +1,3 @@
|
||||
import 'dart:convert';
|
||||
import 'package:cryptography/cryptography.dart';
|
||||
import 'package:hex/hex.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
@ -356,6 +355,7 @@ class OmemoDoubleRatchet {
|
||||
..message = headerBytes;
|
||||
}
|
||||
|
||||
/// Returns a copy of the ratchet.
|
||||
OmemoDoubleRatchet clone() {
|
||||
return OmemoDoubleRatchet(
|
||||
dhs,
|
||||
@ -375,6 +375,15 @@ class OmemoDoubleRatchet {
|
||||
);
|
||||
}
|
||||
|
||||
/// Computes the fingerprint of the double ratchet, according to
|
||||
/// XEP-0384.
|
||||
Future<String> get fingerprint async {
|
||||
final curveKey = await ik.toCurve25519();
|
||||
return HEX.encode(
|
||||
await curveKey.getBytes(),
|
||||
);
|
||||
}
|
||||
|
||||
@visibleForTesting
|
||||
Future<bool> equals(OmemoDoubleRatchet other) async {
|
||||
final dhrMatch = dhr == null
|
||||
|
@ -755,8 +755,43 @@ class OmemoManager {
|
||||
await _leaveRatchetCriticalSection(jid);
|
||||
}
|
||||
|
||||
// TODO
|
||||
Future<List<DeviceFingerprint>?> getFingerprintsForJid(String jid) async => null;
|
||||
/// If ratchets with [jid] exists, returns a list of fingerprints for each
|
||||
/// ratchet.
|
||||
///
|
||||
/// If not ratchets exists, returns null.
|
||||
Future<List<DeviceFingerprint>?> getFingerprintsForJid(String jid) async {
|
||||
await _getFingerprintsForJidImpl(jid);
|
||||
final result = await _getFingerprintsForJidImpl(jid);
|
||||
await _leaveRatchetCriticalSection(jid);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Future<List<DeviceFingerprint>?> _getFingerprintsForJidImpl(String jid) async {
|
||||
// Check if we know of the JID.
|
||||
if (!_deviceList.containsKey(jid)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final devices = _deviceList[jid]!;
|
||||
final fingerprints = List<DeviceFingerprint>.empty(growable: true);
|
||||
for (final device in devices) {
|
||||
final ratchet = _ratchetMap[RatchetMapKey(jid, device)];
|
||||
if (ratchet == null) {
|
||||
_log.warning('getFingerprintsForJid: Ratchet $jid:$device not found.');
|
||||
continue;
|
||||
}
|
||||
|
||||
fingerprints.add(
|
||||
DeviceFingerprint(
|
||||
device,
|
||||
await ratchet.fingerprint,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return fingerprints;
|
||||
}
|
||||
|
||||
/// Returns the device used for encryption and decryption.
|
||||
Future<OmemoDevice> getDevice() => _deviceLock.synchronized(() => _device);
|
||||
|
Loading…
Reference in New Issue
Block a user