Compare commits

..

No commits in common. "master" and "v0.5.0" have entirely different histories.

14 changed files with 75 additions and 329 deletions

View File

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

View File

@ -1,22 +1,11 @@
pipeline: pipeline:
analysis: lint:
image: dart:3.0.7 image: dart:2.18.1
commands: commands:
# Proxy requests to pub.dev using pubcached - dart pub get
- PUB_HOSTED_URL=http://172.17.0.1:8000 dart pub get
- dart analyze --fatal-infos --fatal-warnings - dart analyze --fatal-infos --fatal-warnings
test:
image: dart:2.18.1
commands:
- dart pub get
- dart test - dart test
when:
path:
includes: ['lib/**', 'test/**']
notify:
image: git.polynom.me/papatutuwawa/woodpecker-xmpp
settings:
xmpp_is_muc: 1
xmpp_tls: 1
xmpp_recipient: moxxy-build@muc.moxxy.org
xmpp_alias: 2Bot
secrets: [ xmpp_jid, xmpp_password, xmpp_server ]
when:
status:
- failure

View File

@ -65,13 +65,4 @@ This version is a complete rework of omemo_dart!
- Replace exceptions with errors inside a result type - Replace exceptions with errors inside a result type
- Ratchets and trust data is now loaded and cached on demand - Ratchets and trust data is now loaded and cached on demand
- Accessing the trust manager must happen via `withTrustManager` - Accessing the trust manager must happen via `withTrustManager`
- Overriding the base implementations is replaced by providing callback functions - Overriding the base implementations is replaced by providing callback functions
## 0.5.1
- Remove `added` and `replaced` from the data passed to the `CommitRatchetsCallback`
- Added a list of newly added and replaced ratchets to the encryption and decryption results. This is useful for displaying messages like "Contact added a new device"
## 0.6.0
- Bump dependencies to fix running with never version of Dart

View File

