diff options
Diffstat (limited to 'protocols/WhatsAppWeb/src/main.cpp')
-rw-r--r-- | protocols/WhatsAppWeb/src/main.cpp | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/protocols/WhatsAppWeb/src/main.cpp b/protocols/WhatsAppWeb/src/main.cpp index 0f63d3ba80..790cabcc07 100644 --- a/protocols/WhatsAppWeb/src/main.cpp +++ b/protocols/WhatsAppWeb/src/main.cpp @@ -28,7 +28,43 @@ PLUGININFOEX pluginInfo = { extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = { MIID_PROTOCOL, MIID_LAST }; -///////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////////////////// + +static int hmac_sha256_init(void **hmac_context, const uint8_t *key, size_t key_len, void *) +{ + HMAC_CTX *ctx = new HMAC_CTX; + *hmac_context = ctx; + HMAC_Init(ctx, key, key_len, EVP_sha256()); + return 0; +} + +int hmac_sha256_update(void *hmac_context, const uint8_t *data, size_t data_len, void *) +{ + return HMAC_Update((HMAC_CTX *)hmac_context, data, data_len); +} + +int hmac_sha256_final(void *hmac_context, signal_buffer **output, void *user_data) +{ + BYTE data[200]; + unsigned len = 0; + if (!HMAC_Final((HMAC_CTX *)hmac_context, data, &len)) + return 1; + + *output = signal_buffer_create(data, len); + return 0; +} + +void hmac_sha256_cleanup(void *hmac_context, void *) +{ + HMAC_cleanup((HMAC_CTX *)hmac_context); + delete hmac_context; +} + +static int random_func(uint8_t *pData, size_t size, void *) +{ + Utils_GetRandom(pData, size); + return 0; +} CMPlugin::CMPlugin() : ACCPROTOPLUGIN<WhatsAppProto>(MODULENAME, pluginInfo) @@ -44,6 +80,18 @@ int CMPlugin::Load() // InitIcons(); // InitContactMenus(); + ////////////////////////////////////////////////////////////////////////////////////// + signal_context_create(&pCtx, nullptr); + + signal_crypto_provider prov; + memset(&prov, 0xFF, sizeof(prov)); + prov.hmac_sha256_init_func = hmac_sha256_init; + prov.hmac_sha256_final_func = hmac_sha256_final; + prov.hmac_sha256_update_func = hmac_sha256_update; + prov.hmac_sha256_cleanup_func = hmac_sha256_cleanup; + prov.random_func = random_func; + signal_context_set_crypto_provider(pCtx, &prov); + return 0; } @@ -52,5 +100,6 @@ int CMPlugin::Load() int CMPlugin::Unload() { + signal_context_destroy(pCtx); return 0; } |