Commit 4257e438 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

No longer needed.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@6578 b35dd754-fafc-0310-a699-88a17e54d16e
parent 45b3ddd4
/**
* $RCSfile$
* $Revision: 3174 $
* $Date: 2005-12-08 17:41:00 -0300 (Thu, 08 Dec 2005) $
*
* Copyright (C) 2007 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.wildfire.net;
import org.dom4j.Element;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.wildfire.PacketRouter;
import org.jivesoftware.wildfire.RoutingTable;
import org.jivesoftware.wildfire.auth.UnauthorizedException;
import org.jivesoftware.wildfire.session.ClientSession;
import org.xmlpull.v1.XmlPullParserException;
import org.xmpp.packet.IQ;
import org.xmpp.packet.Message;
import org.xmpp.packet.Presence;
import java.io.IOException;
import java.net.Socket;
/**
* A SocketReader specialized for client connections. This reader will be used when the open
* stream contains a jabber:client namespace. Received packet will have their FROM attribute
* overriden to avoid spoofing.<p>
*
* By default the hostname specified in the stream header sent by clients will not be validated.
* When validated the TO attribute of the stream header has to match the server name or a valid
* subdomain. If the value of the 'to' attribute is not valid then a host-unknown error
* will be returned. To enable the validation set the system property
* <b>xmpp.client.validate.host</b> to true.
*
* @author Gaston Dombiak
*/
public class ClientSocketReader extends SocketReader {
public ClientSocketReader(PacketRouter router, RoutingTable routingTable, String serverName,
Socket socket, SocketConnection connection, boolean useBlockingMode) {
super(router, routingTable, serverName, socket, connection, useBlockingMode);
}
protected void processIQ(IQ packet) throws UnauthorizedException {
// Overwrite the FROM attribute to avoid spoofing
packet.setFrom(session.getAddress());
super.processIQ(packet);
}
protected void processPresence(Presence packet) throws UnauthorizedException {
// Overwrite the FROM attribute to avoid spoofing
packet.setFrom(session.getAddress());
super.processPresence(packet);
}
protected void processMessage(Message packet) throws UnauthorizedException {
// Overwrite the FROM attribute to avoid spoofing
packet.setFrom(session.getAddress());
super.processMessage(packet);
}
/**
* Only packets of type Message, Presence and IQ can be processed by this class. Any other
* type of packet is unknown and thus rejected generating the connection to be closed.
*
* @param doc the unknown DOM element that was received
* @return always false.
*/
protected boolean processUnknowPacket(Element doc) {
return false;
}
boolean createSession(String namespace) throws UnauthorizedException, XmlPullParserException,
IOException {
if ("jabber:client".equals(namespace)) {
// The connected client is a regular client so create a ClientSession
session = ClientSession.createSession(serverName, reader, connection);
return true;
}
return false;
}
String getNamespace() {
return "jabber:client";
}
String getName() {
return "Client SR - " + hashCode();
}
boolean validateHost() {
return JiveGlobals.getBooleanProperty("xmpp.client.validate.host",false);
}
}
/**
* $RCSfile$
* $Revision: 1583 $
* $Date: 2005-07-03 17:55:39 -0300 (Sun, 03 Jul 2005) $
*
* Copyright (C) 2004 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.wildfire.net;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.ConnectionManager;
import org.jivesoftware.wildfire.ServerPort;
import javax.net.ssl.SSLException;
import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;
/**
* Implements a network front end with a dedicated thread reading
* each incoming socket. The old SSL method always uses a blocking model.
*
* @author Gaston Dombiak
*/
public class SSLSocketAcceptThread extends Thread {
/**
* The default Jabber socket
*/
public static final int DEFAULT_PORT = 5223;
/**
* Holds information about the port on which the server will listen for connections.
*/
private ServerPort serverPort;
/**
* True while this thread should continue running.
*/
private boolean notTerminated = true;
/**
* The accept socket we're running
*/
private ServerSocket serverSocket;
/**
* Connection manager handling connections created by this thread. *
*/
private ConnectionManager connManager;
/**
* The number of SSL related exceptions occuring rapidly that should signal a need
* to shutdown the SSL port.
*/
private static final int MAX_SSL_EXCEPTIONS = 10;
/**
* Creates an instance using the default port, TLS transport security, and
* JVM defaults for all security settings.
*
* @param connManager the connection manager that will manage connections
* generated by this thread
* @throws IOException if there was trouble initializing the SSL configuration.
*/
public SSLSocketAcceptThread(ConnectionManager connManager, ServerPort serverPort)
throws IOException {
super("Secure Socket Listener");
// Listen on a specific network interface if it has been set.
String interfaceName = JiveGlobals.getXMLProperty("network.interface");
InetAddress bindInterface = null;
if (interfaceName != null) {
try {
if (interfaceName.trim().length() > 0) {
bindInterface = InetAddress.getByName(interfaceName);
// Create the new server port based on the new bind address
serverPort = new ServerPort(serverPort.getPort(),
serverPort.getDomainNames().get(0), interfaceName, serverPort.isSecure(),
serverPort.getSecurityType(), serverPort.getType());
}
}
catch (UnknownHostException e) {
Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
}
}
this.connManager = connManager;
this.serverPort = serverPort;
int port = serverPort.getPort();
serverSocket = SSLConfig.createServerSocket(port, bindInterface);
}
/**
* Retrieve the port this server socket is bound to.
*
* @return the port the socket is bound to.
*/
public int getPort() {
return serverSocket.getLocalPort();
}
/**
* Returns information about the port on which the server is listening for connections.
*
* @return information about the port on which the server is listening for connections.
*/
public ServerPort getServerPort() {
return serverPort;
}
/**
* Unblock the thread and force it to terminate.
*/
public void shutdown() {
notTerminated = false;
try {
ServerSocket sSock = serverSocket;
serverSocket = null;
if (sSock != null) {
sSock.close();
}
}
catch (IOException e) {
// we don't care, no matter what, the socket should be dead
}
}
/**
* About as simple as it gets. The thread spins around an accept
* call getting sockets and handing them to the SocketManager.
* We need to detect run away failures since an SSL configuration
* problem can cause the loop to spin, constantly rethrowing SSLExceptions
* (e.g. if a certificate is in the keystore that can't be verified).
*/
public void run() {
long lastExceptionTime = 0;
int exceptionCounter = 0;
while (notTerminated) {
try {
Socket sock = serverSocket.accept();
Log.debug("SSL Connect " + sock.toString());
SocketReader reader = connManager.createSocketReader(sock, true, serverPort, true);
// Create a new reading thread for each new connected client
Thread thread = new Thread(reader, reader.getName());
thread.setDaemon(true);
thread.setPriority(Thread.NORM_PRIORITY);
thread.start();
}
catch (SSLException se) {
long exceptionTime = System.currentTimeMillis();
if (exceptionTime - lastExceptionTime > 1000) {
// if the time between SSL exceptions is too long
// reset the counter
exceptionCounter = 1;
}
else {
// If this exception occured within a second of the last one
// we need to count it
exceptionCounter++;
}
lastExceptionTime = exceptionTime;
Log.error(LocaleUtils.getLocalizedString("admin.error.ssl"), se);
// and if the number of consecutive exceptions exceeds the limit
// we should assume there's an SSL problem or DOS attack and shutdown
if (exceptionCounter > MAX_SSL_EXCEPTIONS) {
String msg = "Shutting down SSL port - " +
"suspected configuration problem";
Log.error(msg);
Log.info(msg);
shutdown();
}
}
catch (Throwable e) {
if (notTerminated) {
Log.error(LocaleUtils.getLocalizedString("admin.error.ssl"), e);
}
}
}
try {
ServerSocket sSock = serverSocket;
serverSocket = null;
if (sSock != null) {
sSock.close();
}
}
catch (IOException e) {
// we don't care, no matter what, the socket should be dead
}
}
}
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