summaryrefslogtreecommitdiff
path: root/protocols/WhatsAppWeb
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2022-10-06 17:15:01 +0300
committerGeorge Hazan <ghazan@miranda.im>2022-10-06 17:15:01 +0300
commit732d51e59bcf30e22b991f2daf25095c2a146941 (patch)
treea15e8c90eb6e9b7e58c800c8bee5db8a6ea8cc25 /protocols/WhatsAppWeb
parent8f7bb7e2d0317146e03f533e77c8da539209d7d2 (diff)
mir_signal: C++ helper to get rid of tons code in C
Diffstat (limited to 'protocols/WhatsAppWeb')
-rw-r--r--protocols/WhatsAppWeb/WhatsAppWeb.vcxproj4
-rw-r--r--protocols/WhatsAppWeb/WhatsAppWeb.vcxproj.filters6
-rw-r--r--protocols/WhatsAppWeb/src/signal.cpp25
-rw-r--r--protocols/WhatsAppWeb/src/stdafx.h33
4 files changed, 20 insertions, 48 deletions
diff --git a/protocols/WhatsAppWeb/WhatsAppWeb.vcxproj b/protocols/WhatsAppWeb/WhatsAppWeb.vcxproj
index 50ae4808dd..d39592a2f4 100644
--- a/protocols/WhatsAppWeb/WhatsAppWeb.vcxproj
+++ b/protocols/WhatsAppWeb/WhatsAppWeb.vcxproj
@@ -58,6 +58,9 @@
</ClCompile>
</ItemDefinitionGroup>
<ItemGroup>
+ <ClCompile Include="..\..\utils\mir_signal.cpp">
+ <PrecompiledHeader>NotUsing</PrecompiledHeader>
+ </ClCompile>
<ClCompile Include="src\avatars.cpp" />
<ClCompile Include="src\chats.cpp" />
<ClCompile Include="src\iq.cpp" />
@@ -76,6 +79,7 @@
</ClCompile>
<ClCompile Include="src\utils.cpp" />
<ClCompile Include="src\wanode.cpp" />
+ <ClInclude Include="..\..\utils\mir_signal.h" />
<ClInclude Include="src\db.h" />
<ClInclude Include="src\dicts.h" />
<ClInclude Include="src\proto.h" />
diff --git a/protocols/WhatsAppWeb/WhatsAppWeb.vcxproj.filters b/protocols/WhatsAppWeb/WhatsAppWeb.vcxproj.filters
index 31a86f3851..dca4011eb0 100644
--- a/protocols/WhatsAppWeb/WhatsAppWeb.vcxproj.filters
+++ b/protocols/WhatsAppWeb/WhatsAppWeb.vcxproj.filters
@@ -44,6 +44,9 @@
<ClCompile Include="src\signal.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="..\..\utils\mir_signal.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\db.h">
@@ -67,6 +70,9 @@
<ClInclude Include="src\dicts.h">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="..\..\utils\mir_signal.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="res\version.rc">
diff --git a/protocols/WhatsAppWeb/src/signal.cpp b/protocols/WhatsAppWeb/src/signal.cpp
index 467572737a..92973ac629 100644
--- a/protocols/WhatsAppWeb/src/signal.cpp
+++ b/protocols/WhatsAppWeb/src/signal.cpp
@@ -207,14 +207,10 @@ static int store_pre_key(uint32_t pre_key_id, uint8_t *record, size_t record_len
session_pre_key_deserialize(&prekey, record, record_len, pStore->CTX()); //TODO: handle error
if (prekey) {
ec_key_pair *pre_key_pair = session_pre_key_get_key_pair(prekey);
- signal_buffer *key_buf = nullptr;
- ec_public_key *public_key = ec_key_pair_get_public(pre_key_pair);
- ec_public_key_serialize(&key_buf, public_key);
- SIGNAL_UNREF(public_key);
+ SignalBuffer key_buf(ec_key_pair_get_public(pre_key_pair));
szSetting.Format("PreKey%uPublic", pre_key_id);
- db_set_blob(0, pStore->pProto->m_szModuleName, szSetting, signal_buffer_data(key_buf), (int)signal_buffer_len(key_buf));
- signal_buffer_free(key_buf);
+ db_set_blob(0, pStore->pProto->m_szModuleName, szSetting, key_buf.data(), key_buf.len());
}
return 0;
@@ -330,10 +326,8 @@ void MSignalStore::init()
signal_protocol_key_helper_generate_signed_pre_key(&signed_pre_key, keyPair, 1, time(0), m_pContext);
SIGNAL_UNREF(keyPair);
- signal_buffer *my_prekey;
- session_signed_pre_key_serialize(&my_prekey, signed_pre_key);
- db_set_blob(0, pProto->m_szModuleName, DBKEY_PREKEY, my_prekey->data, (int)my_prekey->len);
- SIGNAL_UNREF(my_prekey);
+ SignalBuffer prekeyBuf(signed_pre_key);
+ db_set_blob(0, pProto->m_szModuleName, DBKEY_PREKEY, prekeyBuf.data(), prekeyBuf.len());
// generate and save pre keys set
CMStringA szSetting;
@@ -342,13 +336,10 @@ void MSignalStore::init()
for (auto *it = keys_root; it; it = signal_protocol_key_helper_key_list_next(it)) {
session_pre_key *pre_key = signal_protocol_key_helper_key_list_element(it);
uint32_t pre_key_id = session_pre_key_get_id(pre_key);
- {
- signal_buffer *serialized_pre_key;
- session_pre_key_serialize(&serialized_pre_key, pre_key);
- szSetting.Format("PreKey%d", pre_key_id);
- db_set_blob(0, pProto->m_szModuleName, szSetting, signal_buffer_data(serialized_pre_key), (unsigned int)signal_buffer_len(serialized_pre_key));
- SIGNAL_UNREF(serialized_pre_key);
- }
+
+ SignalBuffer buf(pre_key);
+ szSetting.Format("PreKey%d", pre_key_id);
+ db_set_blob(0, pProto->m_szModuleName, szSetting, buf.data(), buf.len());
ec_key_pair *pre_key_pair = session_pre_key_get_key_pair(pre_key);
pPubKey = ec_key_pair_get_public(pre_key_pair);
diff --git a/protocols/WhatsAppWeb/src/stdafx.h b/protocols/WhatsAppWeb/src/stdafx.h
index bbcda15825..5c6698d56e 100644
--- a/protocols/WhatsAppWeb/src/stdafx.h
+++ b/protocols/WhatsAppWeb/src/stdafx.h
@@ -51,18 +51,11 @@ Copyright © 2019-22 George Hazan
#include <openssl/kdf.h>
#include "../../libs/libqrencode/src/qrencode.h"
-
-#include "../../libs/libsignal/src/curve.h"
-#include "../../libs/libsignal/src/hkdf.h"
-#include "../../libs/libsignal/src/key_helper.h"
-#include "../../libs/libsignal/src/protocol.h"
-#include "../../libs/libsignal/src/session_cipher.h"
-#include "../../libs/libsignal/src/signal_protocol.h"
-
#include "../../libs/libsodium/src/include/sodium.h"
-
#include "../../libs/zlib/src/zlib.h"
+#include "../../utils/mir_signal.h"
+
/////////////////////////////////////////////////////////////////////////////////////////
// to obtain protobuf library do the following
// - install vcpkg (https://github.com/microsoft/vcpkg);
@@ -79,28 +72,6 @@ using namespace google::protobuf;
/////////////////////////////////////////////////////////////////////////////////////////
-struct signal_buffer
-{
- size_t len;
- uint8_t data[];
-};
-
-struct signal_type_base
-{
- unsigned int ref_count = 0;
- void (*destroy)(signal_type_base *instance) = 0;
-};
-
-struct ec_public_key : public signal_type_base
-{
- uint8_t data[32];
-};
-
-struct ec_private_key : public signal_type_base
-{
- uint8_t data[32];
-};
-
#include "db.h"
#include "utils.h"
#include "proto.h"