summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
authorGluzskiy Alexandr <sss@sss.chaoslab.ru>2017-03-06 08:49:25 +0300
committerGluzskiy Alexandr <sss@sss.chaoslab.ru>2017-03-06 08:50:03 +0300
commitd5ed801570c6a6ed01c31f8a6e42c379d5c91cc5 (patch)
treef7340eaa8ac190774a8164401809767f7d7362c3 /protocols
parentb9b47617b1695d6eb1a739fd4c4259d58d5bbb8f (diff)
omemo: working on 4.3
Diffstat (limited to 'protocols')
-rwxr-xr-xprotocols/JabberG/src/jabber_iqid.cpp7
-rwxr-xr-xprotocols/JabberG/src/jabber_omemo.cpp88
-rwxr-xr-xprotocols/JabberG/src/jabber_proto.h1
3 files changed, 90 insertions, 6 deletions
diff --git a/protocols/JabberG/src/jabber_iqid.cpp b/protocols/JabberG/src/jabber_iqid.cpp
index df2fd4cf42..087ce675a4 100755
--- a/protocols/JabberG/src/jabber_iqid.cpp
+++ b/protocols/JabberG/src/jabber_iqid.cpp
@@ -206,6 +206,13 @@ void CJabberProto::OnLoggedIn()
setString("LastLoggedServer", m_ThreadInfo->conn.server);
m_pepServices.ResetPublishAll();
+
+ //is it correct place ?
+ if (m_options.UseOMEMO)
+ {
+ OmemoAnnounceDevice();
+ OmemoSendBundle();
+ }
}
void CJabberProto::OnIqResultGetAuth(HXML iqNode, CJabberIqInfo*)
diff --git a/protocols/JabberG/src/jabber_omemo.cpp b/protocols/JabberG/src/jabber_omemo.cpp
index e34e28ee55..f3a5e8da07 100755
--- a/protocols/JabberG/src/jabber_omemo.cpp
+++ b/protocols/JabberG/src/jabber_omemo.cpp
@@ -424,10 +424,10 @@ namespace omemo {
if (id == 0)
return true;
ptrA buf(proto->getStringA("OmemoDevicePublicKey"));
- if (!buf[0])
+ if (!buf || !buf[0])
return true;
- buf = ptrA(proto->getStringA("OmemoDevicePrivateKey"));
- if (!buf[0])
+ ptrA buf2(proto->getStringA("OmemoDevicePrivateKey")); //ptrA reinitialization always return "" or random trash
+ if (!buf2 || !buf2[0])
return true;
return false;
@@ -510,7 +510,7 @@ namespace omemo {
DWORD GetOwnDeviceId(CJabberProto *proto)
{
DWORD own_id = proto->getDword("OmemoDeviceId", 0);
- if (own_id = 0)
+ if (own_id == 0)
{
proto->OmemoInitDevice();
own_id = proto->getDword("OmemoDeviceId", 0);
@@ -524,7 +524,6 @@ void CJabberProto::OmemoInitDevice()
{
if (omemo::IsFirstRun(this))
omemo::RefreshDevice(this);
- OmemoAnnounceDevice();
}
@@ -547,7 +546,7 @@ void CJabberProto::OmemoHandleDeviceList(HXML node)
node = XmlGetChildByTag(node, L"list", L"xmlns", JABBER_FEAT_OMEMO); //<list xmlns = 'urn:xmpp:omemo:0'>
if (!node)
return;
- bool own_jid = false; //TODO: detect own jid (not work dues to jabber_thread.cpp:947+)
+ bool own_jid = false; //TODO: detect own jid (not working due to jabber_thread.cpp:947+)
DWORD current_id;
LPCTSTR current_id_str;
if (own_jid)
@@ -581,9 +580,22 @@ void CJabberProto::OmemoHandleDeviceList(HXML node)
mir_snprintf(setting_name, "OmemoDeviceId%d", i);
setDword(hContact, setting_name, current_id);
}
+ //TODO: remove all settings higher than 'i' from db
}
}
+wchar_t* StripResourceFromJid(const wchar_t *source)
+{
+ if (!source)
+ return 0;
+ wchar_t *result = (wchar_t*)mir_alloc(wcslen(source));
+ int i = 0;
+ for (; source[i] != '/' && source[i] != 0; i++)
+ result[i] = source[i];
+ result[i] = 0;
+ return result;
+}
+
void CJabberProto::OmemoAnnounceDevice()
{
//check "OmemoDeviceId%d" for own id and send updated list if not exist
@@ -600,6 +612,7 @@ void CJabberProto::OmemoAnnounceDevice()
//add own device id
//construct node
XmlNodeIq iq(L"set", SerialNext());
+ iq << XATTR(L"from", ptrW(StripResourceFromJid(m_ThreadInfo->fullJID)));
HXML pubsub_node = XmlAddChild(iq, L"pubsub");
xmlAddAttr(pubsub_node, L"xmlns", L"http://jabber.org/protocol/pubsub");
HXML publish_node = XmlAddChild(pubsub_node, L"publish");
@@ -622,3 +635,66 @@ void CJabberProto::OmemoAnnounceDevice()
}
+void CJabberProto::OmemoSendBundle()
+{
+ //get own device id
+ DWORD own_id = omemo::GetOwnDeviceId(this);
+ //construct bundle node
+ XmlNodeIq iq(L"set", SerialNext());
+ iq << XATTR(L"from", ptrW(StripResourceFromJid(m_ThreadInfo->fullJID)));
+ //TODO: add "from"
+ HXML pubsub_node = XmlAddChild(iq, L"pubsub");
+ xmlAddAttr(pubsub_node, L"xmlns", L"http://jabber.org/protocol/pubsub");
+ HXML publish_node = XmlAddChild(pubsub_node, L"publish");
+ {
+ wchar_t attr_val[128];
+ mir_snwprintf(attr_val, L"%s:bundles:%d", JABBER_FEAT_OMEMO, own_id);
+ xmlAddAttr(publish_node, L"node", attr_val);
+ }
+ HXML item_node = XmlAddChild(publish_node, L"item");
+ HXML bundle_node = XmlAddChild(item_node, L"bundle");
+ xmlAddAttr(bundle_node, L"xmlns", JABBER_FEAT_OMEMO);
+ //add signed pre key public
+ {
+ HXML signedPreKeyPublic_node = XmlAddChild(bundle_node, L"signedPreKeyPublic");
+ xmlAddAttr(signedPreKeyPublic_node, L"signedPreKeyId", L"1");
+ ptrW buf(getWStringA("OmemoSignedPreKeyPublic"));
+ xmlSetText(signedPreKeyPublic_node, buf);
+ }
+ //add pre key signature
+ {
+ HXML signedPreKeySignature_node = XmlAddChild(bundle_node, L"signedPreKeySignature");
+ ptrW buf(getWStringA("OmemoSignedPreKeySignature"));
+ xmlSetText(signedPreKeySignature_node, buf);
+ }
+ //add identity key
+ //it is must be a public key right ?, standart is a bit confusing...
+ {
+ HXML identityKey_node = XmlAddChild(bundle_node, L"identityKey");
+ ptrW buf(getWStringA("OmemoDevicePublicKey"));
+ xmlSetText(identityKey_node, buf);
+ }
+ //add prekeys
+ HXML prekeys_node = XmlAddChild(bundle_node, L"prekeys");
+ {
+ int i = 0;
+ char setting_name[64];
+ mir_snprintf(setting_name, "OmemoPreKey%dPublic", i);
+ wchar_t *val;
+ for (val = getWStringA(setting_name); val && val[0]; ++i, mir_snprintf(setting_name, "OmemoPreKey%dPublic", i), val = getWStringA(setting_name))
+ {
+ HXML preKeyPublic_node = XmlAddChild(prekeys_node, L"preKeyPublic");
+ xmlAddAttrInt(preKeyPublic_node, L"preKeyId", i + 1);
+ xmlSetText(preKeyPublic_node, val);
+ mir_free(val);
+ val = nullptr;
+ }
+ mir_free(val);
+ val = nullptr;
+ }
+
+ //send bundle
+ m_ThreadInfo->send(iq);
+
+}
+
diff --git a/protocols/JabberG/src/jabber_proto.h b/protocols/JabberG/src/jabber_proto.h
index ed63eff36c..762db44ea9 100755
--- a/protocols/JabberG/src/jabber_proto.h
+++ b/protocols/JabberG/src/jabber_proto.h
@@ -341,6 +341,7 @@ struct CJabberProto : public PROTO<CJabberProto>, public IJabberInterface
void OmemoHandleDeviceList(HXML node);
void OmemoInitDevice();
void OmemoAnnounceDevice();
+ void OmemoSendBundle();
//---- jabber_console.cpp ------------------------------------------------------------