summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
authorwatcher <watcherhd@gmail.com>2017-04-25 21:42:45 +0000
committerwatcher <watcherhd@gmail.com>2017-04-25 21:42:45 +0000
commit3919b8b2d5270a41cbad66158165a4101b230e95 (patch)
tree0c6d68ead18e209db593a4c453c05fa1d013efd0 /protocols
parent7ba4ca70542a5dad951f030898f6398871e6b993 (diff)
Revert "jabber: omemo: improoved 4.4, working on 4.5"
This reverts commit 26092086b62afd9bdef93f4756ae7558ec681e9a. breaks compilation in MSVS 2010: >src\jabber_omemo.cpp(1253): error C2059: syntax error : '{' 3>src\jabber_omemo.cpp(1253): error C2143: syntax error : missing ';' before '{' 3>src\jabber_omemo.cpp(1257): error C2143: syntax error : missing ';' before '}'
Diffstat (limited to 'protocols')
-rwxr-xr-xprotocols/JabberG/src/jabber_omemo.cpp89
-rwxr-xr-xprotocols/JabberG/src/jabber_proto.cpp2
-rwxr-xr-xprotocols/JabberG/src/jabber_proto.h2
3 files changed, 25 insertions, 68 deletions
diff --git a/protocols/JabberG/src/jabber_omemo.cpp b/protocols/JabberG/src/jabber_omemo.cpp
index 4fdd5e2ee2..94fdb1f335 100755
--- a/protocols/JabberG/src/jabber_omemo.cpp
+++ b/protocols/JabberG/src/jabber_omemo.cpp
@@ -33,7 +33,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <key_helper.h>
#include <session_builder.h>
#include <session_cipher.h>
-#include <protocol.h>
//c++
#include <cstddef>
@@ -575,7 +574,6 @@ namespace omemo {
struct signal_store_backend_user_data
{
MCONTACT hContact;
- unsigned int device_id;
CJabberProto *proto;
};
int load_session_func(signal_buffer **record, const signal_protocol_address *address, void *user_data)
@@ -590,11 +588,6 @@ namespace omemo {
* @param address the address of the remote client
* @return 1 if the session was loaded, 0 if the session was not found, negative on failure
*/
- //some sanity checks
- if (address->device_id <= 0)
- return -1;
- if (address->name_len > 1024)
- return -1;
signal_store_backend_user_data* data = (signal_store_backend_user_data*)user_data;
@@ -852,7 +845,7 @@ namespace omemo {
signal_store_backend_user_data* data = (signal_store_backend_user_data*)user_data;
char *setting_name = (char*)mir_alloc(strlen("OmemoSignalPreKey_") + 32);
- mir_snprintf(setting_name, strlen("OmemoSignalPreKey_") + 31, "%s%d%d", "OmemoSignalSession_", data->device_id, pre_key_id);
+ mir_snprintf(setting_name, strlen("OmemoSignalPreKey_") + 31, "%s%d", "OmemoSignalSession_", pre_key_id);
DBVARIANT dbv = { 0 };
dbv.type = DBVT_BLOB;
db_get(data->hContact, data->proto->m_szModuleName, setting_name, &dbv);
@@ -881,7 +874,7 @@ namespace omemo {
signal_store_backend_user_data* data = (signal_store_backend_user_data*)user_data;
char *setting_name = (char*)mir_alloc(strlen("OmemoSignalPreKey_") + 32);
- mir_snprintf(setting_name, strlen("OmemoSignalPreKey_") + 31, "%s%d%d", "OmemoSignalSession_", data->device_id, pre_key_id);
+ mir_snprintf(setting_name, strlen("OmemoSignalPreKey_") + 31, "%s%d", "OmemoSignalSession_", pre_key_id);
db_set_blob(data->hContact, data->proto->m_szModuleName, setting_name, record, (unsigned int)record_len); //TODO: check return value
mir_free(setting_name);
@@ -901,7 +894,7 @@ namespace omemo {
signal_store_backend_user_data* data = (signal_store_backend_user_data*)user_data;
char *setting_name = (char*)mir_alloc(strlen("OmemoSignalPreKey_") + 32);
- mir_snprintf(setting_name, strlen("OmemoSignalPreKey_") + 31, "%s%d%d", "OmemoSignalSession_", data->device_id, pre_key_id);
+ mir_snprintf(setting_name, strlen("OmemoSignalPreKey_") + 31, "%s%d", "OmemoSignalSession_", pre_key_id);
DBVARIANT dbv = { 0 };
dbv.type = DBVT_BLOB;
db_get(data->hContact, data->proto->m_szModuleName, setting_name, &dbv);
@@ -928,7 +921,7 @@ namespace omemo {
signal_store_backend_user_data* data = (signal_store_backend_user_data*)user_data;
char *setting_name = (char*)mir_alloc(strlen("OmemoSignalPreKey_") + 32);
- mir_snprintf(setting_name, strlen("OmemoSignalPreKey_") + 31, "%s%d%d", "OmemoSignalSession_", data->device_id, pre_key_id);
+ mir_snprintf(setting_name, strlen("OmemoSignalPreKey_") + 31, "%s%d", "OmemoSignalSession_", pre_key_id);
db_unset(data->hContact, data->proto->m_szModuleName, setting_name);
mir_free(setting_name);
@@ -954,7 +947,7 @@ namespace omemo {
signal_store_backend_user_data* data = (signal_store_backend_user_data*)user_data;
char *setting_name = (char*)mir_alloc(strlen("OmemoSignalSignedPreKey_") + 32);
- mir_snprintf(setting_name, strlen("OmemoSignalSignedPreKey_") + 31, "%s%d%d", "OmemoSignalSignedPreKey_", data->device_id, signed_pre_key_id);
+ mir_snprintf(setting_name, strlen("OmemoSignalSignedPreKey_") + 31, "%s%d", "OmemoSignalSignedPreKey_", signed_pre_key_id);
DBVARIANT dbv = { 0 };
dbv.type = DBVT_BLOB;
db_get(data->hContact, data->proto->m_szModuleName, setting_name, &dbv);
@@ -984,7 +977,7 @@ namespace omemo {
signal_store_backend_user_data* data = (signal_store_backend_user_data*)user_data;
char *setting_name = (char*)mir_alloc(strlen("OmemoSignalSignedPreKey_") + 32);
- mir_snprintf(setting_name, strlen("OmemoSignalSignedPreKey_") + 31, "%s%d%d", "OmemoSignalSignedPreKey_", data->device_id, signed_pre_key_id);
+ mir_snprintf(setting_name, strlen("OmemoSignalSignedPreKey_") + 31, "%s%d", "OmemoSignalSignedPreKey_", signed_pre_key_id);
db_set_blob(data->hContact, data->proto->m_szModuleName, setting_name, record, (unsigned int)record_len); //TODO: check return value
mir_free(setting_name);
@@ -1004,7 +997,7 @@ namespace omemo {
signal_store_backend_user_data* data = (signal_store_backend_user_data*)user_data;
char *setting_name = (char*)mir_alloc(strlen("OmemoSignalSignedPreKey_") + 32);
- mir_snprintf(setting_name, strlen("OmemoSignalSignedPreKey_") + 31, "%s%d%d", "OmemoSignalSignedPreKey_", data->device_id, signed_pre_key_id);
+ mir_snprintf(setting_name, strlen("OmemoSignalSignedPreKey_") + 31, "%s%d", "OmemoSignalSignedPreKey_", signed_pre_key_id);
DBVARIANT dbv = { 0 };
dbv.type = DBVT_BLOB;
db_get(data->hContact, data->proto->m_szModuleName, setting_name, &dbv);
@@ -1031,7 +1024,7 @@ namespace omemo {
signal_store_backend_user_data* data = (signal_store_backend_user_data*)user_data;
char *setting_name = (char*)mir_alloc(strlen("OmemoSignalSignedPreKey_") + 32);
- mir_snprintf(setting_name, strlen("OmemoSignalSignedPreKey_") + 31, "%s%d%d", "OmemoSignalSignedPreKey_", data->device_id, signed_pre_key_id);
+ mir_snprintf(setting_name, strlen("OmemoSignalSignedPreKey_") + 31, "%s%d", "OmemoSignalSignedPreKey_", signed_pre_key_id);
db_unset(data->hContact, data->proto->m_szModuleName, setting_name);
mir_free(setting_name);
@@ -1084,10 +1077,9 @@ namespace omemo {
* registration ID, if it was successfully retrieved.
* @return 0 on success, negative on failure
*/
- uint32_t *id = (uint32_t*)mir_alloc(sizeof(uint32_t));
+
signal_store_backend_user_data* data = (signal_store_backend_user_data*)user_data;
- *id = GetOwnDeviceId(data->proto);
- registration_id = id;
+ *registration_id = GetOwnDeviceId(data->proto); //TODO: check it, maybe memory allocation is necessary
return 0;
}
@@ -1188,15 +1180,13 @@ namespace omemo {
bool create_session_store(MCONTACT hContact, LPCTSTR device_id, CJabberProto *proto)
{
-// sessions_internal[hContact].clear();
+ sessions_internal[hContact].clear();
signal_store_backend_user_data *data[4];
- unsigned int device_id_int = _wtoi(device_id);
for (int i = 0; i < 4; i++)
{
data[i] = (signal_store_backend_user_data*)mir_alloc(sizeof(signal_store_backend_user_data));
data[i]->hContact = hContact;
data[i]->proto = proto;
- data[i]->device_id = device_id_int;
}
/* Create the data store context, and add all the callbacks to it */
//TODO: validation of functions return codes
@@ -1248,20 +1238,24 @@ namespace omemo {
/* Instantiate a session_builder for a recipient address. */
char *jid_str = mir_u2a(jid);
int dev_id_int = _wtoi(dev_id);
- signal_protocol_address *address = (signal_protocol_address*)mir_alloc(sizeof(signal_protocol_address)); //libsignal does not copy structure, so we must allocate one manually, does it free it on exit ?
- *address =
+ signal_protocol_address address =
{
- jid_str, //will libsignal free arrav for us on exit ?
- mir_strlen(jid_str),
+ jid_str,
+ mir_strlen(jid_str),
dev_id_int
};
session_builder *builder;
- if (session_builder_create(&builder, sessions_internal[hContact][dev_id_int].store_context, address, global_context) < 0)
+ if (session_builder_create(&builder, sessions_internal[hContact][dev_id_int].store_context, &address, global_context) < 0)
+ {
+ mir_free(jid_str);
return false; //failure
+ }
sessions_internal[hContact][dev_id_int].builder = builder;
+ mir_free(jid_str);
+
int key_id_int = _wtoi(key_id);
char *pre_key_a = mir_u2a(pre_key_public);
@@ -1311,7 +1305,7 @@ namespace omemo {
/* Create the session cipher and encrypt the message */
session_cipher *cipher;
- if (session_cipher_create(&cipher, sessions_internal[hContact][dev_id_int].store_context, address, global_context) < 0)
+ if (session_cipher_create(&cipher, sessions_internal[hContact][dev_id_int].store_context, &address, global_context) < 0)
return false; //failure
sessions_internal[hContact][dev_id_int].cipher = cipher;
@@ -1672,46 +1666,9 @@ void CJabberProto::OmemoOnIqResultGetBundle(HXML iqNode, CJabberIqInfo *pInfo)
}
-void CJabberProto::OmemoEncryptMessage(XmlNode &msg, const wchar_t *msg_text, MCONTACT hContact)
+void CJabberProto::OmemoEncryptMessage(XmlNode &msg, const wchar_t *msg_text)
{
- const EVP_CIPHER *cipher = EVP_aes_128_gcm();
- unsigned char key[16], iv[128];
- Utils_GetRandom(key, 16);
- Utils_GetRandom(iv, 128);
- EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
- EVP_EncryptInit(ctx, cipher, key, iv);
- char *tmp = mir_u2a(msg_text), *out;
- const int inl = strlen(tmp);
- int tmp_len = 0, outl;
- out = (char*)mir_alloc(inl + 16 - 1);
- for (;;)
- {
- EVP_EncryptUpdate(ctx, (unsigned char*)(out + tmp_len), &outl, (unsigned char*)(tmp + tmp_len), inl - tmp_len);
- tmp_len += outl;
- if (tmp_len >= inl - 16 + 1)
- break;
- }
- EVP_EncryptFinal(ctx, (unsigned char*)(out + tmp_len), &outl);
- EVP_CIPHER_CTX_free(ctx);
- //TODO: check if encryption works properly
- mir_free(tmp);
- //TODO: construct "MessageElement" node
- for (std::map<unsigned int, omemo::omemo_session_jabber_internal_ptrs>::iterator i = omemo::sessions_internal[hContact].begin(), end = omemo::sessions_internal[hContact].end(); i != end; i++) //something wrong with map ...
- {
- unsigned int intdev_id = i->first;
- ciphertext_message *encrypted_key;
- if (session_cipher_encrypt(i->second.cipher, (uint8_t*)key, 16, &encrypted_key) != SG_SUCCESS)
- {
- //TODO: handle encryption error
- continue;
- }
- else
- {
- signal_buffer *serialized_encrypted_key = ciphertext_message_get_serialized(encrypted_key);
- SIGNAL_UNREF(encrypted_key);
- }
- }
- //TODO: add "MessageElement" to msg node
+ //TODO:
}
bool CJabberProto::OmemoIsEnabled(MCONTACT hContact)
{
diff --git a/protocols/JabberG/src/jabber_proto.cpp b/protocols/JabberG/src/jabber_proto.cpp
index 71e630bd4a..d2ce816639 100755
--- a/protocols/JabberG/src/jabber_proto.cpp
+++ b/protocols/JabberG/src/jabber_proto.cpp
@@ -964,7 +964,7 @@ int __cdecl CJabberProto::SendMsg(MCONTACT hContact, int, const char* pszSrc)
if(m_options.UseOMEMO && OmemoIsEnabled(hContact) && !mir_wstrcmp(msgType, L"chat")) //omemo enabled in options, omemo enabled for contact
{
- OmemoEncryptMessage(m, msg, hContact);
+ OmemoEncryptMessage(m, msg);
}
else
{
diff --git a/protocols/JabberG/src/jabber_proto.h b/protocols/JabberG/src/jabber_proto.h
index 79d4f7d93b..04414012fc 100755
--- a/protocols/JabberG/src/jabber_proto.h
+++ b/protocols/JabberG/src/jabber_proto.h
@@ -344,7 +344,7 @@ struct CJabberProto : public PROTO<CJabberProto>, public IJabberInterface
void OmemoSendBundle();
void OmemoPublishNodes();
bool OmemoCheckSession(MCONTACT hContact);
- void OmemoEncryptMessage(XmlNode &msg, const wchar_t *msg_text, MCONTACT hContact);
+ void OmemoEncryptMessage(XmlNode &msg, const wchar_t *msg_text);
bool OmemoIsEnabled(MCONTACT hContact);
void OmemoOnIqResultGetBundle(HXML iqNode, CJabberIqInfo *pInfo);