feat: Check the HMAC during decryption

This commit is contained in:
2022-08-03 16:41:33 +02:00
parent 6d8238475c
commit 8d222a160f
3 changed files with 23 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
import 'dart:convert';
import 'package:cryptography/cryptography.dart';
import 'package:omemo_dart/protobuf/schema.pb.dart';
import 'package:omemo_dart/src/errors.dart';
import 'package:omemo_dart/src/helpers.dart';
/// Info string for ENCRYPT
@@ -93,7 +94,9 @@ Future<List<int>> decrypt(List<int> mk, List<int> ciphertext, List<int> associat
secretKey: SecretKey(authenticationKey),
)).bytes.sublist(0, 16);
// TODO(PapaTutuWawa): Check the HMAC result
if (!listsEqual(hmacResult, message.mac)) {
throw InvalidMessageHMACException();
}
final plaintext = await AesCbc.with256bits(
macAlgorithm: MacAlgorithm.empty,