summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xprotocols/JabberG/src/jabber_omemo.cpp72
-rwxr-xr-xprotocols/JabberG/src/jabber_omemo.h3
-rwxr-xr-xprotocols/JabberG/src/jabber_opt.cpp4
3 files changed, 49 insertions, 30 deletions
diff --git a/protocols/JabberG/src/jabber_omemo.cpp b/protocols/JabberG/src/jabber_omemo.cpp
index fb5238b7db..96313ab930 100755
--- a/protocols/JabberG/src/jabber_omemo.cpp
+++ b/protocols/JabberG/src/jabber_omemo.cpp
@@ -397,45 +397,56 @@ namespace omemo {
};
- omemo_impl::omemo_impl(CJabberProto *p) : proto(p)
+ omemo_impl::omemo_impl(CJabberProto *p) : proto(p), signal_mutex(nullptr), provider(nullptr)
{
if (proto->m_options.UseOMEMO)
+ init();
+ }
+ void omemo_impl::init()
+ {
+ if (provider && signal_mutex)
+ return;
+ if (!global_context)
+ signal_context_create(&global_context, this);
+ signal_mutex = new mir_cslockfull(_signal_cs);
+ signal_mutex->unlock(); //fuck...
+ provider = new signal_crypto_provider;
+ provider->random_func = &random_func;
+ provider->hmac_sha256_init_func = &hmac_sha256_init_func;
+ provider->hmac_sha256_update_func = &hmac_sha256_update_func;
+ provider->hmac_sha256_final_func = &hmac_sha256_final_func;
+ provider->hmac_sha256_cleanup_func = &hmac_sha256_cleanup_func;
+ provider->sha512_digest_init_func = &sha512_digest_init_func;
+ provider->sha512_digest_update_func = &sha512_digest_update_func;
+ provider->sha512_digest_final_func = &sha512_digest_final_func;
+ provider->sha512_digest_cleanup_func = &sha512_digest_cleanup_func;
+ provider->encrypt_func = &encrypt_func;
+ provider->decrypt_func = &decrypt_func;
+
+ if (signal_context_set_crypto_provider(global_context, provider))
{
- if (!global_context)
- signal_context_create(&global_context, this);
- signal_mutex = new mir_cslockfull(_signal_cs);
- signal_mutex->unlock(); //fuck...
- provider = new signal_crypto_provider;
- provider->random_func = &random_func;
- provider->hmac_sha256_init_func = &hmac_sha256_init_func;
- provider->hmac_sha256_update_func = &hmac_sha256_update_func;
- provider->hmac_sha256_final_func = &hmac_sha256_final_func;
- provider->hmac_sha256_cleanup_func = &hmac_sha256_cleanup_func;
- provider->sha512_digest_init_func = &sha512_digest_init_func;
- provider->sha512_digest_update_func = &sha512_digest_update_func;
- provider->sha512_digest_final_func = &sha512_digest_final_func;
- provider->sha512_digest_cleanup_func = &sha512_digest_cleanup_func;
- provider->encrypt_func = &encrypt_func;
- provider->decrypt_func = &decrypt_func;
-
- if (signal_context_set_crypto_provider(global_context, provider))
- {
- proto->debugLogA("Jabber OMEMO: signal_context_set_crypto_provider failed");
- //TODO: handle error
- }
+ proto->debugLogA("Jabber OMEMO: signal_context_set_crypto_provider failed");
+ //TODO: handle error
+ }
- if (signal_context_set_locking_functions(global_context, &lock, &unlock))
- {
- proto->debugLogA("Jabber OMEMO: signal_context_set_crypto_provider failed");
- //TODO: handle error
- }
- sessions_internal = new std::map<MCONTACT, std::map<unsigned int, omemo_session_jabber_internal_ptrs> >;
+ if (signal_context_set_locking_functions(global_context, &lock, &unlock))
+ {
+ proto->debugLogA("Jabber OMEMO: signal_context_set_crypto_provider failed");
+ //TODO: handle error
}
+ sessions_internal = new std::map<MCONTACT, std::map<unsigned int, omemo_session_jabber_internal_ptrs> >;
}
omemo_impl::~omemo_impl()
{
if (proto->m_options.UseOMEMO)
{
+ deinit();
+ }
+ }
+ void omemo_impl::deinit()
+ {
+ if (provider && signal_mutex)
+ {
for (std::map<MCONTACT, std::map<unsigned int, omemo_session_jabber_internal_ptrs> >::iterator i = ((std::map<MCONTACT, std::map<unsigned int, omemo_session_jabber_internal_ptrs> >*)sessions_internal)->begin(),
end = ((std::map<MCONTACT, std::map<unsigned int, omemo_session_jabber_internal_ptrs> >*)sessions_internal)->end(); i != end; ++i)
{
@@ -453,7 +464,10 @@ namespace omemo {
delete (std::map<MCONTACT, std::map<unsigned int, omemo_session_jabber_internal_ptrs> >*)sessions_internal;
delete signal_mutex;
delete provider;
+ provider = nullptr;
+ signal_mutex = nullptr;
}
+
}
diff --git a/protocols/JabberG/src/jabber_omemo.h b/protocols/JabberG/src/jabber_omemo.h
index 413256ef21..28d765309c 100755
--- a/protocols/JabberG/src/jabber_omemo.h
+++ b/protocols/JabberG/src/jabber_omemo.h
@@ -10,7 +10,8 @@ namespace omemo {
omemo_impl(CJabberProto *p);
~omemo_impl();
-
+ void init();
+ void deinit();
bool IsFirstRun();
unsigned long GetOwnDeviceId();
void RefreshDevice();
diff --git a/protocols/JabberG/src/jabber_opt.cpp b/protocols/JabberG/src/jabber_opt.cpp
index 84cd744636..fff1c49a35 100755
--- a/protocols/JabberG/src/jabber_opt.cpp
+++ b/protocols/JabberG/src/jabber_opt.cpp
@@ -848,6 +848,10 @@ public:
}
}
}
+ if (m_proto->m_options.UseOMEMO)
+ m_proto->m_omemo.init();
+ else
+ m_proto->m_omemo.deinit();
m_proto->m_clientCapsManager.UpdateFeatHash();
m_proto->SendPresence(m_proto->m_iStatus, true);
}