summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--protocols/WhatsApp/src/appsync.cpp6
-rw-r--r--protocols/WhatsApp/src/iq.cpp2
-rw-r--r--protocols/WhatsApp/src/message.cpp4
-rw-r--r--protocols/WhatsApp/src/noise.cpp8
-rw-r--r--protocols/WhatsApp/src/signal.cpp33
-rw-r--r--protocols/WhatsApp/src/utils.cpp2
6 files changed, 28 insertions, 27 deletions
diff --git a/protocols/WhatsApp/src/appsync.cpp b/protocols/WhatsApp/src/appsync.cpp
index f976c580b6..928e78fe50 100644
--- a/protocols/WhatsApp/src/appsync.cpp
+++ b/protocols/WhatsApp/src/appsync.cpp
@@ -100,7 +100,7 @@ void WhatsAppProto::OnIqServerSync(const WANode &node)
}
MBinBuffer buf = DownloadEncryptedFile(directPath2url(body->directpath), body->mediakey, "App State");
- if (!buf.data()) {
+ if (buf.isEmpty()) {
debugLogA("Invalid downloaded snapshot data, skipping");
continue;
}
@@ -163,7 +163,7 @@ void WhatsAppProto::ParsePatch(WACollection *pColl, const Wa__SyncdRecord *rec,
std::string index((char *)indexBlob.data, indexBlob.len);
MBinBuffer key(getBlob(CMStringA(FORMAT, "AppSyncKey%d", id)));
- if (!key.data()) {
+ if (key.isEmpty()) {
debugLogA("No key with id=%d to decode a patch");
return;
}
@@ -181,7 +181,7 @@ void WhatsAppProto::ParsePatch(WACollection *pColl, const Wa__SyncdRecord *rec,
HKDF(EVP_sha256(), (BYTE *)"", 0, key.data(), key.length(), sttMutationInfo, sizeof(sttMutationInfo) - 1, (BYTE *)&mutationKeys, sizeof(mutationKeys));
MBinBuffer decoded = aesDecrypt(EVP_aes_256_cbc(), mutationKeys.encKey, value.data, value.data + 16, value.len - 32);
- if (!decoded.data()) {
+ if (decoded.isEmpty()) {
debugLogA("Unable to decode patch with key id=%d", id);
return;
}
diff --git a/protocols/WhatsApp/src/iq.cpp b/protocols/WhatsApp/src/iq.cpp
index 7dede1f437..c86e1e23a1 100644
--- a/protocols/WhatsApp/src/iq.cpp
+++ b/protocols/WhatsApp/src/iq.cpp
@@ -178,7 +178,7 @@ void WhatsAppProto::OnIqPairSuccess(const WANode &node)
signal_buffer *result;
ec_private_key key = {};
memcpy(key.data, m_signalStore.signedIdentity.priv.data(), m_signalStore.signedIdentity.priv.length());
- if (curve_calculate_signature(m_signalStore.CTX(), &result, &key, (BYTE *)buf.data(), buf.length()) != 0)
+ if (curve_calculate_signature(m_signalStore.CTX(), &result, &key, buf.data(), buf.length()) != 0)
throw "OnIqPairSuccess: cannot calculate account signature, exiting";
account->devicesignature = proto::SetBinary(result->data, result->len);
diff --git a/protocols/WhatsApp/src/message.cpp b/protocols/WhatsApp/src/message.cpp
index 4eeb62872a..e82cef0334 100644
--- a/protocols/WhatsApp/src/message.cpp
+++ b/protocols/WhatsApp/src/message.cpp
@@ -124,7 +124,7 @@ void WhatsAppProto::OnReceiveMessage(const WANode &node)
}
else throw "Invalid e2e type";
- if (!msgBody.data())
+ if (msgBody.isEmpty())
throw "Invalid e2e message";
iDecryptable++;
@@ -255,7 +255,7 @@ void WhatsAppProto::ProcessMessage(WAMSG type, const Wa__WebMessageInfo &msg)
debugLogA("History sync notification");
if (auto *pHist = protoMsg->historysyncnotification) {
MBinBuffer buf(DownloadEncryptedFile(directPath2url(pHist->directpath), pHist->mediakey, "History"));
- if (buf.data()) {
+ if (!buf.isEmpty()) {
MBinBuffer inflate(unzip(unpadBuffer16(buf)));
proto::HistorySync sync(inflate);
diff --git a/protocols/WhatsApp/src/noise.cpp b/protocols/WhatsApp/src/noise.cpp
index a8d5b1f377..004b71cdef 100644
--- a/protocols/WhatsApp/src/noise.cpp
+++ b/protocols/WhatsApp/src/noise.cpp
@@ -81,7 +81,7 @@ void WANoise::deriveKey(const void *pData, size_t cbLen, MBinBuffer &write, MBin
{
size_t outlen = 64;
uint8_t out[64];
- HKDF(EVP_sha256(), (BYTE *)salt.data(), (int)salt.length(), (BYTE *)pData, (int)cbLen, (BYTE *)"", 0, out, outlen);
+ HKDF(EVP_sha256(), salt.data(), (int)salt.length(), (BYTE *)pData, (int)cbLen, (BYTE *)"", 0, out, outlen);
write.assign(out, 32);
read.assign(out + 32, 32);
@@ -104,9 +104,9 @@ MBinBuffer WANoise::decrypt(const void *pData, size_t cbLen)
MBinBuffer res;
if (!bInitFinished)
- res = aesDecrypt(EVP_aes_256_gcm(), (BYTE *)decKey.data(), iv, pData, cbLen, hash, sizeof(hash));
+ res = aesDecrypt(EVP_aes_256_gcm(), decKey.data(), iv, pData, cbLen, hash, sizeof(hash));
else
- res = aesDecrypt(EVP_aes_256_gcm(), (BYTE *)decKey.data(), iv, pData, cbLen);
+ res = aesDecrypt(EVP_aes_256_gcm(), decKey.data(), iv, pData, cbLen);
updateHash(pData, cbLen);
return res;
@@ -164,7 +164,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_EncryptInit_ex(ctx, EVP_aes_256_gcm(), NULL, encKey.data(), iv);
if (!bInitFinished)
EVP_EncryptUpdate(ctx, NULL, &enc_len, hash, sizeof(hash));
diff --git a/protocols/WhatsApp/src/signal.cpp b/protocols/WhatsApp/src/signal.cpp
index 47bf9462af..e9ec23b014 100644
--- a/protocols/WhatsApp/src/signal.cpp
+++ b/protocols/WhatsApp/src/signal.cpp
@@ -209,12 +209,12 @@ static int load_pre_key(signal_buffer **record, uint32_t pre_key_id, void *user_
CMStringA szSetting(FORMAT, "%s%d", "PreKey", pre_key_id);
MBinBuffer blob(pStore->pProto->getBlob(szSetting));
- if (blob.data() == 0) {
+ if (blob.isEmpty()) {
pStore->pProto->debugLogA("Prekey #%d not found", pre_key_id);
return SG_ERR_INVALID_KEY_ID;
}
- *record = signal_buffer_create((uint8_t *)blob.data(), blob.length());
+ *record = signal_buffer_create(blob.data(), blob.length());
return SG_SUCCESS; //key exists and succesfully loaded
}
@@ -274,7 +274,7 @@ static int load_signed_pre_key(signal_buffer **record, uint32_t signed_pre_key_i
CMStringA szSetting(FORMAT, "%s%d", "SignedPreKey", signed_pre_key_id);
MBinBuffer blob(pStore->pProto->getBlob(szSetting));
- if (blob.data() == 0) {
+ if (blob.isEmpty()) {
pStore->pProto->debugLogA("Signed prekey #%d not found", signed_pre_key_id);
return SG_ERR_INVALID_KEY_ID;
}
@@ -310,7 +310,7 @@ static int get_identity_key_pair(signal_buffer **public_data, signal_buffer **pr
buf.append(pStore->signedIdentity.pub);
*public_data = signal_buffer_create(buf.data(), (int)buf.length());
- *private_data = signal_buffer_create((uint8_t *)pStore->signedIdentity.priv.data(), (int)pStore->signedIdentity.priv.length());
+ *private_data = signal_buffer_create(pStore->signedIdentity.priv.data(), (int)pStore->signedIdentity.priv.length());
return 0;
}
@@ -344,7 +344,7 @@ static int load_sender_key(signal_buffer **record, signal_buffer **, const signa
CMStringA szSetting(FORMAT, "SenderKey_%*s_%*s_%d", (unsigned)skn->group_id_len, skn->group_id, (unsigned)skn->sender.name_len, skn->sender.name, skn->sender.device_id);
MBinBuffer blob(pStore->pProto->getBlob(szSetting));
- if (blob.data() == 0)
+ if (blob.isEmpty())
return 0;
*record = signal_buffer_create(blob.data(), blob.length());
@@ -376,9 +376,10 @@ void MSignalStore::init()
prov.encrypt_func = encrypt_func;
signal_context_set_crypto_provider(m_pContext, &prov);
- // default values calculation
- if (pProto->getDword(DBKEY_PREKEY_NEXT_ID, 0xFFFF) == 0xFFFF) {
- // generate signed identity keys (private & public)
+ // read resident data from database
+ MBinBuffer blob(pProto->getBlob(DBKEY_PREKEY));
+ if (blob.isEmpty()) {
+ // nothing? generate signed identity keys (private & public)
ratchet_identity_key_pair *keyPair;
signal_protocol_key_helper_generate_identity_key_pair(&keyPair, m_pContext);
@@ -393,15 +394,12 @@ void MSignalStore::init()
SignalBuffer prekeyBuf(signed_pre_key);
db_set_blob(0, pProto->m_szModuleName, DBKEY_PREKEY, prekeyBuf.data(), prekeyBuf.len());
+ blob.assign(prekeyBuf.data(), prekeyBuf.len());
+
SIGNAL_UNREF(signed_pre_key);
SIGNAL_UNREF(keyPair);
}
- // read resident data from database
- signedIdentity.pub = pProto->getBlob(DBKEY_SIGNED_IDENTITY_PUB);
- signedIdentity.priv = pProto->getBlob(DBKEY_SIGNED_IDENTITY_PRIV);
-
- MBinBuffer blob(pProto->getBlob(DBKEY_PREKEY));
session_signed_pre_key *signed_pre_key;
session_signed_pre_key_deserialize(&signed_pre_key, blob.data(), blob.length(), m_pContext);
@@ -416,6 +414,9 @@ void MSignalStore::init()
preKey.keyid = session_signed_pre_key_get_id(signed_pre_key);
SIGNAL_UNREF(signed_pre_key);
+ signedIdentity.pub = pProto->getBlob(DBKEY_SIGNED_IDENTITY_PUB);
+ signedIdentity.priv = pProto->getBlob(DBKEY_SIGNED_IDENTITY_PRIV);
+
// create store with callbacks
signal_protocol_store_context_create(&m_pStore, m_pContext);
@@ -518,7 +519,7 @@ MSignalSession* MSignalStore::getSession(const signal_protocol_address *address)
auto *pSession = arSessions.find(&tmp);
if (pSession == nullptr) {
MBinBuffer blob(pProto->getBlob(tmp.getSetting()));
- if (blob.data() == nullptr)
+ if (blob.isEmpty())
return nullptr;
pSession = new MSignalSession(tmp);
@@ -540,7 +541,7 @@ MBinBuffer MSignalStore::decryptSignalProto(const CMStringA &from, const char *p
if (!mir_strcmp(pszType, "pkmsg")) {
pre_key_signal_message *pMsg;
logError(
- pre_key_signal_message_deserialize(&pMsg, (BYTE *)encrypted.data(), encrypted.length(), m_pContext),
+ pre_key_signal_message_deserialize(&pMsg, encrypted.data(), encrypted.length(), m_pContext),
"unable to deserialize prekey message");
logError(
@@ -552,7 +553,7 @@ MBinBuffer MSignalStore::decryptSignalProto(const CMStringA &from, const char *p
else {
signal_message *pMsg;
logError(
- signal_message_deserialize(&pMsg, (BYTE *)encrypted.data(), encrypted.length(), m_pContext),
+ signal_message_deserialize(&pMsg, encrypted.data(), encrypted.length(), m_pContext),
"unable to deserialize signal message");
logError(
diff --git a/protocols/WhatsApp/src/utils.cpp b/protocols/WhatsApp/src/utils.cpp
index 2fde05e080..f4cc2e0e55 100644
--- a/protocols/WhatsApp/src/utils.cpp
+++ b/protocols/WhatsApp/src/utils.cpp
@@ -448,7 +448,7 @@ void WhatsAppProto::GetMessageContent(
szMediaType[0] = toupper(szMediaType[0]);
MBinBuffer buf = DownloadEncryptedFile(directPath2url(szDirectPath), pMediaKey, szMediaType);
- if (buf.data()) {
+ if (!buf.isEmpty()) {
CMStringW pwszFileName(GetTmpFileName(szType, url));
bin2file(buf, pwszFileName);