mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-26 08:12:05 +01:00
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:
parent
ddb47c2d60
commit
bc176d72a3
3 changed files with 32 additions and 5 deletions
|
@ -218,6 +218,11 @@ public abstract class XMPPConnection {
|
||||||
private boolean bindingRequired;
|
private boolean bindingRequired;
|
||||||
private boolean sessionSupported;
|
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.
|
* 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();
|
saslAuthentication.init();
|
||||||
bindingRequired = false;
|
bindingRequired = false;
|
||||||
sessionSupported = false;
|
sessionSupported = false;
|
||||||
|
connectionException = null;
|
||||||
connectInternal();
|
connectInternal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -485,6 +491,18 @@ public abstract class XMPPConnection {
|
||||||
return userJID;
|
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.
|
* Sends the specified packet to the server.
|
||||||
*
|
*
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
|
|
||||||
package org.jivesoftware.smack;
|
package org.jivesoftware.smack;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.packet.Packet;
|
import org.jivesoftware.smack.packet.Packet;
|
||||||
import org.jivesoftware.smack.packet.Presence;
|
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.SASLFailure;
|
||||||
import org.jivesoftware.smack.sasl.SASLMechanism.Success;
|
import org.jivesoftware.smack.sasl.SASLMechanism.Success;
|
||||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||||
|
|
||||||
import org.jivesoftware.smack.SmackException.NoResponseException;
|
import org.jivesoftware.smack.SmackException.NoResponseException;
|
||||||
import org.jivesoftware.smack.SmackException.SecurityRequiredException;
|
import org.jivesoftware.smack.SmackException.SecurityRequiredException;
|
||||||
import org.jivesoftware.smack.XMPPException.StreamErrorException;
|
import org.jivesoftware.smack.XMPPException.StreamErrorException;
|
||||||
|
@ -92,8 +93,9 @@ class PacketReader {
|
||||||
*
|
*
|
||||||
* @throws NoResponseException if the server fails to send an opening stream back
|
* @throws NoResponseException if the server fails to send an opening stream back
|
||||||
* within packetReplyTimeout.
|
* within packetReplyTimeout.
|
||||||
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
synchronized public void startup() throws NoResponseException {
|
synchronized public void startup() throws NoResponseException, IOException {
|
||||||
readerThread.start();
|
readerThread.start();
|
||||||
// Wait for stream tag before returning. We'll wait a couple of seconds before
|
// Wait for stream tag before returning. We'll wait a couple of seconds before
|
||||||
// giving up and throwing an error.
|
// giving up and throwing an error.
|
||||||
|
@ -108,7 +110,7 @@ class PacketReader {
|
||||||
// Ignore.
|
// Ignore.
|
||||||
}
|
}
|
||||||
if (!lastFeaturesParsed) {
|
if (!lastFeaturesParsed) {
|
||||||
throw new NoResponseException();
|
connection.throwConnectionExceptionOrNoResponse();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -716,8 +716,15 @@ public class XMPPTCPConnection extends XMPPConnection {
|
||||||
plain.getInetAddress().getHostAddress(), plain.getPort(), true);
|
plain.getInetAddress().getHostAddress(), plain.getPort(), true);
|
||||||
// Initialize the reader and writer with the new secured version
|
// Initialize the reader and writer with the new secured version
|
||||||
initReaderAndWriter();
|
initReaderAndWriter();
|
||||||
|
|
||||||
|
try {
|
||||||
// Proceed to do the handshake
|
// Proceed to do the handshake
|
||||||
((SSLSocket) socket).startHandshake();
|
((SSLSocket) socket).startHandshake();
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
setConnectionException(e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
//if (((SSLSocket) socket).getWantClientAuth()) {
|
//if (((SSLSocket) socket).getWantClientAuth()) {
|
||||||
// System.err.println("XMPPConnection wants client auth");
|
// System.err.println("XMPPConnection wants client auth");
|
||||||
//}
|
//}
|
||||||
|
|
Loading…
Reference in a new issue