Actually, the problem with SPARK-751 does not resides in SMACK only (the problem with realm), but in OPENFIRE as well.
SMACK use for digest-uri whatever receives from OPENFIRE:
PacketReader.java
else if (parser.getAttributeName(i).equals(“from”)) {
// Use the server name that the server says that it is.
connection.config.setServiceName(parser.getAttributeValue(i));
}
Here is how Openfire calculates the “from” tag:
StanzaHandler.java
private String geStreamHeader() {
StringBuilder sb = new StringBuilder(200);
sb.append("<?xml version=‘1.0’ encoding=’");
sb.append(CHARSET);
sb.append("’?>");
if (connection.isFlashClient()) {
sb.append("<flash:stream xmlns:flash=\"[http://www.jabber.com/streams/flash](http://www.jabber.com/streams/flash)\" ");
}
else {
sb.append("<stream:stream ");
}
sb.append("xmlns:stream=\"[http://etherx.jabber.org/streams](http://etherx.jabber.org/streams)\" xmlns=\"");
sb.append(getNamespace());
sb.append("" from="");
sb.append(serverName);
sb.append("" id="");
sb.append(session.getStreamID());
sb.append("" xml:lang="");
sb.append(connection.getLanguage());
sb.append("" version="");
sb.append(Session.MAJOR_VERSION).append(".").append(Session.MINOR_VERSION);
sb.append("">");
return sb.toString();
}
Looking at:
sb.append("" from="");
sb.append(serverName); - serverName represents session.getServerName() - which may be different than xmpp.fqdn
On the other hand, Openfire creates the SASL Server like this:
Openfire’s SASLAuthentication.java
SaslServer ss = Sasl.createSaslServer(mechanism, “xmpp”,
JiveGlobals.getProperty(“xmpp.fqdn”, session.getServerName()), props,
new XMPPCallbackHandler());
The value JiveGlobals.getProperty(“xmpp.fqdn”, session.getServerName()) is used for creating the digest-uri at server level, but it does not match with the value sent to the client (smack) for creating the client digest-uri.
There is no reason to use JiveGlobals.getProperty(“xmpp.fqdn”, session.getServerName()) , we can use only session.getServerName(), even if it does not have the exact form of RFC-2831 - but server’s digest-uri must be the same with what is sent to the client in the “form” tag
So solution 1) looks more like a hack just to workaround Openfire bug and limits the power of host discovery provided in Spark/Smack. With solution 1 for instance, we cannot never login using IP in login Dialog, we will be restricted to use xmpp.fqdn value
I will post two patches:
1 Patch for smack that fixes the realm issue and separates the meaning of hostname from serviceName - hostname is what smack discovered and serviceName is what openfire sent to the client as the true location of xmpp server to connect to
2.A patch for openfire that synchronizes what is used for creating the SASL server in order to create the server’s digest-uri, and what is sent to the client in the “form” tag
there are to ways to synchronize:
a) one way is to use only session.getServerName() instead of JiveGlobals.getProperty(“xmpp.fqdn”, session.getServerName()) when SASL server is created (the Patch: SPARK-751-SMACK-344-OPENFIRE.patch)
b) other way is vice-versa, to use JiveGlobals.getProperty(“xmpp.fqdn”, serverName) instead of serverName in the StanzaHandler for the “from” tag value creation (the Patch: SPARK-751-SMACK-344-OPENFIRE-2.patch)
Whenever it is decided to update openfire - at least there is a patch for this issue and can be used
And as a second step - lets think a bit more if solution 1) is what we need…
Mircea
SPARK-751-SMACK-344-OPENFIRE-2.patch.zip (462 Bytes)
SPARK-751-SMACK-344.patch.zip (3112 Bytes)
SPARK-751-SMACK-344-OPENFIRE.patch.zip (553 Bytes)