@ -1,7 +1,5 @@
# omemo_dart # omemo_dart
[![status-badge](https://ci.polynom.me/api/badges/16/status.svg)](https://ci.polynom.me/repos/16)
`omemo_dart` is a Dart library to help developers of Dart/Flutter XMPP clients to implement `omemo_dart` is a Dart library to help developers of Dart/Flutter XMPP clients to implement
[OMEMO](https://xmpp.org/extensions/xep-0384.html) in its newest version - currently 0.8.3. [OMEMO](https://xmpp.org/extensions/xep-0384.html) in its newest version - currently 0.8.3.

View File

@ -17,7 +17,7 @@ void main() async {
// implements "Blind Trust Before Verification". To make things simpler, we keep // implements "Blind Trust Before Verification". To make things simpler, we keep
// no persistent data and can thus use the MemoryBTBVTrustManager. If we wanted to keep // no persistent data and can thus use the MemoryBTBVTrustManager. If we wanted to keep
// the state, we would have to override BlindTrustBeforeVerificationTrustManager. // the state, we would have to override BlindTrustBeforeVerificationTrustManager.
BlindTrustBeforeVerificationTrustManager(), MemoryBTBVTrustManager(),
// This function is called whenever we need to send an OMEMO heartbeat to [recipient]. // This function is called whenever we need to send an OMEMO heartbeat to [recipient].
// [result] is the encryted data to include. This needs to be wired into your XMPP library's // [result] is the encryted data to include. This needs to be wired into your XMPP library's
// OMEMO implementation. // OMEMO implementation.
@ -41,7 +41,9 @@ void main() async {
(device) async {}, (device) async {},
); );
// Bob, on his side, also creates an [OmemoManager] similar to Alice. // Alice now wants to chat with Bob at his bare Jid "bob@other.server". To make things
// simple, we just generate the identity bundle ourselves. In the real world, we would
// request it using PEP and then convert the device bundle into a OmemoBundle object.
final bobManager = OmemoManager( final bobManager = OmemoManager(
await OmemoDevice.generateNewDevice(bobJid), await OmemoDevice.generateNewDevice(bobJid),
BlindTrustBeforeVerificationTrustManager(), BlindTrustBeforeVerificationTrustManager(),
@ -49,13 +51,10 @@ void main() async {
(jid) async => [], (jid) async => [],
(jid, id) async => null, (jid, id) async => null,
(jid) async {}, (jid) async {},
(device) async {},
); );
// Alice prepares to send the message to Bob, so she builds the message stanza and // Alice prepares to send the message to Bob, so she builds the message stanza and
// collects all the children of the stanza that should be encrypted into a string. // collects all the children of the stanza that should be encrypted into a string.
// Note that this leaves out the wrapping stanza, i.e. if we want to send a <message />
// we only include the <message />'s children.
const aliceMessageStanzaBody = ''' const aliceMessageStanzaBody = '''
<body>Hello Bob, it's me, Alice!</body> <body>Hello Bob, it's me, Alice!</body>
<super-secret-element xmlns='super-secret-element' /> <super-secret-element xmlns='super-secret-element' />
@ -76,10 +75,10 @@ void main() async {
</envelope> </envelope>
'''; ''';
// Next, we encrypt the envelope element using Alice's [OmemoManager]. It will // Since Alice has no open session with Bob, we need to tell the session manager to build
// automatically attempt to fetch the device bundles of Bob. // it when sending the message.
final message = await aliceManager.onOutgoingStanza( final message = await aliceSession.onOutgoingStanza(
const OmemoOutgoingStanza( OmemoOutgoingStanza(
// The bare receiver Jid // The bare receiver Jid
[bobJid], [bobJid],
@ -88,15 +87,17 @@ void main() async {
), ),
); );
// In a proper implementation, we would also do some error checking here. // In a proper implementation, we should also do some error checking here.
// Alice now builds the actual message stanza for Bob // Alice now builds the actual message stanza for Bob
final payload = base64.encode(message.ciphertext!); final payload = base64.encode(message.ciphertext!);
final aliceDevice = await aliceManager.getDevice(); final aliceDevice = await aliceSession.getDevice();
// ignore: unused_local_variable
final bobDevice = await bobSession.getDevice();
// Since we know we have just one key for Bob, we take a shortcut. However, in the real // Since we know we have just one key for Bob, we take a shortcut. However, in the real
// world, we have to serialise every EncryptedKey to a <key /> element and group them // world, we have to serialise every EncryptedKey to a <key /> element and group them
// per Jid. // per Jid.
final key = message.encryptedKeys[bobJid]![0]; final key = message.encryptedKeys[0];
// Note that the key's "kex" attribute refers to key.kex. It just means that the // Note that the key's "kex" attribute refers to key.kex. It just means that the
// encrypted key also contains the required data for Bob to build a session with Alice. // encrypted key also contains the required data for Bob to build a session with Alice.
@ -106,7 +107,7 @@ void main() async {
<encrypted xmlns='urn:xmpp:omemo:2'> <encrypted xmlns='urn:xmpp:omemo:2'>
<header sid='${aliceDevice.id}'> <header sid='${aliceDevice.id}'>
<keys jid='$bobJid'> <keys jid='$bobJid'>
<key rid='${key.rid} kex='${key.kex}'> <key rid='${key.rid} kex='true'>
${key.value} ${key.value}
</key> </key>
</keys> </keys>
@ -124,7 +125,7 @@ void main() async {
// Bob now receives an OMEMO encrypted message from Alice and wants to decrypt it. // Bob now receives an OMEMO encrypted message from Alice and wants to decrypt it.
// Since we have just one key, let's just deserialise the one key by hand. // Since we have just one key, let's just deserialise the one key by hand.
final keys = [ final keys = [
EncryptedKey(key.rid, key.value, true), EncryptedKey(bobJid, key.rid, key.value, true),
]; ];
// Bob extracts the payload and attempts to decrypt it. // Bob extracts the payload and attempts to decrypt it.
@ -133,9 +134,14 @@ void main() async {
OmemoIncomingStanza( OmemoIncomingStanza(
// The bare sender JID of the message. In this case, it's Alice's. // The bare sender JID of the message. In this case, it's Alice's.
aliceJid, aliceJid,
// The 'sid' attribute of the <header /> element. Here, we know that Alice only has one device. // The 'sid' attribute of the <header /> element. Here, we know that Alice only has one device.
aliceDevice.id, aliceDevice.id,
// Time the message was sent. Since the message was not delayed, we use the
// current time.
DateTime.now().millisecondsSinceEpoch,
/// The decoded <key /> elements. from the header. Note that we only include the ones /// The decoded <key /> elements. from the header. Note that we only include the ones
/// relevant for Bob, so all children of <keys jid='$bobJid' />. /// relevant for Bob, so all children of <keys jid='$bobJid' />.
keys, keys,

View File

@ -1,15 +1,12 @@
{ {
"nodes": { "nodes": {
"flake-utils": { "flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": { "locked": {
"lastModified": 1692799911, "lastModified": 1656065134,
"narHash": "sha256-3eihraek4qL744EvQXsK1Ha6C3CR7nnT8X2qWap4RNk=", "narHash": "sha256-oc6E6ByIw3oJaIyc67maaFcnjYOz1mMcOtHxbEf9NwQ=",
"owner": "numtide", "owner": "numtide",
"repo": "flake-utils", "repo": "flake-utils",
"rev": "f9e7cf818399d17d347f847525c5a5a8032e4e44", "rev": "bee6a7250dd1b01844a2de7e02e4df7d8a0a206c",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -20,16 +17,16 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1727586919, "lastModified": 1657540956,
"narHash": "sha256-e/YXG0tO5GWHDS8QQauj8aj4HhXEm602q9swrrlTlKQ=", "narHash": "sha256-ihGbOFWtAkENwxBE5kV/yWt2MncvW+BObLDsmxCLo/Q=",
"owner": "NixOS", "owner": "NANASHI0X74",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "2dcd9c55e8914017226f5948ac22c53872a13ee2", "rev": "043de04db8a6b0391b3fefaaade160514d866946",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "NixOS", "owner": "NANASHI0X74",
"ref": "nixpkgs-unstable", "ref": "flutter-3-0-0",
"repo": "nixpkgs", "repo": "nixpkgs",
"type": "github" "type": "github"
} }
@ -39,21 +36,6 @@
"flake-utils": "flake-utils", "flake-utils": "flake-utils",
"nixpkgs": "nixpkgs" "nixpkgs": "nixpkgs"
} }
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
} }
}, },
"root": "root", "root": "root",

View File

@ -1,7 +1,7 @@
{ {
description = "omemo_dart"; description = "omemo_dart";
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; nixpkgs.url = "github:NANASHI0X74/nixpkgs/flutter-3-0-0";
flake-utils.url = "github:numtide/flake-utils"; flake-utils.url = "github:numtide/flake-utils";
}; };
outputs = { self, nixpkgs, flake-utils }: flake-utils.lib.eachDefaultSystem (system: let outputs = { self, nixpkgs, flake-utils }: flake-utils.lib.eachDefaultSystem (system: let

View File

@ -3,13 +3,7 @@ import 'package:omemo_dart/src/errors.dart';
@immutable @immutable
class DecryptionResult { class DecryptionResult {
const DecryptionResult( const DecryptionResult(this.payload, this.usedOpkId, this.error);
this.payload,
this.usedOpkId,
this.newRatchets,
this.replacedRatchets,
this.error,
);
/// The decrypted payload or null, if it was an empty OMEMO message. /// The decrypted payload or null, if it was an empty OMEMO message.
final String? payload; final String? payload;
@ -18,13 +12,6 @@ class DecryptionResult {
/// replacing the OPK after a message catch-up. /// replacing the OPK after a message catch-up.
final int? usedOpkId; final int? usedOpkId;
/// Mapping of JIDs to a list of device ids for which we created a new ratchet session.
final Map<String, List<int>> newRatchets;
/// Similar to [newRatchets], but the ratchets listed in [replacedRatchets] where also existent before
/// and replaced with the new ratchet.
final Map<String, List<int>> replacedRatchets;
/// The error that occurred during decryption or null, if no error occurred. /// The error that occurred during decryption or null, if no error occurred.
final OmemoError? error; final OmemoError? error;
} }

View File

@ -8,8 +8,6 @@ class EncryptionResult {
this.ciphertext, this.ciphertext,
this.encryptedKeys, this.encryptedKeys,
this.deviceEncryptionErrors, this.deviceEncryptionErrors,
this.newRatchets,
this.replacedRatchets,
this.canSend, this.canSend,
); );
@ -23,13 +21,6 @@ class EncryptionResult {
/// Mapping of a JID to /// Mapping of a JID to
final Map<String, List<EncryptToJidError>> deviceEncryptionErrors; final Map<String, List<EncryptToJidError>> deviceEncryptionErrors;
/// Mapping of JIDs to a list of device ids for which we created a new ratchet session.
final Map<String, List<int>> newRatchets;
/// Similar to [newRatchets], but the ratchets listed in [replacedRatchets] where also existent before
/// and replaced with the new ratchet.
final Map<String, List<int>> replacedRatchets;
/// A flag indicating that the message could be sent like that, i.e. we were able /// A flag indicating that the message could be sent like that, i.e. we were able
/// to encrypt to at-least one device per recipient. /// to encrypt to at-least one device per recipient.
final bool canSend; final bool canSend;

View File

@ -356,8 +356,6 @@ class OmemoManager {
return DecryptionResult( return DecryptionResult(
null, null,
null, null,
const {},
const {},
NotEncryptedForDeviceError(), NotEncryptedForDeviceError(),
); );
} }
@ -367,8 +365,6 @@ class OmemoManager {
return DecryptionResult( return DecryptionResult(
null, null,
null, null,
const {},
const {},
MalformedEncryptedKeyError(), MalformedEncryptedKeyError(),
); );
} }
@ -377,8 +373,7 @@ class OmemoManager {
final ratchetKey = final ratchetKey =
RatchetMapKey(stanza.bareSenderJid, stanza.senderDeviceId); RatchetMapKey(stanza.bareSenderJid, stanza.senderDeviceId);
var processAsKex = key.kex; var processAsKex = key.kex;
final ratchetAlreadyExists = _ratchetMap.containsKey(ratchetKey); if (key.kex && _ratchetMap.containsKey(ratchetKey)) {
if (key.kex && ratchetAlreadyExists) {
final ratchet = _ratchetMap[ratchetKey]!; final ratchet = _ratchetMap[ratchetKey]!;
final kexMessage = OMEMOKeyExchange.fromBuffer(key.data); final kexMessage = OMEMOKeyExchange.fromBuffer(key.data);
final ratchetEk = await ratchet.kex.ek.getBytes(); final ratchetEk = await ratchet.kex.ek.getBytes();
@ -408,8 +403,6 @@ class OmemoManager {
return DecryptionResult( return DecryptionResult(
null, null,
null, null,
const {},
const {},
UnknownSignedPrekeyError(), UnknownSignedPrekeyError(),
); );
} }
@ -450,13 +443,7 @@ class OmemoManager {
final error = keyAndHmac.get<OmemoError>(); final error = keyAndHmac.get<OmemoError>();
_log.warning('Failed to decrypt symmetric key: $error'); _log.warning('Failed to decrypt symmetric key: $error');
return DecryptionResult( return DecryptionResult(null, null, error);
null,
null,
const {},
const {},
error,
);
} }
Result<OmemoError, String?> result; Result<OmemoError, String?> result;
@ -472,8 +459,6 @@ class OmemoManager {
return DecryptionResult( return DecryptionResult(
null, null,
null, null,
const {},
const {},
error, error,
); );
} }
@ -502,6 +487,8 @@ class OmemoManager {
stanza.bareSenderJid, stanza.bareSenderJid,
stanza.senderDeviceId, stanza.senderDeviceId,
ratchet, ratchet,
true,
false,
), ),
]); ]);
@ -525,14 +512,9 @@ class OmemoManager {
_ratchetMap.containsKey(ratchetKey), _ratchetMap.containsKey(ratchetKey),
); );
final newlyCreatedDevice = {
stanza.bareSenderJid: [stanza.senderDeviceId],
};
return DecryptionResult( return DecryptionResult(
result.get<String?>(), result.get<String?>(),
kexMessage.pkId, kexMessage.pkId,
ratchetAlreadyExists ? {} : newlyCreatedDevice,
ratchetAlreadyExists ? newlyCreatedDevice : {},
null, null,
); );
} else { } else {
@ -544,13 +526,11 @@ class OmemoManager {
.contains(stanza.senderDeviceId)) { .contains(stanza.senderDeviceId)) {
_deviceList[stanza.bareSenderJid]!.add(stanza.senderDeviceId); _deviceList[stanza.bareSenderJid]!.add(stanza.senderDeviceId);
} }
final emptyResult = await _sendOmemoHeartbeat(stanza.bareSenderJid); await _sendOmemoHeartbeat(stanza.bareSenderJid);
return DecryptionResult( return DecryptionResult(
null, null,
null, null,
emptyResult.newRatchets,
emptyResult.replacedRatchets,
NoSessionWithDeviceError(), NoSessionWithDeviceError(),
); );
} }
@ -573,13 +553,7 @@ class OmemoManager {
if (keyAndHmac.isType<OmemoError>()) { if (keyAndHmac.isType<OmemoError>()) {
final error = keyAndHmac.get<OmemoError>(); final error = keyAndHmac.get<OmemoError>();
_log.warning('Failed to decrypt symmetric key: $error'); _log.warning('Failed to decrypt symmetric key: $error');
return DecryptionResult( return DecryptionResult(null, null, error);
null,
null,
const {},
const {},
error,
);
} }
Result<OmemoError, String?> result; Result<OmemoError, String?> result;
@ -594,8 +568,6 @@ class OmemoManager {
return DecryptionResult( return DecryptionResult(
null, null,
null, null,
const {},
const {},
error, error,
); );
} }
@ -617,6 +589,8 @@ class OmemoManager {
stanza.bareSenderJid, stanza.bareSenderJid,
stanza.senderDeviceId, stanza.senderDeviceId,
ratchet, ratchet,
false,
false,
), ),
]); ]);
@ -626,8 +600,6 @@ class OmemoManager {
return DecryptionResult( return DecryptionResult(
result.get<String?>(), result.get<String?>(),
null, null,
const {},
const {},
null, null,
); );
} }
@ -670,8 +642,6 @@ class OmemoManager {
); );
final encryptionErrors = <String, List<EncryptToJidError>>{}; final encryptionErrors = <String, List<EncryptToJidError>>{};
final addedRatchetKeys = List<RatchetMapKey>.empty(growable: true); final addedRatchetKeys = List<RatchetMapKey>.empty(growable: true);
final newRatchets = <String, List<int>>{};
final replacedRatchets = <String, List<int>>{};
final kex = <RatchetMapKey, OMEMOKeyExchange>{}; final kex = <RatchetMapKey, OMEMOKeyExchange>{};
for (final jid in stanza.recipientJids) { for (final jid in stanza.recipientJids) {
final newBundles = await _fetchNewOmemoBundles(jid); final newBundles = await _fetchNewOmemoBundles(jid);
@ -713,11 +683,6 @@ class OmemoManager {
); );
// Track the ratchet // Track the ratchet
if (_ratchetMap.containsKey(ratchetKey)) {
replacedRatchets.appendOrCreate(ratchetKey.jid, ratchetKey.deviceId);
} else {
newRatchets.appendOrCreate(ratchetKey.jid, ratchetKey.deviceId);
}
_ratchetMap[ratchetKey] = newRatchet; _ratchetMap[ratchetKey] = newRatchet;
addedRatchetKeys.add(ratchetKey); addedRatchetKeys.add(ratchetKey);
@ -743,6 +708,8 @@ class OmemoManager {
key.jid, key.jid,
key.deviceId, key.deviceId,
_ratchetMap[key]!, _ratchetMap[key]!,
true,
false,
); );
}).toList(), }).toList(),
); );
@ -852,8 +819,6 @@ class OmemoManager {
ciphertext, ciphertext,
encryptedKeys, encryptedKeys,
encryptionErrors, encryptionErrors,
newRatchets,
replacedRatchets,
successfulEncryptions.values.every((n) => n > 0), successfulEncryptions.values.every((n) => n > 0),
); );
} }
@ -867,7 +832,7 @@ class OmemoManager {
} }
/// Like [sendOmemoHeartbeat], but does not acquire the lock for [jid]. /// Like [sendOmemoHeartbeat], but does not acquire the lock for [jid].
Future<EncryptionResult> _sendOmemoHeartbeat(String jid) async { Future<void> _sendOmemoHeartbeat(String jid) async {
final result = await _onOutgoingStanzaImpl( final result = await _onOutgoingStanzaImpl(
OmemoOutgoingStanza( OmemoOutgoingStanza(
[jid], [jid],
@ -875,7 +840,6 @@ class OmemoManager {
), ),
); );
await sendEmptyOmemoMessageImpl(result, jid); await sendEmptyOmemoMessageImpl(result, jid);
return result;
} }
/// Removes all ratchets associated with [jid]. /// Removes all ratchets associated with [jid].
@ -951,6 +915,8 @@ class OmemoManager {
jid, jid,
device, device,
ratchet, ratchet,
false,
false,
), ),
]); ]);
} }

