summaryrefslogtreecommitdiff
path: root/protocols/WhatsApp/src
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/WhatsApp/src')
-rw-r--r--protocols/WhatsApp/src/appsync.cpp12
-rw-r--r--protocols/WhatsApp/src/message.cpp10
-rw-r--r--protocols/WhatsApp/src/proto.h4
-rw-r--r--protocols/WhatsApp/src/signal.cpp17
-rw-r--r--protocols/WhatsApp/src/utils.cpp13
-rw-r--r--protocols/WhatsApp/src/utils.h2
6 files changed, 42 insertions, 16 deletions
diff --git a/protocols/WhatsApp/src/appsync.cpp b/protocols/WhatsApp/src/appsync.cpp
index 8282317b4d..040983c666 100644
--- a/protocols/WhatsApp/src/appsync.cpp
+++ b/protocols/WhatsApp/src/appsync.cpp
@@ -105,7 +105,11 @@ void WhatsAppProto::OnIqServerSync(const WANode &node)
continue;
}
- proto::SyncdSnapshot snapshot(buf);
+ proto::SyncdSnapshot snapshot(unpad16buf(buf));
+ if (!snapshot) {
+ debugLogA("%s: unable to decode snapshot, skipping");
+ continue;
+ }
dwVersion = snapshot->version->version;
if (dwVersion > pCollection->version) {
@@ -120,6 +124,10 @@ void WhatsAppProto::OnIqServerSync(const WANode &node)
if (auto *pPatchList = coll->getChild("patches")) {
for (auto &it : pPatchList->getChildren()) {
proto::SyncdPatch patch(it->content);
+ if (!patch) {
+ debugLogA("%s: unable to decode patch, skipping");
+ continue;
+ }
dwVersion = patch->version->version;
if (dwVersion > pCollection->version) {
@@ -181,7 +189,7 @@ void WhatsAppProto::ParsePatch(WACollection *pColl, const Wa__SyncdRecord *rec,
return;
}
- proto::SyncActionData data(decoded);
+ proto::SyncActionData data(unpad16buf(decoded));
// debugLogA("Applying patch for %s{%d}: %s", pColl->szName.get(), data.version, data.Utf8DebugString().c_str());
diff --git a/protocols/WhatsApp/src/message.cpp b/protocols/WhatsApp/src/message.cpp
index 1397c7c17c..03275b446d 100644
--- a/protocols/WhatsApp/src/message.cpp
+++ b/protocols/WhatsApp/src/message.cpp
@@ -112,7 +112,7 @@ void WhatsAppProto::OnReceiveMessage(const WANode &node)
if (it->title != "enc" || it->content.length() == 0)
continue;
- SignalBuffer msgBody;
+ MBinBuffer msgBody;
auto *pszType = it->getAttr("type");
try {
if (!mir_strcmp(pszType, "pkmsg") || !mir_strcmp(pszType, "msg")) {
@@ -124,16 +124,12 @@ void WhatsAppProto::OnReceiveMessage(const WANode &node)
}
else throw "Invalid e2e type";
- if (!msgBody)
+ if (!msgBody.data())
throw "Invalid e2e message";
iDecryptable++;
- auto c = msgBody.data() + msgBody.len() - 1;
- if (*c <= 0x10)
- msgBody.reset(msgBody.len() - *c);
-
- proto::Message encMsg(msgBody.data(), msgBody.len());
+ proto::Message encMsg(unpad16buf(msgBody));
if (!encMsg)
throw "Invalid decoded message";
diff --git a/protocols/WhatsApp/src/proto.h b/protocols/WhatsApp/src/proto.h
index 5f315d3ace..c6b98a8fb9 100644
--- a/protocols/WhatsApp/src/proto.h
+++ b/protocols/WhatsApp/src/proto.h
@@ -204,8 +204,8 @@ public:
MSignalSession *createSession(const CMStringA &szName, int deviceId);
- signal_buffer* decryptSignalProto(const CMStringA &from, const char *pszType, const MBinBuffer &encrypted);
- signal_buffer* decryptGroupSignalProto(const CMStringA &from, const CMStringA &author, const MBinBuffer &encrypted);
+ MBinBuffer decryptSignalProto(const CMStringA &from, const char *pszType, const MBinBuffer &encrypted);
+ MBinBuffer decryptGroupSignalProto(const CMStringA &from, const CMStringA &author, const MBinBuffer &encrypted);
signal_buffer* encryptSignalProto(const WAJid &to, const MBinBuffer &buf, int &type);
diff --git a/protocols/WhatsApp/src/signal.cpp b/protocols/WhatsApp/src/signal.cpp
index 1a59fb443b..07f213d8d5 100644
--- a/protocols/WhatsApp/src/signal.cpp
+++ b/protocols/WhatsApp/src/signal.cpp
@@ -487,7 +487,7 @@ MSignalSession* MSignalStore::createSession(const CMStringA &szName, int deviceI
/////////////////////////////////////////////////////////////////////////////////////////
-signal_buffer* MSignalStore::decryptSignalProto(const CMStringA &from, const char *pszType, const MBinBuffer &encrypted)
+MBinBuffer MSignalStore::decryptSignalProto(const CMStringA &from, const char *pszType, const MBinBuffer &encrypted)
{
WAJid jid(from);
auto *pSession = createSession(jid.user, 0);
@@ -518,10 +518,13 @@ signal_buffer* MSignalStore::decryptSignalProto(const CMStringA &from, const cha
signal_message_destroy((signal_type_base *)pMsg);
}
- return result;
+ MBinBuffer res;
+ res.assign(result->data, result->len);
+ signal_buffer_free(result);
+ return res;
}
-signal_buffer* MSignalStore::decryptGroupSignalProto(const CMStringA &group, const CMStringA &sender, const MBinBuffer &encrypted)
+MBinBuffer MSignalStore::decryptGroupSignalProto(const CMStringA &group, const CMStringA &sender, const MBinBuffer &encrypted)
{
WAJid jid(sender);
auto *pSession = createSession(group + CMStringA(FORMAT, "::%s::%d", jid.user.c_str(), jid.device), 0);
@@ -537,7 +540,11 @@ signal_buffer* MSignalStore::decryptGroupSignalProto(const CMStringA &group, con
"unable to decrypt signal message");
signal_message_destroy((signal_type_base *)pMsg);
- return result;
+
+ MBinBuffer res;
+ res.assign(result->data, result->len);
+ signal_buffer_free(result);
+ return res;
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -599,6 +606,6 @@ void MSignalStore::generatePrekeys(int count)
/////////////////////////////////////////////////////////////////////////////////////////
-void MSignalStore::processSenderKeyMessage(const Wa__Message__SenderKeyDistributionMessage *msg)
+void MSignalStore::processSenderKeyMessage(const Wa__Message__SenderKeyDistributionMessage *)
{
}
diff --git a/protocols/WhatsApp/src/utils.cpp b/protocols/WhatsApp/src/utils.cpp
index 983a98a3f7..7210c2e5d0 100644
--- a/protocols/WhatsApp/src/utils.cpp
+++ b/protocols/WhatsApp/src/utils.cpp
@@ -268,6 +268,19 @@ void generateIV(uint8_t *iv, int &pVar)
pVar++;
}
+MBinBuffer unpad16buf(const MBinBuffer &buf)
+{
+ size_t len = buf.length();
+ auto p = buf.data() + len - 1;
+ if (*p <= 0x10) {
+ MBinBuffer res;
+ res.assign(buf.data(), len - *p);
+ return res;
+ }
+
+ return buf;
+}
+
/////////////////////////////////////////////////////////////////////////////////////////
// Popups
diff --git a/protocols/WhatsApp/src/utils.h b/protocols/WhatsApp/src/utils.h
index f102c47c2a..e883d5617f 100644
--- a/protocols/WhatsApp/src/utils.h
+++ b/protocols/WhatsApp/src/utils.h
@@ -205,6 +205,8 @@ CMStringA directPath2url(const char *pszDirectPath);
std::string decodeBinStr(const std::string &buf);
MBinBuffer decodeBufStr(const std::string &buf);
+MBinBuffer unpad16buf(const MBinBuffer &buf);
+
MBinBuffer aesDecrypt(
const EVP_CIPHER *cipher,
const uint8_t *key,