aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/xmpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/juick/xmpp')
-rw-r--r--src/main/java/com/juick/xmpp/s2s/ConnectionIn.java20
-rw-r--r--src/main/java/com/juick/xmpp/s2s/ConnectionOut.java41
-rw-r--r--src/main/java/com/juick/xmpp/s2s/XMPPComponent.java3
3 files changed, 34 insertions, 30 deletions
diff --git a/src/main/java/com/juick/xmpp/s2s/ConnectionIn.java b/src/main/java/com/juick/xmpp/s2s/ConnectionIn.java
index 8fa773b7..554d3b05 100644
--- a/src/main/java/com/juick/xmpp/s2s/ConnectionIn.java
+++ b/src/main/java/com/juick/xmpp/s2s/ConnectionIn.java
@@ -46,15 +46,14 @@ public class ConnectionIn extends Connection implements Runnable {
parser.next(); // stream:stream
updateTsRemoteData();
if (!parser.getName().equals("stream")
- || !parser.getNamespace("stream").equals(NS_STREAM)
- || !parser.getNamespace("db").equals(NS_DB)) {
+ || !parser.getNamespace("stream").equals(NS_STREAM)) {
// || !parser.getAttributeValue(null, "version").equals("1.0")
// || !parser.getAttributeValue(null, "to").equals(Main.HOSTNAME)) {
throw new Exception("STREAM FROM ? " + streamID + " INVALID FIRST PACKET");
}
boolean xmppversionnew = parser.getAttributeValue(null, "version") != null;
- sendOpenStream(xmppversionnew);
+ sendOpenStream(parser.getAttributeValue(null, "from"), xmppversionnew);
while (parser.next() != XmlPullParser.END_DOCUMENT) {
updateTsRemoteData();
@@ -85,7 +84,7 @@ public class ConnectionIn extends Connection implements Runnable {
XMPPComponent.executorService.submit(c);
}
} else {
- throw new Exception("STREAM FROM " + dfrom + " " + streamID + " DIALBACK RESULT FAIL");
+ throw new HostUnknownException("STREAM FROM " + dfrom + " " + streamID + " INVALID TO " + to);
}
} else if (tag.equals("verify") && parser.getNamespace().equals(NS_DB)) {
String vfrom = parser.getAttributeValue(null, "from");
@@ -145,7 +144,7 @@ public class ConnectionIn extends Connection implements Runnable {
closeConnection();
}
} else if (isSecured() && tag.equals("stream") && parser.getNamespace().equals(NS_STREAM)) {
- sendOpenStream(true);
+ sendOpenStream(null, true);
} else {
LOGGER.info("STREAM " + streamID + ": " + XmlUtils.parseToString(parser, true));
}
@@ -157,6 +156,8 @@ public class ConnectionIn extends Connection implements Runnable {
LOGGER.info(String.format("STREAM %s CLOSED (dirty)", streamID));
XMPPComponent.removeConnectionIn(this);
closeConnection();
+ } catch (HostUnknownException e) {
+ LOGGER.warning(e.getMessage());
} catch (Exception e) {
LOGGER.log(Level.WARNING, "STREAM " + streamID + " ERROR", e);
XMPPComponent.removeConnectionIn(this);
@@ -168,13 +169,13 @@ public class ConnectionIn extends Connection implements Runnable {
tsRemoteData = System.currentTimeMillis();
}
- void sendOpenStream(boolean xmppversionnew) throws IOException {
+ void sendOpenStream(String from, boolean xmppversionnew) throws IOException {
String openStream = "<?xml version='1.0'?><stream:stream xmlns='jabber:server' " +
"xmlns:stream='http://etherx.jabber.org/streams' xmlns:db='jabber:server:dialback' from='" +
XMPPComponent.HOSTNAME + "' id='" + streamID + "' version='1.0'>";
if (xmppversionnew) {
openStream += "<stream:features>";
- if (!isSecured()) {
+ if (!isSecured() && !XMPPComponent.brokenSSLhosts.contains(from)) {
openStream += "<starttls xmlns=\"" + NS_TLS + "\"><optional/></starttls>";
}
openStream += "</stream:features>";
@@ -211,4 +212,9 @@ public class ConnectionIn extends Connection implements Runnable {
}
return false;
}
+ class HostUnknownException extends Exception {
+ public HostUnknownException(String message) {
+ super(message);
+ }
+ }
}
diff --git a/src/main/java/com/juick/xmpp/s2s/ConnectionOut.java b/src/main/java/com/juick/xmpp/s2s/ConnectionOut.java
index 4ebeffb6..68851da1 100644
--- a/src/main/java/com/juick/xmpp/s2s/ConnectionOut.java
+++ b/src/main/java/com/juick/xmpp/s2s/ConnectionOut.java
@@ -2,26 +2,17 @@ package com.juick.xmpp.s2s;
import com.juick.xmpp.extensions.StreamFeatures;
import com.juick.xmpp.utils.XmlUtils;
+import org.xmlpull.v1.XmlPullParser;
+import javax.net.ssl.SSLException;
+import javax.net.ssl.SSLSocket;
import java.io.EOFException;
import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
import java.net.InetAddress;
-import java.net.InetSocketAddress;
import java.net.Socket;
-import java.nio.channels.AsynchronousSocketChannel;
-import java.nio.channels.Channels;
-import java.nio.channels.CompletionHandler;
-import java.util.concurrent.ExecutionException;
+import java.net.UnknownHostException;
import java.util.logging.Level;
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
-
-import javax.net.ssl.SSLException;
-import javax.net.ssl.SSLSocket;
-
/**
* @author ugnich
*/
@@ -45,8 +36,8 @@ public class ConnectionOut extends Connection implements Runnable {
}
void sendOpenStream() throws IOException {
- sendStanza("<?xml version='1.0'?><stream:stream xmlns='jabber:server' " +
- "xmlns:stream='http://etherx.jabber.org/streams' xmlns:db='jabber:server:dialback' from='" +
+ sendStanza("<?xml version='1.0'?><stream:stream xmlns='jabber:server' id='" + streamID +
+ "' xmlns:stream='http://etherx.jabber.org/streams' xmlns:db='jabber:server:dialback' from='" +
XMPPComponent.HOSTNAME + "' to='" + to + "' version='1.0'>");
}
@@ -63,10 +54,12 @@ public class ConnectionOut extends Connection implements Runnable {
LOGGER.info("STREAM TO " + to + " START");
try {
HostnamePort addr = DNSQueries.getServerAddress(to);
- socket = new Socket(InetAddress.getByName(addr.hostname), addr.port);
- parser.setInput(new InputStreamReader(socket.getInputStream()));
-
- writer = new OutputStreamWriter(socket.getOutputStream());
+ try {
+ socket = new Socket(InetAddress.getByName(addr.hostname), addr.port);
+ } catch (UnknownHostException e) {
+ socket = new Socket(InetAddress.getByName("talk.google.com"), 5269);
+ }
+ restartParser();
sendOpenStream();
@@ -78,6 +71,10 @@ public class ConnectionOut extends Connection implements Runnable {
LOGGER.info("STREAM TO " + to + " " + streamID + " OPEN");
XMPPComponent.addConnectionOut(ConnectionOut.this);
+ boolean xmppversionnew = parser.getAttributeValue(null, "version") != null;
+ if (!xmppversionnew) {
+ processDialback();
+ }
while (parser.next() != XmlPullParser.END_DOCUMENT) {
if (parser.getEventType() != XmlPullParser.START_TAG) {
@@ -115,7 +112,7 @@ public class ConnectionOut extends Connection implements Runnable {
XmlUtils.skip(parser);
} else if (tag.equals("features") && parser.getNamespace().equals(NS_STREAM)) {
StreamFeatures features = StreamFeatures.parse(parser);
- if (!isSecured() && features.STARTTLS >= 0) {
+ if (!isSecured() && features.STARTTLS >= 0 && !XMPPComponent.brokenSSLhosts.contains(to)) {
System.out.println("STREAM TO " + to + " " + streamID + " SECURING");
sendStanza("<starttls xmlns=\"" + NS_TLS + "\" />");
} else {
@@ -131,7 +128,7 @@ public class ConnectionOut extends Connection implements Runnable {
restartParser();
sendOpenStream();
} catch (SSLException sex) {
- System.err.println("STREAM " + streamID + " SSL ERROR");
+ LOGGER.log(Level.SEVERE, String.format("s2s ssl error: %s %s", to, streamID), sex);
sendStanza("<failed xmlns\"" + NS_TLS + "\" />");
XMPPComponent.removeConnectionOut(this);
closeConnection();
@@ -151,7 +148,7 @@ public class ConnectionOut extends Connection implements Runnable {
XMPPComponent.removeConnectionOut(ConnectionOut.this);
closeConnection();
} catch (Exception e) {
- LOGGER.log(Level.SEVERE, "s2s out exception", e);
+ LOGGER.log(Level.SEVERE, String.format("s2s out exception: %s %s", to, streamID), e);
XMPPComponent.removeConnectionOut(ConnectionOut.this);
closeConnection();
}
diff --git a/src/main/java/com/juick/xmpp/s2s/XMPPComponent.java b/src/main/java/com/juick/xmpp/s2s/XMPPComponent.java
index 03a12c26..2b293fd6 100644
--- a/src/main/java/com/juick/xmpp/s2s/XMPPComponent.java
+++ b/src/main/java/com/juick/xmpp/s2s/XMPPComponent.java
@@ -30,6 +30,7 @@ public class XMPPComponent implements ServletContextListener {
public static String STATSFILE = null;
public static String keystore;
public static String keystorePassword;
+ public static List<String> brokenSSLhosts;
public static ConnectionRouter connRouter;
static final List<ConnectionIn> inConnections = Collections.synchronizedList(new ArrayList<>());
static final List<ConnectionOut> outConnections = Collections.synchronizedList(new ArrayList<>());
@@ -163,7 +164,7 @@ public class XMPPComponent implements ServletContextListener {
STATSFILE = conf.getProperty("statsfile");
keystore = conf.getProperty("keystore");
keystorePassword = conf.getProperty("keystore_password");
-
+ brokenSSLhosts = Arrays.asList(conf.getProperty("broken_ssl_hosts", "").split(","));
Class.forName("com.mysql.jdbc.Driver");
sql = DriverManager.getConnection("jdbc:mysql://localhost/juick?autoReconnect=true&user=" +
conf.getProperty("mysql_username", "") + "&password=" + conf.getProperty("mysql_password", ""));