From 771e0f81583ee61646a9c5a71aa1e1e25c737827 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 28 Sep 2022 15:10:08 +0300 Subject: WhatsApp: another fix for packet decryption --- protocols/WhatsAppWeb/src/noise.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'protocols/WhatsAppWeb/src') diff --git a/protocols/WhatsAppWeb/src/noise.cpp b/protocols/WhatsAppWeb/src/noise.cpp index b85bc8eb7b..207d53d56a 100644 --- a/protocols/WhatsAppWeb/src/noise.cpp +++ b/protocols/WhatsAppWeb/src/noise.cpp @@ -137,8 +137,7 @@ void WANoise::init() void WANoise::finish() { - deriveKey("", 0, salt, encKey); - decKey.assign(encKey.data(), encKey.length()); + deriveKey("", 0, encKey, decKey); readCounter = writeCounter = 0; memset(hash, 0, sizeof(hash)); bInitFinished = true; @@ -184,7 +183,9 @@ MBinBuffer WANoise::decrypt(const void *pData, size_t cbLen) EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new(); EVP_DecryptInit_ex(ctx, EVP_aes_256_gcm(), NULL, (BYTE *)decKey.data(), iv); - EVP_DecryptUpdate(ctx, nullptr, &tag_len, hash, sizeof(hash)); + if (!bInitFinished) + EVP_DecryptUpdate(ctx, nullptr, &tag_len, hash, sizeof(hash)); + cbLen -= 16; EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_TAG, 16, (BYTE *)pData + cbLen); -- cgit v1.2.3