summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
authorGluzskiy Alexandr <sss@sss.chaoslab.ru>2017-02-23 06:01:21 +0300
committerGluzskiy Alexandr <sss@sss.chaoslab.ru>2017-02-23 06:01:21 +0300
commit81f96a9093d92678a9c78ed248ec966fd941a69c (patch)
treefb8f01771c92006669456842ae6c314e320ee16a /protocols
parentaffa00fc0e6eb69d36b6bdb66bbef468f9ed236a (diff)
libs:
libsignal-c: added few more missed exports protocol: jabber: omemo: implemented 4.1 (https://conversations.im/xeps/multi-end.html)
Diffstat (limited to 'protocols')
-rwxr-xr-xprotocols/JabberG/src/jabber_omemo.cpp61
-rwxr-xr-xprotocols/JabberG/src/jabber_proto.cpp21
-rwxr-xr-xprotocols/JabberG/src/jabber_proto.h1
3 files changed, 72 insertions, 11 deletions
diff --git a/protocols/JabberG/src/jabber_omemo.cpp b/protocols/JabberG/src/jabber_omemo.cpp
index be4f896e49..47e70401b9 100755
--- a/protocols/JabberG/src/jabber_omemo.cpp
+++ b/protocols/JabberG/src/jabber_omemo.cpp
@@ -29,6 +29,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <openssl/hmac.h>
#include <openssl/rand.h>
#include <openssl/sha.h>
+#include <signal_protocol_internal.h>
namespace omemo {
@@ -399,10 +400,14 @@ namespace omemo {
ec_key_pair *device_key;
};
- omemo_device* init_device()
+ omemo_device* create_device()
{
omemo_device *dev = (omemo_device*)mir_alloc(sizeof(omemo_device));
- Utils_GetRandom((void*)dev->id, 4);
+ for (dev->id = 0; dev->id == 0;)
+ {
+ Utils_GetRandom((void*)&(dev->id), 4);
+ }
+
if (curve_generate_key_pair(global_context, &(dev->device_key)))
{
//TODO: handle error
@@ -410,9 +415,61 @@ namespace omemo {
return dev;
}
+ bool IsFirstRun(CJabberProto *proto)
+ {
+ int id = proto->getDword("OmemoDeviceId", 0);
+ if (id == 0)
+ return true;
+ DBVARIANT dbv = { 0 };
+ proto->getString("OmemoDevicePublicKey", &dbv);
+ if (!dbv.pszVal[0])
+ {
+ //does it need to free something in DBVARIANT?
+ return true;
+ }
+ proto->getString("OmemoDevicePrivateKey", &dbv);
+ if (!dbv.pszVal[0])
+ {
+ //does it need to free something in DBVARIANT?
+ return true;
+ }
+
+ return false;
+ }
+ void RefreshDevice(CJabberProto *proto)
+ {
+ omemo_device *new_dev = create_device();
+ proto->setDword("OmemoDeviceId", new_dev->id);
+ ec_public_key *public_key = ec_key_pair_get_public(new_dev->device_key);
+ SIGNAL_REF(public_key);
+ signal_buffer *key_buf;
+ ec_public_key_serialize(&key_buf, public_key);
+ char *key = mir_base64_encode(key_buf->data, (unsigned int)key_buf->len);
+ proto->setString("OmemoDevicePublicKey", key);
+ mir_free(key);
+ signal_buffer_free(key_buf);
+ ec_private_key *private_key = ec_key_pair_get_private(new_dev->device_key);
+ SIGNAL_REF(private_key);
+ ec_private_key_serialize(&key_buf, private_key);
+ key = mir_base64_encode(key_buf->data, (unsigned int)key_buf->len);
+ proto->setString("OmemoDevicePrivateKey", key);
+ mir_free(key);
+ signal_buffer_free(key_buf);
+
+ SIGNAL_UNREF(new_dev->device_key);
+
+ }
};
+void CJabberProto::OmemoInitDevice()
+{
+ if (omemo::IsFirstRun(this))
+ omemo::RefreshDevice(this);
+
+}
+
+
void CJabberProto::OmemoHandleMessage(HXML /*node*/)
{
//TODO: handle "encrypted" node here
diff --git a/protocols/JabberG/src/jabber_proto.cpp b/protocols/JabberG/src/jabber_proto.cpp
index 6d46ddb8a1..8c220e2a63 100755
--- a/protocols/JabberG/src/jabber_proto.cpp
+++ b/protocols/JabberG/src/jabber_proto.cpp
@@ -127,6 +127,16 @@ CJabberProto::CJabberProto(const char *aProtoName, const wchar_t *aUserName) :
m_messageManager.FillPermanentHandlers();
m_adhocManager.FillDefaultNodes();
m_clientCapsManager.AddDefaultCaps();
+
+ IconsInit();
+ InitPopups();
+ GlobalMenuInit();
+ WsInit();
+ ConsoleInit();
+
+ m_pepServices.insert(new CPepMood(this));
+ m_pepServices.insert(new CPepActivity(this));
+
if (m_options.UseOMEMO)
{
JabberCapsBits jcb = 0;
@@ -141,16 +151,9 @@ CJabberProto::CJabberProto(const char *aProtoName, const wchar_t *aUserName) :
jcb |= JABBER_CAPS_OMEMO_NOTIFY;
m_clientCapsManager.SetClientCaps(JABBER_CAPS_MIRANDA_NODE, szCoreVersion, jcb);
- }
-
- IconsInit();
- InitPopups();
- GlobalMenuInit();
- WsInit();
- ConsoleInit();
- m_pepServices.insert(new CPepMood(this));
- m_pepServices.insert(new CPepActivity(this));
+ OmemoInitDevice();
+ }
db_set_resident(m_szModuleName, DBSETTING_XSTATUSID);
db_set_resident(m_szModuleName, DBSETTING_XSTATUSNAME);
diff --git a/protocols/JabberG/src/jabber_proto.h b/protocols/JabberG/src/jabber_proto.h
index b2042bcdd1..48c7778461 100755
--- a/protocols/JabberG/src/jabber_proto.h
+++ b/protocols/JabberG/src/jabber_proto.h
@@ -339,6 +339,7 @@ struct CJabberProto : public PROTO<CJabberProto>, public IJabberInterface
//---- jabber_omemo.cpp --------------------------------------------------------------
void OmemoHandleMessage(HXML node);
void OmemoHandleDeviceList(HXML node);
+ void OmemoInitDevice();
//---- jabber_console.cpp ------------------------------------------------------------