Compare commits
9 Commits
fc842fe000
...
v0.1.3
| Author | SHA1 | Date | |
|---|---|---|---|
| 44ab31aebb | |||
| e4f1d7d4b0 | |||
| 7600804aa1 | |||
| a4589b6e09 | |||
| d0986a4608 | |||
| 683a76cc80 | |||
| dad707f71d | |||
| 419be8af4d | |||
| fafc4f2320 |
@@ -4,3 +4,8 @@
|
||||
- Implement the Double Ratchet, X3DH and OMEMO specific bits
|
||||
- Add a Blind-Trust-Before-Verification TrustManager
|
||||
- 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
|
||||
|
||||
@@ -293,7 +293,11 @@ class OmemoDoubleRatchet {
|
||||
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 _dhRatchet(header);
|
||||
}
|
||||
|
||||
@@ -387,11 +387,20 @@ class OmemoSessionManager {
|
||||
});
|
||||
}
|
||||
|
||||
@visibleForTesting
|
||||
OmemoDoubleRatchet getRatchet(String jid, int deviceId) => _ratchetMap[RatchetMapKey(jid, deviceId)]!;
|
||||
/// 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
|
||||
Map<String, List<int>> getDeviceMap() => _deviceMap;
|
||||
OmemoDoubleRatchet getRatchet(String jid, int deviceId) => _ratchetMap[RatchetMapKey(jid, deviceId)]!;
|
||||
|
||||
@visibleForTesting
|
||||
Map<RatchetMapKey, OmemoDoubleRatchet> getRatchetMap() => _ratchetMap;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
name: omemo_dart
|
||||
description: An XMPP library independent OMEMO library
|
||||
version: 0.1.0
|
||||
version: 0.1.3
|
||||
homepage: https://github.com/PapaTutuWawa/omemo_dart
|
||||
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 {
|
||||
const aliceJid = 'alice@server.example';
|
||||
const bobJid = 'bob@other.server.example';
|
||||
|
||||
// Alice and Bob generate their sessions
|
||||
var deviceModified = false;
|
||||
var ratchetModified = 0;
|
||||
@@ -367,4 +366,60 @@ void main() {
|
||||
// untrusted device.
|
||||
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 newDevice = await newSession.getDevice();
|
||||
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);
|
||||
for (final session in oldSession.getRatchetMap().entries) {
|
||||
|
||||
Reference in New Issue
Block a user