Compare commits
6 Commits
dad707f71d
...
v0.1.3
| Author | SHA1 | Date | |
|---|---|---|---|
| 44ab31aebb | |||
| e4f1d7d4b0 | |||
| 7600804aa1 | |||
| a4589b6e09 | |||
| d0986a4608 | |||
| 683a76cc80 |
@@ -4,3 +4,8 @@
|
|||||||
- Implement the Double Ratchet, X3DH and OMEMO specific bits
|
- Implement the Double Ratchet, X3DH and OMEMO specific bits
|
||||||
- Add a Blind-Trust-Before-Verification TrustManager
|
- Add a Blind-Trust-Before-Verification TrustManager
|
||||||
- Supported OMEMO version: 0.8.3
|
- Supported OMEMO version: 0.8.3
|
||||||
|
|
||||||
|
## 0.1.3
|
||||||
|
|
||||||
|
- Fix bug with the Double Ratchet causing only the initial message to be decryptable
|
||||||
|
- Expose `getDeviceMap` as a developer usable function
|
||||||
|
|||||||
@@ -26,10 +26,10 @@ 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.1.0
|
||||||
# [...]
|
# [...]
|
||||||
|
|
||||||
# [...]
|
# [...]
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -293,11 +293,15 @@ class OmemoDoubleRatchet {
|
|||||||
return plaintext;
|
return plaintext;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (header.dhPub != await dhr?.getBytes()) {
|
final dhPubMatches = listsEqual(
|
||||||
|
header.dhPub ?? <int>[],
|
||||||
|
await dhr?.getBytes() ?? <int>[],
|
||||||
|
);
|
||||||
|
if (!dhPubMatches) {
|
||||||
await _skipMessageKeys(header.pn!);
|
await _skipMessageKeys(header.pn!);
|
||||||
await _dhRatchet(header);
|
await _dhRatchet(header);
|
||||||
}
|
}
|
||||||
|
|
||||||
await _skipMessageKeys(header.n!);
|
await _skipMessageKeys(header.n!);
|
||||||
final newCkr = await kdfCk(ckr!, kdfCkNextChainKey);
|
final newCkr = await kdfCk(ckr!, kdfCkNextChainKey);
|
||||||
final mk = await kdfCk(ckr!, kdfCkNextMessageKey);
|
final mk = await kdfCk(ckr!, kdfCkNextMessageKey);
|
||||||
|
|||||||
@@ -386,13 +386,22 @@ class OmemoSessionManager {
|
|||||||
_eventStreamController.add(DeviceModifiedEvent(_device));
|
_eventStreamController.add(DeviceModifiedEvent(_device));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the device map, i.e. the mapping of bare Jid to its device identifiers
|
||||||
|
/// we have built sessions with.
|
||||||
|
Future<Map<String, List<int>>> getDeviceMap() async {
|
||||||
|
Map<String, List<int>>? map;
|
||||||
|
|
||||||
|
await _lock.synchronized(() async {
|
||||||
|
map = _deviceMap;
|
||||||
|
});
|
||||||
|
|
||||||
|
return map!;
|
||||||
|
}
|
||||||
|
|
||||||
@visibleForTesting
|
@visibleForTesting
|
||||||
OmemoDoubleRatchet getRatchet(String jid, int deviceId) => _ratchetMap[RatchetMapKey(jid, deviceId)]!;
|
OmemoDoubleRatchet getRatchet(String jid, int deviceId) => _ratchetMap[RatchetMapKey(jid, deviceId)]!;
|
||||||
|
|
||||||
@visibleForTesting
|
|
||||||
Map<String, List<int>> getDeviceMap() => _deviceMap;
|
|
||||||
|
|
||||||
@visibleForTesting
|
@visibleForTesting
|
||||||
Map<RatchetMapKey, OmemoDoubleRatchet> getRatchetMap() => _ratchetMap;
|
Map<RatchetMapKey, OmemoDoubleRatchet> getRatchetMap() => _ratchetMap;
|
||||||
|
|
||||||
|
|||||||
@@ -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.2
|
version: 0.1.3
|
||||||
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
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ void main() {
|
|||||||
test('Test using OMEMO sessions with only one device per user', () async {
|
test('Test using OMEMO sessions with only one device per user', () async {
|
||||||
const aliceJid = 'alice@server.example';
|
const aliceJid = 'alice@server.example';
|
||||||
const bobJid = 'bob@other.server.example';
|
const bobJid = 'bob@other.server.example';
|
||||||
|
|
||||||
// Alice and Bob generate their sessions
|
// Alice and Bob generate their sessions
|
||||||
var deviceModified = false;
|
var deviceModified = false;
|
||||||
var ratchetModified = 0;
|
var ratchetModified = 0;
|
||||||
@@ -367,4 +366,60 @@ void main() {
|
|||||||
// untrusted device.
|
// untrusted device.
|
||||||
expect(aliceMessage.encryptedKeys.length, 1);
|
expect(aliceMessage.encryptedKeys.length, 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Test by sending multiple messages back and forth', () 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: 1,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Alice encrypts a message for Bob
|
||||||
|
final aliceMessage = await aliceSession.encryptToJid(
|
||||||
|
bobJid,
|
||||||
|
'Hello Bob!',
|
||||||
|
newSessions: [
|
||||||
|
await (await bobSession.getDevice()).toBundle(),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
// Alice sends the message to Bob
|
||||||
|
// ...
|
||||||
|
|
||||||
|
await bobSession.decryptMessage(
|
||||||
|
aliceMessage.ciphertext,
|
||||||
|
aliceJid,
|
||||||
|
(await aliceSession.getDevice()).id,
|
||||||
|
aliceMessage.encryptedKeys,
|
||||||
|
);
|
||||||
|
|
||||||
|
for (var i = 0; i < 100; i++) {
|
||||||
|
final messageText = 'Test Message #$i';
|
||||||
|
// Bob responds to Alice
|
||||||
|
final bobResponseMessage = await bobSession.encryptToJid(
|
||||||
|
aliceJid,
|
||||||
|
messageText,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Bob sends the message to Alice
|
||||||
|
// ...
|
||||||
|
|
||||||
|
// Alice decrypts it
|
||||||
|
final aliceReceivedMessage = await aliceSession.decryptMessage(
|
||||||
|
bobResponseMessage.ciphertext,
|
||||||
|
bobJid,
|
||||||
|
(await bobSession.getDevice()).id,
|
||||||
|
bobResponseMessage.encryptedKeys,
|
||||||
|
);
|
||||||
|
expect(messageText, aliceReceivedMessage);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ void main() {
|
|||||||
final oldDevice = await oldSession.getDevice();
|
final oldDevice = await oldSession.getDevice();
|
||||||
final newDevice = await newSession.getDevice();
|
final newDevice = await newSession.getDevice();
|
||||||
expect(await oldDevice.equals(newDevice), true);
|
expect(await oldDevice.equals(newDevice), true);
|
||||||
expect(oldSession.getDeviceMap(), newSession.getDeviceMap());
|
expect(await oldSession.getDeviceMap(), await newSession.getDeviceMap());
|
||||||
|
|
||||||
expect(oldSession.getRatchetMap().length, newSession.getRatchetMap().length);
|
expect(oldSession.getRatchetMap().length, newSession.getRatchetMap().length);
|
||||||
for (final session in oldSession.getRatchetMap().entries) {
|
for (final session in oldSession.getRatchetMap().entries) {
|
||||||
|
|||||||
Reference in New Issue
Block a user