summaryrefslogtreecommitdiff
path: root/protocols/WhatsApp/src
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/WhatsApp/src')
-rw-r--r--protocols/WhatsApp/src/db.h2
-rw-r--r--protocols/WhatsApp/src/iq.cpp1
-rw-r--r--protocols/WhatsApp/src/proto.h2
-rw-r--r--protocols/WhatsApp/src/signal.cpp43
4 files changed, 32 insertions, 16 deletions
diff --git a/protocols/WhatsApp/src/db.h b/protocols/WhatsApp/src/db.h
index c8cb6e249c..164f2f5fe1 100644
--- a/protocols/WhatsApp/src/db.h
+++ b/protocols/WhatsApp/src/db.h
@@ -19,7 +19,7 @@ Copyright © 2019-22 George Hazan
#define DBKEY_SIGNED_IDENTITY_PUB "SignedIdentityPublicKey"
#define DBKEY_SIGNED_IDENTITY_PRIV "SignedIdentityPrivateKey"
-#define DBKEY_PREKEY "SignedPreKey0"
+#define DBKEY_PREKEY "SignedPreKey1"
#define DBKEY_PREKEY_NEXT_ID "PrekeyNextId"
#define DBKEY_PREKEY_UPLOAD_ID "PrekeyUploadId"
diff --git a/protocols/WhatsApp/src/iq.cpp b/protocols/WhatsApp/src/iq.cpp
index 61c54e4cd8..255682ad81 100644
--- a/protocols/WhatsApp/src/iq.cpp
+++ b/protocols/WhatsApp/src/iq.cpp
@@ -252,7 +252,6 @@ void WhatsAppProto::OnReceiveMessage(const WANode &node)
SendReceipt(szChatId, pszReceiptTo, msgId, pszReceiptType);
}
catch (const char *pszError) {
- debugLogA("Message cannot be parsed: %s", pszError);
}
if (!iDecryptable) {
diff --git a/protocols/WhatsApp/src/proto.h b/protocols/WhatsApp/src/proto.h
index d5fb32e80d..475f564027 100644
--- a/protocols/WhatsApp/src/proto.h
+++ b/protocols/WhatsApp/src/proto.h
@@ -211,6 +211,8 @@ public:
void generatePrekeys(int count);
+ void logError(int code, const char *szMessage);
+
void processSenderKeyMessage(const proto::Message_SenderKeyDistributionMessage &msg);
};
diff --git a/protocols/WhatsApp/src/signal.cpp b/protocols/WhatsApp/src/signal.cpp
index e80eeac4ee..c43b8eb8a3 100644
--- a/protocols/WhatsApp/src/signal.cpp
+++ b/protocols/WhatsApp/src/signal.cpp
@@ -32,6 +32,14 @@ MSignalStore::~MSignalStore()
signal_context_destroy(m_pContext);
}
+void MSignalStore::logError(int err, const char *pszMessage)
+{
+ if (err < 0) {
+ pProto->debugLogA("libsignal error %d: %s", err, pszMessage);
+ throw pszMessage;
+ }
+}
+
/////////////////////////////////////////////////////////////////////////////////////////
static void log_func(int level, const char *pmsg, size_t /*msgLen*/, void *pUserData)
@@ -439,8 +447,9 @@ MSignalSession* MSignalStore::createSession(const CMStringA &szName, int deviceI
}
if (pSession->cipher == nullptr)
- if (session_cipher_create(&pSession->cipher, m_pStore, &pSession->address, m_pContext) < 0)
- throw "session_cipher_create failure";
+ logError(
+ session_cipher_create(&pSession->cipher, m_pStore, &pSession->address, m_pContext),
+ "session_cipher_create failure");
return pSession;
}
@@ -455,21 +464,25 @@ signal_buffer* MSignalStore::decryptSignalProto(const CMStringA &from, const cha
signal_buffer *result = nullptr;
if (!mir_strcmp(pszType, "pkmsg")) {
pre_key_signal_message *pMsg;
- if (pre_key_signal_message_deserialize(&pMsg, (BYTE *)encrypted.data(), encrypted.length(), m_pContext) < 0)
- throw "unable to deserialize prekey message";
+ logError(
+ pre_key_signal_message_deserialize(&pMsg, (BYTE *)encrypted.data(), encrypted.length(), m_pContext),
+ "unable to deserialize prekey message");
- if (session_cipher_decrypt_pre_key_signal_message(pSession->getCipher(), pMsg, this, &result) < 0)
- throw "unable to decrypt prekey message";
+ logError(
+ session_cipher_decrypt_pre_key_signal_message(pSession->getCipher(), pMsg, this, &result),
+ "unable to decrypt prekey message");
pre_key_signal_message_destroy((signal_type_base*)pMsg);
}
else {
signal_message *pMsg;
- if (signal_message_deserialize(&pMsg, (BYTE *)encrypted.data(), encrypted.length(), m_pContext) < 0)
- throw "unable to deserialize signal message";
+ logError(
+ signal_message_deserialize(&pMsg, (BYTE *)encrypted.data(), encrypted.length(), m_pContext),
+ "unable to deserialize signal message");
- if (session_cipher_decrypt_signal_message(pSession->getCipher(), pMsg, this, &result) < 0)
- throw "unable to decrypt signal message";
+ logError(
+ session_cipher_decrypt_signal_message(pSession->getCipher(), pMsg, this, &result),
+ "unable to decrypt signal message");
signal_message_destroy((signal_type_base *)pMsg);
}
@@ -483,12 +496,14 @@ signal_buffer* MSignalStore::decryptGroupSignalProto(const CMStringA &group, con
auto *pSession = createSession(group + CMStringA(FORMAT, "::%s::%d", jid.user.c_str(), jid.device), 0);
signal_message *pMsg;
- if (signal_message_deserialize(&pMsg, (BYTE *)encrypted.data(), encrypted.length(), m_pContext) < 0)
- throw "unable to deserialize signal message";
+ logError(
+ signal_message_deserialize(&pMsg, (BYTE *)encrypted.data(), encrypted.length(), m_pContext),
+ "unable to deserialize signal message");
signal_buffer *result = nullptr;
- if (session_cipher_decrypt_signal_message(pSession->getCipher(), pMsg, this, &result) < 0)
- throw "unable to decrypt signal message";
+ logError(
+ session_cipher_decrypt_signal_message(pSession->getCipher(), pMsg, this, &result),
+ "unable to decrypt signal message");
signal_message_destroy((signal_type_base *)pMsg);
return result;