3 Commits

Author SHA1 Message Date
4346b31637 feat: Add funding
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2022-12-27 01:47:08 +01:00
fe1ba99b14 feat: Indicate whether a ratchet has been created or not
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2022-12-09 20:41:53 +01:00
797bf69856 fix: Crash when calling getDevicesTrust for unknown Jid
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2022-12-09 18:42:23 +01:00
5 changed files with 32 additions and 15 deletions

1
.github/FUNDING.yml vendored Normal file
View File

@@ -0,0 +1 @@
ko_fi: papatutuwawa

View File

@@ -56,3 +56,9 @@ messages' formatting.
Licensed under the MIT license.
See `LICENSE`.
## Support
If you like what I do and you want to support me, feel free to donate to me on Ko-Fi.
[<img src="https://codeberg.org/moxxy/moxxyv2/raw/branch/master/assets/repo/kofi.png" height="36" style="height: 36px; border: 0px;"></img>](https://ko-fi.com/papatutuwawa)

View File

@@ -5,16 +5,17 @@ abstract class OmemoEvent {}
/// Triggered when a ratchet has been modified
class RatchetModifiedEvent extends OmemoEvent {
RatchetModifiedEvent(this.jid, this.deviceId, this.ratchet);
RatchetModifiedEvent(this.jid, this.deviceId, this.ratchet, this.added);
final String jid;
final int deviceId;
final OmemoDoubleRatchet ratchet;
/// Indicates whether the ratchet has just been created (true) or just modified (false).
final bool added;
}
/// Triggered when a ratchet has been removed and should be removed from storage.
class RatchetRemovedEvent extends OmemoEvent {
RatchetRemovedEvent(this.jid, this.deviceId);
final String jid;
final int deviceId;
@@ -22,7 +23,6 @@ class RatchetRemovedEvent extends OmemoEvent {
/// Triggered when the device map has been modified
class DeviceMapModifiedEvent extends OmemoEvent {
DeviceMapModifiedEvent(this.map);
final Map<String, List<int>> map;
}
@@ -30,7 +30,6 @@ class DeviceMapModifiedEvent extends OmemoEvent {
/// Triggered by the OmemoSessionManager when our own device bundle was modified
/// and thus should be republished.
class DeviceModifiedEvent extends OmemoEvent {
DeviceModifiedEvent(this.device);
final Device device;
}

View File

@@ -28,7 +28,6 @@ import 'package:synchronized/synchronized.dart';
const omemoPayloadInfoString = 'OMEMO Payload';
class OmemoSessionManager {
OmemoSessionManager(this._device, this._deviceMap, this._ratchetMap, this._trustManager)
: _lock = Lock(),
_deviceLock = Lock(),
@@ -136,7 +135,7 @@ class OmemoSessionManager {
_ratchetMap[key] = ratchet;
// Commit the ratchet
_eventStreamController.add(RatchetModifiedEvent(jid, deviceId, ratchet));
_eventStreamController.add(RatchetModifiedEvent(jid, deviceId, ratchet, true));
});
}
@@ -321,7 +320,7 @@ class OmemoSessionManager {
}
// Commit the ratchet
_eventStreamController.add(RatchetModifiedEvent(jid, deviceId, ratchet));
_eventStreamController.add(RatchetModifiedEvent(jid, deviceId, ratchet, false));
}
}
});
@@ -346,6 +345,7 @@ class OmemoSessionManager {
mapKey.jid,
mapKey.deviceId,
oldRatchet,
false,
),
);
});
@@ -421,6 +421,7 @@ class OmemoSessionManager {
senderJid,
senderDeviceId,
oldRatchet,
false,
),
);
@@ -476,7 +477,14 @@ class OmemoSessionManager {
}
// Commit the ratchet
_eventStreamController.add(RatchetModifiedEvent(senderJid, senderDeviceId, ratchet));
_eventStreamController.add(
RatchetModifiedEvent(
senderJid,
senderDeviceId,
ratchet,
false,
),
);
try {
return _decryptAndVerifyHmac(ciphertext, keyAndHmac);
@@ -606,7 +614,7 @@ class OmemoSessionManager {
..acknowledged = true;
// Commit it
_eventStreamController.add(RatchetModifiedEvent(jid, deviceId, ratchet));
_eventStreamController.add(RatchetModifiedEvent(jid, deviceId, ratchet, false));
});
}

View File

@@ -122,17 +122,20 @@ abstract class BlindTrustBeforeVerificationTrustManager extends TrustManager {
});
}
/// Returns a mapping from the device identifiers of [jid] to their trust state.
/// Returns a mapping from the device identifiers of [jid] to their trust state. If
/// there are no devices known for [jid], then an empty map is returned.
Future<Map<int, BTBVTrustState>> getDevicesTrust(String jid) async {
final map = <int, BTBVTrustState>{};
return _lock.synchronized(() async {
final map = <int, BTBVTrustState>{};
await _lock.synchronized(() async {
if (!devices.containsKey(jid)) return map;
for (final deviceId in devices[jid]!) {
map[deviceId] = trustCache[RatchetMapKey(jid, deviceId)]!;
}
});
return map;
return map;
});
}
/// Sets the trust of [jid]'s device with identifier [deviceId] to [state].