View File

@ -5,6 +5,8 @@ class OmemoRatchetData {
this.jid, this.jid,
this.id, this.id,
this.ratchet, this.ratchet,
this.added,
this.replaced,
); );
/// The JID we have the ratchet with. /// The JID we have the ratchet with.
@ -15,4 +17,10 @@ class OmemoRatchetData {
/// The actual double ratchet to commit. /// The actual double ratchet to commit.
final OmemoDoubleRatchet ratchet; final OmemoDoubleRatchet ratchet;
/// Indicates whether the ratchet has just been created (true) or just modified (false).
final bool added;
/// Indicates whether the ratchet has been replaced (true) or not.
final bool replaced;
} }

View File

@ -1,53 +0,0 @@
<?xml version='1.0' encoding='UTF-8'?>
<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'
xmlns="http://usefulinc.com/ns/doap#"
xmlns:foaf="http://xmlns.com/foaf/0.1/"
xmlns:xmpp="https://linkmauve.fr/ns/xmpp-doap#"
xmlns:schema="https://schema.org/">
<Project xml:lang='en'>
<!-- Moxxy information -->
<name>omemo_dart</name>
<created>2022-06-30</created>
<homepage rdf:resource="https://github.com/PapaTutuWawa/omemo_dart" />
<os>Linux</os>
<os>Windows</os>
<os>macOS</os>
<os>Android</os>
<os>iOS</os>
<!-- Description -->
<shortdesc xml:lang="de">A Dart implementation of the cryptography needed for OMEMO 0.8.3</shortdesc>
<description xml:lang="en">omemo_dart is a pure Dart implementation of the low-level components (X3DH, Double Ratchet) with a high-level library-agnostic interface for implementing OMEMO 0.8.3.</description>
<!-- Maintainer information -->
<maintainer>
<foaf:Person>
<foaf:name>Alexander "Polynomdivision"</foaf:name>
<foaf:homepage rdf:resource="https://polynom.me" />
</foaf:Person>
</maintainer>
<!-- Channel list -->
<developer-forum rdf:resource='xmpp:dev@muc.moxxy.org?join'/>
<!-- Repository information -->
<programming-language>Dart</programming-language>
<bug-database rdf:resource="https://github.com/PapaTutuWawa/omemo_dart/issues" />
<license rdf:resource="https://github.com/PapaTutuWawa/omemo_dart/blob/master/LICENSE" />
<repository>
<GitRepository>
<browse rdf:resource="https://github.com/PapaTutuWawa/omemo_dart" />
<location rdf:resource="https://github.com/PapaTutuWawa/omemo_dart.git" />
</GitRepository>
</repository>
<!-- XEP list -->
<implements>
<xmpp:SupportedXep>
<xmpp:xep rdf:resource="https://xmpp.org/extensions/xep-0384.html"/>
<xmpp:status>partial</xmpp:status>
<xmpp:version>0.8.3</xmpp:version>
</xmpp:SupportedXep>
</implements>
</Project>
</rdf:RDF>

