Add signal store backend and OMEMO start command
This commit is contained in:
@@ -71,8 +71,80 @@ omemo_bundle_publish(void)
|
||||
}
|
||||
|
||||
void
|
||||
omemo_bundles_fetch(const char * const jid)
|
||||
omemo_bundle_request(const char * const jid, uint32_t device_id, ProfIqCallback func, ProfIqFreeCallback free_func, void *userdata)
|
||||
{
|
||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||
char *id = connection_create_stanza_id("devicelist_request");
|
||||
|
||||
xmpp_stanza_t *iq = stanza_create_omemo_bundle_request(ctx, id, jid, device_id);
|
||||
iq_id_handler_add(id, func, free_func, userdata);
|
||||
|
||||
iq_send_stanza(iq);
|
||||
|
||||
free(id);
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
|
||||
int
|
||||
omemo_start_device_session_handle_bundle(xmpp_stanza_t *const stanza, void *const userdata)
|
||||
{
|
||||
const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
|
||||
if (!from) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!g_strcmp0(from, userdata)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
xmpp_stanza_t *pubsub = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_PUBSUB);
|
||||
if (!pubsub) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
xmpp_stanza_t *items = xmpp_stanza_get_child_by_name(pubsub, "items");
|
||||
if (!items) {
|
||||
return 1;
|
||||
}
|
||||
const char *node = xmpp_stanza_get_attribute(items, "node");
|
||||
char *device_id_str = strstr(node, ":");
|
||||
if (!device_id_str) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint32_t device_id = strtoul(device_id_str, NULL, 10);
|
||||
|
||||
xmpp_stanza_t *item = xmpp_stanza_get_child_by_name(items, "item");
|
||||
if (!item) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
xmpp_stanza_t *bundle = xmpp_stanza_get_child_by_ns(item, STANZA_NS_OMEMO);
|
||||
if (!bundle) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
xmpp_stanza_t *prekeys = xmpp_stanza_get_child_by_name(bundle, "prekeys");
|
||||
if (!prekeys) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Should be random */
|
||||
xmpp_stanza_t *prekey = xmpp_stanza_get_children(prekeys);
|
||||
if (!prekey) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
xmpp_stanza_t *prekey_text = xmpp_stanza_get_children(prekey);
|
||||
if (!prekey_text) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
size_t prekey_len;
|
||||
unsigned char *prekey_raw = g_base64_decode(xmpp_stanza_get_text(prekey_text), &prekey_len);
|
||||
|
||||
omemo_start_device_session(from, device_id, prekey_raw, prekey_len);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
#include <glib.h>
|
||||
|
||||
#include "xmpp/iq.h"
|
||||
|
||||
void omemo_devicelist_subscribe(void);
|
||||
void omemo_devicelist_publish(GList *device_list);
|
||||
void omemo_devicelist_request(const char * const jid);
|
||||
void omemo_bundle_publish(void);
|
||||
void omemo_bundle_request(const char * const jid, uint32_t device_id, ProfIqCallback func, ProfIqFreeCallback free_func, void *userdata);
|
||||
int omemo_start_device_session_handle_bundle(xmpp_stanza_t *const stanza, void *const userdata);
|
||||
|
||||
@@ -2284,6 +2284,31 @@ stanza_create_omemo_bundle_publish(xmpp_ctx_t *ctx, uint32_t device_id,
|
||||
return iq;
|
||||
}
|
||||
|
||||
xmpp_stanza_t*
|
||||
stanza_create_omemo_bundle_request(xmpp_ctx_t *ctx, const char *const id, const char *const jid, uint32_t device_id)
|
||||
{
|
||||
xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_GET, id);
|
||||
xmpp_stanza_set_to(iq, jid);
|
||||
|
||||
xmpp_stanza_t *pubsub = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(pubsub, STANZA_NAME_PUBSUB);
|
||||
xmpp_stanza_set_ns(pubsub, STANZA_NS_PUBSUB);
|
||||
|
||||
xmpp_stanza_t *items = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(items, "items");
|
||||
char *node = g_strdup_printf("%s:%d", STANZA_NS_OMEMO_BUNDLES, device_id);
|
||||
xmpp_stanza_set_attribute(items, "node", node);
|
||||
g_free(node);
|
||||
|
||||
xmpp_stanza_add_child(pubsub, items);
|
||||
xmpp_stanza_add_child(iq, pubsub);
|
||||
|
||||
xmpp_stanza_release(items);
|
||||
xmpp_stanza_release(pubsub);
|
||||
|
||||
return iq;
|
||||
}
|
||||
|
||||
static void
|
||||
_stanza_add_unique_id(xmpp_stanza_t *stanza, char *prefix)
|
||||
{
|
||||
|
||||
@@ -193,6 +193,7 @@
|
||||
#define STANZA_NS_COMMAND "http://jabber.org/protocol/commands"
|
||||
#define STANZA_NS_OMEMO "eu.siacs.conversations.axolotl"
|
||||
#define STANZA_NS_OMEMO_DEVICELIST "eu.siacs.conversations.axolotl.devicelist"
|
||||
#define STANZA_NS_OMEMO_BUNDLES "eu.siacs.conversations.axolotl.bundles"
|
||||
|
||||
#define STANZA_DATAFORM_SOFTWARE "urn:xmpp:dataforms:softwareinfo"
|
||||
|
||||
@@ -292,6 +293,7 @@ xmpp_stanza_t* stanza_create_omemo_devicelist_request(xmpp_ctx_t *ctx, const cha
|
||||
xmpp_stanza_t* stanza_create_omemo_devicelist_subscribe(xmpp_ctx_t *ctx, const char *const jid);
|
||||
xmpp_stanza_t* stanza_create_omemo_devicelist_publish(xmpp_ctx_t *ctx, GList *const ids);
|
||||
xmpp_stanza_t* stanza_create_omemo_bundle_publish(xmpp_ctx_t *ctx, uint32_t device_id, const unsigned char * const identity_key, size_t identity_key_length, const unsigned char * const signed_prekey, size_t signed_prekey_length, const unsigned char * const signed_prekey_signature, size_t signed_prekey_signature_length, GList *const prekeys, GList *const prekeys_id, GList *const prekeys_length);
|
||||
xmpp_stanza_t* stanza_create_omemo_bundle_request(xmpp_ctx_t *ctx, const char *const id, const char *const jid, uint32_t device_id);
|
||||
|
||||
int stanza_get_idle_time(xmpp_stanza_t *const stanza);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user