summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2023-04-20 16:40:32 +0300
committerGeorge Hazan <ghazan@miranda.im>2023-04-20 16:40:32 +0300
commit99fabf4f58d0a8dabbb8a8469fe3a81ef58b2797 (patch)
tree8583b0575efae194338879f333bb3c8dc6a0066e
parentd024fb380fff7333f297ce72a9ecd45e8634f4b6 (diff)
Jabber: more OMEMO fixes
-rw-r--r--protocols/JabberG/src/jabber_ft.cpp4
-rw-r--r--protocols/JabberG/src/jabber_omemo.cpp13
-rw-r--r--protocols/JabberG/src/jabber_proto.cpp10
-rw-r--r--protocols/JabberG/src/jabber_thread.cpp4
4 files changed, 19 insertions, 12 deletions
diff --git a/protocols/JabberG/src/jabber_ft.cpp b/protocols/JabberG/src/jabber_ft.cpp
index 5adc5992a6..6dff008530 100644
--- a/protocols/JabberG/src/jabber_ft.cpp
+++ b/protocols/JabberG/src/jabber_ft.cpp
@@ -140,7 +140,7 @@ void CJabberProto::FtInitiate(filetransfer *ft)
char szSize[100];
int tsize = st.st_size;
- if (m_bUseOMEMO && OmemoIsEnabled(ft->std.hContact) && !isChatRoom(ft->std.hContact))
+ if (OmemoIsEnabled(ft->std.hContact))
tsize += 16;
_i64toa(tsize, szSize, 10);
@@ -696,7 +696,7 @@ LBL_Fail:
}
unsigned char key[32], iv[12], tag[16];
- bool enOmemo = m_bUseOMEMO && OmemoIsEnabled(ft->std.hContact) && !isChatRoom(ft->std.hContact);
+ bool enOmemo = OmemoIsEnabled(ft->std.hContact);
if (enOmemo) {
Utils_GetRandom(key, _countof(key));
Utils_GetRandom(iv, _countof(iv));
diff --git a/protocols/JabberG/src/jabber_omemo.cpp b/protocols/JabberG/src/jabber_omemo.cpp
index d67ad88558..b0bef8b94d 100644
--- a/protocols/JabberG/src/jabber_omemo.cpp
+++ b/protocols/JabberG/src/jabber_omemo.cpp
@@ -1731,13 +1731,19 @@ void CJabberProto::OmemoOnIqResultGetBundle(const TiXmlElement *iqNode, CJabberI
const char *jid = XmlGetAttr(iqNode, "from");
MCONTACT hContact;
- if (jid)
+ if (jid) {
hContact = HContactFromJID(jid);
+ if (!hContact)
+ return;
+ }
else {
hContact = 0;
jid = m_szJabberJID;
}
+ if (!OmemoIsEnabled(hContact))
+ return;
+
const char *type = XmlGetAttr(iqNode, "type");
if (mir_strcmp(type, "result")) {
// failed to get bundle, do not try to build session
@@ -1904,7 +1910,10 @@ int CJabberProto::OmemoEncryptMessage(XmlNode &msg, const char *msg_text, MCONTA
bool CJabberProto::OmemoIsEnabled(MCONTACT hContact)
{
- return !getByte(hContact, "bDisableOmemo");
+ if (!m_bUseOMEMO) // no OMEMO at all
+ return false;
+
+ return !getByte(hContact, "bDisableOmemo") && !isChatRoom(hContact);
}
void CJabberProto::OmemoRequestDeviceList(const char *szBareJid)
diff --git a/protocols/JabberG/src/jabber_proto.cpp b/protocols/JabberG/src/jabber_proto.cpp
index 777f37e450..3b6d5be61e 100644
--- a/protocols/JabberG/src/jabber_proto.cpp
+++ b/protocols/JabberG/src/jabber_proto.cpp
@@ -210,10 +210,8 @@ CJabberProto::CJabberProto(const char *aProtoName, const wchar_t *aUserName) :
m_pepServices.insert(new CPepMood(this));
m_pepServices.insert(new CPepActivity(this));
- if (m_bUseOMEMO) {
- db_set_resident(m_szModuleName, "OmemoSessionChecked");
+ if (m_bUseOMEMO)
OmemoInitDevice();
- }
// avatars
CreateDirectoryTreeW(GetAvatarPath());
@@ -633,7 +631,7 @@ INT_PTR CJabberProto::GetCaps(int type, MCONTACT hContact)
break;
case PFLAG_GETCURRENTENCRYPTION:
- return (INT_PTR)((OmemoIsEnabled(hContact) && m_bUseOMEMO && !isChatRoom(hContact)) ? "OMEMO" : nullptr);
+ return (INT_PTR)((OmemoIsEnabled(hContact)) ? "OMEMO" : nullptr);
}
return 0;
}
@@ -936,7 +934,7 @@ int CJabberProto::SendMsgEx(MCONTACT hContact, const char *pszSrc, XmlNode &m)
return -1;
}
- if (m_bUseOMEMO && OmemoIsEnabled(hContact)) {
+ if (OmemoIsEnabled(hContact)) {
if (!OmemoCheckSession(hContact)) {
OmemoPutMessageToOutgoingQueue(hContact, pszSrc);
int id = SerialNext();
@@ -964,7 +962,7 @@ int CJabberProto::SendMsgEx(MCONTACT hContact, const char *pszSrc, XmlNode &m)
msgType = "chat";
// omemo enabled in options, omemo enabled for contact
- if (m_bUseOMEMO && OmemoIsEnabled(hContact) && !mir_strcmp(msgType, "chat")) {
+ if (OmemoIsEnabled(hContact) && !mir_strcmp(msgType, "chat")) {
if (!OmemoEncryptMessage(m, pszSrc, hContact)) {
ProtoBroadcastAsync(hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, 0, (LPARAM)TranslateT("No valid OMEMO session exists"));
return 0;
diff --git a/protocols/JabberG/src/jabber_thread.cpp b/protocols/JabberG/src/jabber_thread.cpp
index 5ee69b908e..0f7816134c 100644
--- a/protocols/JabberG/src/jabber_thread.cpp
+++ b/protocols/JabberG/src/jabber_thread.cpp
@@ -947,7 +947,7 @@ void CJabberProto::OnProcessPubsubEvent(const TiXmlElement *node)
if (!hContact)
return;
- if (m_bUseOMEMO) {
+ if (OmemoIsEnabled(hContact)) {
auto *itemsNode = XmlGetChildByTag(eventNode, "items", "node", JABBER_FEAT_OMEMO ".devicelist");
if (itemsNode) {
OmemoHandleDeviceList(from, itemsNode);
@@ -1278,7 +1278,7 @@ void CJabberProto::OnProcessMessage(const TiXmlElement *node, ThreadData *info)
return;
}
- if (m_bUseOMEMO && OmemoIsEnabled(hContact)) {
+ if (OmemoIsEnabled(hContact)) {
if (auto *encNode = XmlGetChildByTag(node, "encrypted", "xmlns", JABBER_FEAT_OMEMO)) {
if (!OmemoHandleMessage(encNode, from, msgTime))
OmemoPutMessageToIncommingQueue(encNode, from, msgTime);