Add devicelist and bundle publication
This commit is contained in:
@@ -2,14 +2,54 @@
|
||||
#include "xmpp/iq.h"
|
||||
#include "xmpp/stanza.h"
|
||||
|
||||
#include "omemo/omemo.h"
|
||||
|
||||
void
|
||||
omemo_devicelist_publish(void)
|
||||
omemo_devicelist_subscribe(void)
|
||||
{
|
||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||
char *barejid = xmpp_jid_bare(ctx, session_get_account_name());
|
||||
xmpp_stanza_t *iq = stanza_create_omemo_devicelist_subscription(ctx, barejid);
|
||||
xmpp_stanza_t *iq = stanza_create_omemo_devicelist_subscribe(ctx, barejid);
|
||||
iq_send_stanza(iq);
|
||||
xmpp_stanza_release(iq);
|
||||
|
||||
free(barejid);
|
||||
}
|
||||
|
||||
void
|
||||
omemo_devicelist_publish(void)
|
||||
{
|
||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||
xmpp_stanza_t *iq = stanza_create_omemo_devicelist_publish(ctx, omemo_device_list());
|
||||
iq_send_stanza(iq);
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
|
||||
void
|
||||
omemo_bundle_publish(void)
|
||||
{
|
||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||
unsigned char *identity_key = NULL;
|
||||
size_t identity_key_length;
|
||||
unsigned char *signed_prekey = NULL;
|
||||
size_t signed_prekey_length;
|
||||
unsigned char *signed_prekey_signature = NULL;
|
||||
size_t signed_prekey_signature_length;
|
||||
GList *prekeys = NULL, *ids = NULL, *lengths = NULL;
|
||||
|
||||
omemo_identity_key(&identity_key, &identity_key_length);
|
||||
omemo_signed_prekey(&signed_prekey, &signed_prekey_length);
|
||||
omemo_signed_prekey_signature(&signed_prekey_signature, &signed_prekey_signature_length);
|
||||
omemo_prekeys(&prekeys, &ids, &lengths);
|
||||
|
||||
xmpp_stanza_t *iq = stanza_create_omemo_bundle_publish(ctx, omemo_device_id(),
|
||||
identity_key, identity_key_length, signed_prekey, signed_prekey_length,
|
||||
signed_prekey_signature, signed_prekey_signature_length,
|
||||
prekeys, ids, lengths);
|
||||
iq_send_stanza(iq);
|
||||
xmpp_stanza_release(iq);
|
||||
|
||||
free(identity_key);
|
||||
free(signed_prekey);
|
||||
free(signed_prekey_signature);
|
||||
}
|
||||
|
||||
@@ -1 +1,3 @@
|
||||
void omemo_devicelist_subscribe(void);
|
||||
void omemo_devicelist_publish(void);
|
||||
void omemo_bundle_publish(void);
|
||||
|
||||
@@ -61,6 +61,7 @@
|
||||
#include "xmpp/jid.h"
|
||||
|
||||
#ifdef HAVE_OMEMO
|
||||
#include "omemo/omemo.h"
|
||||
#include "xmpp/omemo.h"
|
||||
#endif
|
||||
|
||||
@@ -318,7 +319,10 @@ session_login_success(gboolean secured)
|
||||
bookmark_request();
|
||||
blocking_request();
|
||||
#ifdef HAVE_OMEMO
|
||||
omemo_devicelist_publish();
|
||||
omemo_devicelist_subscribe();
|
||||
if (omemo_loaded()) {
|
||||
omemo_devicelist_publish();
|
||||
}
|
||||
#endif
|
||||
|
||||
// items discovery
|
||||
|
||||
@@ -2093,7 +2093,7 @@ stanza_create_command_config_submit_iq(xmpp_ctx_t *ctx, const char *const room,
|
||||
}
|
||||
|
||||
xmpp_stanza_t*
|
||||
stanza_create_omemo_devicelist_pubsub_subscription(xmpp_ctx_t *ctx, const char *const jid)
|
||||
stanza_create_omemo_devicelist_subscribe(xmpp_ctx_t *ctx, const char *const jid)
|
||||
{
|
||||
char *id = connection_create_stanza_id("omemo_devicelist_subscribe");
|
||||
xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id);
|
||||
@@ -2104,7 +2104,7 @@ stanza_create_omemo_devicelist_pubsub_subscription(xmpp_ctx_t *ctx, const char *
|
||||
xmpp_stanza_set_ns(pubsub, STANZA_NS_PUBSUB);
|
||||
|
||||
xmpp_stanza_t *subscribe = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(subscribe, "subscribe");
|
||||
xmpp_stanza_set_name(subscribe, STANZA_NAME_SUBSCRIBE);
|
||||
xmpp_stanza_set_attribute(subscribe, "node", "eu.siacs.conversations.axolotl.devicelist");
|
||||
xmpp_stanza_set_attribute(subscribe, "jid", jid);
|
||||
|
||||
@@ -2117,6 +2117,149 @@ stanza_create_omemo_devicelist_pubsub_subscription(xmpp_ctx_t *ctx, const char *
|
||||
return iq;
|
||||
}
|
||||
|
||||
xmpp_stanza_t*
|
||||
stanza_create_omemo_devicelist_publish(xmpp_ctx_t *ctx, GList *const ids)
|
||||
{
|
||||
char *id = connection_create_stanza_id("omemo_devicelist_publish");
|
||||
xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id);
|
||||
free(id);
|
||||
|
||||
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 *publish = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(publish, STANZA_NAME_PUBLISH);
|
||||
xmpp_stanza_set_attribute(publish, "node", "eu.siacs.conversations.axolotl.devicelist");
|
||||
|
||||
xmpp_stanza_t *item = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(item, STANZA_NAME_ITEM);
|
||||
xmpp_stanza_set_attribute(item, "id", "current");
|
||||
|
||||
xmpp_stanza_t *list = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(list, "list");
|
||||
xmpp_stanza_set_ns(list, "eu.siacs.conversations.axolotl");
|
||||
|
||||
GList *i;
|
||||
for (i = ids; i != NULL; i = i->next) {
|
||||
xmpp_stanza_t *device = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(device, "device");
|
||||
char *id = g_strdup_printf("%d", GPOINTER_TO_INT(i->data));
|
||||
xmpp_stanza_set_attribute(device, "id", id);
|
||||
g_free(id);
|
||||
|
||||
xmpp_stanza_add_child(list, device);
|
||||
xmpp_stanza_release(device);
|
||||
}
|
||||
|
||||
xmpp_stanza_add_child(item, list);
|
||||
xmpp_stanza_add_child(publish, item);
|
||||
xmpp_stanza_add_child(pubsub, publish);
|
||||
xmpp_stanza_add_child(iq, pubsub);
|
||||
|
||||
xmpp_stanza_release(list);
|
||||
xmpp_stanza_release(item);
|
||||
xmpp_stanza_release(publish);
|
||||
xmpp_stanza_release(pubsub);
|
||||
|
||||
return iq;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
char *id = connection_create_stanza_id("omemo_bundle_publish");
|
||||
xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id);
|
||||
free(id);
|
||||
|
||||
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 *publish = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(publish, STANZA_NAME_PUBLISH);
|
||||
char *node = g_strdup_printf("%s:%d", "eu.siacs.conversations.axolotl.bundles", device_id);
|
||||
xmpp_stanza_set_attribute(publish, "node", node);
|
||||
g_free(node);
|
||||
|
||||
xmpp_stanza_t *item = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(item, STANZA_NAME_ITEM);
|
||||
xmpp_stanza_set_attribute(item, "id", "current");
|
||||
|
||||
xmpp_stanza_t *bundle = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(bundle, "bundle");
|
||||
xmpp_stanza_set_ns(bundle, "eu.siacs.conversations.axolotl");
|
||||
|
||||
xmpp_stanza_t *signed_prekey_public_stanza = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(signed_prekey_public_stanza , "signedPreKeyPublic");
|
||||
xmpp_stanza_set_attribute(signed_prekey_public_stanza, "signedPreKeyId", "1");
|
||||
|
||||
xmpp_stanza_t *signed_prekey_public_stanza_text= xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_text(signed_prekey_public_stanza_text, g_base64_encode(signed_prekey, signed_prekey_length));
|
||||
xmpp_stanza_add_child(signed_prekey_public_stanza, signed_prekey_public_stanza_text);
|
||||
xmpp_stanza_release(signed_prekey_public_stanza_text);
|
||||
|
||||
xmpp_stanza_t *signed_prekey_signature_stanza = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(signed_prekey_signature_stanza , "signedPreKeySignature");
|
||||
|
||||
xmpp_stanza_t *signed_prekey_signature_stanza_text= xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_text(signed_prekey_signature_stanza_text, g_base64_encode(signed_prekey_signature, signed_prekey_signature_length));
|
||||
xmpp_stanza_add_child(signed_prekey_signature_stanza, signed_prekey_signature_stanza_text);
|
||||
xmpp_stanza_release(signed_prekey_signature_stanza_text);
|
||||
|
||||
xmpp_stanza_t *identity_key_stanza = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(identity_key_stanza , "identityKey");
|
||||
|
||||
xmpp_stanza_t *identity_key_stanza_text= xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_text(identity_key_stanza_text, g_base64_encode(identity_key, identity_key_length));
|
||||
xmpp_stanza_add_child(identity_key_stanza, identity_key_stanza_text);
|
||||
xmpp_stanza_release(identity_key_stanza_text);
|
||||
|
||||
xmpp_stanza_t *prekeys_stanza = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(prekeys_stanza, "prekeys");
|
||||
|
||||
GList *p, *i, *l;
|
||||
for (p = prekeys, i = prekeys_id, l = prekeys_length; p != NULL; p = p->next, i = i->next, l = l->next) {
|
||||
xmpp_stanza_t *prekey = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(prekey, "preKeyPublic");
|
||||
char *id = g_strdup_printf("%d", GPOINTER_TO_INT(i->data));
|
||||
xmpp_stanza_set_attribute(prekey, "id", id);
|
||||
g_free(id);
|
||||
|
||||
xmpp_stanza_t *prekey_text = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_text(prekey_text, g_base64_encode(p->data, GPOINTER_TO_INT(l->data)));
|
||||
|
||||
xmpp_stanza_add_child(prekey, prekey_text);
|
||||
xmpp_stanza_add_child(prekeys_stanza, prekey);
|
||||
xmpp_stanza_release(prekey_text);
|
||||
xmpp_stanza_release(prekey);
|
||||
}
|
||||
|
||||
xmpp_stanza_add_child(bundle, signed_prekey_public_stanza);
|
||||
xmpp_stanza_add_child(bundle, signed_prekey_signature_stanza);
|
||||
xmpp_stanza_add_child(bundle, identity_key_stanza);
|
||||
xmpp_stanza_add_child(bundle, prekeys_stanza);
|
||||
xmpp_stanza_add_child(item, bundle);
|
||||
xmpp_stanza_add_child(publish, item);
|
||||
xmpp_stanza_add_child(pubsub, publish);
|
||||
xmpp_stanza_add_child(iq, pubsub);
|
||||
|
||||
xmpp_stanza_release(signed_prekey_public_stanza);
|
||||
xmpp_stanza_release(signed_prekey_signature_stanza);
|
||||
xmpp_stanza_release(identity_key_stanza);
|
||||
xmpp_stanza_release(prekeys_stanza);
|
||||
xmpp_stanza_release(bundle);
|
||||
xmpp_stanza_release(item);
|
||||
xmpp_stanza_release(publish);
|
||||
xmpp_stanza_release(pubsub);
|
||||
|
||||
return iq;
|
||||
}
|
||||
|
||||
static void
|
||||
_stanza_add_unique_id(xmpp_stanza_t *stanza, char *prefix)
|
||||
{
|
||||
|
||||
@@ -82,6 +82,7 @@
|
||||
#define STANZA_NAME_PUBSUB "pubsub"
|
||||
#define STANZA_NAME_PUBLISH "publish"
|
||||
#define STANZA_NAME_PUBLISH_OPTIONS "publish-options"
|
||||
#define STANZA_NAME_SUBSCRIBE "subscribe"
|
||||
#define STANZA_NAME_FIELD "field"
|
||||
#define STANZA_NAME_STORAGE "storage"
|
||||
#define STANZA_NAME_NICK "nick"
|
||||
@@ -284,7 +285,9 @@ xmpp_stanza_t* stanza_create_room_kick_iq(xmpp_ctx_t *const ctx, const char *con
|
||||
xmpp_stanza_t* stanza_create_command_exec_iq(xmpp_ctx_t *ctx, const char *const target, const char *const node);
|
||||
xmpp_stanza_t* stanza_create_command_config_submit_iq(xmpp_ctx_t *ctx, const char *const room, const char *const node, const char *const sessionid, DataForm *form);
|
||||
|
||||
xmpp_stanza_t* stanza_create_omemo_devicelist_pubsub_subscription(xmpp_ctx_t *ctx, const char *const jid);
|
||||
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);
|
||||
|
||||
int stanza_get_idle_time(xmpp_stanza_t *const stanza);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user