fix: Fix some issues found by integrating
This commit is contained in:
parent
ed0701bdcd
commit
234fee167f
11
CHANGELOG.md
11
CHANGELOG.md
@ -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`
|
@ -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 {}
|
||||||
|
@ -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,18 +441,23 @@ class OmemoManager {
|
|||||||
return DecryptionResult(null, error);
|
return DecryptionResult(null, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
final result = await _decryptAndVerifyHmac(
|
Result<OmemoError, String?> result;
|
||||||
stanza.payload?.fromBase64(),
|
if (stanza.payload != null) {
|
||||||
keyAndHmac.get<List<int>>(),
|
result = await _decryptAndVerifyHmac(
|
||||||
);
|
stanza.payload?.fromBase64(),
|
||||||
if (result.isType<OmemoError>()) {
|
keyAndHmac.get<List<int>>(),
|
||||||
final error = result.get<OmemoError>();
|
|
||||||
_log.warning('Decrypting payload failed: $error');
|
|
||||||
|
|
||||||
return DecryptionResult(
|
|
||||||
null,
|
|
||||||
error,
|
|
||||||
);
|
);
|
||||||
|
if (result.isType<OmemoError>()) {
|
||||||
|
final error = result.get<OmemoError>();
|
||||||
|
_log.warning('Decrypting payload failed: $error');
|
||||||
|
|
||||||
|
return DecryptionResult(
|
||||||
|
null,
|
||||||
|
error,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
result = const Result(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notify the trust manager
|
// Notify the trust manager
|
||||||
@ -530,17 +543,22 @@ class OmemoManager {
|
|||||||
return DecryptionResult(null, error);
|
return DecryptionResult(null, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
final result = await _decryptAndVerifyHmac(
|
Result<OmemoError, String?> result;
|
||||||
stanza.payload?.fromBase64(),
|
if (stanza.payload != null) {
|
||||||
keyAndHmac.get<List<int>>(),
|
result = await _decryptAndVerifyHmac(
|
||||||
);
|
stanza.payload?.fromBase64(),
|
||||||
if (result.isType<OmemoError>()) {
|
keyAndHmac.get<List<int>>(),
|
||||||
final error = result.get<OmemoError>();
|
|
||||||
_log.warning('Failed to decrypt message: $error');
|
|
||||||
return DecryptionResult(
|
|
||||||
null,
|
|
||||||
error,
|
|
||||||
);
|
);
|
||||||
|
if (result.isType<OmemoError>()) {
|
||||||
|
final error = result.get<OmemoError>();
|
||||||
|
_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
|
// 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
|
// 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),
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user