Throw exceptions of SSLSocket.startHandshake() in connect()

instead of throwing a NoResponseException in case startHandshake()
throws an Exception. The NoResponseException was then thrown when
performing SASL auth, which usually directly followes securing the
connection via TLS (if enabled and provided by the server).
This commit is contained in:
Florian Schmaus 2014-04-28 08:29:12 +02:00
parent ddb47c2d60
commit bc176d72a3
3 changed files with 32 additions and 5 deletions

View File

@ -218,6 +218,11 @@ public abstract class XMPPConnection {
private boolean bindingRequired;
private boolean sessionSupported;
/**
*
*/
private IOException connectionException;
/**
* Create an executor to deliver incoming packets to listeners. We'll use a single thread with an unbounded queue.
*/
@ -355,6 +360,7 @@ public abstract class XMPPConnection {
saslAuthentication.init();
bindingRequired = false;
sessionSupported = false;
connectionException = null;
connectInternal();
}
@ -485,6 +491,18 @@ public abstract class XMPPConnection {
return userJID;
}
protected void setConnectionException(IOException exception) {
connectionException = exception;
}
protected void throwConnectionExceptionOrNoResponse() throws IOException, NoResponseException {
if (connectionException != null) {
throw connectionException;
} else {
throw new NoResponseException();
}
}
/**
* Sends the specified packet to the server.
*

View File

@ -17,6 +17,8 @@
package org.jivesoftware.smack;
import java.io.IOException;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.Presence;
@ -26,7 +28,6 @@ import org.jivesoftware.smack.sasl.SASLMechanism.Challenge;
import org.jivesoftware.smack.sasl.SASLMechanism.SASLFailure;
import org.jivesoftware.smack.sasl.SASLMechanism.Success;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smack.SmackException.NoResponseException;
import org.jivesoftware.smack.SmackException.SecurityRequiredException;
import org.jivesoftware.smack.XMPPException.StreamErrorException;
@ -92,8 +93,9 @@ class PacketReader {
*
* @throws NoResponseException if the server fails to send an opening stream back
* within packetReplyTimeout.
* @throws IOException
*/
synchronized public void startup() throws NoResponseException {
synchronized public void startup() throws NoResponseException, IOException {
readerThread.start();
// Wait for stream tag before returning. We'll wait a couple of seconds before
// giving up and throwing an error.
@ -108,7 +110,7 @@ class PacketReader {
// Ignore.
}
if (!lastFeaturesParsed) {
throw new NoResponseException();
connection.throwConnectionExceptionOrNoResponse();
}
}

View File

@ -716,8 +716,15 @@ public class XMPPTCPConnection extends XMPPConnection {
plain.getInetAddress().getHostAddress(), plain.getPort(), true);
// Initialize the reader and writer with the new secured version
initReaderAndWriter();
// Proceed to do the handshake
((SSLSocket) socket).startHandshake();
try {
// Proceed to do the handshake
((SSLSocket) socket).startHandshake();
}
catch (IOException e) {
setConnectionException(e);
throw e;
}
//if (((SSLSocket) socket).getWantClientAuth()) {
// System.err.println("XMPPConnection wants client auth");
//}