View File

@ -1,27 +1,27 @@
name: omemo_dart name: omemo_dart
description: An XMPP library independent OMEMO library description: An XMPP library independent OMEMO library
version: 0.6.0 version: 0.5.0
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
environment: environment:
sdk: ">=3.0.0 <4.0.0" sdk: '>=2.17.0 <3.0.0'
dependencies: dependencies:
collection: ^1.18.0 collection: ^1.16.0
cryptography: ^2.7.0 cryptography: ^2.0.5
hex: ^0.2.0 hex: ^0.2.0
logging: ^1.2.0 logging: ^1.0.2
meta: ^1.15.0 meta: ^1.7.0
moxlib: moxlib:
version: ^0.2.0 version: ^0.2.0
hosted: https://git.polynom.me/api/packages/Moxxy/pub hosted: https://git.polynom.me/api/packages/Moxxy/pub
pinenacl: ^0.6.0 pinenacl: ^0.5.1
protobuf: ^3.1.0 protobuf: ^2.1.0
protoc_plugin: ^21.1.2 protoc_plugin: ^20.0.1
synchronized: ^3.3.0+3 synchronized: ^3.0.0+2
dev_dependencies: dev_dependencies:
lints: ^5.0.0 lints: ^2.0.0
test: ^1.25.8 test: ^1.21.0
very_good_analysis: ^6.0.0 very_good_analysis: ^3.0.1

