From 9f5da6753929a1a368dabcb67f91c2cf461997f8 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sat, 24 Sep 2022 11:59:53 +0200 Subject: [PATCH] use bind:0 namespace --- .../conversations/parser/MessageParser.java | 2 +- .../eu/siacs/conversations/xml/Namespace.java | 2 +- .../conversations/xmpp/XmppConnection.java | 32 +++++++++++-------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java index 76945c472..46355354a 100644 --- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java +++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java @@ -233,7 +233,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece Element item = items.findChild("item"); Set deviceIds = mXmppConnectionService.getIqParser().deviceIds(item); Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Received PEP device list " + deviceIds + " update from " + from + ", processing... "); - AxolotlService axolotlService = account.getAxolotlService(); + final AxolotlService axolotlService = account.getAxolotlService(); axolotlService.registerDevices(from, deviceIds); } else if (Namespace.BOOKMARKS.equals(node) && account.getJid().asBareJid().equals(from)) { if (account.getXmppConnection().getFeatures().bookmarksConversion()) { diff --git a/src/main/java/eu/siacs/conversations/xml/Namespace.java b/src/main/java/eu/siacs/conversations/xml/Namespace.java index 819e5fb21..7c7edde6e 100644 --- a/src/main/java/eu/siacs/conversations/xml/Namespace.java +++ b/src/main/java/eu/siacs/conversations/xml/Namespace.java @@ -26,7 +26,7 @@ public final class Namespace { public static final String NICK = "http://jabber.org/protocol/nick"; public static final String FLEXIBLE_OFFLINE_MESSAGE_RETRIEVAL = "http://jabber.org/protocol/offline"; public static final String BIND = "urn:ietf:params:xml:ns:xmpp-bind"; - public static final String BIND2 = "urn:xmpp:bind2:1"; + public static final String BIND2 = "urn:xmpp:bind:0"; public static final String STREAM_MANAGEMENT = "urn:xmpp:sm:3"; public static final String CSI = "urn:xmpp:csi:0"; public static final String CARBONS = "urn:xmpp:carbons:2"; diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java index d4335db50..5e4a6c0ed 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java @@ -60,7 +60,6 @@ import javax.net.ssl.SSLSocketFactory; import javax.net.ssl.X509KeyManager; import javax.net.ssl.X509TrustManager; -import eu.siacs.conversations.BuildConfig; import eu.siacs.conversations.Config; import eu.siacs.conversations.R; import eu.siacs.conversations.crypto.XmppDomainVerifier; @@ -1233,16 +1232,16 @@ public class XmppConnection implements Runnable { } private void authenticate(final SaslMechanism.Version version) throws IOException { - final Element element; + final Element authElement; if (version == SaslMechanism.Version.SASL) { - element = this.streamFeatures.findChild("mechanisms", Namespace.SASL); + authElement = this.streamFeatures.findChild("mechanisms", Namespace.SASL); } else { - element = this.streamFeatures.findChild("authentication", Namespace.SASL_2); + authElement = this.streamFeatures.findChild("authentication", Namespace.SASL_2); } final Collection mechanisms = Collections2.transform( Collections2.filter( - element.getChildren(), + authElement.getChildren(), c -> c != null && "mechanism".equals(c.getName())), c -> c == null ? null : c.getContent()); final Element cbElement = @@ -1297,24 +1296,29 @@ public class XmppConnection implements Runnable { } final Element userAgent = authenticate.addChild("user-agent"); userAgent.setAttribute("id", account.getUuid()); - userAgent.addChild("software").setContent(mXmppConnectionService.getString(R.string.app_name)); + userAgent + .addChild("software") + .setContent(mXmppConnectionService.getString(R.string.app_name)); if (!PhoneHelper.isEmulator()) { userAgent .addChild("device") .setContent(String.format("%s %s", Build.MANUFACTURER, Build.MODEL)); } - final Element inline = this.streamFeatures.findChild("inline", Namespace.SASL_2); + final Element inline = authElement.findChild("inline", Namespace.SASL_2); final boolean inlineStreamManagement = inline != null && inline.hasChild("sm", "urn:xmpp:sm:3"); - final boolean inlineBind2 = inline != null && inline.hasChild("bind", Namespace.BIND2); - final Element inlineBindFeatures = - this.streamFeatures.findChild("inline", Namespace.BIND2); - if (inlineBind2 && inlineBindFeatures != null) { + final Element inlineBind2 = + inline != null ? inline.findChild("bind", Namespace.BIND2) : null; + final Element inlineBind2Inline = + inlineBind2 != null ? inlineBind2.findChild("inline", Namespace.BIND2) : null; + if (inlineBind2 != null) { final Element bind = generateBindRequest( - Collections2.transform( - inlineBindFeatures.getChildren(), - c -> c == null ? null : c.getAttribute("var"))); + inlineBind2Inline == null + ? Collections.emptyList() + : Collections2.transform( + inlineBind2Inline.getChildren(), + c -> c == null ? null : c.getAttribute("var"))); authenticate.addChild(bind); } if (inlineStreamManagement && streamId != null) {