diff --git a/CHANGELOG.md b/CHANGELOG.md
index 210eb12..74a727d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -54,3 +54,14 @@
## 0.4.3
- Fix bug that causes ratchets to be unable to decrypt anything after receiving a heartbeat with a completely new session
+
+## 0.5.0
+
+This version is a complete rework of omemo_dart!
+
+- Removed events from `OmemoManager`
+- Removed `OmemoSessionManager`
+- Removed serialization/deserialization code
+- Replace exceptions with errors inside a result type
+- Ratchets and trust data is now loaded and cached on demand
+- Accessing the trust manager must happen via `withTrustManager`
\ No newline at end of file
diff --git a/lib/src/errors.dart b/lib/src/errors.dart
index 8e7aecf..0925a16 100644
--- a/lib/src/errors.dart
+++ b/lib/src/errors.dart
@@ -34,3 +34,6 @@ class MalformedCiphertextError extends OmemoError {
/// The exception that was raised while decryption.
final Object ex;
}
+
+/// Caused by an empty element
+class MalformedEncryptedKeyError extends OmemoError {}
diff --git a/lib/src/omemo/omemo.dart b/lib/src/omemo/omemo.dart
index 1d8232d..dd054d0 100644
--- a/lib/src/omemo/omemo.dart
+++ b/lib/src/omemo/omemo.dart
@@ -356,6 +356,14 @@ class OmemoManager {
);
}
+ // Protobuf will happily parse this and return bogus data.
+ if (key.value.isEmpty) {
+ return DecryptionResult(
+ null,
+ MalformedEncryptedKeyError(),
+ );
+ }
+
// Check how we should process the message
final ratchetKey =
RatchetMapKey(stanza.bareSenderJid, stanza.senderDeviceId);
@@ -433,18 +441,23 @@ class OmemoManager {
return DecryptionResult(null, error);
}
- final result = await _decryptAndVerifyHmac(
- stanza.payload?.fromBase64(),
- keyAndHmac.get>(),
- );
- if (result.isType()) {
- final error = result.get();
- _log.warning('Decrypting payload failed: $error');
-
- return DecryptionResult(
- null,
- error,
+ Result result;
+ if (stanza.payload != null) {
+ result = await _decryptAndVerifyHmac(
+ stanza.payload?.fromBase64(),
+ keyAndHmac.get>(),
);
+ if (result.isType()) {
+ final error = result.get();
+ _log.warning('Decrypting payload failed: $error');
+
+ return DecryptionResult(
+ null,
+ error,
+ );
+ }
+ } else {
+ result = const Result(null);
}
// Notify the trust manager
@@ -530,17 +543,22 @@ class OmemoManager {
return DecryptionResult(null, error);
}
- final result = await _decryptAndVerifyHmac(
- stanza.payload?.fromBase64(),
- keyAndHmac.get>(),
- );
- if (result.isType()) {
- final error = result.get();
- _log.warning('Failed to decrypt message: $error');
- return DecryptionResult(
- null,
- error,
+ Result result;
+ if (stanza.payload != null) {
+ result = await _decryptAndVerifyHmac(
+ stanza.payload?.fromBase64(),
+ keyAndHmac.get>(),
);
+ if (result.isType()) {
+ final error = result.get();
+ _log.warning('Failed to decrypt message: $error');
+ return DecryptionResult(
+ null,
+ error,
+ );
+ }
+ } else {
+ result = const Result(null);
}
// If we received an empty OMEMO message, mark the ratchet as acknowledged
@@ -587,7 +605,7 @@ class OmemoManager {
// Encrypt the payload, if we have any
final List payloadKey;
- final List ciphertext;
+ final List? ciphertext;
if (stanza.payload != null) {
// Generate the key and encrypt the plaintext
final rawKey = generateRandomBytes(32);
@@ -601,7 +619,7 @@ class OmemoManager {
payloadKey = concat([rawKey, hmac]);
} else {
payloadKey = List.filled(32, 0x0);
- ciphertext = [];
+ ciphertext = null;
}
final encryptionErrors = >{};
@@ -942,7 +960,9 @@ class OmemoManager {
/// Trust management functions
Future withTrustManager(
- String jid, Future Function(TrustManager) callback) async {
+ String jid,
+ Future Function(TrustManager) callback,
+ ) async {
await _ratchetQueue.synchronized(
[jid],
() => callback(_trustManager),
diff --git a/pubspec.yaml b/pubspec.yaml
index 6f7ff94..8e1d40e 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,6 +1,6 @@
name: omemo_dart
description: An XMPP library independent OMEMO library
-version: 0.4.3
+version: 0.5.0
homepage: https://github.com/PapaTutuWawa/omemo_dart
publish_to: https://git.polynom.me/api/packages/PapaTutuWawa/pub