4 Commits

Author SHA1 Message Date
e29ee07015 release: Tag 0.4.2
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2023-01-07 22:16:15 +01:00
cc31475671 fix: Ratchets are not removed when using removeAllRatchets
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-01-07 22:14:10 +01:00
de85ab7955 chore: Bump version
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2023-01-02 13:57:15 +01:00
a08c654295 feat: Do not fetch bundles for our own device 2023-01-02 13:56:22 +01:00
4 changed files with 102 additions and 7 deletions

View File

@@ -42,3 +42,11 @@
- Implement queued access to the ratchets inside the `OmemoManager`.
- Implement heartbeat messages.
- [BREAKING] Rename `Device` to `OmemoDevice`.
## 0.4.1
- Fix fetching the current device and building a ratchet session with it when encrypting for our own JID
## 0.4.2
- Fix removeAllRatchets not removing, well, all ratchets. In fact, it did not remove any ratchet.

View File

@@ -277,7 +277,7 @@ class OmemoManager {
if (rawKey.kex) {
// If the ratchet already existed, we store it. If it didn't, oldRatchet will stay
// null.
final oldRatchet = _getRatchet(ratchetKey)?.clone();
final oldRatchet = getRatchet(ratchetKey)?.clone();
final kex = OmemoKeyExchange.fromBuffer(decodedRawKey);
authMessage = kex.message!;
message = OmemoMessage.fromBuffer(authMessage.message!);
@@ -341,7 +341,7 @@ class OmemoManager {
}
// We can guarantee that the ratchet exists at this point in time
final ratchet = _getRatchet(ratchetKey)!;
final ratchet = getRatchet(ratchetKey)!;
oldRatchet ??= ratchet.clone();
try {
@@ -378,7 +378,8 @@ class OmemoManager {
/// Returns, if it exists, the ratchet associated with [key].
/// NOTE: Must be called from within the ratchet critical section.
OmemoDoubleRatchet? _getRatchet(RatchetMapKey key) => _ratchetMap[key];
@visibleForTesting
OmemoDoubleRatchet? getRatchet(RatchetMapKey key) => _ratchetMap[key];
/// Figure out what bundles we have to still build a session with.
Future<List<OmemoBundle>> _fetchNewBundles(String jid) async {
@@ -408,9 +409,12 @@ class OmemoManager {
if (bundlesToFetch.isNotEmpty) {
_log.finest('Fetching bundles $bundlesToFetch for $jid');
}
final device = await getDevice();
final newBundles = List<OmemoBundle>.empty(growable: true);
for (final id in bundlesToFetch) {
if (jid == device.jid && id == device.id) continue;
final bundle = await fetchDeviceBundleImpl(jid, id);
if (bundle != null) newBundles.add(bundle);
}
@@ -591,7 +595,7 @@ class OmemoManager {
}
// Check if the ratchet is acked
final ratchet = _getRatchet(ratchetKey);
final ratchet = getRatchet(ratchetKey);
assert(ratchet != null, 'We decrypted the message, so the ratchet must exist');
if (ratchet!.acknowledged) {
@@ -759,7 +763,7 @@ class OmemoManager {
for (final deviceId in _deviceList[jid]!) {
// Remove the ratchet and commit it
_ratchetMap.remove(jid);
_ratchetMap.remove(RatchetMapKey(jid, deviceId));
_eventStreamController.add(RatchetRemovedEvent(jid, deviceId));
}

View File

@@ -1,6 +1,6 @@
name: omemo_dart
description: An XMPP library independent OMEMO library
version: 0.4.0
version: 0.4.2
homepage: https://github.com/PapaTutuWawa/omemo_dart
publish_to: https://git.polynom.me/api/packages/PapaTutuWawa/pub

View File

@@ -942,4 +942,87 @@ void main() {
expect(aliceReceivedMessage.payload, messageText);
}
});
test('Test removing all ratchets and sending a message', () async {
const aliceJid = 'alice@server1';
const bobJid = 'bob@server2';
final aliceDevice = await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
final bobDevice = await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
final aliceManager = OmemoManager(
aliceDevice,
AlwaysTrustingTrustManager(),
(result, recipientJid) async {},
(jid) async {
expect(jid, bobJid);
return [bobDevice.id];
},
(jid, id) async {
expect(jid, bobJid);
return bobDevice.toBundle();
},
(jid) async {},
);
final bobManager = OmemoManager(
bobDevice,
AlwaysTrustingTrustManager(),
(result, recipientJid) async {},
(jid) async => null,
(jid, id) async => null,
(jid) async {},
);
// Alice encrypts a message for Bob
final aliceResult1 = await aliceManager.onOutgoingStanza(
const OmemoOutgoingStanza(
[bobJid],
'Hello Bob!',
),
);
// And Bob decrypts it
await bobManager.onIncomingStanza(
OmemoIncomingStanza(
aliceJid,
aliceDevice.id,
DateTime.now().millisecondsSinceEpoch,
aliceResult1.encryptedKeys,
base64.encode(aliceResult1.ciphertext!),
),
);
// Ratchets are acked
await aliceManager.ratchetAcknowledged(
bobJid,
bobDevice.id,
);
// Alice now removes all ratchets for Bob and sends another new message
await aliceManager.removeAllRatchets(bobJid);
expect(aliceManager.getRatchet(RatchetMapKey(bobJid, bobDevice.id)), null);
final aliceResult2 = await aliceManager.onOutgoingStanza(
const OmemoOutgoingStanza(
[bobJid],
'I did not trust your last device, Bob!',
),
);
// Bob decrypts it
final bobResult2 = await bobManager.onIncomingStanza(
OmemoIncomingStanza(
aliceJid,
aliceDevice.id,
DateTime.now().millisecondsSinceEpoch,
aliceResult2.encryptedKeys,
base64.encode(aliceResult2.ciphertext!),
),
);
expect(bobResult2.payload, 'I did not trust your last device, Bob!');
});
}