summaryrefslogtreecommitdiff
path: root/protocols/WhatsAppWeb/src
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2022-09-27 21:58:08 +0300
committerGeorge Hazan <ghazan@miranda.im>2022-09-27 21:58:08 +0300
commit49069bcc23da6ef9790c6efb2d0e5d3c92c6b7fd (patch)
treec1a25fbee57d3e17b7e2d5dc25674515aa567087 /protocols/WhatsAppWeb/src
parent9c87b08dd62901761f3bd41cb13122b79233c75b (diff)
WhatsApp: fix for encryption mechanism
Diffstat (limited to 'protocols/WhatsAppWeb/src')
-rw-r--r--protocols/WhatsAppWeb/src/noise.cpp11
-rw-r--r--protocols/WhatsAppWeb/src/server.cpp7
2 files changed, 12 insertions, 6 deletions
diff --git a/protocols/WhatsAppWeb/src/noise.cpp b/protocols/WhatsAppWeb/src/noise.cpp
index 0ff9ac2ab5..79dc19e266 100644
--- a/protocols/WhatsAppWeb/src/noise.cpp
+++ b/protocols/WhatsAppWeb/src/noise.cpp
@@ -244,9 +244,10 @@ MBinBuffer WANoise::encodeFrame(const void *pData, size_t cbLen)
MBinBuffer WANoise::encrypt(const void *pData, size_t cbLen)
{
+ auto counter = encodeBigEndian(writeCounter);
uint8_t iv[12];
- memset(iv, 0, 8);
- memcpy(iv + 8, &writeCounter, sizeof(int));
+ memset(iv, 0, sizeof(iv));
+ memcpy(iv + 8, counter.c_str(), sizeof(int));
writeCounter++;
MBinBuffer res;
@@ -255,6 +256,7 @@ MBinBuffer WANoise::encrypt(const void *pData, size_t cbLen)
int enc_len = 0, final_len = 0;
EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
EVP_EncryptInit_ex(ctx, EVP_aes_256_gcm(), NULL, (BYTE *)encKey.data(), iv);
+ EVP_EncryptUpdate(ctx, NULL, &enc_len, hash, sizeof(hash));
for (size_t len = 0; len < cbLen; len += 1024) {
size_t portionSize = cbLen - len;
EVP_EncryptUpdate(ctx, outbuf, &enc_len, (BYTE *)pData + len, (int)min(portionSize, 1024));
@@ -263,6 +265,11 @@ MBinBuffer WANoise::encrypt(const void *pData, size_t cbLen)
EVP_EncryptFinal_ex(ctx, outbuf, &final_len);
if (final_len)
res.append(outbuf, final_len);
+
+ uint8_t tag[16];
+ EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_GET_TAG, sizeof(tag), tag);
+ res.append(tag, sizeof(tag));
+
EVP_CIPHER_CTX_free(ctx);
updateHash(res.data(), res.length());
diff --git a/protocols/WhatsAppWeb/src/server.cpp b/protocols/WhatsAppWeb/src/server.cpp
index 3677ca7176..4633fd74ac 100644
--- a/protocols/WhatsAppWeb/src/server.cpp
+++ b/protocols/WhatsAppWeb/src/server.cpp
@@ -71,10 +71,10 @@ bool WhatsAppProto::ProcessHandshake(const MBinBuffer &keyEnc)
pAppVersion->set_quaternary(v[3]);
proto::DeviceProps pCompanion;
- pCompanion.set_os("Chrome");
+ pCompanion.set_os("Miranda");
pCompanion.set_allocated_version(pAppVersion);
pCompanion.set_platformtype(proto::DeviceProps_PlatformType_DESKTOP);
- pCompanion.set_requirefullsync(true);
+ pCompanion.set_requirefullsync(false);
MBinBuffer buf(pCompanion.ByteSize());
pCompanion.SerializeToArray(buf.data(), (int)buf.length());
@@ -233,8 +233,7 @@ bool WhatsAppProto::ServerThreadWorker()
m_iPktNumber = 0;
m_szClientToken = getMStringA(DBKEY_CLIENT_TOKEN);
- auto &pubKey = m_noise->noiseKeys.pub;
- ptrA szPubKey(mir_base64_encode(pubKey.data(), pubKey.length()));
+ auto &pubKey = m_noise->ephemeral.pub;
auto *client = new proto::HandshakeMessage::ClientHello(); client->set_ephemeral(pubKey.data(), pubKey.length());
proto::HandshakeMessage msg; msg.set_allocated_clienthello(client);
WSSend(msg, &WhatsAppProto::OnStartSession);