From 9f3d2d2f2883ac9adcdd4264d89d8d9441b7998b Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Sat, 16 Feb 2019 21:26:02 +0100 Subject: [PATCH] Log if reported XMPP domain does not match expected --- .../smack/AbstractXMPPConnection.java | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java index 6b13b8010..dfe4d5662 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java @@ -1,6 +1,6 @@ /** * - * Copyright 2009 Jive Software, 2018 Florian Schmaus. + * Copyright 2009 Jive Software, 2018-2019 Florian Schmaus. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -123,7 +123,9 @@ import org.jivesoftware.smack.util.dns.SmackDaneVerifier; import org.jxmpp.jid.DomainBareJid; import org.jxmpp.jid.EntityFullJid; import org.jxmpp.jid.Jid; +import org.jxmpp.jid.impl.JidCreate; import org.jxmpp.jid.parts.Resourcepart; +import org.jxmpp.stringprep.XmppStringprepException; import org.jxmpp.util.XmppStringUtils; import org.minidns.dnsname.DnsName; import org.xmlpull.v1.XmlPullParser; @@ -1849,8 +1851,24 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { streamId = parser.getAttributeValue("", "id"); incomingStreamXmlEnvironment = XmlEnvironment.from(parser); - String reportedServerDomain = parser.getAttributeValue("", "from"); - assert (config.getXMPPServiceDomain().equals(reportedServerDomain)); + String reportedServerDomainString = parser.getAttributeValue("", "from"); + if (reportedServerDomainString == null) { + // RFC 6120 ยง 4.7.1. makes no explicit statement whether or not 'from' in the stream open from the server + // in c2s connections is required or not. + return; + } + DomainBareJid reportedServerDomain; + try { + reportedServerDomain = JidCreate.domainBareFrom(reportedServerDomainString); + DomainBareJid configuredXmppServiceDomain = config.getXMPPServiceDomain(); + if (!configuredXmppServiceDomain.equals(reportedServerDomain)) { + LOGGER.warning("Domain reported by server '" + reportedServerDomain + + "' does not match configured domain '" + configuredXmppServiceDomain + "'"); + } + } catch (XmppStringprepException e) { + LOGGER.log(Level.WARNING, "XMPP service domain '" + reportedServerDomainString + + "' as reported by server could not be transformed to a valid JID", e); + } } }