Compare commits

..

No commits in common. "fda06cef55909b02806366e103f58a38c5e957bc" and "5a097e4d2a88d16207da212d93d803c949cea6aa" have entirely different histories.

4 changed files with 5 additions and 86 deletions

View File

@ -5,6 +5,6 @@ line-length=72
[title-trailing-punctuation]
[title-hard-tab]
[title-match-regex]
regex=^(feat|fix|test|release|chore|security|docs|refactor|style):.*$
regex=^(feat|fix|test|release|chore|security|docs|refactor):.*$
[body-trailing-whitespace]
[body-first-line-empty]

View File

@ -67,7 +67,6 @@ class OmemoDoubleRatchet {
this.ik,
this.sessionAd,
this.mkSkipped, // MKSKIPPED
this.acknowledged,
);
factory OmemoDoubleRatchet.fromJson(Map<String, dynamic> data) {
@ -84,7 +83,6 @@ class OmemoDoubleRatchet {
'pn': 0,
'ik_pub': 'base/64/encoded',
'session_ad': 'base/64/encoded',
'acknowledged': true | false,
'mkskipped': [
{
'key': 'base/64/encoded',
@ -119,7 +117,6 @@ class OmemoDoubleRatchet {
),
base64.decode(data['session_ad']! as String),
mkSkipped,
data['acknowledged']! as bool,
);
}
@ -151,10 +148,6 @@ class OmemoDoubleRatchet {
final Map<SkippedKey, List<int>> mkSkipped;
/// Indicates whether we received an empty OMEMO message after building a session with
/// the device.
bool acknowledged;
/// Create an OMEMO session using the Signed Pre Key [spk], the shared secret [sk] that
/// was obtained using a X3DH and the associated data [ad] that was also obtained through
/// a X3DH. [ik] refers to Bob's (the receiver's) IK public key.
@ -176,7 +169,6 @@ class OmemoDoubleRatchet {
ik,
ad,
{},
false,
);
}
@ -197,7 +189,6 @@ class OmemoDoubleRatchet {
ik,
ad,
{},
true,
);
}
@ -223,7 +214,6 @@ class OmemoDoubleRatchet {
'ik_pub': base64.encode(await ik.getBytes()),
'session_ad': base64.encode(sessionAd),
'mkskipped': mkSkippedSerialised,
'acknowledged': acknowledged,
};
}

View File

@ -431,33 +431,6 @@ class OmemoSessionManager {
});
}
/// 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.
Future<List<int>> getUnacknowledgedRatchets(String jid) async {
final ret = List<int>.empty(growable: true);
await _lock.synchronized(() async {
final devices = _deviceMap[jid]!;
for (final device in devices) {
final ratchet = _ratchetMap[RatchetMapKey(jid, device)]!;
if (!ratchet.acknowledged) ret.add(device);
}
});
return ret;
}
/// Mark the ratchet for device [deviceId] from [jid] as acked.
Future<void> ratchetAcknowledged(String jid, int deviceId) async {
await _lock.synchronized(() async {
final ratchet = _ratchetMap[RatchetMapKey(jid, deviceId)]!
..acknowledged = true;
// Commit it
_eventStreamController.add(RatchetModifiedEvent(jid, deviceId, ratchet));
});
}
@visibleForTesting
OmemoDoubleRatchet getRatchet(String jid, int deviceId) => _ratchetMap[RatchetMapKey(jid, deviceId)]!;

View File

@ -444,7 +444,7 @@ void main() {
);
// Alice sends a message to those two Bobs
await aliceSession.encryptToJid(
final aliceMessage = await aliceSession.encryptToJid(
bobJid,
'Hallo Welt',
newSessions: [
@ -458,7 +458,7 @@ void main() {
final id2 = (await bobSession2.getDevice()).id;
await aliceSession.removeRatchet(bobJid, id1);
final map = aliceSession.getRatchetMap();
final map = await aliceSession.getRatchetMap();
expect(map.containsKey(RatchetMapKey(bobJid, id1)), false);
expect(map.containsKey(RatchetMapKey(bobJid, id2)), true);
final deviceMap = await aliceSession.getDeviceMap();
@ -481,7 +481,7 @@ void main() {
);
// Alice sends a message to those two Bobs
await aliceSession.encryptToJid(
final aliceMessage = await aliceSession.encryptToJid(
bobJid,
'Hallo Welt',
newSessions: [
@ -493,54 +493,10 @@ void main() {
final id = (await bobSession.getDevice()).id;
await aliceSession.removeRatchet(bobJid, id);
final map = aliceSession.getRatchetMap();
final map = await aliceSession.getRatchetMap();
expect(map.containsKey(RatchetMapKey(bobJid, id)), false);
final deviceMap = await aliceSession.getDeviceMap();
expect(deviceMap.containsKey(bobJid), false);
});
});
test('Test acknowledging a ratchet', () 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 sends Bob a message
await aliceSession.encryptToJid(
bobJid,
'Hallo Welt',
newSessions: [
await (await bobSession.getDevice()).toBundle(),
],
);
expect(
await aliceSession.getUnacknowledgedRatchets(bobJid),
[
(await bobSession.getDevice()).id,
],
);
// Bob sends alice an empty message
// ...
// Alice decrypts it
// ...
// Alice marks the ratchet as acknowledged
await aliceSession.ratchetAcknowledged(bobJid, (await bobSession.getDevice()).id);
expect(
(await aliceSession.getUnacknowledgedRatchets(bobJid)).isEmpty,
true,
);
});
}