feat: Attempt to detect already decrypted messages
This commit is contained in:
parent
2aa3674c4b
commit
0826d043d5
@ -40,3 +40,9 @@ class InvalidKeyExchangeException implements Exception {
|
|||||||
final int actualPn;
|
final int actualPn;
|
||||||
String errMsg() => 'The pn attribute of the key exchange is invalid. Expected $expectedPn, got $actualPn';
|
String errMsg() => 'The pn attribute of the key exchange is invalid. Expected $expectedPn, got $actualPn';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Triggered by the Session Manager when a message's sequence number is smaller than we
|
||||||
|
/// expect it to be.
|
||||||
|
class MessageAlreadyDecryptedException implements Exception {
|
||||||
|
String errMsg() => 'The message has already been decrypted';
|
||||||
|
}
|
||||||
|
@ -401,6 +401,12 @@ class OmemoSessionManager {
|
|||||||
final ratchet = (await _getRatchet(ratchetKey))!;
|
final ratchet = (await _getRatchet(ratchetKey))!;
|
||||||
oldRatchet ??= ratchet.clone();
|
oldRatchet ??= ratchet.clone();
|
||||||
|
|
||||||
|
if (!rawKey.kex) {
|
||||||
|
if (message.n! < ratchet.nr - 1) {
|
||||||
|
throw MessageAlreadyDecryptedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (rawKey.kex) {
|
if (rawKey.kex) {
|
||||||
keyAndHmac = await ratchet.ratchetDecrypt(message, authMessage.writeToBuffer());
|
keyAndHmac = await ratchet.ratchetDecrypt(message, authMessage.writeToBuffer());
|
||||||
|
@ -730,7 +730,9 @@ void main() {
|
|||||||
msg.encryptedKeys,
|
msg.encryptedKeys,
|
||||||
);
|
);
|
||||||
expect(true, false);
|
expect(true, false);
|
||||||
} catch (_) {
|
} on MessageAlreadyDecryptedException catch (_) {
|
||||||
|
errorCounter++;
|
||||||
|
} on InvalidKeyExchangeException catch (_) {
|
||||||
errorCounter++;
|
errorCounter++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user