more error handling in xmppconnection

This commit is contained in:
iNPUTmice 2014-11-03 10:03:45 +01:00
parent 1ea2e7dc3b
commit 27f42dfb63

View file

@ -1,5 +1,19 @@
package eu.siacs.conversations.xmpp;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Parcelable;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.os.SystemClock;
import android.preference.PreferenceManager;
import android.util.Log;
import android.util.SparseArray;
import org.apache.http.conn.ssl.StrictHostnameVerifier;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@ -22,31 +36,16 @@ import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.X509TrustManager;
import org.apache.http.conn.ssl.StrictHostnameVerifier;
import org.xmlpull.v1.XmlPullParserException;
import de.duenndns.ssl.MemorizingTrustManager;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Parcelable;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.os.SystemClock;
import android.preference.PreferenceManager;
import android.util.Log;
import android.util.SparseArray;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.utils.CryptoHelper;
import eu.siacs.conversations.utils.DNSHelper;
import eu.siacs.conversations.utils.zlib.ZLibOutputStream;
import eu.siacs.conversations.utils.zlib.ZLibInputStream;
import eu.siacs.conversations.utils.zlib.ZLibOutputStream;
import eu.siacs.conversations.xml.Element;
import eu.siacs.conversations.xml.Tag;
import eu.siacs.conversations.xml.TagWriter;
@ -188,13 +187,22 @@ public class XmppConnection implements Runnable {
socket.connect(addr, 20000);
socketError = false;
} catch (UnknownHostException e) {
Log.d(Config.LOGTAG, account.getJid() + ": " + e.getMessage());
i++;
} catch (IOException e) {
Log.d(Config.LOGTAG, account.getJid() + ": " + e.getMessage());
i++;
}
}
if (socketError) {
throw new IOException();
this.changeStatus(Account.STATUS_SERVER_NOT_FOUND);
if (wakeLock.isHeld()) {
try {
wakeLock.release();
} catch (RuntimeException re) {
}
}
return;
}
} else if (result.containsKey("error")
&& "nosrv".equals(result.getString("error", null))) {
@ -235,6 +243,7 @@ public class XmppConnection implements Runnable {
}
return;
} catch (IOException e) {
Log.d(Config.LOGTAG, account.getJid() + ": " + e.getMessage());
this.changeStatus(Account.STATUS_OFFLINE);
if (wakeLock.isHeld()) {
try {
@ -244,6 +253,7 @@ public class XmppConnection implements Runnable {
}
return;
} catch (NoSuchAlgorithmException e) {
Log.d(Config.LOGTAG, account.getJid() + ": " + e.getMessage());
this.changeStatus(Account.STATUS_OFFLINE);
Log.d(Config.LOGTAG, "compression exception " + e.getMessage());
if (wakeLock.isHeld()) {
@ -254,8 +264,8 @@ public class XmppConnection implements Runnable {
}
return;
} catch (XmlPullParserException e) {
Log.d(Config.LOGTAG, account.getJid() + ": " + e.getMessage());
this.changeStatus(Account.STATUS_OFFLINE);
Log.d(Config.LOGTAG, "xml exception " + e.getMessage());
if (wakeLock.isHeld()) {
try {
wakeLock.release();
@ -553,6 +563,10 @@ public class XmppConnection implements Runnable {
mRandom);
SSLSocketFactory factory = sc.getSocketFactory();
if (factory == null) {
throw new IOException("SSLSocketFactory was null");
}
HostnameVerifier verifier = this.mMemorizingTrustManager
.wrapHostnameVerifier(new StrictHostnameVerifier());
SSLSocket sslSocket = (SSLSocket) factory.createSocket(socket,
@ -578,10 +592,8 @@ public class XmppConnection implements Runnable {
if (verifier != null
&& !verifier.verify(account.getServer(),
sslSocket.getSession())) {
Log.d(Config.LOGTAG, account.getJid()
+ ": host mismatch in TLS connection");
sslSocket.close();
throw new IOException();
throw new IOException("host mismatch in TLS connection");
}
tagReader.setInputStream(sslSocket.getInputStream());
tagWriter.setOutputStream(sslSocket.getOutputStream());