force tls

This commit is contained in:
iNPUTmice 2014-10-19 20:48:01 +02:00
parent 9372a98c0c
commit e8bf75d79b

View file

@ -80,6 +80,7 @@ public class XmppConnection implements Runnable {
private SparseArray<String> messageReceipts = new SparseArray<String>(); private SparseArray<String> messageReceipts = new SparseArray<String>();
private boolean usingCompression = false; private boolean usingCompression = false;
private boolean usingEncryption = false;
private int stanzasReceived = 0; private int stanzasReceived = 0;
private int stanzasSent = 0; private int stanzasSent = 0;
@ -135,6 +136,7 @@ public class XmppConnection implements Runnable {
protected void connect() { protected void connect() {
Log.d(Config.LOGTAG, account.getJid() + ": connecting"); Log.d(Config.LOGTAG, account.getJid() + ": connecting");
usingCompression = false; usingCompression = false;
usingEncryption = false;
lastConnect = SystemClock.elapsedRealtime(); lastConnect = SystemClock.elapsedRealtime();
lastPingSent = SystemClock.elapsedRealtime(); lastPingSent = SystemClock.elapsedRealtime();
this.attempt++; this.attempt++;
@ -546,6 +548,7 @@ public class XmppConnection implements Runnable {
sendStartStream(); sendStartStream();
Log.d(Config.LOGTAG, account.getJid() Log.d(Config.LOGTAG, account.getJid()
+ ": TLS connection established"); + ": TLS connection established");
usingEncryption = true;
processStream(tagReader.readTag()); processStream(tagReader.readTag());
sslSocket.close(); sslSocket.close();
} catch (NoSuchAlgorithmException e1) { } catch (NoSuchAlgorithmException e1) {
@ -575,8 +578,7 @@ public class XmppConnection implements Runnable {
private void processStreamFeatures(Tag currentTag) private void processStreamFeatures(Tag currentTag)
throws XmlPullParserException, IOException { throws XmlPullParserException, IOException {
this.streamFeatures = tagReader.readElement(currentTag); this.streamFeatures = tagReader.readElement(currentTag);
if (this.streamFeatures.hasChild("starttls") if (this.streamFeatures.hasChild("starttls") && !usingEncryption) {
&& account.isOptionSet(Account.OPTION_USETLS)) {
sendStartTLS(); sendStartTLS();
} else if (compressionAvailable()) { } else if (compressionAvailable()) {
sendCompressionZlib(); sendCompressionZlib();
@ -588,7 +590,7 @@ public class XmppConnection implements Runnable {
changeStatus(Account.STATUS_REGISTRATION_NOT_SUPPORTED); changeStatus(Account.STATUS_REGISTRATION_NOT_SUPPORTED);
disconnect(true); disconnect(true);
} else if (this.streamFeatures.hasChild("mechanisms") } else if (this.streamFeatures.hasChild("mechanisms")
&& shouldAuthenticate) { && shouldAuthenticate && usingEncryption) {
List<String> mechanisms = extractMechanisms(streamFeatures List<String> mechanisms = extractMechanisms(streamFeatures
.findChild("mechanisms")); .findChild("mechanisms"));
if (mechanisms.contains("PLAIN")) { if (mechanisms.contains("PLAIN")) {