fix: Fix some issues found by integrating

This commit is contained in:
PapaTutuWawa 2023-06-17 20:32:06 +02:00
parent ed0701bdcd
commit 234fee167f
4 changed files with 59 additions and 25 deletions

View File

@ -54,3 +54,14 @@
## 0.4.3 ## 0.4.3
- Fix bug that causes ratchets to be unable to decrypt anything after receiving a heartbeat with a completely new session - 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`

View File

@ -34,3 +34,6 @@ class MalformedCiphertextError extends OmemoError {
/// The exception that was raised while decryption. /// The exception that was raised while decryption.
final Object ex; final Object ex;
} }
/// Caused by an empty <key /> element
class MalformedEncryptedKeyError extends OmemoError {}

View File

@ -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 // Check how we should process the message
final ratchetKey = final ratchetKey =
RatchetMapKey(stanza.bareSenderJid, stanza.senderDeviceId); RatchetMapKey(stanza.bareSenderJid, stanza.senderDeviceId);
@ -433,7 +441,9 @@ class OmemoManager {
return DecryptionResult(null, error); return DecryptionResult(null, error);
} }
final result = await _decryptAndVerifyHmac( Result<OmemoError, String?> result;
if (stanza.payload != null) {
result = await _decryptAndVerifyHmac(
stanza.payload?.fromBase64(), stanza.payload?.fromBase64(),
keyAndHmac.get<List<int>>(), keyAndHmac.get<List<int>>(),
); );
@ -446,6 +456,9 @@ class OmemoManager {
error, error,
); );
} }
} else {
result = const Result(null);
}
// Notify the trust manager // Notify the trust manager
await _trustManager.onNewSession( await _trustManager.onNewSession(
@ -530,7 +543,9 @@ class OmemoManager {
return DecryptionResult(null, error); return DecryptionResult(null, error);
} }
final result = await _decryptAndVerifyHmac( Result<OmemoError, String?> result;
if (stanza.payload != null) {
result = await _decryptAndVerifyHmac(
stanza.payload?.fromBase64(), stanza.payload?.fromBase64(),
keyAndHmac.get<List<int>>(), keyAndHmac.get<List<int>>(),
); );
@ -542,6 +557,9 @@ class OmemoManager {
error, error,
); );
} }
} else {
result = const Result(null);
}
// If we received an empty OMEMO message, mark the ratchet as acknowledged // If we received an empty OMEMO message, mark the ratchet as acknowledged
if (result.get<String?>() == null) { if (result.get<String?>() == null) {
@ -587,7 +605,7 @@ class OmemoManager {
// Encrypt the payload, if we have any // Encrypt the payload, if we have any
final List<int> payloadKey; final List<int> payloadKey;
final List<int> ciphertext; final List<int>? ciphertext;
if (stanza.payload != null) { if (stanza.payload != null) {
// Generate the key and encrypt the plaintext // Generate the key and encrypt the plaintext
final rawKey = generateRandomBytes(32); final rawKey = generateRandomBytes(32);
@ -601,7 +619,7 @@ class OmemoManager {
payloadKey = concat([rawKey, hmac]); payloadKey = concat([rawKey, hmac]);
} else { } else {
payloadKey = List<int>.filled(32, 0x0); payloadKey = List<int>.filled(32, 0x0);
ciphertext = []; ciphertext = null;
} }
final encryptionErrors = <String, List<EncryptToJidError>>{}; final encryptionErrors = <String, List<EncryptToJidError>>{};
@ -942,7 +960,9 @@ class OmemoManager {
/// Trust management functions /// Trust management functions
Future<void> withTrustManager( Future<void> withTrustManager(
String jid, Future<void> Function(TrustManager) callback) async { String jid,
Future<void> Function(TrustManager) callback,
) async {
await _ratchetQueue.synchronized( await _ratchetQueue.synchronized(
[jid], [jid],
() => callback(_trustManager), () => callback(_trustManager),

View File

@ -1,6 +1,6 @@
name: omemo_dart name: omemo_dart
description: An XMPP library independent OMEMO library description: An XMPP library independent OMEMO library
version: 0.4.3 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