Commit dccc8377 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Improved detection of unknown hosts.

git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@2894 b35dd754-fafc-0310-a699-88a17e54d16e
parent 3e2fd850
...@@ -13,8 +13,8 @@ package org.jivesoftware.messenger.net; ...@@ -13,8 +13,8 @@ package org.jivesoftware.messenger.net;
import org.dom4j.Element; import org.dom4j.Element;
import org.dom4j.io.XPPPacketReader; import org.dom4j.io.XPPPacketReader;
import org.jivesoftware.messenger.PacketRouter; import org.jivesoftware.messenger.*;
import org.jivesoftware.messenger.Session; import org.jivesoftware.messenger.server.OutgoingSessionPromise;
import org.jivesoftware.messenger.auth.UnauthorizedException; import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.jivesoftware.messenger.component.InternalComponentManager; import org.jivesoftware.messenger.component.InternalComponentManager;
import org.jivesoftware.messenger.interceptor.InterceptorManager; import org.jivesoftware.messenger.interceptor.InterceptorManager;
...@@ -61,7 +61,7 @@ public abstract class SocketReader implements Runnable { ...@@ -61,7 +61,7 @@ public abstract class SocketReader implements Runnable {
private PacketRouter router; private PacketRouter router;
XPPPacketReader reader = null; XPPPacketReader reader = null;
protected boolean open; protected boolean open;
private InternalComponentManager componentManager; private RoutingTable routingTable = XMPPServer.getInstance().getRoutingTable();
static { static {
try { try {
...@@ -86,7 +86,6 @@ public abstract class SocketReader implements Runnable { ...@@ -86,7 +86,6 @@ public abstract class SocketReader implements Runnable {
this.router = router; this.router = router;
this.connection = connection; this.connection = connection;
this.socket = socket; this.socket = socket;
componentManager = InternalComponentManager.getInstance();
} }
/** /**
...@@ -432,8 +431,7 @@ public abstract class SocketReader implements Runnable { ...@@ -432,8 +431,7 @@ public abstract class SocketReader implements Runnable {
// subdomain. If the value of the 'to' attribute is not valid then return a host-unknown // subdomain. If the value of the 'to' attribute is not valid then return a host-unknown
// error and close the underlying connection. // error and close the underlying connection.
String host = reader.getXPPParser().getAttributeValue("", "to"); String host = reader.getXPPParser().getAttributeValue("", "to");
if (validateHost() && !serverName.equals(host) && if (validateHost() && isHostUnknown(host)) {
componentManager.getComponent(host) == null) {
Writer writer = connection.getWriter(); Writer writer = connection.getWriter();
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("<?xml version='1.0' encoding='"); sb.append("<?xml version='1.0' encoding='");
...@@ -469,6 +467,32 @@ public abstract class SocketReader implements Runnable { ...@@ -469,6 +467,32 @@ public abstract class SocketReader implements Runnable {
} }
} }
private boolean isHostUnknown(String host) {
if (host == null) {
// Answer false since when using server dialback the stream header will not
// have a TO attribute
return false;
}
if (serverName.equals(host)) {
// requested host matched the server name
return false;
}
// Check if the host matches a subdomain of this host
RoutableChannelHandler route = null;
try {
route = routingTable.getRoute(new JID(host));
if (route instanceof OutgoingSessionPromise) {
return true;
}
else {
return false;
}
}
catch (NoSuchRouteException e) {
return true;
}
}
/** /**
* Tries to secure the connection using TLS. If the connection is secured then reset * Tries to secure the connection using TLS. If the connection is secured then reset
* the parser to use the new secured reader. But if the connection failed to be secured * the parser to use the new secured reader. But if the connection failed to be secured
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment