Compare commits
10 Commits
fda06cef55
...
v0.2.1
| Author | SHA1 | Date | |
|---|---|---|---|
| b6aa28e1ee | |||
| 2e10842c54 | |||
| 0e2af1f2a3 | |||
| 80e1b20f27 | |||
| f68e45af26 | |||
| 345596923e | |||
| d5d4aa9014 | |||
| ee7b09bdb0 | |||
| 73613e266f | |||
| 0a03483aaf |
11
CHANGELOG.md
11
CHANGELOG.md
@@ -9,3 +9,14 @@
|
|||||||
|
|
||||||
- Fix bug with the Double Ratchet causing only the initial message to be decryptable
|
- Fix bug with the Double Ratchet causing only the initial message to be decryptable
|
||||||
- Expose `getDeviceMap` as a developer usable function
|
- Expose `getDeviceMap` as a developer usable function
|
||||||
|
|
||||||
|
## 0.2.0
|
||||||
|
|
||||||
|
- Add convenience functions `getDeviceId` and `getDeviceBundle`
|
||||||
|
- Creating a new ratchet with an id for which we already have a ratchet will now overwrite the old ratchet
|
||||||
|
- Ratchet now carry an "acknowledged" attribute
|
||||||
|
|
||||||
|
## 0.2.1
|
||||||
|
|
||||||
|
- Add `isRatchetAcknowledged`
|
||||||
|
- Ratchets that are created due to accepting a kex are now unacknowledged
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ Include `omemo_dart` in your `pubspec.yaml` like this:
|
|||||||
dependencies:
|
dependencies:
|
||||||
omemo_dart:
|
omemo_dart:
|
||||||
hosted: https://git.polynom.me/api/packages/PapaTutuWawa/pub
|
hosted: https://git.polynom.me/api/packages/PapaTutuWawa/pub
|
||||||
version: ^0.1.0
|
version: ^0.2.0
|
||||||
# [...]
|
# [...]
|
||||||
|
|
||||||
# [...]
|
# [...]
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ void main() async {
|
|||||||
// a new session. Let's also assume that Bob only has one device. We may, however,
|
// a new session. Let's also assume that Bob only has one device. We may, however,
|
||||||
// add more bundles to newSessions, if we know of more.
|
// add more bundles to newSessions, if we know of more.
|
||||||
newSessions: [
|
newSessions: [
|
||||||
await (await bobSession.getDevice()).toBundle(),
|
await bobSession.getDeviceBundle(),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ class OmemoDoubleRatchet {
|
|||||||
ik,
|
ik,
|
||||||
ad,
|
ad,
|
||||||
{},
|
{},
|
||||||
true,
|
false,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -163,6 +163,23 @@ class Device {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns a new device that is equal to this one with the exception that the new
|
||||||
|
/// device's id is a new number between 0 and 2**32 - 1.
|
||||||
|
@internal
|
||||||
|
Device withNewId() {
|
||||||
|
return Device(
|
||||||
|
jid,
|
||||||
|
generateRandom32BitNumber(),
|
||||||
|
ik,
|
||||||
|
spk,
|
||||||
|
spkId,
|
||||||
|
spkSignature,
|
||||||
|
oldSpk,
|
||||||
|
oldSpkId,
|
||||||
|
opks,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/// Converts this device into an OmemoBundle that could be used for publishing.
|
/// Converts this device into an OmemoBundle that could be used for publishing.
|
||||||
Future<OmemoBundle> toBundle() async {
|
Future<OmemoBundle> toBundle() async {
|
||||||
final encodedOpks = <int, String>{};
|
final encodedOpks = <int, String>{};
|
||||||
|
|||||||
@@ -103,6 +103,18 @@ class OmemoSessionManager {
|
|||||||
|
|
||||||
return dev!;
|
return dev!;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the id attribute of our own device. This is just a short-hand for
|
||||||
|
/// ```await (session.getDevice()).id```.
|
||||||
|
Future<int> getDeviceId() async {
|
||||||
|
return _deviceLock.synchronized(() => _device.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the device as an OmemoBundle. This is just a short-hand for
|
||||||
|
/// ```await (await session.getDevice()).toBundle()```.
|
||||||
|
Future<OmemoBundle> getDeviceBundle() async {
|
||||||
|
return _deviceLock.synchronized(() async => _device.toBundle());
|
||||||
|
}
|
||||||
|
|
||||||
/// Add a session [ratchet] with the [deviceId] to the internal tracking state.
|
/// Add a session [ratchet] with the [deviceId] to the internal tracking state.
|
||||||
Future<void> _addSession(String jid, int deviceId, OmemoDoubleRatchet ratchet) async {
|
Future<void> _addSession(String jid, int deviceId, OmemoDoubleRatchet ratchet) async {
|
||||||
@@ -110,21 +122,22 @@ class OmemoSessionManager {
|
|||||||
// Add the bundle Id
|
// Add the bundle Id
|
||||||
if (!_deviceMap.containsKey(jid)) {
|
if (!_deviceMap.containsKey(jid)) {
|
||||||
_deviceMap[jid] = [deviceId];
|
_deviceMap[jid] = [deviceId];
|
||||||
} else {
|
|
||||||
_deviceMap[jid]!.add(deviceId);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Commit the device map
|
// Commit the device map
|
||||||
_eventStreamController.add(DeviceMapModifiedEvent(_deviceMap));
|
_eventStreamController.add(DeviceMapModifiedEvent(_deviceMap));
|
||||||
|
} else {
|
||||||
|
// Prevent having the same device multiple times in the list
|
||||||
|
if (!_deviceMap[jid]!.contains(deviceId)) {
|
||||||
|
_deviceMap[jid]!.add(deviceId);
|
||||||
|
|
||||||
|
// Commit the device map
|
||||||
|
_eventStreamController.add(DeviceMapModifiedEvent(_deviceMap));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Add the ratchet session
|
// Add the ratchet session
|
||||||
final key = RatchetMapKey(jid, deviceId);
|
final key = RatchetMapKey(jid, deviceId);
|
||||||
if (!_ratchetMap.containsKey(key)) {
|
_ratchetMap[key] = ratchet;
|
||||||
_ratchetMap[key] = ratchet;
|
|
||||||
} else {
|
|
||||||
// TODO(PapaTutuWawa): What do we do now?
|
|
||||||
throw Exception();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Commit the ratchet
|
// Commit the ratchet
|
||||||
_eventStreamController.add(RatchetModifiedEvent(jid, deviceId, ratchet));
|
_eventStreamController.add(RatchetModifiedEvent(jid, deviceId, ratchet));
|
||||||
@@ -433,20 +446,27 @@ class OmemoSessionManager {
|
|||||||
|
|
||||||
/// Returns the list of device identifiers belonging to [jid] that are yet unacked, i.e.
|
/// Returns the list of device identifiers belonging to [jid] that are yet unacked, i.e.
|
||||||
/// we have not yet received an empty OMEMO message from.
|
/// we have not yet received an empty OMEMO message from.
|
||||||
Future<List<int>> getUnacknowledgedRatchets(String jid) async {
|
Future<List<int>?> getUnacknowledgedRatchets(String jid) async {
|
||||||
final ret = List<int>.empty(growable: true);
|
return _lock.synchronized(() async {
|
||||||
|
final ret = List<int>.empty(growable: true);
|
||||||
|
final devices = _deviceMap[jid];
|
||||||
|
if (devices == null) return null;
|
||||||
|
|
||||||
await _lock.synchronized(() async {
|
|
||||||
final devices = _deviceMap[jid]!;
|
|
||||||
for (final device in devices) {
|
for (final device in devices) {
|
||||||
final ratchet = _ratchetMap[RatchetMapKey(jid, device)]!;
|
final ratchet = _ratchetMap[RatchetMapKey(jid, device)]!;
|
||||||
if (!ratchet.acknowledged) ret.add(device);
|
if (!ratchet.acknowledged) ret.add(device);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns true if the ratchet for [jid] with device identifier [deviceId] is
|
||||||
|
/// acknowledged. Returns false if not.
|
||||||
|
Future<bool> isRatchetAcknowledged(String jid, int deviceId) async {
|
||||||
|
return _lock.synchronized(() => _ratchetMap[RatchetMapKey(jid, deviceId)]!.acknowledged);
|
||||||
|
}
|
||||||
|
|
||||||
/// Mark the ratchet for device [deviceId] from [jid] as acked.
|
/// Mark the ratchet for device [deviceId] from [jid] as acked.
|
||||||
Future<void> ratchetAcknowledged(String jid, int deviceId) async {
|
Future<void> ratchetAcknowledged(String jid, int deviceId) async {
|
||||||
await _lock.synchronized(() async {
|
await _lock.synchronized(() async {
|
||||||
@@ -457,6 +477,28 @@ class OmemoSessionManager {
|
|||||||
_eventStreamController.add(RatchetModifiedEvent(jid, deviceId, ratchet));
|
_eventStreamController.add(RatchetModifiedEvent(jid, deviceId, ratchet));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Generates an entirely new device. May be useful when the user wants to reset their cryptographic
|
||||||
|
/// identity. Triggers an event to commit it to storage.
|
||||||
|
Future<void> regenerateDevice({ int opkAmount = 100 }) async {
|
||||||
|
await _deviceLock.synchronized(() async {
|
||||||
|
_device = await Device.generateNewDevice(_device.jid, opkAmount: opkAmount);
|
||||||
|
|
||||||
|
// Commit it
|
||||||
|
_eventStreamController.add(DeviceModifiedEvent(_device));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Make our device have a new identifier. Only useful before publishing it as a bundle
|
||||||
|
/// to make sure that our device has a id that is account unique.
|
||||||
|
Future<void> regenerateDeviceId() async {
|
||||||
|
await _deviceLock.synchronized(() async {
|
||||||
|
_device = _device.withNewId();
|
||||||
|
|
||||||
|
// Commit it
|
||||||
|
_eventStreamController.add(DeviceModifiedEvent(_device));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@visibleForTesting
|
@visibleForTesting
|
||||||
OmemoDoubleRatchet getRatchet(String jid, int deviceId) => _ratchetMap[RatchetMapKey(jid, deviceId)]!;
|
OmemoDoubleRatchet getRatchet(String jid, int deviceId) => _ratchetMap[RatchetMapKey(jid, deviceId)]!;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
name: omemo_dart
|
name: omemo_dart
|
||||||
description: An XMPP library independent OMEMO library
|
description: An XMPP library independent OMEMO library
|
||||||
version: 0.1.3
|
version: 0.2.1
|
||||||
homepage: https://github.com/PapaTutuWawa/omemo_dart
|
homepage: https://github.com/PapaTutuWawa/omemo_dart
|
||||||
publish_to: https://git.polynom.me/api/packages/PapaTutuWawa/pub
|
publish_to: https://git.polynom.me/api/packages/PapaTutuWawa/pub
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ void main() {
|
|||||||
bobJid,
|
bobJid,
|
||||||
messagePlaintext,
|
messagePlaintext,
|
||||||
newSessions: [
|
newSessions: [
|
||||||
await (await bobSession.getDevice()).toBundle(),
|
await bobSession.getDeviceBundle(),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
expect(aliceMessage.encryptedKeys.length, 1);
|
expect(aliceMessage.encryptedKeys.length, 1);
|
||||||
@@ -50,7 +50,7 @@ void main() {
|
|||||||
final bobMessage = await bobSession.decryptMessage(
|
final bobMessage = await bobSession.decryptMessage(
|
||||||
aliceMessage.ciphertext,
|
aliceMessage.ciphertext,
|
||||||
aliceJid,
|
aliceJid,
|
||||||
(await aliceSession.getDevice()).id,
|
await aliceSession.getDeviceId(),
|
||||||
aliceMessage.encryptedKeys,
|
aliceMessage.encryptedKeys,
|
||||||
);
|
);
|
||||||
expect(messagePlaintext, bobMessage);
|
expect(messagePlaintext, bobMessage);
|
||||||
@@ -81,7 +81,7 @@ void main() {
|
|||||||
final aliceReceivedMessage = await aliceSession.decryptMessage(
|
final aliceReceivedMessage = await aliceSession.decryptMessage(
|
||||||
bobResponseMessage.ciphertext,
|
bobResponseMessage.ciphertext,
|
||||||
bobJid,
|
bobJid,
|
||||||
(await bobSession.getDevice()).id,
|
await bobSession.getDeviceId(),
|
||||||
bobResponseMessage.encryptedKeys,
|
bobResponseMessage.encryptedKeys,
|
||||||
);
|
);
|
||||||
expect(bobResponseText, aliceReceivedMessage);
|
expect(bobResponseText, aliceReceivedMessage);
|
||||||
@@ -115,8 +115,8 @@ void main() {
|
|||||||
bobJid,
|
bobJid,
|
||||||
messagePlaintext,
|
messagePlaintext,
|
||||||
newSessions: [
|
newSessions: [
|
||||||
await (await bobSession.getDevice()).toBundle(),
|
await bobSession.getDeviceBundle(),
|
||||||
await (await bobSession2.getDevice()).toBundle(),
|
await bobSession2.getDeviceBundle(),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
expect(aliceMessage.encryptedKeys.length, 2);
|
expect(aliceMessage.encryptedKeys.length, 2);
|
||||||
@@ -130,7 +130,7 @@ void main() {
|
|||||||
final bobMessage = await bobSession.decryptMessage(
|
final bobMessage = await bobSession.decryptMessage(
|
||||||
aliceMessage.ciphertext,
|
aliceMessage.ciphertext,
|
||||||
aliceJid,
|
aliceJid,
|
||||||
(await aliceSession.getDevice()).id,
|
await aliceSession.getDeviceId(),
|
||||||
aliceMessage.encryptedKeys,
|
aliceMessage.encryptedKeys,
|
||||||
);
|
);
|
||||||
expect(messagePlaintext, bobMessage);
|
expect(messagePlaintext, bobMessage);
|
||||||
@@ -149,7 +149,7 @@ void main() {
|
|||||||
final aliceReceivedMessage = await aliceSession.decryptMessage(
|
final aliceReceivedMessage = await aliceSession.decryptMessage(
|
||||||
bobResponseMessage.ciphertext,
|
bobResponseMessage.ciphertext,
|
||||||
bobJid,
|
bobJid,
|
||||||
(await bobSession.getDevice()).id,
|
await bobSession.getDeviceId(),
|
||||||
bobResponseMessage.encryptedKeys,
|
bobResponseMessage.encryptedKeys,
|
||||||
);
|
);
|
||||||
expect(bobResponseText, aliceReceivedMessage);
|
expect(bobResponseText, aliceReceivedMessage);
|
||||||
@@ -192,8 +192,8 @@ void main() {
|
|||||||
[bobJid, aliceJid],
|
[bobJid, aliceJid],
|
||||||
messagePlaintext,
|
messagePlaintext,
|
||||||
newSessions: [
|
newSessions: [
|
||||||
await (await bobSession.getDevice()).toBundle(),
|
await bobSession.getDeviceBundle(),
|
||||||
await (await aliceSession2.getDevice()).toBundle(),
|
await aliceSession2.getDeviceBundle(),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
expect(aliceMessage.encryptedKeys.length, 2);
|
expect(aliceMessage.encryptedKeys.length, 2);
|
||||||
@@ -205,7 +205,7 @@ void main() {
|
|||||||
final bobMessage = await bobSession.decryptMessage(
|
final bobMessage = await bobSession.decryptMessage(
|
||||||
aliceMessage.ciphertext,
|
aliceMessage.ciphertext,
|
||||||
aliceJid,
|
aliceJid,
|
||||||
(await aliceSession1.getDevice()).id,
|
await aliceSession1.getDeviceId(),
|
||||||
aliceMessage.encryptedKeys,
|
aliceMessage.encryptedKeys,
|
||||||
);
|
);
|
||||||
expect(messagePlaintext, bobMessage);
|
expect(messagePlaintext, bobMessage);
|
||||||
@@ -214,7 +214,7 @@ void main() {
|
|||||||
final aliceMessage2 = await aliceSession2.decryptMessage(
|
final aliceMessage2 = await aliceSession2.decryptMessage(
|
||||||
aliceMessage.ciphertext,
|
aliceMessage.ciphertext,
|
||||||
aliceJid,
|
aliceJid,
|
||||||
(await aliceSession1.getDevice()).id,
|
await aliceSession1.getDeviceId(),
|
||||||
aliceMessage.encryptedKeys,
|
aliceMessage.encryptedKeys,
|
||||||
);
|
);
|
||||||
expect(messagePlaintext, aliceMessage2);
|
expect(messagePlaintext, aliceMessage2);
|
||||||
@@ -241,7 +241,7 @@ void main() {
|
|||||||
bobJid,
|
bobJid,
|
||||||
null,
|
null,
|
||||||
newSessions: [
|
newSessions: [
|
||||||
await (await bobSession.getDevice()).toBundle(),
|
await bobSession.getDeviceBundle(),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
expect(aliceMessage.encryptedKeys.length, 1);
|
expect(aliceMessage.encryptedKeys.length, 1);
|
||||||
@@ -254,13 +254,13 @@ void main() {
|
|||||||
final bobMessage = await bobSession.decryptMessage(
|
final bobMessage = await bobSession.decryptMessage(
|
||||||
aliceMessage.ciphertext,
|
aliceMessage.ciphertext,
|
||||||
aliceJid,
|
aliceJid,
|
||||||
(await aliceSession.getDevice()).id,
|
await aliceSession.getDeviceId(),
|
||||||
aliceMessage.encryptedKeys,
|
aliceMessage.encryptedKeys,
|
||||||
);
|
);
|
||||||
expect(bobMessage, null);
|
expect(bobMessage, null);
|
||||||
|
|
||||||
// This call must not cause an exception
|
// This call must not cause an exception
|
||||||
bobSession.getRatchet(aliceJid, (await aliceSession.getDevice()).id);
|
bobSession.getRatchet(aliceJid, await aliceSession.getDeviceId());
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Test rotating the Signed Prekey', () async {
|
test('Test rotating the Signed Prekey', () async {
|
||||||
@@ -316,7 +316,7 @@ void main() {
|
|||||||
bobJid,
|
bobJid,
|
||||||
messagePlaintext,
|
messagePlaintext,
|
||||||
newSessions: [
|
newSessions: [
|
||||||
await (await bobSession.getDevice()).toBundle(),
|
await bobSession.getDeviceBundle(),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
expect(aliceMessage.encryptedKeys.length, 1);
|
expect(aliceMessage.encryptedKeys.length, 1);
|
||||||
@@ -331,7 +331,7 @@ void main() {
|
|||||||
final bobMessage = await bobSession.decryptMessage(
|
final bobMessage = await bobSession.decryptMessage(
|
||||||
aliceMessage.ciphertext,
|
aliceMessage.ciphertext,
|
||||||
aliceJid,
|
aliceJid,
|
||||||
(await aliceSession.getDevice()).id,
|
await aliceSession.getDeviceId(),
|
||||||
aliceMessage.encryptedKeys,
|
aliceMessage.encryptedKeys,
|
||||||
);
|
);
|
||||||
expect(messagePlaintext, bobMessage);
|
expect(messagePlaintext, bobMessage);
|
||||||
@@ -358,7 +358,7 @@ void main() {
|
|||||||
bobJid,
|
bobJid,
|
||||||
null,
|
null,
|
||||||
newSessions: [
|
newSessions: [
|
||||||
await (await bobSession.getDevice()).toBundle(),
|
await bobSession.getDeviceBundle(),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -387,7 +387,7 @@ void main() {
|
|||||||
bobJid,
|
bobJid,
|
||||||
'Hello Bob!',
|
'Hello Bob!',
|
||||||
newSessions: [
|
newSessions: [
|
||||||
await (await bobSession.getDevice()).toBundle(),
|
await bobSession.getDeviceBundle(),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -397,7 +397,7 @@ void main() {
|
|||||||
await bobSession.decryptMessage(
|
await bobSession.decryptMessage(
|
||||||
aliceMessage.ciphertext,
|
aliceMessage.ciphertext,
|
||||||
aliceJid,
|
aliceJid,
|
||||||
(await aliceSession.getDevice()).id,
|
await aliceSession.getDeviceId(),
|
||||||
aliceMessage.encryptedKeys,
|
aliceMessage.encryptedKeys,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -416,7 +416,7 @@ void main() {
|
|||||||
final aliceReceivedMessage = await aliceSession.decryptMessage(
|
final aliceReceivedMessage = await aliceSession.decryptMessage(
|
||||||
bobResponseMessage.ciphertext,
|
bobResponseMessage.ciphertext,
|
||||||
bobJid,
|
bobJid,
|
||||||
(await bobSession.getDevice()).id,
|
await bobSession.getDeviceId(),
|
||||||
bobResponseMessage.encryptedKeys,
|
bobResponseMessage.encryptedKeys,
|
||||||
);
|
);
|
||||||
expect(messageText, aliceReceivedMessage);
|
expect(messageText, aliceReceivedMessage);
|
||||||
@@ -448,14 +448,14 @@ void main() {
|
|||||||
bobJid,
|
bobJid,
|
||||||
'Hallo Welt',
|
'Hallo Welt',
|
||||||
newSessions: [
|
newSessions: [
|
||||||
await (await bobSession1.getDevice()).toBundle(),
|
await bobSession1.getDeviceBundle(),
|
||||||
await (await bobSession2.getDevice()).toBundle(),
|
await bobSession2.getDeviceBundle(),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
// One of those two sessions is broken, so Alice removes the session2 ratchet
|
// One of those two sessions is broken, so Alice removes the session2 ratchet
|
||||||
final id1 = (await bobSession1.getDevice()).id;
|
final id1 = await bobSession1.getDeviceId();
|
||||||
final id2 = (await bobSession2.getDevice()).id;
|
final id2 = await bobSession2.getDeviceId();
|
||||||
await aliceSession.removeRatchet(bobJid, id1);
|
await aliceSession.removeRatchet(bobJid, id1);
|
||||||
|
|
||||||
final map = aliceSession.getRatchetMap();
|
final map = aliceSession.getRatchetMap();
|
||||||
@@ -485,12 +485,12 @@ void main() {
|
|||||||
bobJid,
|
bobJid,
|
||||||
'Hallo Welt',
|
'Hallo Welt',
|
||||||
newSessions: [
|
newSessions: [
|
||||||
await (await bobSession.getDevice()).toBundle(),
|
await bobSession.getDeviceBundle(),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
// One of those two sessions is broken, so Alice removes the session2 ratchet
|
// One of those two sessions is broken, so Alice removes the session2 ratchet
|
||||||
final id = (await bobSession.getDevice()).id;
|
final id = await bobSession.getDeviceId();
|
||||||
await aliceSession.removeRatchet(bobJid, id);
|
await aliceSession.removeRatchet(bobJid, id);
|
||||||
|
|
||||||
final map = aliceSession.getRatchetMap();
|
final map = aliceSession.getRatchetMap();
|
||||||
@@ -520,13 +520,13 @@ void main() {
|
|||||||
bobJid,
|
bobJid,
|
||||||
'Hallo Welt',
|
'Hallo Welt',
|
||||||
newSessions: [
|
newSessions: [
|
||||||
await (await bobSession.getDevice()).toBundle(),
|
await bobSession.getDeviceBundle(),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
expect(
|
expect(
|
||||||
await aliceSession.getUnacknowledgedRatchets(bobJid),
|
await aliceSession.getUnacknowledgedRatchets(bobJid),
|
||||||
[
|
[
|
||||||
(await bobSession.getDevice()).id,
|
await bobSession.getDeviceId(),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -537,10 +537,81 @@ void main() {
|
|||||||
// ...
|
// ...
|
||||||
|
|
||||||
// Alice marks the ratchet as acknowledged
|
// Alice marks the ratchet as acknowledged
|
||||||
await aliceSession.ratchetAcknowledged(bobJid, (await bobSession.getDevice()).id);
|
await aliceSession.ratchetAcknowledged(bobJid, await bobSession.getDeviceId());
|
||||||
expect(
|
expect(
|
||||||
(await aliceSession.getUnacknowledgedRatchets(bobJid)).isEmpty,
|
(await aliceSession.getUnacknowledgedRatchets(bobJid))!.isEmpty,
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Test overwriting sessions', () async {
|
||||||
|
const aliceJid = 'alice@server.example';
|
||||||
|
const bobJid = 'bob@other.server.example';
|
||||||
|
// Alice and Bob generate their sessions
|
||||||
|
final aliceSession = await OmemoSessionManager.generateNewIdentity(
|
||||||
|
aliceJid,
|
||||||
|
AlwaysTrustingTrustManager(),
|
||||||
|
opkAmount: 1,
|
||||||
|
);
|
||||||
|
final bobSession = await OmemoSessionManager.generateNewIdentity(
|
||||||
|
bobJid,
|
||||||
|
AlwaysTrustingTrustManager(),
|
||||||
|
opkAmount: 2,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Alice sends Bob a message
|
||||||
|
final msg1 = await aliceSession.encryptToJid(
|
||||||
|
bobJid,
|
||||||
|
'Hallo Welt',
|
||||||
|
newSessions: [
|
||||||
|
await bobSession.getDeviceBundle(),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
await bobSession.decryptMessage(
|
||||||
|
msg1.ciphertext,
|
||||||
|
aliceJid,
|
||||||
|
await aliceSession.getDeviceId(),
|
||||||
|
msg1.encryptedKeys,
|
||||||
|
);
|
||||||
|
final aliceRatchet1 = aliceSession.getRatchet(
|
||||||
|
bobJid,
|
||||||
|
await bobSession.getDeviceId(),
|
||||||
|
);
|
||||||
|
final bobRatchet1 = bobSession.getRatchet(
|
||||||
|
aliceJid,
|
||||||
|
await aliceSession.getDeviceId(),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Alice is impatient and immediately sends another message before the original one
|
||||||
|
// can be acknowledged by Bob
|
||||||
|
final msg2 = await aliceSession.encryptToJid(
|
||||||
|
bobJid,
|
||||||
|
"Why don't you answer?",
|
||||||
|
newSessions: [
|
||||||
|
await bobSession.getDeviceBundle(),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
await bobSession.decryptMessage(
|
||||||
|
msg2.ciphertext,
|
||||||
|
aliceJid,
|
||||||
|
await aliceSession.getDeviceId(),
|
||||||
|
msg2.encryptedKeys,
|
||||||
|
);
|
||||||
|
final aliceRatchet2 = aliceSession.getRatchet(
|
||||||
|
bobJid,
|
||||||
|
await bobSession.getDeviceId(),
|
||||||
|
);
|
||||||
|
final bobRatchet2 = bobSession.getRatchet(
|
||||||
|
aliceJid,
|
||||||
|
await aliceSession.getDeviceId(),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Both should only have one ratchet
|
||||||
|
expect(aliceSession.getRatchetMap().length, 1);
|
||||||
|
expect(bobSession.getRatchetMap().length, 1);
|
||||||
|
|
||||||
|
// The ratchets should both be different
|
||||||
|
expect(await aliceRatchet1.equals(aliceRatchet2), false);
|
||||||
|
expect(await bobRatchet1.equals(bobRatchet2), false);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,16 +49,16 @@ void main() {
|
|||||||
bobJid,
|
bobJid,
|
||||||
'Hello Bob!',
|
'Hello Bob!',
|
||||||
newSessions: [
|
newSessions: [
|
||||||
await (await bobSession.getDevice()).toBundle(),
|
await bobSession.getDeviceBundle(),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
await bobSession.decryptMessage(
|
await bobSession.decryptMessage(
|
||||||
aliceMessage.ciphertext,
|
aliceMessage.ciphertext,
|
||||||
aliceJid,
|
aliceJid,
|
||||||
(await aliceSession.getDevice()).id,
|
await aliceSession.getDeviceId(),
|
||||||
aliceMessage.encryptedKeys,
|
aliceMessage.encryptedKeys,
|
||||||
);
|
);
|
||||||
final aliceOld = aliceSession.getRatchet(bobJid, (await bobSession.getDevice()).id);
|
final aliceOld = aliceSession.getRatchet(bobJid, await bobSession.getDeviceId());
|
||||||
final aliceSerialised = await aliceOld.toJson();
|
final aliceSerialised = await aliceOld.toJson();
|
||||||
final aliceNew = OmemoDoubleRatchet.fromJson(aliceSerialised);
|
final aliceNew = OmemoDoubleRatchet.fromJson(aliceSerialised);
|
||||||
|
|
||||||
@@ -79,8 +79,8 @@ void main() {
|
|||||||
);
|
);
|
||||||
await oldSession.addSessionFromBundle(
|
await oldSession.addSessionFromBundle(
|
||||||
'bob@localhost',
|
'bob@localhost',
|
||||||
(await bobSession.getDevice()).id,
|
await bobSession.getDeviceId(),
|
||||||
await (await bobSession.getDevice()).toBundle(),
|
await bobSession.getDeviceBundle(),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Serialise and deserialise
|
// Serialise and deserialise
|
||||||
|
|||||||
Reference in New Issue
Block a user