View File

@ -1880,12 +1880,7 @@ void main() {
); );
expect(aliceResult2.error, isNull); expect(aliceResult2.error, isNull);
expect(aliceResult2.payload, isNull); expect(aliceResult2.payload, isNull);
expect( expect(aliceManager.getRatchet(RatchetMapKey(bobJid, bobDevice.id))!.acknowledged, isTrue);
aliceManager
.getRatchet(RatchetMapKey(bobJid, bobDevice.id))!
.acknowledged,
isTrue,
);
// Now Alice sends something to Bob // Now Alice sends something to Bob
final aliceResult3 = await aliceManager.onOutgoingStanza( final aliceResult3 = await aliceManager.onOutgoingStanza(
@ -1908,118 +1903,4 @@ void main() {
expect(bobResult.error, isNull); expect(bobResult.error, isNull);
expect(bobResult.payload, 'Hello Bob'); expect(bobResult.payload, 'Hello Bob');
}); });
test('Test correct new and replaced lists', () async {
const aliceJid = 'alice@server1';
const bobJid = 'bob@server2';
final aliceDevice =
await OmemoDevice.generateNewDevice(aliceJid, opkAmount: 1);
final bobDevice = await OmemoDevice.generateNewDevice(bobJid, opkAmount: 1);
final aliceManager = OmemoManager(
aliceDevice,
AlwaysTrustingTrustManager(),
(result, recipientJid) async {},
(jid) async {
expect(jid, bobJid);
return [bobDevice.id];
},
(jid, id) async {
expect(jid, bobJid);
return bobDevice.toBundle();
},
(jid) async {},
(_) async {},
);
EncryptionResult? bobEmptyMessage;
final bobManager = OmemoManager(
bobDevice,
TestingTrustManager(),
(result, recipientJid) async {
bobEmptyMessage = result;
},
(jid) async {
expect(jid, aliceJid);
return [
aliceDevice.id,
];
},
(jid, id) async {
expect(jid, aliceJid);
if (id == aliceDevice.id) {
return aliceDevice.toBundle();
}
return null;
},
(jid) async {},
(_) async {},
);
// Alice sends Bob a message
final aliceResult1 = await aliceManager.onOutgoingStanza(
const OmemoOutgoingStanza(
[bobJid],
'Hello World!',
),
);
expect(aliceResult1.newRatchets[bobJid], [bobDevice.id]);
expect(aliceResult1.replacedRatchets.isEmpty, isTrue);
// Bob decrypts Alice's message
final bobResult1 = await bobManager.onIncomingStanza(
OmemoIncomingStanza(
aliceJid,
aliceDevice.id,
aliceResult1.encryptedKeys[bobJid]!,
base64.encode(aliceResult1.ciphertext!),
false,
),
);
expect(bobResult1.error, null);
expect(bobEmptyMessage, isNotNull);
expect(bobResult1.newRatchets[aliceJid], [aliceDevice.id]);
expect(bobResult1.replacedRatchets.isEmpty, isTrue);
// Bob now sends the empty OMEMO message to Alice, who then decrypts
// it.
final aliceResult2 = await aliceManager.onIncomingStanza(
OmemoIncomingStanza(
bobJid,
bobDevice.id,
bobEmptyMessage!.encryptedKeys[aliceJid]!,
bobEmptyMessage!.ciphertext?.toBase64(),
false,
),
);
expect(aliceResult2.newRatchets.isEmpty, isTrue);
expect(aliceResult2.replacedRatchets.isEmpty, isTrue);
// Bob now removes all ratchets and sends a new message to alice
await bobManager.removeAllRatchets(aliceJid);
final bobResult2 = await bobManager.onOutgoingStanza(
const OmemoOutgoingStanza(
[aliceJid],
'New Ratchet, so cool',
),
);
// And Alice decrypts it
final aliceResult3 = await aliceManager.onIncomingStanza(
OmemoIncomingStanza(
bobJid,
bobDevice.id,
bobResult2.encryptedKeys[aliceJid]!,
bobResult2.ciphertext?.toBase64(),
false,
),
);
expect(aliceResult3.error, isNull);
expect(aliceResult3.payload, 'New Ratchet, so cool');
expect(aliceResult3.newRatchets.isEmpty, isTrue);
expect(aliceResult3.replacedRatchets[bobJid], [bobDevice.id]);
});
} }