Set OMEMO devicelist + bundle node access model to public

This commit is contained in:
fiaxh 2019-08-08 03:17:34 +02:00
parent cd5c3e28a8
commit 3ad2891eb8
4 changed files with 48 additions and 26 deletions

View file

@ -71,6 +71,13 @@ public class Manager : StreamInteractionModule, Object {
stream_interactor.get_module(RosterManager.IDENTITY).mutual_subscription.connect(on_mutual_subscription);
}
public void clear_device_list(Account account) {
XmppStream? stream = stream_interactor.get_stream(account);
if (stream == null) return;
stream.get_module(StreamModule.IDENTITY).clear_device_list(stream);
}
private Gee.List<Jid> get_occupants(Jid jid, Account account){
Gee.List<Jid> occupants = new ArrayList<Jid>(Jid.equals_bare_func);
if(!stream_interactor.get_module(MucManager.IDENTITY).is_groupchat(jid, account)){
@ -234,7 +241,7 @@ public class Manager : StreamInteractionModule, Object {
}
public void on_bundle_fetched(Account account, Jid jid, int32 device_id, Bundle bundle) {
private void on_bundle_fetched(Account account, Jid jid, int32 device_id, Bundle bundle) {
int identity_id = db.identity.get_id(account.id);
if (identity_id < 0) return;
@ -356,26 +363,6 @@ public class Manager : StreamInteractionModule, Object {
}
}
public bool can_encrypt(Entities.Conversation conversation) {
if (stream_interactor.get_module(MucManager.IDENTITY).is_public_room(conversation.account, conversation.counterpart)){
debug("Can't enable OMEMO for %s: Room not members-only or non-anonymous", conversation.counterpart.to_string());
return false;
}
if (stream_interactor.get_module(MucManager.IDENTITY).is_private_room(conversation.account, conversation.counterpart)){
foreach(Jid jid in stream_interactor.get_module(MucManager.IDENTITY).get_offline_members(conversation.counterpart, conversation.account)) {
if (!trust_manager.is_known_address(conversation.account, jid.bare_jid)) {
debug("Can't enable OMEMO for %s: missing keys for %s", conversation.counterpart.to_string(), jid.bare_jid.to_string());
return false;
}
}
return true;
}
return trust_manager.is_known_address(conversation.account, conversation.counterpart.bare_jid);
}
public async bool ensure_get_keys_for_conversation(Conversation conversation) {
if (stream_interactor.get_module(MucManager.IDENTITY).is_private_room(conversation.account, conversation.counterpart)) {
foreach (Jid offline_member in stream_interactor.get_module(MucManager.IDENTITY).get_offline_members(conversation.counterpart, conversation.account)) {

View file

@ -74,7 +74,7 @@ public class StreamModule : XmppStreamModule {
if (!am_on_devicelist) {
debug("Not on device list, adding id");
node.put_node(new StanzaNode.build("device", NS_URI).put_attribute("id", store.local_registration_id.to_string()));
stream.get_module(Pubsub.Module.IDENTITY).publish(stream, jid, NODE_DEVICELIST, NODE_DEVICELIST, id, node);
stream.get_module(Pubsub.Module.IDENTITY).publish(stream, jid, NODE_DEVICELIST, id, node, Xmpp.Xep.Pubsub.ACCESS_MODEL_OPEN);
}
publish_bundles_if_needed(stream, jid);
}
@ -130,6 +130,10 @@ public class StreamModule : XmppStreamModule {
}
}
public void clear_device_list(XmppStream stream) {
stream.get_module(Pubsub.Module.IDENTITY).delete_node(stream, null, NODE_DEVICELIST);
}
private void on_other_bundle_result(XmppStream stream, Jid jid, int device_id, string? id, StanzaNode? node) {
if (node == null) {
// Device not registered, shouldn't exist
@ -276,7 +280,7 @@ public class StreamModule : XmppStreamModule {
}
bundle.put_node(prekeys);
stream.get_module(Pubsub.Module.IDENTITY).publish(stream, null, @"$NODE_BUNDLES:$device_id", @"$NODE_BUNDLES:$device_id", "1", bundle);
stream.get_module(Pubsub.Module.IDENTITY).publish(stream, null, @"$NODE_BUNDLES:$device_id", "1", bundle, Xmpp.Xep.Pubsub.ACCESS_MODEL_OPEN);
}
public override string get_ns() {

View file

@ -3,6 +3,13 @@ using Gee;
namespace Xmpp.Xep.Pubsub {
private const string NS_URI = "http://jabber.org/protocol/pubsub";
private const string NS_URI_EVENT = NS_URI + "#event";
private const string NS_URI_OWNER = NS_URI + "#owner";
public const string ACCESS_MODEL_AUTHORIZE = "authorize";
public const string ACCESS_MODEL_OPEN = "open";
public const string ACCESS_MODEL_PRESENCE = "presence";
public const string ACCESS_MODEL_ROSTER = "roster";
public const string ACCESS_MODEL_WHITELIST = "whitelist";
public class Module : XmppStreamModule {
public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "0060_pubsub_module");
@ -27,7 +34,7 @@ namespace Xmpp.Xep.Pubsub {
});
}
public void publish(XmppStream stream, Jid? jid, string node_id, string node, string? item_id, StanzaNode content) {
public void publish(XmppStream stream, Jid? jid, string node_id, string? item_id, StanzaNode content, string? access_model=null) {
StanzaNode pubsub_node = new StanzaNode.build("pubsub", NS_URI).add_self_xmlns();
StanzaNode publish_node = new StanzaNode.build("publish", NS_URI).put_attribute("node", node_id);
pubsub_node.put_node(publish_node);
@ -35,6 +42,30 @@ namespace Xmpp.Xep.Pubsub {
if (item_id != null) items_node.put_attribute("id", item_id);
items_node.put_node(content);
publish_node.put_node(items_node);
if (access_model != null) {
StanzaNode publish_options_node = new StanzaNode.build("publish-options", NS_URI);
pubsub_node.put_node(publish_options_node);
DataForms.DataForm data_form = new DataForms.DataForm();
DataForms.DataForm.HiddenField form_type_field = new DataForms.DataForm.HiddenField() { var="FORM_TYPE" };
form_type_field.set_value_string(NS_URI + "#publish-options");
data_form.add_field(form_type_field);
DataForms.DataForm.Field field = new DataForms.DataForm.Field() { var="pubsub#access_model" };
field.set_value_string(access_model);
data_form.add_field(field);
publish_options_node.put_node(data_form.get_submit_node());
}
Iq.Stanza iq = new Iq.Stanza.set(pubsub_node);
stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq, null);
}
public void delete_node(XmppStream stream, Jid? jid, string node_id) {
StanzaNode pubsub_node = new StanzaNode.build("pubsub", NS_URI_OWNER).add_self_xmlns();
StanzaNode publish_node = new StanzaNode.build("delete", NS_URI_OWNER).put_attribute("node", node_id);
pubsub_node.put_node(publish_node);
Iq.Stanza iq = new Iq.Stanza.set(pubsub_node);
stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq, null);
}

View file

@ -18,7 +18,7 @@ namespace Xmpp.Xep.UserAvatars {
string sha1 = Checksum.compute_for_data(ChecksumType.SHA1, image);
StanzaNode data_node = new StanzaNode.build("data", NS_URI_DATA).add_self_xmlns()
.put_node(new StanzaNode.text(Base64.encode(image)));
stream.get_module(Pubsub.Module.IDENTITY).publish(stream, null, NS_URI_DATA, NS_URI_DATA, sha1, data_node);
stream.get_module(Pubsub.Module.IDENTITY).publish(stream, null, NS_URI_DATA, sha1, data_node);
StanzaNode metadata_node = new StanzaNode.build("metadata", NS_URI_METADATA).add_self_xmlns();
StanzaNode info_node = new StanzaNode.build("info", NS_URI_METADATA)
@ -28,7 +28,7 @@ namespace Xmpp.Xep.UserAvatars {
.put_attribute("height", height.to_string())
.put_attribute("type", "image/png");
metadata_node.put_node(info_node);
stream.get_module(Pubsub.Module.IDENTITY).publish(stream, null, NS_URI_METADATA, NS_URI_METADATA, sha1, metadata_node);
stream.get_module(Pubsub.Module.IDENTITY).publish(stream, null, NS_URI_METADATA, sha1, metadata_node);
}
public override void attach(XmppStream stream) {