From baea5162d4a855d2ae1ad630ed65861c8faac0e7 Mon Sep 17 00:00:00 2001 From: Marvin W Date: Mon, 27 Jul 2026 14:24:52 +0200 Subject: bind2: Add user agent id and details --- libdino/src/entity/account.vala | 8 ++++++++ libdino/src/service/database.vala | 5 +++-- libdino/src/service/module_manager.vala | 2 +- xmpp-vala/src/module/xep/0386_bind2.vala | 8 +++++--- xmpp-vala/src/module/xep/0388_extensible_sasl_profile.vala | 11 ++++++++++- 5 files changed, 27 insertions(+), 7 deletions(-) diff --git a/libdino/src/entity/account.vala b/libdino/src/entity/account.vala index f5c99307..0ee7fe79 100644 --- a/libdino/src/entity/account.vala +++ b/libdino/src/entity/account.vala @@ -22,6 +22,7 @@ public class Account : Object { public string? alias { get; set; } public bool enabled { get; set; default = false; } public string? roster_version { get; set; } + public string? user_agent_id { get; set; } private Database? db; @@ -33,6 +34,7 @@ public class Account : Object { error("Auto-generated resource was invalid (%s)", e.message); } this.password = password; + this.user_agent_id = random_uuid(); } public Account.from_row(Database db, Qlite.Row row) throws InvalidJidError { @@ -43,8 +45,12 @@ public class Account : Object { alias = row[db.account.alias]; enabled = row[db.account.enabled]; roster_version = row[db.account.roster_version]; + user_agent_id = row[db.account.user_agent_id]; notify.connect(on_update); + + // Add user agent id if missing + if (user_agent_id == null) user_agent_id = random_uuid(); } public void persist(Database db) { @@ -105,6 +111,8 @@ public class Account : Object { update.set(db.account.enabled, enabled); break; case "roster-version": update.set(db.account.roster_version, roster_version); break; + case "user-agent-id": + update.set(db.account.user_agent_id, user_agent_id); break; } update.perform(); } diff --git a/libdino/src/service/database.vala b/libdino/src/service/database.vala index 27c70ffb..b38ccfca 100644 --- a/libdino/src/service/database.vala +++ b/libdino/src/service/database.vala @@ -7,7 +7,7 @@ using Dino.Entities; namespace Dino { public class Database : Qlite.Database { - private const int VERSION = 32; + private const int VERSION = 33; public class AccountTable : Table { public Column id = new Column.Integer("id") { primary_key = true, auto_increment = true }; @@ -19,10 +19,11 @@ public class Database : Qlite.Database { public Column roster_version = new Column.Text("roster_version") { min_version=2 }; // no longer used. all usages already removed. remove db column at some point. public Column mam_earliest_synced = new Column.Long("mam_earliest_synced") { min_version=4 }; + public Column user_agent_id = new Column.Text("user_agent_id") { min_version=33 }; internal AccountTable(Database db) { base(db, "account"); - init({id, bare_jid, resourcepart, password, alias, enabled, roster_version, mam_earliest_synced}); + init({id, bare_jid, resourcepart, password, alias, enabled, roster_version, mam_earliest_synced, user_agent_id}); } } diff --git a/libdino/src/service/module_manager.vala b/libdino/src/service/module_manager.vala index f83ce425..5ba4fe80 100644 --- a/libdino/src/service/module_manager.vala +++ b/libdino/src/service/module_manager.vala @@ -47,7 +47,7 @@ public class ModuleManager { module_map[account] = new ArrayList(); module_map[account].add(new Iq.Module()); - var sasl2_module = new Xep.ExtensibleSaslProfile.Module(account.bare_jid.localpart, account.password); + var sasl2_module = new Xep.ExtensibleSaslProfile.Module(account.bare_jid.localpart, account.password, account.user_agent_id); module_map[account].add(sasl2_module); module_map[account].add(new Sasl.Module(account.bare_jid.to_string(), account.password)); module_map[account].add(new Xep.StreamManagement.Module()); diff --git a/xmpp-vala/src/module/xep/0386_bind2.vala b/xmpp-vala/src/module/xep/0386_bind2.vala index cc21d62e..b9c37562 100644 --- a/xmpp-vala/src/module/xep/0386_bind2.vala +++ b/xmpp-vala/src/module/xep/0386_bind2.vala @@ -6,9 +6,11 @@ namespace Xmpp.Xep.Bind2 { public class Sasl2Activation : ExtensibleSaslProfile.Sasl2InlineActivation { public HashMap inline_activation_providers = new HashMap(); + public string tag { get; set; default = "dino"; } + public override StanzaNode? get_activation_node(XmppStream stream, StanzaNode inline_node) { - var res = new StanzaNode.build("bind", Bind2.NS_URI).add_self_xmlns().put_node( - new StanzaNode.build("tag", Bind2.NS_URI).put_node(new StanzaNode.text("dino"))); + var res = new StanzaNode.build("bind", NS_URI).add_self_xmlns().put_node( + new StanzaNode.build("tag", NS_URI).put_node(new StanzaNode.text(tag))); StanzaNode bind_inline_node = inline_node.get_subnode("bind", NS_URI).get_subnode("inline", NS_URI); @@ -33,7 +35,7 @@ namespace Xmpp.Xep.Bind2 { stream.add_flag(bind_flag); stream.get_module(Bind.Module.IDENTITY).bound_to_resource(stream, bind_flag.my_jid); - StanzaNode? bound_node = success_node.get_subnode("bound", Bind2.NS_URI); + StanzaNode? bound_node = success_node.get_subnode("bound", NS_URI); if (bound_node != null) { foreach (var inline_activation in inline_activation_providers.values) { inline_activation.on_bound(stream, bound_node); diff --git a/xmpp-vala/src/module/xep/0388_extensible_sasl_profile.vala b/xmpp-vala/src/module/xep/0388_extensible_sasl_profile.vala index f7db524d..1c6afb30 100644 --- a/xmpp-vala/src/module/xep/0388_extensible_sasl_profile.vala +++ b/xmpp-vala/src/module/xep/0388_extensible_sasl_profile.vala @@ -11,12 +11,16 @@ namespace Xmpp.Xep.ExtensibleSaslProfile { public string name { get; set; } public string password { get; set; } + public string user_agent_id { get; set; } + public string? user_agent_software { get; set; default = "Dino"; } + public string? user_agent_device { get; set; } public signal void received_auth_failure(XmppStream stream, StanzaNode node); - public Module(string name, string password) { + public Module(string name, string password, string user_agent_id) { this.name = name; this.password = password; + this.user_agent_id = user_agent_id; } public override void attach(XmppStream stream) { @@ -117,6 +121,11 @@ namespace Xmpp.Xep.ExtensibleSaslProfile { } } + StanzaNode user_agent_node = new StanzaNode.build("user-agent", NS_URI).put_attribute("id", user_agent_id); + if (user_agent_software != null) user_agent_node.put_node(new StanzaNode.build("software", NS_URI).put_node(new StanzaNode.text(user_agent_software))); + if (user_agent_device != null) user_agent_node.put_node(new StanzaNode.build("device", NS_URI).put_node(new StanzaNode.text(user_agent_device))); + authenticate_node.put_node(user_agent_node); + stream.write(authenticate_node); } -- cgit v1.3