fix: Track new KEX entries using a ratchet key

This commit is contained in:
PapaTutuWawa 2022-12-27 12:47:45 +01:00
parent 5f844dafda
commit 6a9e98665d

View File

@ -435,10 +435,10 @@ class OmemoManager {
keyPayload = List<int>.filled(32, 0x0); keyPayload = List<int>.filled(32, 0x0);
} }
final kex = <int, OmemoKeyExchange>{}; final kex = <RatchetMapKey, OmemoKeyExchange>{};
for (final jid in jids) { for (final jid in jids) {
for (final newSession in await _fetchNewBundles(jid)) { for (final newSession in await _fetchNewBundles(jid)) {
kex[newSession.id] = await addSessionFromBundle( kex[RatchetMapKey(jid, newSession.id)] = await addSessionFromBundle(
newSession.jid, newSession.jid,
newSession.id, newSession.id,
newSession, newSession,
@ -477,9 +477,9 @@ class OmemoManager {
final ciphertext = (await ratchet.ratchetEncrypt(keyPayload)).ciphertext; final ciphertext = (await ratchet.ratchetEncrypt(keyPayload)).ciphertext;
if (kex.isNotEmpty && kex.containsKey(deviceId)) { if (kex.containsKey(ratchetKey)) {
// The ratchet did not exist // The ratchet did not exist
final k = kex[deviceId]! final k = kex[ratchetKey]!
..message = OmemoAuthenticatedMessage.fromBuffer(ciphertext); ..message = OmemoAuthenticatedMessage.fromBuffer(ciphertext);
final buffer = base64.encode(k.writeToBuffer()); final buffer = base64.encode(k.writeToBuffer());
encryptedKeys.add( encryptedKeys.add(
@ -656,7 +656,7 @@ class OmemoManager {
Future<Device> getDevice() => _deviceLock.synchronized(() => _device); Future<Device> getDevice() => _deviceLock.synchronized(() => _device);
/// Returns the id of the device used for encryption and decryption. /// Returns the id of the device used for encryption and decryption.
Future<int> getDeviceId() => (await getDevice()).id; Future<int> getDeviceId() async => (await getDevice()).id;
/// Returns the fingerprints for all devices of [jid] that we have a session with. /// Returns the fingerprints for all devices of [jid] that we have a session with.
/// If there are not sessions with [jid], then returns null. /// If there are not sessions with [jid], then returns null.