From 008fb731e3e3b587f596afba1cfe7446de7f0cac Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Sat, 15 Apr 2017 15:26:18 +0300 Subject: jabber: omemo: 4.4 is done ? 4.5 is next --- protocols/JabberG/src/jabber_omemo.cpp | 40 +++++++++++++++++++++++++++++----- protocols/JabberG/src/jabber_proto.cpp | 3 +++ 2 files changed, 38 insertions(+), 5 deletions(-) (limited to 'protocols/JabberG/src') diff --git a/protocols/JabberG/src/jabber_omemo.cpp b/protocols/JabberG/src/jabber_omemo.cpp index d3326db08e..c6e04b3857 100755 --- a/protocols/JabberG/src/jabber_omemo.cpp +++ b/protocols/JabberG/src/jabber_omemo.cpp @@ -1502,6 +1502,7 @@ void CJabberProto::OmemoPublishNodes() OmemoSendBundle(); } + bool CJabberProto::OmemoCheckSession(MCONTACT hContact) { if (getBool(hContact, "OmemoSessionChecked")) @@ -1515,6 +1516,7 @@ bool CJabberProto::OmemoCheckSession(MCONTACT hContact) mir_snprintf(setting_name, "OmemoDeviceId%d", i); mir_snprintf(setting_name2, "%sChecked", setting_name); + db_set_resident(m_szModuleName, setting_name2); id = getDword(hContact, setting_name, 0); checked = getBool(hContact, setting_name2); while (id) @@ -1523,7 +1525,9 @@ bool CJabberProto::OmemoCheckSession(MCONTACT hContact) { pending_check = true; wchar_t szBareJid[JABBER_MAX_JID_LEN]; - XmlNodeIq iq(AddIQ(&CJabberProto::OmemoOnIqResultGetBundle, JABBER_IQ_TYPE_GET)); + unsigned int *dev_id = (unsigned int*)mir_alloc(sizeof(unsigned int)); + *dev_id = id; + XmlNodeIq iq(AddIQ(&CJabberProto::OmemoOnIqResultGetBundle, JABBER_IQ_TYPE_GET, 0, 0UL, -1, dev_id)); iq << XATTR(L"from", JabberStripJid(m_ThreadInfo->fullJID, szBareJid, _countof_portable(szBareJid))); wchar_t *jid = ContactToJID(hContact); iq << XATTR(L"to", jid); @@ -1546,7 +1550,7 @@ bool CJabberProto::OmemoCheckSession(MCONTACT hContact) return false; } -void CJabberProto::OmemoOnIqResultGetBundle(HXML iqNode, CJabberIqInfo * /*pInfo*/) +void CJabberProto::OmemoOnIqResultGetBundle(HXML iqNode, CJabberIqInfo *pInfo) { if (iqNode == NULL) return; @@ -1603,13 +1607,39 @@ void CJabberProto::OmemoOnIqResultGetBundle(HXML iqNode, CJabberIqInfo * /*pInfo if (!preKeyId) return; + MCONTACT hContact = HContactFromJID(jid); //TODO: we have all required data, we need to create session with device here - if (!omemo::create_session_store(HContactFromJID(jid), this)) + if (!omemo::create_session_store(hContact, this)) return; //failed to create session store - if (!omemo::build_session(HContactFromJID(jid), jid, device_id, preKeyId, preKeyPublic, signedPreKeyId, signedPreKeyPublic, signedPreKeySignature, identityKey)) + if (!omemo::build_session(hContact, jid, device_id, preKeyId, preKeyPublic, signedPreKeyId, signedPreKeyPublic, signedPreKeySignature, identityKey)) return; //failed to build signal(omemo) session + + unsigned int *dev_id = (unsigned int*)pInfo->GetUserData(); + //TODO: write session checked 1 + char setting_name[64], setting_name2[64]; + DWORD id = 0; + bool checked = false; + int i = 0; + + mir_snprintf(setting_name, "OmemoDeviceId%d", i); + mir_snprintf(setting_name2, "%sChecked", setting_name); + db_set_resident(m_szModuleName, setting_name2); + id = getDword(hContact, setting_name, 0); + while (id) + { + if (id == *dev_id) + { + setByte(hContact, setting_name2, 1); + break; + } + i++; + mir_snprintf(setting_name, "OmemoDeviceId%d", i); + mir_snprintf(setting_name2, "%sChecked", setting_name); + id = getDword(hContact, setting_name, 0); + } + /* ciphertext_message *encrypted_message; @@ -1640,5 +1670,5 @@ void CJabberProto::OmemoEncryptMessage(XmlNode &msg, const wchar_t *msg_text) bool CJabberProto::OmemoIsEnabled(MCONTACT hContact) { //TODO: - return false; + return true; } diff --git a/protocols/JabberG/src/jabber_proto.cpp b/protocols/JabberG/src/jabber_proto.cpp index de718d8375..d2ce816639 100755 --- a/protocols/JabberG/src/jabber_proto.cpp +++ b/protocols/JabberG/src/jabber_proto.cpp @@ -138,7 +138,10 @@ CJabberProto::CJabberProto(const char *aProtoName, const wchar_t *aUserName) : m_pepServices.insert(new CPepActivity(this)); if (m_options.UseOMEMO) + { + db_set_resident(m_szModuleName, "OmemoSessionChecked"); OmemoInitDevice(); + } db_set_resident(m_szModuleName, DBSETTING_XSTATUSID); db_set_resident(m_szModuleName, DBSETTING_XSTATUSNAME); -- cgit v1.2.3